本文整理汇总了C#中Component.CheckIn方法的典型用法代码示例。如果您正苦于以下问题:C# Component.CheckIn方法的具体用法?C# Component.CheckIn怎么用?C# Component.CheckIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Component
的用法示例。
在下文中一共展示了Component.CheckIn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetOrUpdateMetadata
private void SetOrUpdateMetadata(Component subject, EventArgs args, EventPhases phase)
{
// quick first test for ECL stub Component
if (!subject.Title.StartsWith("ecl:") || subject.ComponentType != ComponentType.Multimedia) return;
using (IEclSession eclSession = SessionFactory.CreateEclSession(subject.Session))
{
// determine if subject is an ECL stub Component from the list of available mountpoints
IEclUri eclUri = eclSession.TryGetEclUriFromTcmUri(subject.Id);
if (eclUri != null && MountPointIds.Contains(eclUri.MountPointId))
{
// check if metadata field exists
ItemFields metadataFields = new ItemFields(subject.Metadata, subject.MetadataSchema);
if (metadataFields.Contains(_metadataXmlFieldName))
{
// only set value when update is true or metadata is not set
string metadata = ((SingleLineTextField)metadataFields[_metadataXmlFieldName]).Value;
if (_update || string.IsNullOrEmpty(metadata))
{
using (IContentLibraryContext context = eclSession.GetContentLibrary(eclUri))
{
// load actual ECL item so you can access its properties and metadata
IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem) context.GetItem(eclUri);
try
{
// implement your custom code here to set the metadata value
// currently this reads the configured ECL metadata field and sets its value in the stub metadata
if (!string.IsNullOrEmpty(eclItem.MetadataXml))
{
XNamespace ns = GetNamespace(eclItem.MetadataXml);
XDocument eclMetadata = XDocument.Parse(eclItem.MetadataXml);
XElement field = (from xml in eclMetadata.Descendants(ns + _metadataXmlFieldName) select xml).FirstOrDefault();
if (field != null)
{
string value = field.Value;
// only save value when metadata is empty or update is true and value differs
if (string.IsNullOrEmpty(metadata) || (_update && !metadata.Equals(value)))
{
// update metadata
if (_asynchronous)
{
subject.CheckOut();
}
((SingleLineTextField) metadataFields[_metadataXmlFieldName]).Value = value;
subject.Metadata = metadataFields.ToXml();
subject.Save();
if (_asynchronous)
{
subject.CheckIn();
}
Logger.Write(string.Format("added {0} to metadata of {1}", value, eclUri), "EclStubComponentEventHandlerExtension", LoggingCategory.General, TraceEventType.Information);
}
}
}
}
catch (Exception e)
{
Logger.Write(e, "EclStubComponentEventHandlerExtension", LoggingCategory.General);
}
}
}
}
}
}
}