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


C# Component.CheckIn方法代码示例

本文整理汇总了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);
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:SGAnonymous,项目名称:sdl-tridion-world,代码行数:68,代码来源:EventHandler.cs


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