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


C# Sitecore.GetPropertyValue方法代码示例

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


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

示例1: SaveItem

        /// <summary>
        /// Save changes that were made to an item to the database.
        /// </summary>
        /// <param name="itemDefinition">Used to identify the particular item</param>
        /// <param name="changes">A holder object that keeps track of the changes</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override bool SaveItem(ItemDefinition itemDefinition, Sitecore.Data.Items.ItemChanges changes, CallContext context)
        {
            if (! ItemsById.ContainsKey(itemDefinition.ID))
            {
                return false;
            }

            SyncItem current = ItemsById[itemDefinition.ID];
            if (changes.HasPropertiesChanged)
            {
                current.Name = Sitecore.StringUtil.GetString(changes.GetPropertyValue("name"), itemDefinition.Name);

                ID templateId = Sitecore.MainUtil.GetObject(changes.GetPropertyValue("templateid"), itemDefinition.TemplateID) as ID;
                current.TemplateID = templateId != ID.Null ? GetIdAsString(templateId) : null;

                ID branchId = Sitecore.MainUtil.GetObject(changes.GetPropertyValue("branchid"), itemDefinition.BranchId) as ID;
                current.BranchId = branchId != ID.Null ? GetIdAsString(branchId) : null;
            }
            if (changes.HasFieldsChanged)
            {
                foreach (Sitecore.Data.Items.FieldChange change in changes.FieldChanges)
                {
                    string changeFieldId = GetIdAsString(change.FieldID);
                    var matchingSharedFields = current.SharedFields.Where(fv => changeFieldId.Equals(fv.FieldID));
                    var matchingVersions = current.Versions
                        .Where(vr => vr.Version.Equals(change.Version.Number.ToString()) && vr.Language.Equals(change.Language.Name));
                    var matchingNonSharedFields = matchingVersions
                        .SelectMany(vr => vr.Fields.Select(fl => new { Ver = vr, Field = fl } ))
                        .Where(fv => changeFieldId.Equals(fv.Field.FieldID));
                    if (change.RemoveField)
                    {
                        if (matchingSharedFields.Any())
                        {
                            current.SharedFields.Remove(matchingSharedFields.First());
                        }
                        if (matchingNonSharedFields.Any())
                        {
                            matchingNonSharedFields.First().Ver.RemoveField(matchingNonSharedFields.First().Field.FieldName);
                        }
                    }
                    else
                    {
                        bool changeMade = false;
                        if (matchingSharedFields.Any())
                        {
                            matchingSharedFields.First().FieldValue = change.Value;
                            changeMade = true;
                        }
                        if (matchingNonSharedFields.Any())
                        {
                            matchingNonSharedFields.First().Field.FieldValue = change.Value;
                            changeMade = true;
                        }
                        if (! changeMade && change.Definition != null)
                        {
                            if (change.Definition.IsShared || change.Definition.IsUnversioned)
                            {
                                current.AddSharedField(changeFieldId, change.Definition.Name, change.Definition.Key, change.Value, true);
                            }
                            else if(matchingVersions.Any())
                            {
                                matchingVersions.First().AddField(changeFieldId, change.Definition.Name, change.Definition.Key, change.Value, true);
                            }
                        }
                    }
                }
            }
            return true;
        }
开发者ID:vtml,项目名称:Sitecore-FixtureDataProvider,代码行数:76,代码来源:FixtureDataProvider.cs

示例2: SaveItem

        /// <summary>
        /// Save changes that were made to an item to the database.
        /// </summary>
        /// <param name="itemDefinition">Used to identify the particular item</param>
        /// <param name="changes">A holder object that keeps track of the changes</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override bool SaveItem(ItemDefinition itemDefinition, Sitecore.Data.Items.ItemChanges changes, CallContext context)
        {
            Item current = Items.FindOneById(itemDefinition.ID.ToGuid());
            if (current == null)
            {
                return false;
            }

            if (changes.HasPropertiesChanged)
            {
                current.Name = StringUtil.GetString(changes.GetPropertyValue("name"), itemDefinition.Name);

                ID templateId = MainUtil.GetObject(changes.GetPropertyValue("templateid"), itemDefinition.TemplateID) as ID;
                current.TemplateID = templateId != ID.Null ? templateId.ToGuid() : Guid.Empty;

                ID branchId = MainUtil.GetObject(changes.GetPropertyValue("branchid"), itemDefinition.BranchId) as ID;
                current.BranchID = branchId != ID.Null ? branchId.ToGuid() : Guid.Empty;
            }
            if (changes.HasFieldsChanged)
            {
                foreach (Sitecore.Data.Items.FieldChange change in changes.FieldChanges)
                {
                    VersionUri fieldVersionUri = new VersionUri(
                        change.Definition == null || change.Definition.IsShared ? null : change.Language,
                        change.Definition == null || change.Definition.IsUnversioned ? null : change.Version);
                    var matchingFields = current.FieldValues.Where(fv => fv.Key.Matches(fieldVersionUri) && fv.Key.FieldId.Equals(change.FieldID.ToGuid()));

                    if (change.RemoveField)
                    {
                        if(matchingFields.Count() > 0)
                        {
                            current.FieldValues.Remove(matchingFields.First().Key);
                        }
                    }
                    else
                    {
                        if (matchingFields.Count() > 0)
                        {
                            current.FieldValues[matchingFields.First().Key] = change.Value;
                        }
                        else
                        {
                            current.FieldValues.Add(new FieldValueId()
                                {
                                    FieldId = change.FieldID.ToGuid(),
                                    Language = fieldVersionUri.Language != null ? fieldVersionUri.Language.Name : null,
                                    Version = fieldVersionUri.Version != null ? fieldVersionUri.Version.Number : null as int?
                                }, change.Value);
                        }
                    }
                }

                Items.Save(current, SafeMode);
            }
            return true;
        }
开发者ID:hermanussen,项目名称:MongoDataProvider,代码行数:63,代码来源:MongoDataProvider.cs


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