本文整理汇总了C#中ContentItem.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# ContentItem.Clone方法的具体用法?C# ContentItem.Clone怎么用?C# ContentItem.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentItem
的用法示例。
在下文中一共展示了ContentItem.Clone方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTemplate
public TemplateDefinition GetTemplate(ContentItem item)
{
var template = CreateTemplate(map.GetOrCreateDefinition(item));
template.OriginalFactory = () => item;
template.TemplateFactory = () => item.Clone(false);
return template;
}
示例2: SaveVersion
/// <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 SaveVersion(ContentItem item)
{
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;
ContentItem oldVersion = item.Clone(false);
if(item.State == ContentState.Published)
stateChanger.ChangeTo(oldVersion, ContentState.Unpublished);
else
stateChanger.ChangeTo(oldVersion, ContentState.Draft);
oldVersion.Expires = Utility.CurrentTime().AddSeconds(-1);
oldVersion.Updated = Utility.CurrentTime().AddSeconds(-1);
oldVersion.Parent = null;
oldVersion.VersionOf = item;
if (item.Parent != null)
oldVersion["ParentID"] = item.Parent.ID;
itemRepository.SaveOrUpdate(oldVersion);
if (ItemSavedVersion != null)
ItemSavedVersion.Invoke(this, new ItemEventArgs(oldVersion));
TrimVersionCountTo(item, maximumVersionsPerItem);
return oldVersion;
}
示例3: GetTemplate
public TemplateDefinition GetTemplate(ContentItem item)
{
if (item["TemplatName"] != null)
return null;
var template = CreateTemplate(map.GetOrCreateDefinition(item));
template.Original = () => item;
template.Template = () => item.Clone(false);
return template;
}
示例4: CommandContext
public CommandContext(ItemDefinition definition, ContentItem content, string userInterface, IPrincipal user, IContentForm<CommandContext> binder, IValidator<CommandContext> validator)
{
Definition = definition;
Content = content;
Original = content.VersionOf.Value ?? content.Clone(false);
Interface = userInterface;
User = user;
Binder = binder;
Validator = validator;
ValidationErrors = new List<ValidationError>();
Errors = new List<Exception>();
Parameters = new Dictionary<string, object>();
}
示例5: UpdateItem
protected override bool UpdateItem(NameValueCollection request, ContentItem item)
{
item = item.Clone(true);
item.Name = null;
item.ZoneName = request["zone"];
foreach (var child in Find.EnumerateChildren(item, true, false))
child.SetVersionKey(Guid.NewGuid().ToString());
int newIndex;
var parent = GetParentAndIndex(request, Page, out newIndex);
if (parent == null)
throw new Exception("could not locate target of action");
InsertItem(parent, item, newIndex);
return true;
}
示例6: CreateTemplateInfo
private TemplateDefinition CreateTemplateInfo(ContentItem template)
{
var info = new TemplateDefinition
{
Name = template.Name,
Title = template.Title,
Description = template.GetDetail(TemplateDescription, ""),
TemplateUrl = template.Url,
Definition = map.GetOrCreateDefinition(template.GetContentType(), template.Name),
TemplateFactory = () =>
{
var clone = template.Clone(true);
clone.SetDetail(TemplateDescription, null, typeof(string));
clone.Title = "";
clone.Name = null;
clone.TemplateKey = template.Name;
return clone;
},
OriginalFactory = () => template
};
return info;
}
示例7: Copy
public override ContentItem Copy(ContentItem source, ContentItem destination)
{
Trace.TraceInformation("ContentPersister.Copy " + source + " to " + destination);
ContentItem cloned = source.Clone(includeChildren:true);
if (cloned.Name == source.ID.ToString())
cloned.Name = null;
cloned.Parent = destination;
Save(cloned);
foreach (var descendant in Find.EnumerateChildren(cloned).ToArray())
Save(descendant);
return cloned;
}
示例8: Copy
public override ContentItem Copy(ContentItem source, ContentItem destination)
{
Trace.TraceInformation("ContentPersister.Copy " + source + " to " + destination);
ContentItem cloned = source.Clone(includeChildren:true);
if (cloned.Name == source.ID.ToString())
cloned.Name = null;
cloned.Parent = destination;
Save(cloned);
return cloned;
}
示例9: CreateTemplateInfo
private TemplateDefinition CreateTemplateInfo(ContentItem template)
{
var clone = template.Clone(true);
clone.SetDetail(TemplateDescription, null, typeof(string));
clone.Title = "";
clone.Name = null;
clone["TemplateName"] = template.Name;
var info = new TemplateDefinition
{
Name = template.Name,
Title = template.Title,
Description = template.GetDetail(TemplateDescription, ""),
TemplateUrl = template.Url,
Definition = definitions.GetDefinition(template.GetContentType()).Clone(),
Template = clone,
Original = template
};
info.Definition.Template = template.Name;
return info;
}
示例10: SaveVersion
/// <summary>Creates an old version of an item. This must be called before the item item is modified.</summary>
/// <param name="item">The item to create a old version of.</param>
/// <returns>The old version.</returns>
public virtual ContentItem SaveVersion(ContentItem item)
{
CancelItemEventArgs args = new CancelItemEventArgs(item);
if (ItemSavingVersion != null)
ItemSavingVersion.Invoke(this, args);
if (!args.Cancel)
{
item = args.AffectedItem;
ContentItem oldVersion = item.Clone(false);
oldVersion.Expires = Utility.CurrentTime().AddSeconds(-1);
oldVersion.Updated = Utility.CurrentTime().AddSeconds(-1);
oldVersion.Parent = null;
oldVersion.TranslationOf = null;
oldVersion.VersionOf = item;
if (item.Parent != null)
oldVersion["ParentID"] = item.Parent.ID;
if (item.TranslationOf != null)
oldVersion["TranslationOfID"] = item.TranslationOf.ID;
_itemRepository.SaveOrUpdate(oldVersion);
if (ItemSavedVersion != null)
ItemSavedVersion.Invoke(this, new ItemEventArgs(oldVersion));
return oldVersion;
}
return null;
}
示例11: CreateTemplateInfo
private ContentTemplate CreateTemplateInfo(ContentItem template)
{
var clone = template.Clone(true);
var info = new ContentTemplate
{
Name = template.Name,
Title = template.Title,
Description = template.GetDetail(TemplateDescription, ""),
TemplateUrl = template.Url,
Definition = definitions.GetDefinition(template.GetContentType()),
Template = clone,
Original = template
//HiddenEditors = (template.GetDetailCollection("HiddenEditors", false) ?? new DetailCollection()).ToList<string>(),
};
clone.SetDetail(TemplateDescription, null, typeof(string));
clone.Title = "";
clone.Name = null;
return info;
}