private static void DeleteChildContents(TextContent textContent, TextFolder parentFolder, TextFolder childFolder)
 {
     var repository = textContent.GetRepository();
     var childContents = childFolder.CreateQuery().WhereEquals("ParentFolder", parentFolder.FullName)
         .WhereEquals("ParentUUID", textContent.UUID);
     foreach (var content in childContents)
     {
         Services.ServiceFactory.TextContentManager.Delete(repository, childFolder, content.UUID);
     }
 }
Exemple #2
0
        public void LogVersion(TextContent content)
        {
            VersionInfo versionInfo = new VersionInfo()
            {
                CommitUser = content.UserId,
                UtcCommitDate = content.LastModificationDate,
                TextContent = new Dictionary<string, object>(content)
            };
            if (!string.IsNullOrEmpty(content.FolderName))
            {
                versionInfo.Categories = ServiceFactory.TextContentManager
                                     .QueryCategories(content.GetRepository(), content.FolderName, content.UUID)
                                     .Select(it => new Category()
                                     {
                                         FolderName = it.CategoryFolder.FullName,
                                         Contents = it.Contents.Select(c => new CategoryContent() { UUID = c.UUID, DisplayName = c.GetSummary() }).ToArray()
                                     })
                                     .ToArray();
            }

            DataContractSerializationHelper.Serialize(versionInfo, GetNextVersionFile(content));
        }
Exemple #3
0
        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.CreationDate = DateTime.UtcNow;
            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 = Versioning.VersionManager.AllVersionInfos(originalContent).ToArray();
            if (versions.Any())
            {
                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;
        }
Exemple #4
0
 public static void LogVersion(TextContent content)
 {
     if (content.GetRepository().AsActual().EnableVersioning.Value == true)
     {
         VersionLogger.LogVersion(content);
     }
 }