コード例 #1
0
        /// <summary>
        /// Performs all needed startup operations.
        /// </summary>
        public static void Startup()
        {
            // Load Host
            Host.Instance = new Host();

            // Initialize MimeTypes
            MimeTypes.Init();

            GlobalSettings.CanOverridePublicDirectory = false;

            // Initialize Collectors
            Collectors.InitCollectors();
            Collectors.FileNames = new Dictionary <string, string>(10);

            // Load Global Config
            IGlobalSettingsStorageProviderV40 globalSettingsStorageProvider = ProviderLoader.LoadGlobalSettingsStorageProvider(WebConfigurationManager.AppSettings["GlobalSettingsStorageProvider"]);

            Collectors.AddGlobalSettingsStorageProvider(globalSettingsStorageProvider.GetType(), Assembly.GetAssembly(globalSettingsStorageProvider.GetType()));
            globalSettingsStorageProvider.SetUp(Host.Instance, GetGlobalSettingsStorageProviderConfiguration());
            globalSettingsStorageProvider.Dispose();

            // Add StorageProviders, from WebConfig, to Collectors and Setup them
            ProviderLoader.LoadStorageProviders <ISettingsStorageProviderV40>(new List <StorageProvider>()
            {
                ((List <StorageProvider>)WebConfigurationManager.GetWebApplicationSection("storageProviders/settingsProvider"))[0]
            });
            ProviderLoader.LoadStorageProviders <IFilesStorageProviderV40>((List <StorageProvider>)WebConfigurationManager.GetWebApplicationSection("storageProviders/filesProviders"));
            ProviderLoader.LoadStorageProviders <IThemesStorageProviderV40>((List <StorageProvider>)WebConfigurationManager.GetWebApplicationSection("storageProviders/themesProviders"));
            ProviderLoader.LoadStorageProviders <IUsersStorageProviderV40>((List <StorageProvider>)WebConfigurationManager.GetWebApplicationSection("storageProviders/usersProviders"));
            ProviderLoader.LoadStorageProviders <IPagesStorageProviderV40>((List <StorageProvider>)WebConfigurationManager.GetWebApplicationSection("storageProviders/pagesProviders"));
            ProviderLoader.LoadStorageProviders <IIndexDirectoryProviderV40>((List <StorageProvider>)WebConfigurationManager.GetWebApplicationSection("storageProviders/indexDirectoryProviders"));

            ProviderLoader.LoadAllFormatterProviders();

            foreach (Wiki.PluginFramework.Wiki wiki in Collectors.CollectorsBox.GlobalSettingsProvider.GetAllWikis())
            {
                ISettingsStorageProviderV40 ssp = Collectors.CollectorsBox.GetSettingsProvider(wiki.WikiName);
                if (ssp.IsFirstApplicationStart())
                {
                    if (ssp.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null, Defaults.AccountActivationMessageContent);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.EditNotice, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.EditNotice, null, Defaults.EditNoticeContent);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.Footer, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.Footer, null, Defaults.FooterContent);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.Header, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.Header, null, Defaults.HeaderContent);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null, Defaults.PasswordResetProcedureMessageContent);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.Sidebar, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.Sidebar, null, Defaults.SidebarContent);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.PageChangeMessage, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.PageChangeMessage, null, Defaults.PageChangeMessage);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null, Defaults.DiscussionChangeMessage);
                    }
                    if (ssp.GetMetaDataItem(MetaDataItem.ApproveDraftMessage, null) == "")
                    {
                        ssp.SetMetaDataItem(MetaDataItem.ApproveDraftMessage, null, Defaults.ApproveDraftMessage);
                    }
                }

                bool groupsCreated = VerifyAndCreateDefaultGroups(wiki.WikiName);

                if (groupsCreated)
                {
                    // It is necessary to set default permissions for file management
                    UserGroup administratorsGroup = Users.FindUserGroup(wiki.WikiName, Settings.GetAdministratorsGroup(wiki.WikiName));
                    UserGroup anonymousGroup      = Users.FindUserGroup(wiki.WikiName, Settings.GetAnonymousGroup(wiki.WikiName));
                    UserGroup usersGroup          = Users.FindUserGroup(wiki.WikiName, Settings.GetUsersGroup(wiki.WikiName));

                    SetAdministratorsGroupDefaultPermissions(wiki.WikiName, administratorsGroup);
                    SetUsersGroupDefaultPermissions(wiki.WikiName, usersGroup);
                    SetAnonymousGroupDefaultPermissions(wiki.WikiName, anonymousGroup);
                }

                // Create the Main Page, if needed
                if (Pages.FindPage(wiki.WikiName, Settings.GetDefaultPage(wiki.WikiName)) == null)
                {
                    CreateMainPage(wiki.WikiName);
                }

                Log.LogEntry("Wiki " + wiki.WikiName + " is ready", EntryType.General, Log.SystemUsername, null);

                Pages.RebuildPageLinks(Pages.GetPages(wiki.WikiName, null));
                foreach (ScrewTurn.Wiki.PluginFramework.NamespaceInfo nspace in Pages.GetNamespaces(wiki.WikiName))
                {
                    Pages.RebuildPageLinks(Pages.GetPages(wiki.WikiName, nspace));
                }
            }

            Log.LogEntry("ScrewTurn Wiki is ready", EntryType.General, Log.SystemUsername, null);
        }