Example #1
0
        /// <summary>
        ///
        /// </summary>
        public static void Initialize()
        {
            new ExtendFieldRepository();

            //设置依赖反转
            Ioc.Configure(_ =>
            {
                _.For <ISiteServiceContract>().Singleton().Use <SiteService>();
                _.For <IArchiveServiceContract>().Singleton().Use <ArchiveService>();
                _.For <IContentServiceContract>().Singleton().Use <ContentService>();
                _.For <IUserServiceContract>().Singleton().Use <UserService>();

                _.For <ISiteRepo>().Singleton().Use <SiteRepository>();
                _.For <IContentRepository>().Singleton().Use <ContentRepository>();
                _.For <ICategoryRepo>().Singleton().Use <CategoryRepository>();
                _.For <IExtendFieldRepository>().Singleton().Use <ExtendFieldRepository>();
                _.For <IArchiveRepository>().Singleton().Use <ArchiveRepository>();
                _.For <ITemplateRepo>().Singleton().Use <TemplateRepoImpl>();

                _.For <IUserRepository>().Singleton().Use <UserRepository>();

                //x.For<IArchiveModel>().Singleton().Use<ArchiveBLL>();
                // x.For<ICategoryModel>().Singleton().Use<CategoryBLL>();
                _.For <IComment>().Singleton().Use <CommentBll>();
                // x.For<ILink>().Singleton().Use<LinkBLL>();
                _.For <Imember>().Singleton().Use <MemberBll>();
                _.For <Imessage>().Singleton().Use <MessageBll>();
                _.For <Imodule>().Singleton().Use <ModuleBLL>();
                //x.For<ISite>().Singleton().Use<SiteBLL>();
                // x.For<TemplateBind>().Singleton().Use<TemplateBindBLL>();
                _.For <IUserBll>().Singleton().Use <UserBllBll>();
                _.For <ITable>().Singleton().Use <TableBll>();
            });
            ExportManager.Initialize(AppDomain.CurrentDomain.BaseDirectory + "public/query/", CmsDataBase.Instance);
        }
    static void AssertDisconnectedStrategies()
    {
        Schema s = Schema.Current;

        var result = EnumerableExtensions.JoinStrict(
            strategies.Keys,
            s.Tables.Keys.Where(a => !a.IsEnumEntity()),
            a => a,
            a => a,
            (a, b) => 0);

        var extra = result.Extra.OrderBy(a => a.Namespace).ThenBy(a => a.Name).ToString(t => "  DisconnectedLogic.Register<{0}>(Download.None, Upload.None);".FormatWith(t.Name), "\r\n");

        var lacking = result.Missing.GroupBy(a => a.Namespace).OrderBy(gr => gr.Key).ToString(gr => "  //{0}\r\n".FormatWith(gr.Key) +
                                                                                              gr.ToString(t => "  DisconnectedLogic.Register<{0}>(Download.None, Upload.None);".FormatWith(t.Name), "\r\n"), "\r\n\r\n");

        if (extra.HasText() || lacking.HasText())
        {
            throw new InvalidOperationException("DisconnectedLogic's download strategies are not synchronized with the Schema.\r\n" +
                                                (extra.HasText() ? ("Remove something like:\r\n" + extra + "\r\n\r\n") : null) +
                                                (lacking.HasText() ? ("Add something like:\r\n" + lacking + "\r\n\r\n") : null));
        }

        string errors = strategies.Where(kvp => kvp.Value.Upload == Upload.Subset && s.Table(kvp.Key).Ticks == null).ToString(a => a.Key.Name, "\r\n");

        if (errors.HasText())
        {
            throw new InvalidOperationException("Ticks is mandatory for this Disconnected strategy. Tables: \r\n" + errors.Indent(4));
        }

        foreach (var item in strategies.Where(kvp => kvp.Value.Upload != Upload.None).Select(a => a.Key))
        {
            giRegisterPreUnsafeInsert.GetInvoker(item)();
        }

        ExportManager.Initialize();
        ImportManager.Initialize();
    }