本文整理汇总了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);
}
示例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;
}
}