private static void InitializeData() { TextContent textContent1 = new TextContent(); textContent1.FolderName = folder.FullName; textContent1.SchemaName = schema.Name; textContent1.Repository = repository.Name; textContent1.UtcCreationDate = DateTime.UtcNow; textContent1.UtcLastModificationDate = DateTime.UtcNow; textContent1.UserKey = "userkey1"; textContent1["Title"] = "news1"; textContent1["Comments"] = 100; textContent1.Published = true; textContentProvider.Add(textContent1); TextContent textContent2 = new TextContent(); textContent2.FolderName = folder.FullName; textContent2.SchemaName = schema.Name; textContent2.Repository = repository.Name; textContent2.UtcCreationDate = DateTime.UtcNow; textContent2.UtcLastModificationDate = DateTime.UtcNow; textContent2.UserKey = "userkey2"; textContent2["Title"] = "news2"; textContent2["Comments"] = 102; textContent2.Published = true; textContentProvider.Add(textContent2); }
private static void InitializeData() { dynamic news1 = new TextContent(repository.Name, newsSchema.Name, newsFolder.Name) { UserKey = "news1" }; news1.title = "news1"; textContentProvider.Add(news1); dynamic comment1 = new TextContent(repository.Name, commentSchema.Name, null) { UserKey = "comment1", ParentUUID = news1.UUID }; comment1.Title = "comment1"; textContentProvider.Add(comment1); dynamic comment2 = new TextContent(repository.Name, commentSchema.Name, null) { UserKey = "comment2", ParentUUID = news1.UUID }; comment2.Title = "comment2"; textContentProvider.Add(comment2); }
public void Insert() { TextContent news1 = new TextContent(repository.Name, newsSchema.Name, textFolder.FullName); news1["Title"] = "title1"; news1["body"] = "body1"; provider.Add(news1); }
public virtual ContentBase Add(Repository repository, TextFolder folder, string parentFolder, string parentUUID, NameValueCollection values , HttpFileCollectionBase files, IEnumerable <TextContent> categories, string userid = "") { var textFolder = (TextFolder)folder.AsActual(); var schema = new Schema(repository, textFolder.SchemaName); var textContent = new TextContent(repository.Name, schema.Name, textFolder.FullName); textContent = Binder.Bind(schema, textContent, values); textContent.ParentFolder = parentFolder; textContent.ParentUUID = parentUUID; textContent.UserId = userid; textContent.UtcLastModificationDate = textContent.UtcCreationDate = DateTime.Now; textContent.ContentFiles = GetPostFiles(files); EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent); TextContentProvider.Add(textContent); if (categories != null) { AddCategories(repository, textContent, categories.ToArray()); } EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent); return(textContent); }
public void TestClearCategory() { var contentProvider = new TextContentProvider(); dynamic category1 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.Name); category1.UserKey = "TestClearCategory-category1"; category1.Title = "TestClearCategory-category1"; contentProvider.Add(category1); dynamic content1 = new TextContent(repository.Name, newsSchema.Name, newsFolder.Name); content1.UserKey = "TestClearCategory-news1"; content1.Title = "TestClearCategory-news1"; contentProvider.Add(content1); contentProvider.AddCategories(content1, new Category() { ContentUUID = content1.uuid, CategoryFolder = categoryFolder.Name, CategoryUUID = category1.UUID }); contentProvider.ClearCategories(content1); }
public virtual TEntity Add(TEntity entity, TextFolder folder) { entity.Repository = Repository.Name; entity.FolderName = folder.FullName; entity.SchemaName = folder.SchemaName; ContentEvent.Fire(ContentAction.PreAdd, entity); TextContentProvider.Add(entity); ContentEvent.Fire(ContentAction.Add, entity); return(entity); }
public virtual TEntity AddSubContent(TEntity entity, TextFolder folder, string parentFolderName, string parentUUID) { entity.Repository = Repository.Name; entity.FolderName = folder.FullName; entity.SchemaName = folder.SchemaName; entity.ParentFolder = parentFolderName; entity.ParentUUID = parentUUID; ContentEvent.Fire(ContentAction.PreAdd, entity); TextContentProvider.Add(entity); ContentEvent.Fire(ContentAction.Add, entity); return(entity); }
private static void InitializeData() { dynamic category1 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.Name) { UserKey = "category1" }; category1.Title = "category1"; textContentProvider.Add(category1); dynamic category2 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.Name) { UserKey = "category2" }; category2.Title = "category2"; textContentProvider.Add(category2); dynamic news1 = new TextContent(repository.Name, newsSchema.Name, newsFolder.Name) { UserKey = "news1" }; news1.title = "news1"; textContentProvider.Add(news1); textContentProvider.AddCategories(news1, new Category() { ContentUUID = news1.uuid, CategoryFolder = categoryFolder.FullName, CategoryUUID = (string)(category1.UUID) }, new Category() { ContentUUID = news1.uuid, CategoryFolder = categoryFolder.FullName, CategoryUUID = (string)(category2.UUID) }); }
public virtual TextContent Add(Repository repository, Schema schema, string parentUUID, NameValueCollection values, HttpFileCollectionBase files, string userid = "") { var textContent = new TextContent(repository.Name, schema.Name, null); textContent.ParentUUID = parentUUID; textContent = Binder.Bind(schema, textContent, values); textContent.UtcLastModificationDate = textContent.UtcCreationDate = DateTime.Now.ToUniversalTime(); textContent.UserId = userid; if (files != null) { textContent.ContentFiles = GetPostFiles(files); } EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent); TextContentProvider.Add(textContent); EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent); return(textContent); }
public virtual TextContent Copy(Schema schema, string uuid) { var repository = schema.Repository; var content = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); if (content != null) { var textContent = new TextContent(content); textContent.Id = ""; textContent.UUID = ""; textContent.UtcCreationDate = DateTime.Now; textContent.UtcLastModificationDate = DateTime.Now; textContent.Published = null; textContent.Sequence = 0; textContent.UserKey = null; var titleField = schema.AsActual().GetSummarizeColumn(); if (titleField != null) { textContent[titleField.Name] = (content[titleField.Name] ?? "") + " - Copy".Localize(); } EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent); TextContentProvider.Add(textContent); var categories = this.QueryCategories(repository, content.FolderName, uuid); this.AddCategories(repository, textContent, categories.SelectMany(it => it.Contents).ToArray()); EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent); return(textContent); } return(null); }
public void TestContentCUD() { TextContent textContent = new TextContent(); textContent.FolderName = newsFolder.FullName; textContent.SchemaName = newsSchema.Name; textContent.Repository = repository.Name; textContent.UtcCreationDate = DateTime.UtcNow; textContent.UtcLastModificationDate = DateTime.UtcNow; textContent.UserKey = "userkey1"; textContent["Title"] = "news1"; textContent["Comments"] = 100; textContentProvider.Add(textContent); textContent["Title"] = "news1-updated"; textContent["Comments"] = 101; textContentProvider.Update(textContent, textContent); textContentProvider.Delete(textContent); }
public QueryTests() { EmptyUserKeyGenerator.DefaultGenerator = new EmptyUserKeyGenerator(); Providers.DefaultProviderFactory = new MongoDB.ProviderFactory(); repository = new Repository(Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(10).ToString()); Providers.DefaultProviderFactory.GetProvider <IRepositoryProvider>().Add(repository); categorySchema = new Schema(repository, "category") { IsDummy = false }; categorySchema.AddColumn(new Column() { Name = "Title" }); categoryFolder = new TextFolder(repository, "Category") { SchemaName = categorySchema.Name, IsDummy = false }; Providers.DefaultProviderFactory.GetProvider <ITextFolderProvider>().Add(categoryFolder); newsSchema = new Schema(repository, "News") { IsDummy = false }; newsSchema.AddColumn(new Column() { Name = "title", DataType = Data.DataType.String }); newsSchema.AddColumn(new Column() { Name = "Body", DataType = Data.DataType.String }); newsSchema.AddColumn(new Column() { Name = "Comments", DataType = Data.DataType.Int }); Providers.DefaultProviderFactory.GetProvider <ISchemaProvider>().Add(newsSchema); newsFolder = new TextFolder(repository, "News") { SchemaName = newsSchema.Name, Categories = new List <CategoryFolder>() { new CategoryFolder() { FolderName = categoryFolder.FullName, SingleChoice = false } }, OrderSetting = new OrderSetting() { FieldName = "Sequence", Direction = OrderDirection.Descending } }; Providers.DefaultProviderFactory.GetProvider <ITextFolderProvider>().Add(newsFolder); commentSchema = new Schema(repository, "Comment") { IsDummy = false }; commentSchema.AddColumn(new Column() { Name = "Title" }); Providers.DefaultProviderFactory.GetProvider <ISchemaProvider>().Add(commentSchema); category1 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.FullName); category1["title"] = "category1"; provider.Add(category1); category2 = new TextContent(repository.Name, categorySchema.Name, categoryFolder.FullName); category2["title"] = "category2"; provider.Add(category2); newsContent = new TextContent(repository.Name, newsSchema.Name, newsFolder.FullName); newsContent["title"] = "news1"; newsContent["body"] = "body"; newsContent["comments"] = 1; provider.Add(newsContent); news2 = new TextContent(repository.Name, newsSchema.Name, newsFolder.FullName); news2["title"] = "news2"; news2["body"] = "body"; news2["comments"] = 0; provider.Add(news2); news3 = new TextContent(repository.Name, newsSchema.Name, newsFolder.FullName); news3["title"] = "news2"; news3["body"] = "body"; news3["comments"] = 5; provider.Add(news3); provider.AddCategories(newsContent, new Category() { ContentUUID = newsContent.UUID, CategoryUUID = category1.UUID, CategoryFolder = category1.FolderName }); provider.AddCategories(newsContent, new Category() { ContentUUID = newsContent.UUID, CategoryUUID = category2.UUID, CategoryFolder = category2.FolderName }); commenContent = new TextContent(repository.Name, commentSchema.Name, ""); commenContent.ParentFolder = newsContent.FolderName; commenContent.ParentUUID = newsContent.UUID; commenContent["title"] = "comment1"; provider.Add(commenContent); }
public virtual ContentBase Copy(TextContent originalContent, TextFolder textFolder, bool keepStatus, bool keepUUID, NameValueCollection values) { textFolder = textFolder.AsActual(); var repository = textFolder.Repository; var schema = new Schema(repository, textFolder.SchemaName); var copyedContent = new TextContent(originalContent); copyedContent.Id = ""; copyedContent.UUID = ""; if (keepUUID) { copyedContent.UUID = originalContent.UUID; } copyedContent.UtcCreationDate = DateTime.Now.ToUniversalTime(); copyedContent.Repository = textFolder.Repository.Name; copyedContent.FolderName = textFolder.FullName; copyedContent.SchemaName = textFolder.SchemaName; copyedContent.OriginalUUID = originalContent.UUID; copyedContent.OriginalRepository = originalContent.Repository; copyedContent.OriginalFolder = originalContent.FolderName; copyedContent.IsLocalized = false; copyedContent.Sequence = 0; copyedContent.UserId = originalContent.UserId; var versions = Kooboo.CMS.Content.Versioning.VersionManager.AllVersionInfos(originalContent); if (versions.Count() > 0) { copyedContent.OriginalLastestVisitedVersionId = versions.Max(it => it.Version); } if (values != null) { originalContent = Binder.Bind(schema, copyedContent, values); } if (!keepStatus) { copyedContent.Published = false; } //如果没有Content event,那么在发送设置的“转发”功能就会失效。 EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, copyedContent); TextContentProvider.Add(copyedContent); if (textFolder.Categories != null && textFolder.Categories.Count > 0) { var originalRepository = originalContent.GetRepository(); var originalFolder = originalContent.GetFolder().AsActual(); var originalCategories = QueryCategories(originalRepository, originalFolder.FullName, originalContent.UUID); List <TextContent> categories = new List <TextContent>(); foreach (var category in originalCategories) { foreach (var originalCategoryContent in category.Contents) { foreach (var categoryFolder in textFolder.Categories) { var categoryContent = (new TextFolder(textFolder.Repository, categoryFolder.FolderName)).CreateQuery() .WhereEquals("UUID", originalCategoryContent.UUID).FirstOrDefault(); if (categoryContent != null) { categories.Add(categoryContent); break; } } } } AddCategories(repository, copyedContent, categories.ToArray()); } EventBus.Content.ContentEvent.Fire(ContentAction.Add, copyedContent); return(copyedContent); }
public void Test_AddCategories() { provider.Add(news1); provider.Add(category1); provider.AddCategories(news1, categories); provider.ClearCategories(news1); provider.AddCategories(news1, categories); provider.DeleteCategories(news1, categories); provider.Delete(news1); provider.Delete(category1); }