Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ProviderUpdater" /> class.
        /// </summary>
        /// <param name="globalSettingsProvider">The settings storage provider.</param>
        /// <param name="fileNamesForProviders">A provider->file dictionary.</param>
        /// <param name="plugins">The providers to update.</param>
        public ProviderUpdater(IGlobalSettingsStorageProviderV60 globalSettingsProvider,
                               Dictionary <string, string> fileNamesForProviders,
                               IFormatterProviderV50[] plugins)
        {
            if (globalSettingsProvider == null)
            {
                throw new ArgumentNullException("settingsProvider");
            }
            if (fileNamesForProviders == null)
            {
                throw new ArgumentNullException("fileNamesForProviders");
            }
            if (plugins == null)
            {
                throw new ArgumentNullException("providers");
            }
            if (plugins.Length == 0)
            {
                throw new ArgumentException("Providers cannot be empty", "providers");
            }

            this.globalSettingsProvider = globalSettingsProvider;
            this.fileNamesForProviders  = fileNamesForProviders;

            this.plugins = plugins.ToList();

            visitedUrls = new List <string>(10);
        }
Exemple #2
0
        public void Init()
        {
            IGlobalSettingsStorageProviderV60 prov = GetProvider();

            prov.Init(MockHost(), connString, "-");

            Assert.IsNotNull(prov.Information, "Information should not be null");
        }
Exemple #3
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
            IGlobalSettingsStorageProviderV60 globalSettingsStorageProvider = ProviderLoader.LoadGlobalSettingsStorageProvider(ApplicationSettings.Instance.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 <ISettingsStorageProviderV60>(new List <StorageProvider>()
            {
                ApplicationSettings.Instance.SettingProvider
            });
            ProviderLoader.LoadStorageProviders <IFilesStorageProviderV60>(ApplicationSettings.Instance.FilesProviders);
            ProviderLoader.LoadStorageProviders <IThemesStorageProviderV60>(ApplicationSettings.Instance.ThemesProviders);
            ProviderLoader.LoadStorageProviders <IUsersStorageProviderV60>(ApplicationSettings.Instance.UsersProviders);
            ProviderLoader.LoadStorageProviders <IPagesStorageProviderV60>(ApplicationSettings.Instance.PagesProviders);
            ProviderLoader.LoadStorageProviders <IIndexDirectoryProviderV60>(new List <StorageProvider>()
            {
                ApplicationSettings.Instance.IndexDirectoryProvider
            });

            ProviderLoader.LoadAllFormatterProviders();

            foreach (Configuration.Wiki wiki in Collectors.CollectorsBox.GlobalSettingsProvider.GetAllWikis())
            {
                ISettingsStorageProviderV60 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);
        }
Exemple #4
0
 /// <summary>
 /// Gets the Master Password of the given wiki, used to encrypt the Users data.
 /// </summary>
 public static string GetMasterPassword(IGlobalSettingsStorageProviderV60 provider)
 {
     return((string)Cache.GetCachedItem("MasterPassword", () => SettingsTools.GetString(provider.GetSetting("MasterPassword"), "")));
 }
Exemple #5
0
        /// <summary>
        /// Loads the proper Global Setting Storage Provider, given its name.
        /// </summary>
        /// <param name="name">The fully qualified name (such as "Namespace.ProviderClass, MyAssembly"), or <c>null</c>/<b>String.Empty</b>/"<b>default</b>" for the default provider.</param>
        /// <returns>The global settings storage provider.</returns>
        public static IGlobalSettingsStorageProviderV60 LoadGlobalSettingsStorageProvider(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw new Exception("Global Settings Storage Provider must be specified in the Web.congfig file.");
            }

            IGlobalSettingsStorageProviderV60 result = null;

            Exception inner = null;

            if (name.Contains(","))
            {
                string[] fields = name.Split(',');
                if (fields.Length == 2)
                {
                    fields[0] = fields[0].Trim(' ', '"');
                    fields[1] = fields[1].Trim(' ', '"');
                    try {
                        // assemblyName should be an absolute path or a relative path in bin or public\Plugins

                        Assembly asm;
                        Type     t;
                        string   assemblyName = fields[1];
                        if (!assemblyName.ToLowerInvariant().EndsWith(".dll"))
                        {
                            assemblyName += ".dll";
                        }

                        if (File.Exists(assemblyName))
                        {
                            asm = Assembly.Load(LoadAssemblyFromDisk(assemblyName));
                            t   = asm.GetType(fields[0]);
                            GlobalSettingsStorageProviderAssemblyName = Path.GetFileName(assemblyName);
                        }
                        else
                        {
                            string tentativePluginsPath = null;
                            try {
                                // Settings.PublicDirectory is only available when running the web app
                                tentativePluginsPath = Path.Combine(GlobalSettings.PublicDirectory, "Plugins");
                                tentativePluginsPath = Path.Combine(tentativePluginsPath, assemblyName);
                            }
                            catch { }

                            if (!string.IsNullOrEmpty(tentativePluginsPath) && File.Exists(tentativePluginsPath))
                            {
                                asm = Assembly.Load(LoadAssemblyFromDisk(tentativePluginsPath));
                                t   = asm.GetType(fields[0]);
                                GlobalSettingsStorageProviderAssemblyName = Path.GetFileName(tentativePluginsPath);
                            }
                            else
                            {
                                // Trim .dll
                                t = Type.GetType(fields[0] + "," + assemblyName.Substring(0, assemblyName.Length - 4), true, true);
                                GlobalSettingsStorageProviderAssemblyName = assemblyName;
                            }
                        }

                        result = t.GetConstructor(new Type[0]).Invoke(new object[0]) as IGlobalSettingsStorageProviderV60;
                    }
                    catch (Exception ex) {
                        inner  = ex;
                        result = null;
                    }
                }
            }

            if (result == null)
            {
                throw new ArgumentException("Could not load the specified Global Settings Storage Provider", inner);
            }
            else
            {
                return(result);
            }
        }