Ejemplo n.º 1
0
        /// <summary>
        /// Backups all the providers (excluded global settings storage provider).
        /// </summary>
        /// <param name="backupZipFileName">The name of the zip file where to store the backup file.</param>
        /// <param name="plugins">The available plugins.</param>
        /// <param name="settingsStorageProvider">The settings storage provider.</param>
        /// <param name="pagesStorageProviders">The pages storage providers.</param>
        /// <param name="usersStorageProviders">The users storage providers.</param>
        /// <param name="filesStorageProviders">The files storage providers.</param>
        /// <returns><c>true</c> if the backup has been succesfull.</returns>
        public static bool BackupAll(string backupZipFileName, string[] plugins, ISettingsStorageProviderV30 settingsStorageProvider, IPagesStorageProviderV30[] pagesStorageProviders, IUsersStorageProviderV30[] usersStorageProviders, IFilesStorageProviderV30[] filesStorageProviders)
        {
            string tempPath = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());
            Directory.CreateDirectory(tempPath);

            using(ZipFile backupZipFile = new ZipFile(backupZipFileName)) {

                // Find all namespaces
                List<string> namespaces = new List<string>();
                foreach(IPagesStorageProviderV30 pagesStorageProvider in pagesStorageProviders) {
                    foreach(NamespaceInfo ns in pagesStorageProvider.GetNamespaces()) {
                        namespaces.Add(ns.Name);
                    }
                }

                // Backup settings storage provider
                string zipSettingsBackup = Path.Combine(tempPath, "SettingsBackup-" + settingsStorageProvider.GetType().FullName + ".zip");
                BackupSettingsStorageProvider(zipSettingsBackup, settingsStorageProvider, namespaces.ToArray(), plugins);
                backupZipFile.AddFile(zipSettingsBackup, "");

                // Backup pages storage providers
                foreach(IPagesStorageProviderV30 pagesStorageProvider in pagesStorageProviders) {
                    string zipPagesBackup = Path.Combine(tempPath, "PagesBackup-" + pagesStorageProvider.GetType().FullName + ".zip");
                    BackupPagesStorageProvider(zipPagesBackup, pagesStorageProvider);
                    backupZipFile.AddFile(zipPagesBackup, "");
                }

                // Backup users storage providers
                foreach(IUsersStorageProviderV30 usersStorageProvider in usersStorageProviders) {
                    string zipUsersProvidersBackup = Path.Combine(tempPath, "UsersBackup-" + usersStorageProvider.GetType().FullName + ".zip");
                    BackupUsersStorageProvider(zipUsersProvidersBackup, usersStorageProvider);
                    backupZipFile.AddFile(zipUsersProvidersBackup, "");
                }

                // Backup files storage providers
                foreach(IFilesStorageProviderV30 filesStorageProvider in filesStorageProviders) {
                    string zipFilesProviderBackup = Path.Combine(tempPath, "FilesBackup-" + filesStorageProvider.GetType().FullName + ".zip");
                    BackupFilesStorageProvider(zipFilesProviderBackup, filesStorageProvider, pagesStorageProviders);
                    backupZipFile.AddFile(zipFilesProviderBackup, "");
                }
                backupZipFile.Save();
            }

            Directory.Delete(tempPath, true);
            return true;
        }
        public void SetSetting_GetAllSettings()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Collectors.SettingsProvider = prov;

            Assert.IsTrue(prov.SetSetting("TS1", "Value1"), "SetSetting should return true");
            Assert.IsTrue(prov.SetSetting("TS2", "Value2"), "SetSetting should return true");
            Assert.IsTrue(prov.SetSetting("TS3", "Value3"), "SetSetting should return true");

            IDictionary <string, string> settings = prov.GetAllSettings();

            Assert.AreEqual(3, settings.Count, "Wrong setting count");
            Assert.AreEqual("Value1", settings["TS1"], "Wrong setting value");
            Assert.AreEqual("Value2", settings["TS2"], "Wrong setting value");
            Assert.AreEqual("Value3", settings["TS3"], "Wrong setting value");
        }
Ejemplo n.º 3
0
        public void StoreOutgoingLinks_GetOutgoingLinks_Overwrite()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Assert.AreEqual(0, prov.GetOutgoingLinks("Page").Length, "Wrong initial link count");

            Assert.IsTrue(prov.StoreOutgoingLinks("Page", new string[] { "Page1", "Sub.Page1", "Page5" }), "StoreOutgoingLinks should return true");
            Assert.IsTrue(prov.StoreOutgoingLinks("Page", new string[] { "Page2", "Sub.Page", "Page3" }), "StoreOutgoingLinks should return true");

            string[] links = prov.GetOutgoingLinks("Page");

            Assert.AreEqual(3, links.Length, "Wrong link count");

            Array.Sort(links);
            Assert.AreEqual("Page2", links[0], "Wrong link");
            Assert.AreEqual("Page3", links[1], "Wrong link");
            Assert.AreEqual("Sub.Page", links[2], "Wrong link");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ProviderUpdater" /> class.
        /// </summary>
        /// <param name="settingsProvider">The settings storage provider.</param>
        /// <param name="fileNamesForProviders">A provider->file dictionary.</param>
        /// <param name="providers">The providers to update.</param>
        public ProviderUpdater(ISettingsStorageProviderV30 settingsProvider,
            Dictionary<string, string> fileNamesForProviders,
            params IProviderV30[][] providers)
        {
            if(settingsProvider == null) throw new ArgumentNullException("settingsProvider");
            if(fileNamesForProviders == null) throw new ArgumentNullException("fileNamesForProviders");
            if(providers == null) throw new ArgumentNullException("providers");
            if(providers.Length == 0) throw new ArgumentException("Providers cannot be empty", "providers");

            this.settingsProvider = settingsProvider;
            this.fileNamesForProviders = fileNamesForProviders;

            this.providers = new List<IProviderV30>(20);
            foreach(IProviderV30[] group in providers) {
                this.providers.AddRange(group);
            }

            visitedUrls = new List<string>(10);
        }
Ejemplo n.º 5
0
        public void StorePluginAssembly_RetrievePluginAssembly_ListPluginAssemblies()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Collectors.SettingsProvider = prov;

            byte[] stuff = new byte[50];
            for (int i = 0; i < stuff.Length; i++)
            {
                stuff[i] = (byte)i;
            }

            Assert.AreEqual(0, prov.ListPluginAssemblies().Length, "Wrong length");

            Assert.IsTrue(prov.StorePluginAssembly("Plugin.dll", stuff), "StorePluginAssembly should return true");

            string[] asms = prov.ListPluginAssemblies();
            Assert.AreEqual(1, asms.Length, "Wrong length");
            Assert.AreEqual("Plugin.dll", asms[0], "Wrong assembly name");

            byte[] output = prov.RetrievePluginAssembly("Plugin.dll");
            Assert.AreEqual(stuff.Length, output.Length, "Wrong content length");
            for (int i = 0; i < stuff.Length; i++)
            {
                Assert.AreEqual(stuff[i], output[i], "Wrong content");
            }

            stuff = new byte[30];
            for (int i = stuff.Length - 1; i >= 0; i--)
            {
                stuff[i] = (byte)i;
            }

            Assert.IsTrue(prov.StorePluginAssembly("Plugin.dll", stuff), "StorePluginAssembly should return true");

            output = prov.RetrievePluginAssembly("Plugin.dll");
            Assert.AreEqual(stuff.Length, output.Length, "Wrong content length");
            for (int i = 0; i < stuff.Length; i++)
            {
                Assert.AreEqual(stuff[i], output[i], "Wrong content");
            }
        }
Ejemplo n.º 6
0
        public void AddRecentChange_NullMessageSubject_NullDescription()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Collectors.SettingsProvider = prov;

            DateTime dt = DateTime.Now;

            Assert.IsTrue(prov.AddRecentChange("Page", "Title", null, dt, "User", ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, null), "AddRecentChange should return true");

            RecentChange c = prov.GetRecentChanges()[0];

            Assert.AreEqual("Page", c.Page, "Wrong page");
            Assert.AreEqual("Title", c.Title, "Wrong title");
            Assert.AreEqual("", c.MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt, c.DateTime);
            Assert.AreEqual("User", c.User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, c.Change, "Wrong change");
            Assert.AreEqual("", c.Description, "Wrong description");
        }
Ejemplo n.º 7
0
        protected void btnCopySettings_Click(object sender, EventArgs e)
        {
            ISettingsStorageProviderV30 to = null;

            ISettingsStorageProviderV30[] allProviders = ProviderLoader.LoadAllSettingsStorageProviders(Settings.Provider);
            foreach (ISettingsStorageProviderV30 prov in allProviders)
            {
                if (prov.GetType().ToString() == lstSettingsDestination.SelectedValue)
                {
                    to = prov;
                    break;
                }
            }

            Log.LogEntry("Settings data copy requested to " + to.Information.Name, EntryType.General, SessionFacade.CurrentUsername);

            try {
                to.Init(Host.Instance, txtSettingsDestinationConfig.Text);
            }
            catch (InvalidConfigurationException ex) {
                Log.LogEntry("Provider rejected configuration: " + ex, EntryType.Error, Log.SystemUsername);
                lblCopySettingsResult.CssClass = "resulterror";
                lblCopySettingsResult.Text     = Properties.Messages.ProviderRejectedConfiguration;
                return;
            }

            // Find namespaces
            List <string> namespaces = new List <string>(5);

            foreach (NamespaceInfo ns in Pages.GetNamespaces())
            {
                namespaces.Add(ns.Name);
            }

            DataMigrator.CopySettingsStorageProviderData(Settings.Provider, to, namespaces.ToArray(), Collectors.GetAllProviders());

            lblCopySettingsResult.CssClass = "resultok";
            lblCopySettingsResult.Text     = Properties.Messages.DataCopied;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates the DLLs into the settings storage provider, if appropriate.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="settingsProviderAsmName">The file name of the assembly that contains the current Settings Storage Provider.</param>
        private static void UpdateDllsIntoSettingsProvider(ISettingsStorageProviderV30 provider, string settingsProviderAsmName)
        {
            // Look into public\Plugins (hardcoded)
            string fullPath = Path.Combine(Settings.PublicDirectory, "Plugins");

            if (!Directory.Exists(fullPath))
            {
                return;
            }

            string[] dlls          = Directory.GetFiles(fullPath, "*.dll");
            string[] installedDlls = provider.ListPluginAssemblies();

            foreach (string dll in dlls)
            {
                bool   found    = false;
                string filename = Path.GetFileName(dll);
                foreach (string instDll in installedDlls)
                {
                    if (instDll.ToLowerInvariant() == filename.ToLowerInvariant())
                    {
                        found = true;
                        break;
                    }
                }

                if (!found && filename.ToLowerInvariant() == settingsProviderAsmName.ToLowerInvariant())
                {
                    found = true;
                }

                if (found)
                {
                    // Update DLL
                    provider.StorePluginAssembly(filename, File.ReadAllBytes(dll));
                }
            }
        }
Ejemplo n.º 9
0
        public void DeletePluginAssembly()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Collectors.SettingsProvider = prov;

            Assert.IsFalse(prov.DeletePluginAssembly("Assembly.dll"), "DeletePluginAssembly should return false");

            byte[] stuff = new byte[50];
            for (int i = 0; i < stuff.Length; i++)
            {
                stuff[i] = (byte)i;
            }

            prov.StorePluginAssembly("Plugin.dll", stuff);
            prov.StorePluginAssembly("Assembly.dll", stuff);

            Assert.IsTrue(prov.DeletePluginAssembly("Assembly.dll"), "DeletePluginAssembly should return true");

            string[] asms = prov.ListPluginAssemblies();

            Assert.AreEqual(1, asms.Length, "Wrong length");
            Assert.AreEqual("Plugin.dll", asms[0], "Wrong assembly");
        }
Ejemplo n.º 10
0
        public void SetPluginConfiguration_GetPluginConfiguration()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Collectors.SettingsProvider = prov;

            Assert.IsEmpty(prov.GetPluginConfiguration("My.Test.Plugin"), "GetPluginConfiguration should return an empty string");

            Assert.IsTrue(prov.SetPluginConfiguration("My.Test.Plugin", "config"), "SetPluginConfiguration should return true");

            Assert.AreEqual("config", prov.GetPluginConfiguration("My.Test.Plugin"), "Wrong config");

            Assert.IsTrue(prov.SetPluginConfiguration("My.Test.Plugin", "config222"), "SetPluginConfiguration should return true");

            Assert.AreEqual("config222", prov.GetPluginConfiguration("My.Test.Plugin"), "Wrong config");

            Assert.IsTrue(prov.SetPluginConfiguration("My.Test.Plugin", ""), "SetPluginConfiguration should return true");

            Assert.AreEqual("", prov.GetPluginConfiguration("My.Test.Plugin"), "Wrong config");

            Assert.IsTrue(prov.SetPluginConfiguration("My.Test.Plugin", null), "SetPluginConfiguration should return true");

            Assert.AreEqual("", prov.GetPluginConfiguration("My.Test.Plugin"), "Wrong config");
        }
Ejemplo n.º 11
0
        public void Init_NullHost()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.Init(null, "");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Updates the DLLs into the settings storage provider, if appropriate.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="settingsProviderAsmName">The file name of the assembly that contains the current Settings Storage Provider.</param>
        private static void UpdateDllsIntoSettingsProvider(ISettingsStorageProviderV30 provider, string settingsProviderAsmName)
        {
            // Look into public\Plugins (hardcoded)
            string fullPath = Path.Combine(Settings.PublicDirectory, "Plugins");

            if(!Directory.Exists(fullPath)) return;

            string[] dlls = Directory.GetFiles(fullPath, "*.dll");
            string[] installedDlls = provider.ListPluginAssemblies();

            foreach(string dll in dlls) {
                bool found = false;
                string filename = Path.GetFileName(dll);
                foreach(string instDll in installedDlls) {
                    if(instDll.ToLowerInvariant() == filename.ToLowerInvariant()) {
                        found = true;
                        break;
                    }
                }

                if(!found && filename.ToLowerInvariant() == settingsProviderAsmName.ToLowerInvariant()) {
                    found = true;
                }

                if(found) {
                    // Update DLL
                    provider.StorePluginAssembly(filename, File.ReadAllBytes(dll));
                }
            }
        }
Ejemplo n.º 13
0
        public void CopySettingsStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            ISettingsStorageProviderV30 source      = mocks.StrictMock <ISettingsStorageProviderV30>();
            ISettingsStorageProviderV30 destination = mocks.StrictMock <ISettingsStorageProviderV30>();
            IAclManager sourceAclManager            = mocks.StrictMock <IAclManager>();
            IAclManager destinationAclManager       = mocks.StrictMock <IAclManager>();

            // Setup SOURCE ---------------------

            // Settings
            Dictionary <string, string> settings = new Dictionary <string, string>()
            {
                { "Set1", "Value1" },
                { "Set2", "Value2" }
            };

            Expect.Call(source.GetAllSettings()).Return(settings);

            // Meta-data (global)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null)).Return("AAM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null)).Return("PRM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.LoginNotice, null)).Return("");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageChangeMessage, null)).Return("PCM");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null)).Return("DCM");

            // Meta-data (root)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.EditNotice, null)).Return("");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Footer, null)).Return("FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Header, null)).Return("HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.HtmlHead, null)).Return("HTML");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageFooter, null)).Return("P_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageHeader, null)).Return("P_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Sidebar, null)).Return("SIDEBAR");

            // Meta-data ("NS" namespace)
            Expect.Call(source.GetMetaDataItem(MetaDataItem.EditNotice, "NS")).Return("NS_EDIT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Footer, "NS")).Return("NS_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Header, "NS")).Return("NS_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.HtmlHead, "NS")).Return("NS_HTML");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageFooter, "NS")).Return("NS_P_FOOT");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.PageHeader, "NS")).Return("NS_P_HEADER");
            Expect.Call(source.GetMetaDataItem(MetaDataItem.Sidebar, "NS")).Return("NS_SIDEBAR");

            // Plugin assemblies
            byte[] asm1 = new byte[] { 1, 2, 3, 4, 5 };
            byte[] asm2 = new byte[] { 6, 7, 8, 9, 10, 11, 12 };
            Expect.Call(source.ListPluginAssemblies()).Return(new string[] { "Plugins1.dll", "Plugins2.dll" });
            Expect.Call(source.RetrievePluginAssembly("Plugins1.dll")).Return(asm1);
            Expect.Call(source.RetrievePluginAssembly("Plugins2.dll")).Return(asm2);

            // Plugin status
            Expect.Call(source.GetPluginStatus("Test1.Plugin1")).Return(true);
            Expect.Call(source.GetPluginStatus("Test2.Plugin2")).Return(false);

            // Plugin config
            Expect.Call(source.GetPluginConfiguration("Test1.Plugin1")).Return("Config1");
            Expect.Call(source.GetPluginConfiguration("Test2.Plugin2")).Return("");

            // Outgoing links
            Dictionary <string, string[]> outgoingLinks = new Dictionary <string, string[]>()
            {
                { "Page1", new string[] { "Page2", "Page3" } },
                { "Page2", new string[] { "Page3" } },
                { "Page3", new string[] { "Page4", "Page3" } }
            };

            Expect.Call(source.GetAllOutgoingLinks()).Return(outgoingLinks);

            // ACLs
            Expect.Call(source.AclManager).Return(sourceAclManager);
            AclEntry[] entries = new AclEntry[] {
                new AclEntry("Res1", "Act1", "Subj1", Value.Grant),
                new AclEntry("Res2", "Act2", "Subj2", Value.Deny)
            };
            Expect.Call(sourceAclManager.RetrieveAllEntries()).Return(entries);

            // Setup DESTINATION -----------------

            // Settings
            destination.BeginBulkUpdate();
            LastCall.On(destination).Repeat.Once();
            foreach (KeyValuePair <string, string> pair in settings)
            {
                Expect.Call(destination.SetSetting(pair.Key, pair.Value)).Return(true);
            }
            destination.EndBulkUpdate();
            LastCall.On(destination).Repeat.Once();

            // Meta-data (global)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null, "AAM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null, "PRM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.LoginNotice, null, "")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageChangeMessage, null, "PCM")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null, "DCM")).Return(true);

            // Meta-data (root)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.EditNotice, null, "")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Footer, null, "FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Header, null, "HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.HtmlHead, null, "HTML")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageFooter, null, "P_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageHeader, null, "P_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Sidebar, null, "SIDEBAR")).Return(true);

            // Meta-data ("NS" namespace)
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.EditNotice, "NS", "NS_EDIT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Footer, "NS", "NS_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Header, "NS", "NS_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.HtmlHead, "NS", "NS_HTML")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageFooter, "NS", "NS_P_FOOT")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.PageHeader, "NS", "NS_P_HEADER")).Return(true);
            Expect.Call(destination.SetMetaDataItem(MetaDataItem.Sidebar, "NS", "NS_SIDEBAR")).Return(true);

            // Plugin assemblies
            Expect.Call(destination.StorePluginAssembly("Plugins1.dll", asm1)).Return(true);
            Expect.Call(destination.StorePluginAssembly("Plugins2.dll", asm2)).Return(true);

            // Plugin status
            Expect.Call(destination.SetPluginStatus("Test1.Plugin1", true)).Return(true);
            Expect.Call(destination.SetPluginStatus("Test2.Plugin2", false)).Return(true);

            // Plugin config
            Expect.Call(destination.SetPluginConfiguration("Test1.Plugin1", "Config1")).Return(true);
            Expect.Call(destination.SetPluginConfiguration("Test2.Plugin2", "")).Return(true);

            // Outgoing links
            foreach (KeyValuePair <string, string[]> pair in outgoingLinks)
            {
                Expect.Call(destination.StoreOutgoingLinks(pair.Key, pair.Value)).Return(true);
            }

            // ACLs
            Expect.Call(destination.AclManager).Return(destinationAclManager).Repeat.Any();
            foreach (AclEntry e in entries)
            {
                Expect.Call(destinationAclManager.StoreEntry(e.Resource, e.Action, e.Subject, e.Value)).Return(true);
            }

            mocks.ReplayAll();

            DataMigrator.CopySettingsStorageProviderData(source, destination,
                                                         new string[] { "NS" }, new string[] { "Test1.Plugin1", "Test2.Plugin2" });

            mocks.VerifyAll();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Migrates all the stored files and page attachments from a Provider to another.
        /// </summary>
        /// <param name="source">The source Provider.</param>
        /// <param name="destination">The destination Provider.</param>
        /// <param name="settingsProvider">The settings storage provider that handles permissions.</param>
        public static void MigrateFilesStorageProviderData(IFilesStorageProviderV30 source, IFilesStorageProviderV30 destination, ISettingsStorageProviderV30 settingsProvider)
        {
            // Directories
            MigrateDirectories(source, destination, "/", settingsProvider);

            // Attachments
            foreach (string page in source.GetPagesWithAttachments())
            {
                PageInfo pageInfo = new PageInfo(page, null, DateTime.Now);

                string[] attachments = source.ListPageAttachments(pageInfo);

                foreach (string attachment in attachments)
                {
                    // Copy file content
                    using (MemoryStream ms = new MemoryStream(1048576)) {
                        source.RetrievePageAttachment(pageInfo, attachment, ms, false);
                        ms.Seek(0, SeekOrigin.Begin);
                        destination.StorePageAttachment(pageInfo, attachment, ms, false);
                    }

                    // Copy download count
                    FileDetails fileDetails = source.GetPageAttachmentDetails(pageInfo, attachment);
                    destination.SetPageAttachmentRetrievalCount(pageInfo, attachment, fileDetails.RetrievalCount);

                    // Delete attachment
                    source.DeletePageAttachment(pageInfo, attachment);
                }
            }
        }
Ejemplo n.º 15
0
        private static void MigrateDirectories(IFilesStorageProviderV30 source, IFilesStorageProviderV30 destination, string current, ISettingsStorageProviderV30 settingsProvider)
        {
            // Copy files
            string[] files = source.ListFiles(current);
            foreach (string file in files)
            {
                // Copy file content
                using (MemoryStream ms = new MemoryStream(1048576)) {
                    source.RetrieveFile(file, ms, false);
                    ms.Seek(0, SeekOrigin.Begin);
                    destination.StoreFile(file, ms, false);
                }

                // Copy download count
                FileDetails fileDetails = source.GetFileDetails(file);
                destination.SetFileRetrievalCount(file, fileDetails.RetrievalCount);

                // Delete source file, if root
                if (current == "/")
                {
                    source.DeleteFile(file);
                }
            }

            settingsProvider.AclManager.RenameResource(
                Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, current),
                Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, current));

            // Copy directories
            string[] directories = source.ListDirectories(current);
            foreach (string dir in directories)
            {
                destination.CreateDirectory(current, dir.Substring(dir.TrimEnd('/').LastIndexOf("/") + 1).Trim('/'));
                MigrateDirectories(source, destination, dir, settingsProvider);

                // Delete directory, if root
                if (current == "/")
                {
                    source.DeleteDirectory(dir);
                }
            }
        }
Ejemplo n.º 16
0
        public void StoreOutgoingLinks_InvalidPage(string p)
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.StoreOutgoingLinks(p, new string[] { "P1", "P2" });
        }
Ejemplo n.º 17
0
        public void StoreOutgoingLinks_InvalidLinksEntry(string e)
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.StoreOutgoingLinks("Page", new string[] { "P1", e, "P3" });
        }
Ejemplo n.º 18
0
        public void DeleteOutgoingLinks_InvalidPage(string p)
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.DeleteOutgoingLinks(p);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Performs all needed startup operations.
        /// </summary>
        public static void Startup()
        {
            // Load Host
            Host.Instance = new Host();

            // Load config
            ISettingsStorageProviderV30 ssp = ProviderLoader.LoadSettingsStorageProvider(WebConfigurationManager.AppSettings["SettingsStorageProvider"]);

            ssp.Init(Host.Instance, GetSettingsStorageProviderConfiguration());
            Collectors.SettingsProvider = ssp;

            if (!(ssp is SettingsStorageProvider))
            {
                // Update DLLs from public\Plugins
                UpdateDllsIntoSettingsProvider(ssp, ProviderLoader.SettingsStorageProviderAssemblyName);
            }

            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);
                }
            }

            // Load config
            IIndexDirectoryProviderV30 idp = ProviderLoader.LoadIndexDirectoryProvider(WebConfigurationManager.AppSettings["IndexDirectoryProvider"]);

            idp.Init(Host.Instance, GetSettingsStorageProviderConfiguration());
            Collectors.IndexDirectoryProvider = idp;

            MimeTypes.Init();

            // Load Providers
            Collectors.FileNames = new System.Collections.Generic.Dictionary <string, string>(10);
            Collectors.UsersProviderCollector             = new ProviderCollector <IUsersStorageProviderV30>();
            Collectors.PagesProviderCollector             = new ProviderCollector <IPagesStorageProviderV30>();
            Collectors.FilesProviderCollector             = new ProviderCollector <IFilesStorageProviderV30>();
            Collectors.FormatterProviderCollector         = new ProviderCollector <IFormatterProviderV30>();
            Collectors.CacheProviderCollector             = new ProviderCollector <ICacheProviderV30>();
            Collectors.DisabledUsersProviderCollector     = new ProviderCollector <IUsersStorageProviderV30>();
            Collectors.DisabledPagesProviderCollector     = new ProviderCollector <IPagesStorageProviderV30>();
            Collectors.DisabledFilesProviderCollector     = new ProviderCollector <IFilesStorageProviderV30>();
            Collectors.DisabledFormatterProviderCollector = new ProviderCollector <IFormatterProviderV30>();
            Collectors.DisabledCacheProviderCollector     = new ProviderCollector <ICacheProviderV30>();

            // Load built-in providers

            // Files storage providers have to be loaded BEFORE users storage providers in order to properly set permissions
            FilesStorageProvider f = new FilesStorageProvider();

            if (!ProviderLoader.IsDisabled(f.GetType().FullName))
            {
                f.Init(Host.Instance, "");
                Collectors.FilesProviderCollector.AddProvider(f);
                Log.LogEntry("Provider " + f.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Collectors.DisabledFilesProviderCollector.AddProvider(f);
                Log.LogEntry("Provider " + f.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
            }

            UsersStorageProvider u = new UsersStorageProvider();

            if (!ProviderLoader.IsDisabled(u.GetType().FullName))
            {
                u.Init(Host.Instance, "");
                Collectors.UsersProviderCollector.AddProvider(u);
                Log.LogEntry("Provider " + u.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Collectors.DisabledUsersProviderCollector.AddProvider(u);
                Log.LogEntry("Provider " + u.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
            }

            // Load Users (pages storage providers might need access to users/groups data for upgrading from 2.0 to 3.0)
            ProviderLoader.FullLoad(true, false, false, false, false);
            //Users.Instance = new Users();
            bool groupsCreated = VerifyAndCreateDefaultGroups();

            PagesStorageProvider p = new PagesStorageProvider();

            if (!ProviderLoader.IsDisabled(p.GetType().FullName))
            {
                p.Init(Host.Instance, "");
                Collectors.PagesProviderCollector.AddProvider(p);
                Log.LogEntry("Provider " + p.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Collectors.DisabledPagesProviderCollector.AddProvider(p);
                Log.LogEntry("Provider " + p.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
            }

            CacheProvider c = new CacheProvider();

            if (!ProviderLoader.IsDisabled(c.GetType().FullName))
            {
                c.Init(Host.Instance, "");
                Collectors.CacheProviderCollector.AddProvider(c);
                Log.LogEntry("Provider " + c.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Collectors.DisabledCacheProviderCollector.AddProvider(c);
                Log.LogEntry("Provider " + c.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
            }

            // Load all other providers
            ProviderLoader.FullLoad(false, true, true, true, true);

            if (groupsCreated)
            {
                // It is necessary to set default permissions for file management
                UserGroup administratorsGroup = Users.FindUserGroup(Settings.AdministratorsGroup);
                UserGroup anonymousGroup      = Users.FindUserGroup(Settings.AnonymousGroup);
                UserGroup usersGroup          = Users.FindUserGroup(Settings.UsersGroup);

                SetAdministratorsGroupDefaultPermissions(administratorsGroup);
                SetUsersGroupDefaultPermissions(usersGroup);
                SetAnonymousGroupDefaultPermissions(anonymousGroup);
            }

            // Init cache
            //Cache.Instance = new Cache(Collectors.CacheProviderCollector.GetProvider(Settings.DefaultCacheProvider));
            if (Collectors.CacheProviderCollector.GetProvider(Settings.DefaultCacheProvider) == null)
            {
                Log.LogEntry("Default Cache Provider was not loaded, backing to integrated provider", EntryType.Error, Log.SystemUsername);
                Settings.DefaultCacheProvider = typeof(CacheProvider).FullName;
                Collectors.TryEnable(Settings.DefaultCacheProvider);
            }

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

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

            System.Threading.ThreadPool.QueueUserWorkItem(ignored =>
            {
                SearchClass.RebuildIndex();
            });
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Copies the settings from a Provider to another.
        /// </summary>
        /// <param name="source">The source Provider.</param>
        /// <param name="destination">The destination Provider.</param>
        /// <param name="knownNamespaces">The currently known page namespaces.</param>
        /// <param name="knownPlugins">The currently known plugins.</param>
        public static void CopySettingsStorageProviderData(ISettingsStorageProviderV30 source, ISettingsStorageProviderV30 destination,
                                                           string[] knownNamespaces, string[] knownPlugins)
        {
            // Settings
            destination.BeginBulkUpdate();
            foreach (KeyValuePair <string, string> pair in source.GetAllSettings())
            {
                destination.SetSetting(pair.Key, pair.Value);
            }
            destination.EndBulkUpdate();

            // Meta-data (global)
            destination.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null));
            destination.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null));
            destination.SetMetaDataItem(MetaDataItem.LoginNotice, null,
                                        source.GetMetaDataItem(MetaDataItem.LoginNotice, null));
            destination.SetMetaDataItem(MetaDataItem.PageChangeMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.PageChangeMessage, null));
            destination.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null,
                                        source.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null));

            // Meta-data (ns-specific)
            List <string> namespacesToProcess = new List <string>();

            namespacesToProcess.Add(null);
            namespacesToProcess.AddRange(knownNamespaces);
            foreach (string nspace in namespacesToProcess)
            {
                destination.SetMetaDataItem(MetaDataItem.EditNotice, nspace,
                                            source.GetMetaDataItem(MetaDataItem.EditNotice, nspace));
                destination.SetMetaDataItem(MetaDataItem.Footer, nspace,
                                            source.GetMetaDataItem(MetaDataItem.Footer, nspace));
                destination.SetMetaDataItem(MetaDataItem.Header, nspace,
                                            source.GetMetaDataItem(MetaDataItem.Header, nspace));
                destination.SetMetaDataItem(MetaDataItem.HtmlHead, nspace,
                                            source.GetMetaDataItem(MetaDataItem.HtmlHead, nspace));
                destination.SetMetaDataItem(MetaDataItem.PageFooter, nspace,
                                            source.GetMetaDataItem(MetaDataItem.PageFooter, nspace));
                destination.SetMetaDataItem(MetaDataItem.PageHeader, nspace,
                                            source.GetMetaDataItem(MetaDataItem.PageHeader, nspace));
                destination.SetMetaDataItem(MetaDataItem.Sidebar, nspace,
                                            source.GetMetaDataItem(MetaDataItem.Sidebar, nspace));
            }

            // Plugin assemblies
            string[] assemblies = source.ListPluginAssemblies();
            foreach (string asm in assemblies)
            {
                destination.StorePluginAssembly(asm,
                                                source.RetrievePluginAssembly(asm));
            }

            // Plugin status and config
            foreach (string plug in knownPlugins)
            {
                destination.SetPluginStatus(plug,
                                            source.GetPluginStatus(plug));

                destination.SetPluginConfiguration(plug,
                                                   source.GetPluginConfiguration(plug));
            }

            // Outgoing links
            IDictionary <string, string[]> allLinks = source.GetAllOutgoingLinks();

            foreach (KeyValuePair <string, string[]> link in allLinks)
            {
                destination.StoreOutgoingLinks(link.Key, link.Value);
            }

            // ACLs
            AclEntry[] allEntries = source.AclManager.RetrieveAllEntries();
            foreach (AclEntry entry in allEntries)
            {
                destination.AclManager.StoreEntry(entry.Resource, entry.Action, entry.Subject, entry.Value);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Loads the proper 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 settings storage provider.</returns>
        public static ISettingsStorageProviderV30 LoadSettingsStorageProvider(string name)
        {
            if (string.IsNullOrEmpty(name) || string.Compare(name, "default", true, CultureInfo.InvariantCulture) == 0)
            {
                return(new SettingsStorageProvider( ));
            }

            ISettingsStorageProviderV30 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]);
                            SettingsStorageProviderAssemblyName = Path.GetFileName(assemblyName);
                        }
                        else
                        {
                            string tentativePluginsPath = null;
                            try
                            {
                                // Settings.PublicDirectory is only available when running the web app
                                tentativePluginsPath = Path.Combine(Settings.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]);
                                SettingsStorageProviderAssemblyName = Path.GetFileName(tentativePluginsPath);
                            }
                            else
                            {
                                // Trim .dll
                                t = Type.GetType(fields[0] + "," + assemblyName.Substring(0, assemblyName.Length - 4), true, true);
                                SettingsStorageProviderAssemblyName = assemblyName;
                            }
                        }

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

            if (result == null)
            {
                throw new ArgumentException("Could not load the specified Settings Storage Provider", inner);
            }
            return(result);
        }
Ejemplo n.º 22
0
        public void Init_NullConfig()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.Init(MockHost(), null);
        }
        public void Init_InvalidConnString(string c)
        {
            ISettingsStorageProviderV30 prov = GetProvider( );

            prov.Init(MockHost( ), c);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Backups the specified settings provider.
        /// </summary>
        /// <param name="zipFileName">The zip file name where to store the backup.</param>
        /// <param name="settingsStorageProvider">The source settings provider.</param>
        /// <param name="knownNamespaces">The currently known page namespaces.</param>
        /// <param name="knownPlugins">The currently known plugins.</param>
        /// <returns><c>true</c> if the backup file has been succesfully created.</returns>
        public static bool BackupSettingsStorageProvider(string zipFileName, ISettingsStorageProviderV30 settingsStorageProvider, string[] knownNamespaces, string[] knownPlugins)
        {
            SettingsBackup settingsBackup = new SettingsBackup();

            // Settings
            settingsBackup.Settings = (Dictionary<string, string>)settingsStorageProvider.GetAllSettings();

            // Plugins Status and Configuration
            settingsBackup.PluginsFileNames = knownPlugins.ToList();
            Dictionary<string, bool> pluginsStatus = new Dictionary<string, bool>();
            Dictionary<string, string> pluginsConfiguration = new Dictionary<string, string>();
            foreach(string plugin in knownPlugins) {
                pluginsStatus[plugin] = settingsStorageProvider.GetPluginStatus(plugin);
                pluginsConfiguration[plugin] = settingsStorageProvider.GetPluginConfiguration(plugin);
            }
            settingsBackup.PluginsStatus = pluginsStatus;
            settingsBackup.PluginsConfiguration = pluginsConfiguration;

            // Metadata
            List<MetaData> metadataList = new List<MetaData>();
            // Meta-data (global)
            metadataList.Add(new MetaData() {
                Item = MetaDataItem.AccountActivationMessage,
                Tag = null,
                Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null)
            });
            metadataList.Add(new MetaData() { Item = MetaDataItem.PasswordResetProcedureMessage, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null) });
            metadataList.Add(new MetaData() { Item = MetaDataItem.LoginNotice, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.LoginNotice, null) });
            metadataList.Add(new MetaData() { Item = MetaDataItem.PageChangeMessage, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PageChangeMessage, null) });
            metadataList.Add(new MetaData() { Item = MetaDataItem.DiscussionChangeMessage, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null) });
            // Meta-data (ns-specific)
            List<string> namespacesToProcess = new List<string>();
            namespacesToProcess.Add("");
            namespacesToProcess.AddRange(knownNamespaces);
            foreach(string nspace in namespacesToProcess) {
                metadataList.Add(new MetaData() { Item = MetaDataItem.EditNotice, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.EditNotice, nspace) });
                metadataList.Add(new MetaData() { Item = MetaDataItem.Footer, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.Footer, nspace) });
                metadataList.Add(new MetaData() { Item = MetaDataItem.Header, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.Header, nspace) });
                metadataList.Add(new MetaData() { Item = MetaDataItem.HtmlHead, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.HtmlHead, nspace) });
                metadataList.Add(new MetaData() { Item = MetaDataItem.PageFooter, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PageFooter, nspace) });
                metadataList.Add(new MetaData() { Item = MetaDataItem.PageHeader, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PageHeader, nspace) });
                metadataList.Add(new MetaData() { Item = MetaDataItem.Sidebar, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.Sidebar, nspace) });
            }
            settingsBackup.Metadata = metadataList;

            // RecentChanges
            settingsBackup.RecentChanges = settingsStorageProvider.GetRecentChanges().ToList();

            // OutgoingLinks
            settingsBackup.OutgoingLinks = (Dictionary<string, string[]>)settingsStorageProvider.GetAllOutgoingLinks();

            // ACLEntries
            AclEntry[] aclEntries = settingsStorageProvider.AclManager.RetrieveAllEntries();
            settingsBackup.AclEntries = new List<AclEntryBackup>(aclEntries.Length);
            foreach(AclEntry aclEntry in aclEntries) {
                settingsBackup.AclEntries.Add(new AclEntryBackup() {
                    Action = aclEntry.Action,
                    Resource = aclEntry.Resource,
                    Subject = aclEntry.Subject,
                    Value = aclEntry.Value
                });
            }

            JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();
            javascriptSerializer.MaxJsonLength = javascriptSerializer.MaxJsonLength * 10;

            string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());
            Directory.CreateDirectory(tempDir);

            FileStream tempFile = File.Create(Path.Combine(tempDir, "Settings.json"));
            byte[] buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(settingsBackup));
            tempFile.Write(buffer, 0, buffer.Length);
            tempFile.Close();

            tempFile = File.Create(Path.Combine(tempDir, "Version.json"));
            buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(generateVersionFile("Settings")));
            tempFile.Write(buffer, 0, buffer.Length);
            tempFile.Close();

            using(ZipFile zipFile = new ZipFile()) {
                zipFile.AddDirectory(tempDir, "");
                zipFile.Save(zipFileName);
            }
            Directory.Delete(tempDir, true);

            return true;
        }
Ejemplo n.º 25
0
        public void AddRecentChange_GetRecentChanges()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            Collectors.SettingsProvider = prov;

            DateTime dt = DateTime.Now;

            Assert.IsTrue(prov.AddRecentChange("MainPage", "Main Page", null, dt, Log.SystemUsername, ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, ""), "AddRecentChange should return true");
            Assert.IsTrue(prov.AddRecentChange("MainPage", "Home Page", null, dt.AddHours(1), "admin", ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, "Added info"), "AddRecentChange should return true");

            Assert.IsTrue(prov.AddRecentChange("MainPage", "Home Page", null, dt.AddHours(5), "admin", ScrewTurn.Wiki.PluginFramework.Change.PageRenamed, ""), "AddRecentChange should return true");
            Assert.IsTrue(prov.AddRecentChange("MainPage", "Main Page", null, dt.AddHours(6), "admin", ScrewTurn.Wiki.PluginFramework.Change.PageRolledBack, ""), "AddRecentChange should return true");
            Assert.IsTrue(prov.AddRecentChange("MainPage", "Main Page", null, dt.AddHours(7), "admin", ScrewTurn.Wiki.PluginFramework.Change.PageDeleted, ""), "AddRecentChange should return true");

            Assert.IsTrue(prov.AddRecentChange("MainPage", "Main Page", "Subject", dt.AddHours(2), "admin", ScrewTurn.Wiki.PluginFramework.Change.MessagePosted, ""), "AddRecentChange should return true");
            Assert.IsTrue(prov.AddRecentChange("MainPage", "Main Page", "Subject", dt.AddHours(3), "admin", ScrewTurn.Wiki.PluginFramework.Change.MessageEdited, ""), "AddRecentChange should return true");
            Assert.IsTrue(prov.AddRecentChange("MainPage", "Main Page", "Subject", dt.AddHours(4), "admin", ScrewTurn.Wiki.PluginFramework.Change.MessageDeleted, ""), "AddRecentChange should return true");

            RecentChange[] changes = prov.GetRecentChanges();

            Assert.AreEqual(8, changes.Length, "Wrong recent change count");

            Assert.AreEqual("MainPage", changes[0].Page, "Wrong page");
            Assert.AreEqual("Main Page", changes[0].Title, "Wrong title");
            Assert.AreEqual("", changes[0].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt, changes[0].DateTime);
            Assert.AreEqual(Log.SystemUsername, changes[0].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, changes[0].Change, "Wrong change");
            Assert.AreEqual("", changes[0].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[1].Page, "Wrong page");
            Assert.AreEqual("Home Page", changes[1].Title, "Wrong title");
            Assert.AreEqual("", changes[1].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(1), changes[1].DateTime);
            Assert.AreEqual("admin", changes[1].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, changes[1].Change, "Wrong change");
            Assert.AreEqual("Added info", changes[1].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[2].Page, "Wrong page");
            Assert.AreEqual("Main Page", changes[2].Title, "Wrong title");
            Assert.AreEqual("Subject", changes[2].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(2), changes[2].DateTime);
            Assert.AreEqual("admin", changes[2].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.MessagePosted, changes[2].Change, "Wrong change");
            Assert.AreEqual("", changes[2].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[3].Page, "Wrong page");
            Assert.AreEqual("Main Page", changes[3].Title, "Wrong title");
            Assert.AreEqual("Subject", changes[3].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(3), changes[3].DateTime);
            Assert.AreEqual("admin", changes[3].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.MessageEdited, changes[3].Change, "Wrong change");
            Assert.AreEqual("", changes[3].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[4].Page, "Wrong page");
            Assert.AreEqual("Main Page", changes[4].Title, "Wrong title");
            Assert.AreEqual("Subject", changes[4].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(4), changes[4].DateTime);
            Assert.AreEqual("admin", changes[4].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.MessageDeleted, changes[4].Change, "Wrong change");
            Assert.AreEqual("", changes[4].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[5].Page, "Wrong page");
            Assert.AreEqual("Home Page", changes[5].Title, "Wrong title");
            Assert.AreEqual("", changes[5].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(5), changes[5].DateTime);
            Assert.AreEqual("admin", changes[5].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageRenamed, changes[5].Change, "Wrong change");
            Assert.AreEqual("", changes[5].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[6].Page, "Wrong page");
            Assert.AreEqual("Main Page", changes[6].Title, "Wrong title");
            Assert.AreEqual("", changes[6].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(6), changes[6].DateTime);
            Assert.AreEqual("admin", changes[6].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageRolledBack, changes[6].Change, "Wrong change");
            Assert.AreEqual("", changes[6].Description, "Wrong description");

            Assert.AreEqual("MainPage", changes[7].Page, "Wrong page");
            Assert.AreEqual("Main Page", changes[7].Title, "Wrong title");
            Assert.AreEqual("", changes[7].MessageSubject, "Wrong message subject");
            Tools.AssertDateTimesAreEqual(dt.AddHours(7), changes[7].DateTime);
            Assert.AreEqual("admin", changes[7].User, "Wrong user");
            Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageDeleted, changes[7].Change, "Wrong change");
            Assert.AreEqual("", changes[7].Description, "Wrong description");
        }
Ejemplo n.º 26
0
        public void StoreOutgoingLinks_NullLinks()
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.StoreOutgoingLinks("Page", null);
        }
Ejemplo n.º 27
0
        public void MigrateFilesStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            IFilesStorageProviderV30    source           = mocks.StrictMock <IFilesStorageProviderV30>();
            IFilesStorageProviderV30    destination      = mocks.StrictMock <IFilesStorageProviderV30>();
            ISettingsStorageProviderV30 settingsProvider = mocks.StrictMock <ISettingsStorageProviderV30>();
            IAclManager aclManager = mocks.StrictMock <IAclManager>();

            Expect.Call(settingsProvider.AclManager).Return(aclManager).Repeat.Any();

            // Setup SOURCE -----------------

            // Directories
            Expect.Call(source.ListDirectories("/")).Return(new string[] { "/Dir1/", "/Dir2/" });
            Expect.Call(source.ListDirectories("/Dir1/")).Return(new string[] { "/Dir1/Sub/" });
            Expect.Call(source.ListDirectories("/Dir2/")).Return(new string[0]);
            Expect.Call(source.ListDirectories("/Dir1/Sub/")).Return(new string[0]);

            // Settings (permissions)
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/"))).Return(true);
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/Dir1/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/Dir1/"))).Return(true);
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/Dir2/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/Dir2/"))).Return(true);
            Expect.Call(aclManager.RenameResource(
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(source, "/Dir1/Sub/"),
                            Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(destination, "/Dir1/Sub/"))).Return(true);

            // Filenames
            Expect.Call(source.ListFiles("/")).Return(new string[] { "/File1.txt", "/File2.txt" });
            Expect.Call(source.ListFiles("/Dir1/")).Return(new string[] { "/Dir1/File.txt" });
            Expect.Call(source.ListFiles("/Dir2/")).Return(new string[0]);
            Expect.Call(source.ListFiles("/Dir1/Sub/")).Return(new string[] { "/Dir1/Sub/File.txt" });

            // File content
            Expect.Call(source.RetrieveFile("/File1.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File1.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content1");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrieveFile("/File2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content2");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrieveFile("/Dir1/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content3");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrieveFile("/Dir1/Sub/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/Sub/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveFile(
                    delegate(string file, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content4");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            // File details
            Expect.Call(source.GetFileDetails("/File1.txt")).Return(new FileDetails(8, DateTime.Now, 52));
            Expect.Call(source.GetFileDetails("/File2.txt")).Return(new FileDetails(8, DateTime.Now, 0));
            Expect.Call(source.GetFileDetails("/Dir1/File.txt")).Return(new FileDetails(8, DateTime.Now, 21));
            Expect.Call(source.GetFileDetails("/Dir1/Sub/File.txt")).Return(new FileDetails(8, DateTime.Now, 123));

            // Page attachments
            Expect.Call(source.GetPagesWithAttachments()).Return(new string[] { "MainPage", "Sub.Page", "Sub.Another" });
            Expect.Call(source.ListPageAttachments(null)).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); })).Return(new string[] { "Attachment.txt" });
            Expect.Call(source.ListPageAttachments(null)).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); })).Return(new string[] { "Attachment2.txt" });
            Expect.Call(source.ListPageAttachments(null)).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Another"); })).Return(new string[0]);

            // Page attachment content
            Expect.Call(source.RetrievePageAttachment(null, "Attachment.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveAttachment(
                    delegate(PageInfo page, string name, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content5");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            Expect.Call(source.RetrievePageAttachment(null, "Attachment2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(
                new RetrieveAttachment(
                    delegate(PageInfo page, string name, Stream stream, bool count) {
                byte[] stuff = Encoding.Unicode.GetBytes("content6");
                stream.Write(stuff, 0, stuff.Length);
                return(true);
            }));

            // Attachment details
            Expect.Call(source.GetPageAttachmentDetails(null, "Attachment.txt")).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt")).Return(new FileDetails(8, DateTime.Now, 8));
            Expect.Call(source.GetPageAttachmentDetails(null, "Attachment2.txt")).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt")).Return(new FileDetails(8, DateTime.Now, 29));

            // Setup DESTINATION ------------------------

            // Directories
            Expect.Call(destination.CreateDirectory("/", "Dir1")).Return(true);
            Expect.Call(destination.CreateDirectory("/", "Dir2")).Return(true);
            Expect.Call(destination.CreateDirectory("/Dir1/", "Sub")).Return(true);

            // Files
            Expect.Call(destination.StoreFile("/File1.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File1.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                              delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content1", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StoreFile("/File2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/File2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                              delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content2", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StoreFile("/Dir1/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                                  delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content3", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StoreFile("/Dir1/Sub/File.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Equal("/Dir1/Sub/File.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreFile(
                                                                                                                                                                      delegate(string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content4", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            // File retrieval count
            destination.SetFileRetrievalCount("/File1.txt", 52);
            LastCall.On(destination).Repeat.Once();
            destination.SetFileRetrievalCount("/File2.txt", 0);
            LastCall.On(destination).Repeat.Once();
            destination.SetFileRetrievalCount("/Dir1/File.txt", 21);
            LastCall.On(destination).Repeat.Once();
            destination.SetFileRetrievalCount("/Dir1/Sub/File.txt", 123);
            LastCall.On(destination).Repeat.Once();

            // Page attachments
            Expect.Call(destination.StorePageAttachment(null, "Attachment.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreAttachment(
                                                                                                                                                                                                                                                                   delegate(PageInfo page, string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content5", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            Expect.Call(destination.StorePageAttachment(null, "Attachment2.txt", null, false)).Constraints(
                Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt"), Rhino.Mocks.Constraints.Is.TypeOf <Stream>(), Rhino.Mocks.Constraints.Is.Equal(false)).Do(new StoreAttachment(
                                                                                                                                                                                                                                                                    delegate(PageInfo page, string name, Stream stream, bool overwrite) {
                byte[] buff = new byte[512];
                int read    = stream.Read(buff, 0, (int)stream.Length);
                Assert.AreEqual("content6", Encoding.Unicode.GetString(buff, 0, read), "Wrong data");
                return(true);
            }));

            // Attachment retrieval count
            destination.SetPageAttachmentRetrievalCount(null, "Attachment.txt", 8);
            LastCall.On(destination).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt"), Rhino.Mocks.Constraints.Is.Equal(8)).Repeat.Once();
            destination.SetPageAttachmentRetrievalCount(null, "Attachment2.txt", 29);
            LastCall.On(destination).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt"), Rhino.Mocks.Constraints.Is.Equal(29)).Repeat.Once();

            // Delete source content
            Expect.Call(source.DeleteFile("/File1.txt")).Return(true);
            Expect.Call(source.DeleteFile("/File2.txt")).Return(true);
            Expect.Call(source.DeleteDirectory("/Dir1/")).Return(true);
            Expect.Call(source.DeleteDirectory("/Dir2/")).Return(true);

            Expect.Call(source.DeletePageAttachment(null, "Attachment.aspx")).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "MainPage"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment.txt")).Return(true);
            Expect.Call(source.DeletePageAttachment(null, "Attachment2.aspx")).Constraints(Rhino.Mocks.Constraints.Is.Matching(delegate(PageInfo p) { return(p.FullName == "Sub.Page"); }), Rhino.Mocks.Constraints.Is.Equal("Attachment2.txt")).Return(true);

            mocks.Replay(source);
            mocks.Replay(destination);
            mocks.Replay(settingsProvider);
            mocks.Replay(aclManager);

            DataMigrator.MigrateFilesStorageProviderData(source, destination, settingsProvider);

            mocks.Verify(source);
            mocks.Verify(destination);
            mocks.Verify(settingsProvider);
            mocks.Verify(aclManager);
        }
Ejemplo n.º 28
0
        public void GetSetting_InvalidName(string n)
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.GetSetting(n);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Performs all needed startup operations.
        /// </summary>
        public static void Startup()
        {
            // Load Host
            Host.Instance = new Host();

            // Load config
            ISettingsStorageProviderV30 ssp = ProviderLoader.LoadSettingsStorageProvider(WebConfigurationManager.AppSettings["SettingsStorageProvider"]);

            ssp.Init(Host.Instance, GetSettingsStorageProviderConfiguration());
            Collectors.SettingsProvider = ssp;

            Settings.CanOverridePublicDirectory = false;

            if (!(ssp is SettingsStorageProvider))
            {
                // Update DLLs from public\Plugins
                UpdateDllsIntoSettingsProvider(ssp, ProviderLoader.SettingsStorageProviderAssemblyName);
            }

            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);
                }
            }

            MimeTypes.Init();

            // Load Providers
            Collectors.FileNames = new System.Collections.Generic.Dictionary <string, string>(10);
            Collectors.UsersProviderCollector             = new ProviderCollector <IUsersStorageProviderV30>();
            Collectors.PagesProviderCollector             = new ProviderCollector <IPagesStorageProviderV30>();
            Collectors.FilesProviderCollector             = new ProviderCollector <IFilesStorageProviderV30>();
            Collectors.FormatterProviderCollector         = new ProviderCollector <IFormatterProviderV30>();
            Collectors.CacheProviderCollector             = new ProviderCollector <ICacheProviderV30>();
            Collectors.DisabledUsersProviderCollector     = new ProviderCollector <IUsersStorageProviderV30>();
            Collectors.DisabledPagesProviderCollector     = new ProviderCollector <IPagesStorageProviderV30>();
            Collectors.DisabledFilesProviderCollector     = new ProviderCollector <IFilesStorageProviderV30>();
            Collectors.DisabledFormatterProviderCollector = new ProviderCollector <IFormatterProviderV30>();
            Collectors.DisabledCacheProviderCollector     = new ProviderCollector <ICacheProviderV30>();

            // Load built-in providers
            var providers = new IProviderV30[] {
                new FilesStorageProvider(),
                new UsersStorageProvider(),
                new Footnotes()
            };

            foreach (var provider in providers)
            {
                var isDisabled = ProviderLoader.IsDisabled(provider.GetType().FullName);
                if (!isDisabled)
                {
                    provider.Init(Host.Instance, "");
                    Log.LogEntry("Provider " + provider.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
                }
                else
                {
                    Log.LogEntry("Provider " + provider.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
                }
                if (provider is IUsersStorageProviderV30)
                {
                    (isDisabled ? Collectors.DisabledUsersProviderCollector : Collectors.UsersProviderCollector).AddProvider(provider as IUsersStorageProviderV30);
                }
                else if (provider is IPagesStorageProviderV30)
                {
                    (isDisabled ? Collectors.DisabledPagesProviderCollector : Collectors.PagesProviderCollector).AddProvider(provider as IPagesStorageProviderV30);
                }
                else if (provider is IFilesStorageProviderV30)
                {
                    (isDisabled ? Collectors.DisabledFilesProviderCollector : Collectors.FilesProviderCollector).AddProvider(provider as IFilesStorageProviderV30);
                }
                else if (provider is IFormatterProviderV30)
                {
                    (isDisabled ? Collectors.DisabledFormatterProviderCollector : Collectors.FormatterProviderCollector).AddProvider(provider as IFormatterProviderV30);
                }
                else if (provider is ICacheProviderV30)
                {
                    (isDisabled ? Collectors.DisabledCacheProviderCollector : Collectors.CacheProviderCollector).AddProvider(provider as ICacheProviderV30);
                }
            }


            // Load Users (pages storage providers might need access to users/groups data for upgrading from 2.0 to 3.0)
            ProviderLoader.FullLoad(true, false, false, false, false);
            //Users.Instance = new Users();
            bool groupsCreated = VerifyAndCreateDefaultGroups();

            PagesStorageProvider p = new PagesStorageProvider();

            if (!ProviderLoader.IsDisabled(p.GetType().FullName))
            {
                p.Init(Host.Instance, "");
                Collectors.PagesProviderCollector.AddProvider(p);
                Log.LogEntry("Provider " + p.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Collectors.DisabledPagesProviderCollector.AddProvider(p);
                Log.LogEntry("Provider " + p.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
            }

            CacheProvider c = new CacheProvider();

            if (!ProviderLoader.IsDisabled(c.GetType().FullName))
            {
                c.Init(Host.Instance, "");
                Collectors.CacheProviderCollector.AddProvider(c);
                Log.LogEntry("Provider " + c.Information.Name + " loaded (Enabled)", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Collectors.DisabledCacheProviderCollector.AddProvider(c);
                Log.LogEntry("Provider " + c.Information.Name + " loaded (Disabled)", EntryType.General, Log.SystemUsername);
            }

            // Load all other providers
            ProviderLoader.FullLoad(false, true, true, true, true);

            if (groupsCreated)
            {
                // It is necessary to set default permissions for file management
                UserGroup administratorsGroup = Users.FindUserGroup(Settings.AdministratorsGroup);
                UserGroup anonymousGroup      = Users.FindUserGroup(Settings.AnonymousGroup);
                UserGroup usersGroup          = Users.FindUserGroup(Settings.UsersGroup);

                SetAdministratorsGroupDefaultPermissions(administratorsGroup);
                SetUsersGroupDefaultPermissions(usersGroup);
                SetAnonymousGroupDefaultPermissions(anonymousGroup);
            }

            // Init cache
            //Cache.Instance = new Cache(Collectors.CacheProviderCollector.GetProvider(Settings.DefaultCacheProvider));
            if (Collectors.CacheProviderCollector.GetProvider(Settings.DefaultCacheProvider) == null)
            {
                Log.LogEntry("Default Cache Provider was not loaded, backing to integrated provider", EntryType.Error, Log.SystemUsername);
                Settings.DefaultCacheProvider = typeof(CacheProvider).FullName;
                Collectors.TryEnable(Settings.DefaultCacheProvider);
            }

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

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

            System.Threading.ThreadPool.QueueUserWorkItem(state => {
                using (((WindowsIdentity)state).Impersonate()) {
                    if ((DateTime.Now - Settings.LastPageIndexing).TotalDays > 7)
                    {
                        Settings.LastPageIndexing = DateTime.Now;
                        System.Threading.Thread.Sleep(10000);
                        using (MemoryStream ms = new MemoryStream()) {
                            using (StreamWriter wr = new System.IO.StreamWriter(ms)) {
                                System.Web.HttpContext.Current = new System.Web.HttpContext(new System.Web.Hosting.SimpleWorkerRequest("", "", wr));
                                foreach (var provider in Collectors.PagesProviderCollector.AllProviders)
                                {
                                    if (!provider.ReadOnly)
                                    {
                                        Log.LogEntry("Starting automatic rebuilding index for provider: " + provider.Information.Name, EntryType.General, Log.SystemUsername);
                                        provider.RebuildIndex();
                                        Log.LogEntry("Finished automatic rebuilding index for provider: " + provider.Information.Name, EntryType.General, Log.SystemUsername);
                                    }
                                }
                            }
                        }

                        Pages.RebuildPageLinks(Pages.GetPages(null));
                        foreach (ScrewTurn.Wiki.PluginFramework.NamespaceInfo nspace in Pages.GetNamespaces())
                        {
                            Pages.RebuildPageLinks(Pages.GetPages(nspace));
                        }
                    }
                }
            }, WindowsIdentity.GetCurrent());
        }
Ejemplo n.º 30
0
        public void UpdateOutgoingLinksForRename_InvalidNewName(string n)
        {
            ISettingsStorageProviderV30 prov = GetProvider();

            prov.UpdateOutgoingLinksForRename("OldName", n);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Backups the specified settings provider.
        /// </summary>
        /// <param name="zipFileName">The zip file name where to store the backup.</param>
        /// <param name="settingsStorageProvider">The source settings provider.</param>
        /// <param name="knownNamespaces">The currently known page namespaces.</param>
        /// <param name="knownPlugins">The currently known plugins.</param>
        /// <returns><c>true</c> if the backup file has been succesfully created.</returns>
        public static bool BackupSettingsStorageProvider(string zipFileName, ISettingsStorageProviderV30 settingsStorageProvider, string[] knownNamespaces, string[] knownPlugins)
        {
            SettingsBackup settingsBackup = new SettingsBackup();

            // Settings
            settingsBackup.Settings = (Dictionary <string, string>)settingsStorageProvider.GetAllSettings();

            // Plugins Status and Configuration
            settingsBackup.PluginsFileNames = knownPlugins.ToList();
            Dictionary <string, bool>   pluginsStatus        = new Dictionary <string, bool>();
            Dictionary <string, string> pluginsConfiguration = new Dictionary <string, string>();

            foreach (string plugin in knownPlugins)
            {
                pluginsStatus[plugin]        = settingsStorageProvider.GetPluginStatus(plugin);
                pluginsConfiguration[plugin] = settingsStorageProvider.GetPluginConfiguration(plugin);
            }
            settingsBackup.PluginsStatus        = pluginsStatus;
            settingsBackup.PluginsConfiguration = pluginsConfiguration;

            // Metadata
            List <MetaData> metadataList = new List <MetaData>();

            // Meta-data (global)
            metadataList.Add(new MetaData()
            {
                Item    = MetaDataItem.AccountActivationMessage,
                Tag     = null,
                Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null)
            });
            metadataList.Add(new MetaData()
            {
                Item = MetaDataItem.PasswordResetProcedureMessage, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null)
            });
            metadataList.Add(new MetaData()
            {
                Item = MetaDataItem.LoginNotice, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.LoginNotice, null)
            });
            metadataList.Add(new MetaData()
            {
                Item = MetaDataItem.PageChangeMessage, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PageChangeMessage, null)
            });
            metadataList.Add(new MetaData()
            {
                Item = MetaDataItem.DiscussionChangeMessage, Tag = null, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null)
            });
            // Meta-data (ns-specific)
            List <string> namespacesToProcess = new List <string>();

            namespacesToProcess.Add("");
            namespacesToProcess.AddRange(knownNamespaces);
            foreach (string nspace in namespacesToProcess)
            {
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.EditNotice, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.EditNotice, nspace)
                });
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.Footer, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.Footer, nspace)
                });
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.Header, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.Header, nspace)
                });
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.HtmlHead, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.HtmlHead, nspace)
                });
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.PageFooter, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PageFooter, nspace)
                });
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.PageHeader, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.PageHeader, nspace)
                });
                metadataList.Add(new MetaData()
                {
                    Item = MetaDataItem.Sidebar, Tag = nspace, Content = settingsStorageProvider.GetMetaDataItem(MetaDataItem.Sidebar, nspace)
                });
            }
            settingsBackup.Metadata = metadataList;

            // RecentChanges
            settingsBackup.RecentChanges = settingsStorageProvider.GetRecentChanges().ToList();

            // OutgoingLinks
            settingsBackup.OutgoingLinks = (Dictionary <string, string[]>)settingsStorageProvider.GetAllOutgoingLinks();

            // ACLEntries
            AclEntry[] aclEntries = settingsStorageProvider.AclManager.RetrieveAllEntries();
            settingsBackup.AclEntries = new List <AclEntryBackup>(aclEntries.Length);
            foreach (AclEntry aclEntry in aclEntries)
            {
                settingsBackup.AclEntries.Add(new AclEntryBackup()
                {
                    Action   = aclEntry.Action,
                    Resource = aclEntry.Resource,
                    Subject  = aclEntry.Subject,
                    Value    = aclEntry.Value
                });
            }

            JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();

            javascriptSerializer.MaxJsonLength = javascriptSerializer.MaxJsonLength * 10;

            string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempDir);

            FileStream tempFile = File.Create(Path.Combine(tempDir, "Settings.json"));

            byte[] buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(settingsBackup));
            tempFile.Write(buffer, 0, buffer.Length);
            tempFile.Close();

            tempFile = File.Create(Path.Combine(tempDir, "Version.json"));
            buffer   = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(generateVersionFile("Settings")));
            tempFile.Write(buffer, 0, buffer.Length);
            tempFile.Close();

            using (ZipFile zipFile = new ZipFile()) {
                zipFile.AddDirectory(tempDir, "");
                zipFile.Save(zipFileName);
            }
            Directory.Delete(tempDir, true);

            return(true);
        }