/// <summary> /// Adds a new content template. /// </summary> /// <param name="name">The name of the template.</param> /// <param name="content">The content of the template.</param> /// <param name="provider">The target provider (<c>null</c> for the default provider).</param> /// <returns><c>true</c> if the template is added, <c>false</c> otherwise.</returns> public static bool AddTemplate(string name, string content, IPagesStorageProviderV30 provider) { if(Find(name) != null) return false; if(provider == null) provider = Collectors.PagesProviderCollector.GetProvider(Settings.DefaultPagesProvider); ContentTemplate result = provider.AddContentTemplate(name, content); if(result != null) Log.LogEntry("Content Template " + name + " created", EntryType.General, Log.SystemUsername); else Log.LogEntry("Creation failed for Content Template " + name, EntryType.Error, Log.SystemUsername); return result != null; }
/// <summary> /// Adds a new Navigation Path. /// </summary> /// <param name="nspace">The target namespace (<c>null</c> for the root).</param> /// <param name="name">The Name.</param> /// <param name="pages">The Pages.</param> /// <param name="provider">The Provider to use for the new Navigation Path, or <c>null</c> for the default provider.</param> /// <returns>True if the Path is added successfully.</returns> public static bool AddNavigationPath(NamespaceInfo nspace, string name, List<PageInfo> pages, IPagesStorageProviderV30 provider) { string namespaceName = nspace != null ? nspace.Name : null; string fullName = NameTools.GetFullName(namespaceName, name); if(Exists(fullName)) return false; if(provider == null) provider = Collectors.PagesProviderCollector.GetProvider(Settings.DefaultPagesProvider); NavigationPath newPath = provider.AddNavigationPath(namespaceName, name, pages.ToArray()); if(newPath != null) Log.LogEntry("Navigation Path " + fullName + " added", EntryType.General, Log.SystemUsername); else Log.LogEntry("Creation failed for Navigation Path " + fullName, EntryType.Error, Log.SystemUsername); return newPath != null; }
/// <summary> /// Creates a new Snippet. /// </summary> /// <param name="name">The name of the Snippet.</param> /// <param name="content">The content of the Snippet.</param> /// <param name="provider">The Provider to use to store the Snippet (<c>null</c> for the default provider).</param> /// <returns>True if the Snippets has been addedd successfully.</returns> public static bool AddSnippet(string name, string content, IPagesStorageProviderV30 provider) { if(Find(name) != null) return false; if(provider == null) provider = Collectors.PagesProviderCollector.GetProvider(Settings.DefaultPagesProvider); Snippet newSnippet = provider.AddSnippet(name, content); if(newSnippet != null) { Log.LogEntry("Snippet " + name + " created", EntryType.General, Log.SystemUsername); Content.ClearPseudoCache(); Content.InvalidateAllPages(); } else Log.LogEntry("Creation failed for Snippet " + name, EntryType.Error, Log.SystemUsername); return newSnippet != null; }
/// <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; }
/// <summary> /// Initializes a new instance of the <b>PageInfo</b> class. /// </summary> /// <param name="fullName">The Full Name of the Page.</param> /// <param name="provider">The Pages Storage Provider that manages this Page.</param> /// <param name="creationDateTime">The creation Date/Time.</param> /// <param name="file">The relative path of the file used for data storage.</param> public LocalPageInfo(string fullName, IPagesStorageProviderV30 provider, DateTime creationDateTime, string file) : base(fullName, provider, creationDateTime) { this.file = file; }
private void DoChecksFor_RebuildIndex_ManyPages(IPagesStorageProviderV30 prov) { int docCount, wordCount, matchCount; long size; prov.GetIndexStats(out docCount, out wordCount, out matchCount, out size); Assert.AreEqual(PagesContent.Length, docCount, "Wrong document count"); Assert.IsTrue(wordCount > 0, "Wrong word count"); Assert.IsTrue(matchCount > 0, "Wrong match count"); Assert.IsTrue(size > 0, "Wrong size"); SearchResultCollection results = prov.PerformSearch(new SearchParameters("lorem")); Assert.IsTrue(results.Count > 0, "No results returned"); }
/// <summary> /// Initializes a new instance of the <see cref="T:IndexRow" /> class. /// </summary> /// <param name="provider">The original provider.</param> public IndexRow(IPagesStorageProviderV30 provider) { this.provider = provider.Information.Name; providerType = provider.GetType().FullName; int docCount, wordCount, matchCount; long size; provider.GetIndexStats(out docCount, out wordCount, out matchCount, out size); this.documents = docCount.ToString(); this.words = wordCount.ToString(); this.occurrences = matchCount.ToString(); this.size = Tools.BytesToString(size); this.isOk = !provider.IsIndexCorrupted; }
/// <summary> /// Backups the files storage provider. /// </summary> /// <param name="zipFileName">The zip file name where to store the backup.</param> /// <param name="filesStorageProvider">The files storage provider.</param> /// <param name="pagesStorageProviders">The pages storage providers.</param> /// <returns><c>true</c> if the backup file has been succesfully created.</returns> public static bool BackupFilesStorageProvider(string zipFileName, IFilesStorageProviderV30 filesStorageProvider, IPagesStorageProviderV30[] pagesStorageProviders) { JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer(); javascriptSerializer.MaxJsonLength = javascriptSerializer.MaxJsonLength * 10; string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempDir); DirectoryBackup directoriesBackup = BackupDirectory(filesStorageProvider, tempDir, null); FileStream tempFile = File.Create(Path.Combine(tempDir, "Files.json")); byte[] buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(directoriesBackup)); tempFile.Write(buffer, 0, buffer.Length); tempFile.Close(); // Backup Pages Attachments string[] pagesWithAttachment = filesStorageProvider.GetPagesWithAttachments(); foreach(string pageWithAttachment in pagesWithAttachment) { PageInfo pageInfo = FindPageInfo(pageWithAttachment, pagesStorageProviders); if(pageInfo != null) { string[] attachments = filesStorageProvider.ListPageAttachments(pageInfo); List<AttachmentBackup> attachmentsBackup = new List<AttachmentBackup>(attachments.Length); foreach(string attachment in attachments) { FileDetails attachmentDetails = filesStorageProvider.GetPageAttachmentDetails(pageInfo, attachment); attachmentsBackup.Add(new AttachmentBackup() { Name = attachment, PageFullName = pageWithAttachment, LastModified = attachmentDetails.LastModified, Size = attachmentDetails.Size }); using(MemoryStream stream = new MemoryStream()) { filesStorageProvider.RetrievePageAttachment(pageInfo, attachment, stream, false); stream.Seek(0, SeekOrigin.Begin); byte[] tempBuffer = new byte[stream.Length]; stream.Read(tempBuffer, 0, (int)stream.Length); DirectoryInfo dir = Directory.CreateDirectory(Path.Combine(tempDir, Path.Combine("__attachments", pageInfo.FullName))); tempFile = File.Create(Path.Combine(dir.FullName, attachment)); tempFile.Write(tempBuffer, 0, tempBuffer.Length); tempFile.Close(); } } tempFile = File.Create(Path.Combine(tempDir, Path.Combine("__attachments", Path.Combine(pageInfo.FullName, "Attachments.json")))); buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(attachmentsBackup)); tempFile.Write(buffer, 0, buffer.Length); tempFile.Close(); } } tempFile = File.Create(Path.Combine(tempDir, "Version.json")); buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(generateVersionFile("Files"))); 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; }
private static PageInfo FindPageInfo(string pageWithAttachment, IPagesStorageProviderV30[] pagesStorageProviders) { foreach(IPagesStorageProviderV30 pagesStorageProvider in pagesStorageProviders) { PageInfo pageInfo = pagesStorageProvider.GetPage(pageWithAttachment); if(pageInfo != null) return pageInfo; } return null; }
/// <summary> /// Backups the pages storage provider. /// </summary> /// <param name="zipFileName">The zip file name where to store the backup.</param> /// <param name="pagesStorageProvider">The pages storage provider.</param> /// <returns><c>true</c> if the backup file has been succesfully created.</returns> public static bool BackupPagesStorageProvider(string zipFileName, IPagesStorageProviderV30 pagesStorageProvider) { JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer(); javascriptSerializer.MaxJsonLength = javascriptSerializer.MaxJsonLength * 10; string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempDir); List<NamespaceInfo> nspaces = new List<NamespaceInfo>(pagesStorageProvider.GetNamespaces()); nspaces.Add(null); List<NamespaceBackup> namespaceBackupList = new List<NamespaceBackup>(nspaces.Count); foreach(NamespaceInfo nspace in nspaces) { // Backup categories CategoryInfo[] categories = pagesStorageProvider.GetCategories(nspace); List<CategoryBackup> categoriesBackup = new List<CategoryBackup>(categories.Length); foreach(CategoryInfo category in categories) { // Add this category to the categoriesBackup list categoriesBackup.Add(new CategoryBackup() { FullName = category.FullName, Pages = category.Pages }); } // Backup NavigationPaths NavigationPath[] navigationPaths = pagesStorageProvider.GetNavigationPaths(nspace); List<NavigationPathBackup> navigationPathsBackup = new List<NavigationPathBackup>(navigationPaths.Length); foreach(NavigationPath navigationPath in navigationPaths) { navigationPathsBackup.Add(new NavigationPathBackup() { FullName = navigationPath.FullName, Pages = navigationPath.Pages }); } // Add this namespace to the namespaceBackup list namespaceBackupList.Add(new NamespaceBackup() { Name = nspace == null ? "" : nspace.Name, DefaultPageFullName = nspace == null ? "" : nspace.DefaultPage.FullName, Categories = categoriesBackup, NavigationPaths = navigationPathsBackup }); // Backup pages (one json file for each page containing a maximum of 100 revisions) PageInfo[] pages = pagesStorageProvider.GetPages(nspace); foreach(PageInfo page in pages) { PageContent pageContent = pagesStorageProvider.GetContent(page); PageBackup pageBackup = new PageBackup(); pageBackup.FullName = page.FullName; pageBackup.CreationDateTime = page.CreationDateTime; pageBackup.LastModified = pageContent.LastModified; pageBackup.Content = pageContent.Content; pageBackup.Comment = pageContent.Comment; pageBackup.Description = pageContent.Description; pageBackup.Keywords = pageContent.Keywords; pageBackup.Title = pageContent.Title; pageBackup.User = pageContent.User; pageBackup.LinkedPages = pageContent.LinkedPages; pageBackup.Categories = (from c in pagesStorageProvider.GetCategoriesForPage(page) select c.FullName).ToArray(); // Backup the 100 most recent versions of the page List<PageRevisionBackup> pageContentBackupList = new List<PageRevisionBackup>(); int[] revisions = pagesStorageProvider.GetBackups(page); for(int i = revisions.Length - 1; i > revisions.Length - 100 && i >= 0; i--) { PageContent pageRevision = pagesStorageProvider.GetBackupContent(page, revisions[i]); PageRevisionBackup pageContentBackup = new PageRevisionBackup() { Revision = revisions[i], Content = pageRevision.Content, Comment = pageRevision.Comment, Description = pageRevision.Description, Keywords = pageRevision.Keywords, Title = pageRevision.Title, User = pageRevision.User, LastModified = pageRevision.LastModified }; pageContentBackupList.Add(pageContentBackup); } pageBackup.Revisions = pageContentBackupList; // Backup draft of the page PageContent draft = pagesStorageProvider.GetDraft(page); if(draft != null) { pageBackup.Draft = new PageRevisionBackup() { Content = draft.Content, Comment = draft.Comment, Description = draft.Description, Keywords = draft.Keywords, Title = draft.Title, User = draft.User, LastModified = draft.LastModified }; } // Backup all messages of the page List<MessageBackup> messageBackupList = new List<MessageBackup>(); foreach(Message message in pagesStorageProvider.GetMessages(page)) { messageBackupList.Add(BackupMessage(message)); } pageBackup.Messages = messageBackupList; FileStream tempFile = File.Create(Path.Combine(tempDir, page.FullName + ".json")); byte[] buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(pageBackup)); tempFile.Write(buffer, 0, buffer.Length); tempFile.Close(); } } FileStream tempNamespacesFile = File.Create(Path.Combine(tempDir, "Namespaces.json")); byte[] namespacesBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(namespaceBackupList)); tempNamespacesFile.Write(namespacesBuffer, 0, namespacesBuffer.Length); tempNamespacesFile.Close(); // Backup content templates ContentTemplate[] contentTemplates = pagesStorageProvider.GetContentTemplates(); List<ContentTemplateBackup> contentTemplatesBackup = new List<ContentTemplateBackup>(contentTemplates.Length); foreach(ContentTemplate contentTemplate in contentTemplates) { contentTemplatesBackup.Add(new ContentTemplateBackup() { Name = contentTemplate.Name, Content = contentTemplate.Content }); } FileStream tempContentTemplatesFile = File.Create(Path.Combine(tempDir, "ContentTemplates.json")); byte[] contentTemplateBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(contentTemplatesBackup)); tempContentTemplatesFile.Write(contentTemplateBuffer, 0, contentTemplateBuffer.Length); tempContentTemplatesFile.Close(); // Backup Snippets Snippet[] snippets = pagesStorageProvider.GetSnippets(); List<SnippetBackup> snippetsBackup = new List<SnippetBackup>(snippets.Length); foreach(Snippet snippet in snippets) { snippetsBackup.Add(new SnippetBackup() { Name = snippet.Name, Content = snippet.Content }); } FileStream tempSnippetsFile = File.Create(Path.Combine(tempDir, "Snippets.json")); byte[] snippetBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(snippetsBackup)); tempSnippetsFile.Write(snippetBuffer, 0, snippetBuffer.Length); tempSnippetsFile.Close(); FileStream tempVersionFile = File.Create(Path.Combine(tempDir, "Version.json")); byte[] versionBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(generateVersionFile("Pages"))); tempVersionFile.Write(versionBuffer, 0, versionBuffer.Length); tempVersionFile.Close(); using(ZipFile zipFile = new ZipFile()) { zipFile.AddDirectory(tempDir, ""); zipFile.Save(zipFileName); } Directory.Delete(tempDir, true); return true; }
/// <summary> /// Backups the pages storage provider. /// </summary> /// <param name="zipFileName">The zip file name where to store the backup.</param> /// <param name="pagesStorageProvider">The pages storage provider.</param> /// <returns><c>true</c> if the backup file has been succesfully created.</returns> public static bool BackupPagesStorageProvider(string zipFileName, IPagesStorageProviderV30 pagesStorageProvider) { var javascriptSerializer = new JavaScriptSerializer(); javascriptSerializer.MaxJsonLength = javascriptSerializer.MaxJsonLength * 10; var tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempDir); var nspaces = new List <NamespaceInfo>(pagesStorageProvider.GetNamespaces()); nspaces.Add(null); var namespaceBackupList = new List <NamespaceBackup>(nspaces.Count); foreach (var nspace in nspaces) { // Backup categories var categories = pagesStorageProvider.GetCategories(nspace); var categoriesBackup = new List <CategoryBackup>(categories.Count); foreach (var category in categories) { // Add this category to the categoriesBackup list categoriesBackup.Add(new CategoryBackup { FullName = category.FullName, Pages = category.Pages }); } // Backup NavigationPaths var navigationPaths = pagesStorageProvider.GetNavigationPaths(nspace); var navigationPathsBackup = new List <NavigationPathBackup>(navigationPaths.Count); foreach (var navigationPath in navigationPaths) { navigationPathsBackup.Add(new NavigationPathBackup { FullName = navigationPath.FullName, Pages = navigationPath.Pages }); } // Add this namespace to the namespaceBackup list namespaceBackupList.Add(new NamespaceBackup { Name = nspace == null ? "" : nspace.Name, DefaultPageFullName = nspace == null ? "" : nspace.DefaultPage.FullName, Categories = categoriesBackup, NavigationPaths = navigationPathsBackup }); // Backup pages (one json file for each page containing a maximum of 100 revisions) var pages = pagesStorageProvider.GetPages(nspace); foreach (var page in pages) { var pageContent = pagesStorageProvider.GetContent(page); var pageBackup = new PageBackup(); pageBackup.FullName = page.FullName; pageBackup.CreationDateTime = page.CreationDateTime; pageBackup.LastModified = pageContent.LastModified; pageBackup.Content = pageContent.Content; pageBackup.Comment = pageContent.Comment; pageBackup.Description = pageContent.Description; pageBackup.Keywords = pageContent.Keywords; pageBackup.Title = pageContent.Title; pageBackup.User = pageContent.User; pageBackup.LinkedPages = pageContent.LinkedPages; pageBackup.Categories = (from c in pagesStorageProvider.GetCategoriesForPage(page) select c.FullName).ToArray(); // Backup the 100 most recent versions of the page var pageContentBackupList = new List <PageRevisionBackup>(); var revisions = pagesStorageProvider.GetBackups(page); for (var i = revisions.Length - 1; i > revisions.Length - 100 && i >= 0; i--) { var pageRevision = pagesStorageProvider.GetBackupContent(page, revisions[i]); var pageContentBackup = new PageRevisionBackup { Revision = revisions[i], Content = pageRevision.Content, Comment = pageRevision.Comment, Description = pageRevision.Description, Keywords = pageRevision.Keywords, Title = pageRevision.Title, User = pageRevision.User, LastModified = pageRevision.LastModified }; pageContentBackupList.Add(pageContentBackup); } pageBackup.Revisions = pageContentBackupList; // Backup draft of the page var draft = pagesStorageProvider.GetDraft(page); if (draft != null) { pageBackup.Draft = new PageRevisionBackup { Content = draft.Content, Comment = draft.Comment, Description = draft.Description, Keywords = draft.Keywords, Title = draft.Title, User = draft.User, LastModified = draft.LastModified }; } // Backup all messages of the page var messageBackupList = new List <MessageBackup>(); foreach (var message in pagesStorageProvider.GetMessages(page)) { messageBackupList.Add(BackupMessage(message)); } pageBackup.Messages = messageBackupList; var tempFile = File.Create(Path.Combine(tempDir, page.FullName + ".json")); var buffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(pageBackup)); tempFile.Write(buffer, 0, buffer.Length); tempFile.Close(); } } var tempNamespacesFile = File.Create(Path.Combine(tempDir, "Namespaces.json")); var namespacesBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(namespaceBackupList)); tempNamespacesFile.Write(namespacesBuffer, 0, namespacesBuffer.Length); tempNamespacesFile.Close(); // Backup content templates var contentTemplates = pagesStorageProvider.GetContentTemplates(); var contentTemplatesBackup = new List <ContentTemplateBackup>(contentTemplates.Length); foreach (var contentTemplate in contentTemplates) { contentTemplatesBackup.Add(new ContentTemplateBackup { Name = contentTemplate.Name, Content = contentTemplate.Content }); } var tempContentTemplatesFile = File.Create(Path.Combine(tempDir, "ContentTemplates.json")); var contentTemplateBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(contentTemplatesBackup)); tempContentTemplatesFile.Write(contentTemplateBuffer, 0, contentTemplateBuffer.Length); tempContentTemplatesFile.Close(); // Backup Snippets var snippets = pagesStorageProvider.GetSnippets(); var snippetsBackup = new List <SnippetBackup>(snippets.Count); foreach (var snippet in snippets) { snippetsBackup.Add(new SnippetBackup { Name = snippet.Name, Content = snippet.Content }); } var tempSnippetsFile = File.Create(Path.Combine(tempDir, "Snippets.json")); var snippetBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(snippetsBackup)); tempSnippetsFile.Write(snippetBuffer, 0, snippetBuffer.Length); tempSnippetsFile.Close(); var tempVersionFile = File.Create(Path.Combine(tempDir, "Version.json")); var versionBuffer = Encoding.Unicode.GetBytes(javascriptSerializer.Serialize(generateVersionFile("Pages"))); tempVersionFile.Write(versionBuffer, 0, versionBuffer.Length); tempVersionFile.Close(); using (var zipFile = new ZipFile()) { zipFile.AddDirectory(tempDir, ""); zipFile.Save(zipFileName); } Directory.Delete(tempDir, true); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="T:PageInfo" /> class. /// </summary> /// <param name="fullName">The Full Name of the Page.</param> /// <param name="provider">The Pages Storage Provider that manages this Page.</param> /// <param name="creationDateTime">The Page creation Date/Time.</param> public PageInfo(string fullName, IPagesStorageProviderV30 provider, DateTime creationDateTime) { NameTools.ExpandFullName(fullName, out nspace, out name); Provider = provider; CreationDateTime = creationDateTime; }
public void MigratePagesStorageProviderData() { MockRepository mocks = new MockRepository(); IPagesStorageProviderV30 source = mocks.StrictMock <IPagesStorageProviderV30>(); IPagesStorageProviderV30 destination = mocks.StrictMock <IPagesStorageProviderV30>(); // Setup SOURCE ------------------------- // Setup snippets Snippet s1 = new Snippet("S1", "Blah1", source); Snippet s2 = new Snippet("S2", "Blah2", source); Expect.Call(source.GetSnippets()).Return(new Snippet[] { s1, s2 }); // Setup content templates ContentTemplate ct1 = new ContentTemplate("CT1", "Template 1", source); ContentTemplate ct2 = new ContentTemplate("CT2", "Template 2", source); Expect.Call(source.GetContentTemplates()).Return(new ContentTemplate[] { ct1, ct2 }); // Setup namespaces NamespaceInfo ns1 = new NamespaceInfo("NS1", source, null); NamespaceInfo ns2 = new NamespaceInfo("NS2", source, null); Expect.Call(source.GetNamespaces()).Return(new NamespaceInfo[] { ns1, ns2 }); // Setup pages PageInfo p1 = new PageInfo("Page", source, DateTime.Now); PageInfo p2 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page"), source, DateTime.Now); PageInfo p3 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page1"), source, DateTime.Now); Expect.Call(source.GetPages(null)).Return(new PageInfo[] { p1 }); Expect.Call(source.GetPages(ns1)).Return(new PageInfo[] { p2, p3 }); Expect.Call(source.GetPages(ns2)).Return(new PageInfo[0]); // Set default page for NS1 ns1.DefaultPage = p2; // Setup categories/bindings CategoryInfo c1 = new CategoryInfo("Cat", source); c1.Pages = new string[] { p1.FullName }; CategoryInfo c2 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat"), source); c2.Pages = new string[] { p2.FullName }; CategoryInfo c3 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat1"), source); c3.Pages = new string[0]; Expect.Call(source.GetCategories(null)).Return(new CategoryInfo[] { c1 }); Expect.Call(source.GetCategories(ns1)).Return(new CategoryInfo[] { c2, c3 }); Expect.Call(source.GetCategories(ns2)).Return(new CategoryInfo[0]); // Setup drafts PageContent d1 = new PageContent(p1, "Draft", "NUnit", DateTime.Now, "Comm", "Cont", new string[] { "k1", "k2" }, "Descr"); Expect.Call(source.GetDraft(p1)).Return(d1); Expect.Call(source.GetDraft(p2)).Return(null); Expect.Call(source.GetDraft(p3)).Return(null); // Setup content PageContent ctn1 = new PageContent(p1, "Title1", "User1", DateTime.Now, "Comm1", "Cont1", null, "Descr1"); PageContent ctn2 = new PageContent(p2, "Title2", "User2", DateTime.Now, "Comm2", "Cont2", null, "Descr2"); PageContent ctn3 = new PageContent(p3, "Title3", "User3", DateTime.Now, "Comm3", "Cont3", null, "Descr3"); Expect.Call(source.GetContent(p1)).Return(ctn1); Expect.Call(source.GetContent(p2)).Return(ctn2); Expect.Call(source.GetContent(p3)).Return(ctn3); // Setup backups Expect.Call(source.GetBackups(p1)).Return(new int[] { 0, 1 }); Expect.Call(source.GetBackups(p2)).Return(new int[] { 0 }); Expect.Call(source.GetBackups(p3)).Return(new int[0]); PageContent bak1_0 = new PageContent(p1, "K1_0", "U1_0", DateTime.Now, "", "Cont", null, null); PageContent bak1_1 = new PageContent(p1, "K1_1", "U1_1", DateTime.Now, "", "Cont", null, null); PageContent bak2_0 = new PageContent(p2, "K2_0", "U2_0", DateTime.Now, "", "Cont", null, null); Expect.Call(source.GetBackupContent(p1, 0)).Return(bak1_0); Expect.Call(source.GetBackupContent(p1, 1)).Return(bak1_1); Expect.Call(source.GetBackupContent(p2, 0)).Return(bak2_0); // Messages Message m1 = new Message(1, "User1", "Subject1", DateTime.Now, "Body1"); m1.Replies = new Message[] { new Message(2, "User2", "Subject2", DateTime.Now, "Body2") }; Message[] p1m = new Message[] { m1 }; Message[] p2m = new Message[0]; Message[] p3m = new Message[0]; Expect.Call(source.GetMessages(p1)).Return(p1m); Expect.Call(source.GetMessages(p2)).Return(p2m); Expect.Call(source.GetMessages(p3)).Return(p3m); // Setup navigation paths NavigationPath n1 = new NavigationPath("N1", source); n1.Pages = new string[] { p1.FullName }; NavigationPath n2 = new NavigationPath(NameTools.GetFullName(ns1.Name, "N1"), source); n2.Pages = new string[] { p2.FullName, p3.FullName }; Expect.Call(source.GetNavigationPaths(null)).Return(new NavigationPath[] { n1 }); Expect.Call(source.GetNavigationPaths(ns1)).Return(new NavigationPath[] { n2 }); Expect.Call(source.GetNavigationPaths(ns2)).Return(new NavigationPath[0]); // Setup DESTINATION -------------------------- // Snippets Expect.Call(destination.AddSnippet(s1.Name, s1.Content)).Return(new Snippet(s1.Name, s1.Content, destination)); Expect.Call(source.RemoveSnippet(s1.Name)).Return(true); Expect.Call(destination.AddSnippet(s2.Name, s2.Content)).Return(new Snippet(s2.Name, s2.Content, destination)); Expect.Call(source.RemoveSnippet(s2.Name)).Return(true); // Content templates Expect.Call(destination.AddContentTemplate(ct1.Name, ct1.Content)).Return(new ContentTemplate(ct1.Name, ct1.Name, destination)); Expect.Call(source.RemoveContentTemplate(ct1.Name)).Return(true); Expect.Call(destination.AddContentTemplate(ct2.Name, ct2.Content)).Return(new ContentTemplate(ct2.Name, ct2.Name, destination)); Expect.Call(source.RemoveContentTemplate(ct2.Name)).Return(true); // Namespaces NamespaceInfo ns1Out = new NamespaceInfo(ns1.Name, destination, null); NamespaceInfo ns2Out = new NamespaceInfo(ns2.Name, destination, null); Expect.Call(destination.AddNamespace(ns1.Name)).Return(ns1Out); Expect.Call(source.RemoveNamespace(ns1)).Return(true); Expect.Call(destination.AddNamespace(ns2.Name)).Return(ns2Out); Expect.Call(source.RemoveNamespace(ns2)).Return(true); // Pages/drafts/content/backups/messages PageInfo p1Out = new PageInfo(p1.FullName, destination, p1.CreationDateTime); Expect.Call(destination.AddPage(null, p1.FullName, p1.CreationDateTime)).Return(p1Out); Expect.Call(destination.ModifyPage(p1Out, ctn1.Title, ctn1.User, ctn1.LastModified, ctn1.Comment, ctn1.Content, ctn1.Keywords, ctn1.Description, SaveMode.Normal)).Return(true); Expect.Call(destination.ModifyPage(p1Out, d1.Title, d1.User, d1.LastModified, d1.Comment, d1.Content, d1.Keywords, d1.Description, SaveMode.Draft)).Return(true); Expect.Call(destination.SetBackupContent(bak1_0, 0)).Return(true); Expect.Call(destination.SetBackupContent(bak1_1, 1)).Return(true); Expect.Call(destination.BulkStoreMessages(p1Out, p1m)).Return(true); Expect.Call(source.RemovePage(p1)).Return(true); PageInfo p2Out = new PageInfo(p2.FullName, destination, p2.CreationDateTime); Expect.Call(destination.AddPage(NameTools.GetNamespace(p2.FullName), NameTools.GetLocalName(p2.FullName), p2.CreationDateTime)).Return(p2Out); Expect.Call(destination.ModifyPage(p2Out, ctn2.Title, ctn2.User, ctn2.LastModified, ctn2.Comment, ctn2.Content, ctn2.Keywords, ctn2.Description, SaveMode.Normal)).Return(true); Expect.Call(destination.SetBackupContent(bak2_0, 0)).Return(true); Expect.Call(destination.BulkStoreMessages(p2Out, p2m)).Return(true); Expect.Call(source.RemovePage(p2)).Return(true); PageInfo p3Out = new PageInfo(p3.FullName, destination, p3.CreationDateTime); Expect.Call(destination.AddPage(NameTools.GetNamespace(p3.FullName), NameTools.GetLocalName(p3.FullName), p3.CreationDateTime)).Return(p3Out); Expect.Call(destination.ModifyPage(p3Out, ctn3.Title, ctn3.User, ctn3.LastModified, ctn3.Comment, ctn3.Content, ctn3.Keywords, ctn3.Description, SaveMode.Normal)).Return(true); Expect.Call(destination.BulkStoreMessages(p3Out, p3m)).Return(true); Expect.Call(source.RemovePage(p3)).Return(true); // Categories/bindings CategoryInfo c1Out = new CategoryInfo(c1.FullName, destination); CategoryInfo c2Out = new CategoryInfo(c2.FullName, destination); CategoryInfo c3Out = new CategoryInfo(c3.FullName, destination); Expect.Call(destination.AddCategory(null, c1.FullName)).Return(c1Out); Expect.Call(destination.AddCategory(NameTools.GetNamespace(c2.FullName), NameTools.GetLocalName(c2.FullName))).Return(c2Out); Expect.Call(destination.AddCategory(NameTools.GetNamespace(c3.FullName), NameTools.GetLocalName(c3.FullName))).Return(c3Out); Expect.Call(destination.RebindPage(p1Out, new string[] { c1.FullName })).Return(true); Expect.Call(destination.RebindPage(p2Out, new string[] { c2.FullName })).Return(true); Expect.Call(destination.RebindPage(p3Out, new string[0])).Return(true); Expect.Call(source.RemoveCategory(c1)).Return(true); Expect.Call(source.RemoveCategory(c2)).Return(true); Expect.Call(source.RemoveCategory(c3)).Return(true); // Navigation paths NavigationPath n1Out = new NavigationPath(n1.FullName, destination); n1Out.Pages = n1.Pages; NavigationPath n2Out = new NavigationPath(n2.FullName, destination); n2Out.Pages = n2.Pages; Expect.Call(destination.AddNavigationPath(null, n1.FullName, new PageInfo[] { p1 })).Return(n1Out).Constraints( RMC.Is.Null(), RMC.Is.Equal(n1.FullName), RMC.Is.Matching <PageInfo[]>(delegate(PageInfo[] array) { return(array[0].FullName == p1.FullName); })); Expect.Call(destination.AddNavigationPath(NameTools.GetNamespace(n2.FullName), NameTools.GetLocalName(n2.FullName), new PageInfo[] { p2, p3 })).Return(n2Out).Constraints( RMC.Is.Equal(NameTools.GetNamespace(n2.FullName)), RMC.Is.Equal(NameTools.GetLocalName(n2.FullName)), RMC.Is.Matching <PageInfo[]>(delegate(PageInfo[] array) { return(array[0].FullName == p2.FullName && array[1].FullName == p3.FullName); })); Expect.Call(source.RemoveNavigationPath(n1)).Return(true); Expect.Call(source.RemoveNavigationPath(n2)).Return(true); Expect.Call(destination.SetNamespaceDefaultPage(ns1Out, p2Out)).Return(ns1Out); Expect.Call(destination.SetNamespaceDefaultPage(ns2Out, null)).Return(ns2Out); // Used for navigation paths Expect.Call(destination.GetPages(null)).Return(new PageInfo[] { p1Out }); Expect.Call(destination.GetPages(ns1Out)).Return(new PageInfo[] { p2Out, p3Out }); Expect.Call(destination.GetPages(ns2Out)).Return(new PageInfo[0]); mocks.Replay(source); mocks.Replay(destination); DataMigrator.MigratePagesStorageProviderData(source, destination); mocks.Verify(source); mocks.Verify(destination); }
/// <summary> /// Loads Providers from an assembly. /// </summary> /// <param name="assembly">The path of the Assembly to load the Providers from.</param> /// <param name="users">The Users Providers.</param> /// <param name="files">The Files Providers.</param> /// <param name="pages">The Pages Providers.</param> /// <param name="formatters">The Formatter Providers.</param> /// <param name="cache">The Cache Providers.</param> /// <remarks>The Components returned are <b>not</b> initialized.</remarks> public static void LoadFrom(string assembly, out IUsersStorageProviderV30[] users, out IPagesStorageProviderV30[] pages, out IFilesStorageProviderV30[] files, out IFormatterProviderV30[] formatters, out ICacheProviderV30[] cache) { Assembly asm = null; try { //asm = Assembly.LoadFile(assembly); // This way the DLL is not locked and can be deleted at runtime asm = Assembly.Load(LoadAssemblyFromProvider(Path.GetFileName(assembly))); } catch { files = new IFilesStorageProviderV30[0]; users = new IUsersStorageProviderV30[0]; pages = new IPagesStorageProviderV30[0]; formatters = new IFormatterProviderV30[0]; cache = new ICacheProviderV30[0]; Log.LogEntry("Unable to load assembly " + Path.GetFileNameWithoutExtension(assembly), EntryType.Error, Log.SystemUsername); return; } Type[] types = null; try { types = asm.GetTypes(); } catch (ReflectionTypeLoadException) { files = new IFilesStorageProviderV30[0]; users = new IUsersStorageProviderV30[0]; pages = new IPagesStorageProviderV30[0]; formatters = new IFormatterProviderV30[0]; cache = new ICacheProviderV30[0]; Log.LogEntry("Unable to load providers from (probably v2) assembly " + Path.GetFileNameWithoutExtension(assembly), EntryType.Error, Log.SystemUsername); return; } List <IUsersStorageProviderV30> urs = new List <IUsersStorageProviderV30>(); List <IPagesStorageProviderV30> pgs = new List <IPagesStorageProviderV30>(); List <IFilesStorageProviderV30> fls = new List <IFilesStorageProviderV30>(); List <IFormatterProviderV30> frs = new List <IFormatterProviderV30>(); List <ICacheProviderV30> che = new List <ICacheProviderV30>(); Type[] interfaces; for (int i = 0; i < types.Length; i++) { // Avoid to load abstract classes as they cannot be instantiated if (types[i].IsAbstract) { continue; } interfaces = types[i].GetInterfaces(); foreach (Type iface in interfaces) { if (iface == typeof(IUsersStorageProviderV30)) { IUsersStorageProviderV30 tmpu = CreateInstance <IUsersStorageProviderV30>(asm, types[i]); if (tmpu != null) { urs.Add(tmpu); Collectors.FileNames[tmpu.GetType().FullName] = assembly; } } if (iface == typeof(IPagesStorageProviderV30)) { IPagesStorageProviderV30 tmpp = CreateInstance <IPagesStorageProviderV30>(asm, types[i]); if (tmpp != null) { pgs.Add(tmpp); Collectors.FileNames[tmpp.GetType().FullName] = assembly; } } if (iface == typeof(IFilesStorageProviderV30)) { IFilesStorageProviderV30 tmpd = CreateInstance <IFilesStorageProviderV30>(asm, types[i]); if (tmpd != null) { fls.Add(tmpd); Collectors.FileNames[tmpd.GetType().FullName] = assembly; } } if (iface == typeof(IFormatterProviderV30)) { IFormatterProviderV30 tmpf = CreateInstance <IFormatterProviderV30>(asm, types[i]); if (tmpf != null) { frs.Add(tmpf); Collectors.FileNames[tmpf.GetType().FullName] = assembly; } } if (iface == typeof(ICacheProviderV30)) { ICacheProviderV30 tmpc = CreateInstance <ICacheProviderV30>(asm, types[i]); if (tmpc != null) { che.Add(tmpc); Collectors.FileNames[tmpc.GetType().FullName] = assembly; } } } } users = urs.ToArray(); pages = pgs.ToArray(); files = fls.ToArray(); formatters = frs.ToArray(); cache = che.ToArray(); }
/// <summary> /// Initializes a new instance of the <see cref="T:CategoryInfo" /> class. /// </summary> /// <param name="fullName">The Full Name of the Category.</param> /// <param name="provider">The Storage that manages the category.</param> public CategoryInfo(string fullName, IPagesStorageProviderV30 provider) { NameTools.ExpandFullName(fullName, out nspace, out name); this.provider = provider; }
/// <summary> /// Initializes a new instance of the <b>NavigationPath</b> class. /// </summary> /// <param name="fullName">The Full Name of the Navigation Path.</param> /// <param name="provider">The Provider</param> public NavigationPath(string fullName, IPagesStorageProviderV30 provider) { NameTools.ExpandFullName(fullName, out nspace, out name); this.provider = provider; pages = new string[0]; }