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