当前位置: 首页>>代码示例>>C#>>正文


C# ContentItem.CloneForVersioningRecursive方法代码示例

本文整理汇总了C#中ContentItem.CloneForVersioningRecursive方法的典型用法代码示例。如果您正苦于以下问题:C# ContentItem.CloneForVersioningRecursive方法的具体用法?C# ContentItem.CloneForVersioningRecursive怎么用?C# ContentItem.CloneForVersioningRecursive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentItem的用法示例。


在下文中一共展示了ContentItem.CloneForVersioningRecursive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddVersion

        /// <summary>Creates a version of the item. This must be called before the item item is modified to save a version before modifications.</summary>
        /// <param name="item">The item to create a old version of.</param>
        /// <returns>The old version.</returns>
        public virtual ContentItem AddVersion(ContentItem item, bool asPreviousVersion = true)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            CancellableItemEventArgs args = new CancellableItemEventArgs(item);
            if (ItemSavingVersion != null)
                ItemSavingVersion.Invoke(this, args);

            if (args.Cancel)
                return null;

            item = args.AffectedItem;

            if (!item.IsPage)
            {
                var page = Find.ClosestPage(item);
                if (page == null)
                    throw new InvalidOperationException("Cannot create version of part which isn't on a page: " + item);

                var pageVersion = AddVersion(page, asPreviousVersion: asPreviousVersion);
                var partVersion = pageVersion.FindPartVersion(item);
                return partVersion;
            }

            ContentItem version = item.CloneForVersioningRecursive(stateChanger, asPreviousVersion);

            if (item.Parent != null)
                version["ParentID"] = item.Parent.ID;

			//ContentVersion savedVersion;
            if (asPreviousVersion)
            {
				/*savedVersion = */Repository.Save(version, asPreviousVersion);
                item.VersionIndex = Repository.GetGreatestVersionIndex(item) + 1;
                itemRepository.SaveOrUpdate(item);
            }
            else
            {
                version.VersionIndex = Repository.GetGreatestVersionIndex(item) + 1;
				/*savedVersion = */Repository.Save(version, asPreviousVersion);
            }

            if (ItemSavedVersion != null)
                ItemSavedVersion.Invoke(this, new ItemEventArgs(version));

            TrimVersionCountTo(item, maximumVersionsPerItem);

			return version;// Repository.DeserializeVersion(savedVersion);
        }
开发者ID:JohnsonYuan,项目名称:n2cms,代码行数:53,代码来源:VersionManager.cs

示例2: UpgradeVersion

        public ContentVersion UpgradeVersion(ContentItem version)
        {
            using (var tx = itemRepository.BeginTransaction())
            {
                var clone = version.CloneForVersioningRecursive();
                clone.VersionOf = version.VersionOf.Value;

                foreach (var child in version.VersionOf.Children.FindParts())
                {
                    child.CloneForVersioningRecursive().AddTo(clone);
                }
                
                var newVersion = versionRepository.Save(clone);
                itemRepository.Delete(version);

                tx.Commit();

                return newVersion;
            }
        }
开发者ID:brianmatic,项目名称:n2cms,代码行数:20,代码来源:UpgradeVersionWorker.cs


注:本文中的ContentItem.CloneForVersioningRecursive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。