本文整理汇总了C#中AbstractDataMappingContext类的典型用法代码示例。如果您正苦于以下问题:C# AbstractDataMappingContext类的具体用法?C# AbstractDataMappingContext怎么用?C# AbstractDataMappingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractDataMappingContext类属于命名空间,在下文中一共展示了AbstractDataMappingContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MapToCms
/// <summary>
/// Maps data from the .Net property value to the CMS value
/// </summary>
/// <param name="mappingContext"></param>
/// <exception cref="MapperException">You can not set an empty or null Item name</exception>
/// <exception cref="System.NotSupportedException">
/// Can't set Name. Value is not of type System.String
/// or
/// You can not save UmbracoInfo {0}.Formatted(config.Type)
/// </exception>
public override void MapToCms(AbstractDataMappingContext mappingContext)
{
var context = mappingContext as UmbracoDataMappingContext;
var content = context.Content;
var value = context.PropertyValue;
var config = Configuration as UmbracoInfoConfiguration;
switch (config.Type)
{
case UmbracoInfoType.Name:
if (value is string || value == null)
{
//if the name is null or empty nothing should happen
if ((value ?? string.Empty).ToString().IsNullOrEmpty())
throw new MapperException("You can not set an empty or null Item name");
if (content.Name != value.ToString())
{
content.Name = value.ToString();
context.Service.ContentService.Save(content);
}
}
else
throw new NotSupportedException("Can't set Name. Value is not of type System.String");
break;
default:
throw new NotSupportedException("You can not save UmbracoInfo {0}".Formatted(config.Type));
}
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:39,代码来源:UmbracoInfoMapper.cs
示例2: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scConfig = Configuration as SitecoreNodeConfiguration;
var scContext = mappingContext as SitecoreDataMappingContext;
var item = scContext.Item;
Item targetItem = null;
if (scConfig.Id.IsNotNullOrEmpty())
{
var guid = Guid.Empty;
if (Guid.TryParse(scConfig.Id, out guid) && guid != Guid.Empty)
{
targetItem = item.Database.GetItem(new ID(guid), item.Language);
}
}
else if (!scConfig.Path.IsNullOrEmpty())
{
targetItem = item.Database.GetItem(scConfig.Path, item.Language);
}
if (targetItem == null || targetItem.Versions.Count == 0)
{
return null;
}
else
{
return scContext.Service.CreateType(scConfig.PropertyInfo.PropertyType, targetItem, scConfig.IsLazy,
scConfig.InferType, null);
}
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:38,代码来源:SitecoreItemMapper.cs
示例3: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext"></param>
/// <returns></returns>
/// <exception cref="MapperException">UmbracoInfoType {0} not supported.Formatted(config.Type)</exception>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var context = mappingContext as UmbracoDataMappingContext;
var content = context.Content;
var config = Configuration as UmbracoInfoConfiguration;
switch (config.Type)
{
case UmbracoInfoType.Name:
return content.Name;
case UmbracoInfoType.Path:
return content.Path;
case UmbracoInfoType.ContentTypeAlias:
return content.ContentType.Alias;
case UmbracoInfoType.ContentTypeName:
return content.ContentType.Name;
//case UmbracoInfoType.Url:
// return content.Name.FormatUrl().ToLower();
case UmbracoInfoType.CreateDate:
return content.CreateDate;
case UmbracoInfoType.UpdateDate:
return content.UpdateDate;
case UmbracoInfoType.Version:
return content.Version;
case UmbracoInfoType.Creator:
var user = new User(content.CreatorId);
return user.LoginName;
default:
throw new MapperException("UmbracoInfoType {0} not supported".Formatted(config.Type));
}
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:37,代码来源:UmbracoInfoMapper.cs
示例4: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext"></param>
/// <returns></returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var umbContext = mappingContext as UmbracoDataMappingContext;
var umbConfig = Configuration as UmbracoChildrenConfiguration;
Type genericType = Utilities.GetGenericArgument(Configuration.PropertyInfo.PropertyType);
Func<IEnumerable<IContent>> getItems = null;
if (umbContext.PublishedOnly)
{
getItems = () => umbContext.Service.ContentService.GetChildren(umbContext.Content.Id)
.Select(c => umbContext.Service.ContentService.GetPublishedVersion(c.Id));
}
else
{
getItems = () => umbContext.Service.ContentService.GetChildren(umbContext.Content.Id);
}
return Utilities.CreateGenericType(
typeof(LazyContentEnumerable<>),
new[] {genericType},
getItems,
umbConfig.IsLazy,
umbConfig.InferType,
umbContext.Service
);
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:32,代码来源:UmbracoChildrenMapper.cs
示例5: MapToCms
/// <summary>
/// Maps data from the .Net property value to the CMS value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>The value to write</returns>
/// <exception cref="System.NotSupportedException">
/// Can't set DisplayName. Value is not of type System.String
/// or
/// Can't set Name. Value is not of type System.String
/// or
/// You can not save SitecoreInfo {0}.Formatted(scConfig.Type)
/// </exception>
/// <exception cref="Glass.Mapper.MapperException">You can not set an empty or null Item name</exception>
public override void MapToCms(AbstractDataMappingContext mappingContext)
{
var context = mappingContext as SitecoreDataMappingContext;
var item = context.Item;
var value = context.PropertyValue;
var scConfig = Configuration as SitecoreInfoConfiguration;
switch (scConfig.Type)
{
case SitecoreInfoType.DisplayName:
if (value is string || value == null)
item[Global.Fields.DisplayName] = (value ?? string.Empty).ToString();
else
throw new NotSupportedException("Can't set DisplayName. Value is not of type System.String");
break;
case SitecoreInfoType.Name:
if (value is string || value == null)
{
//if the name is null or empty nothing should happen
if ((value ?? string.Empty).ToString().IsNullOrEmpty())
throw new MapperException("You can not set an empty or null Item name");
if (item.Name != value.ToString())
{
item.Name = value.ToString();
}
}
else
throw new NotSupportedException("Can't set Name. Value is not of type System.String");
break;
default:
throw new NotSupportedException("You can not save SitecoreInfo {0}".Formatted(scConfig.Type));
}
}
开发者ID:uv20,项目名称:Glass.Mapper,代码行数:48,代码来源:SitecoreInfoMapper.cs
示例6: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
var scConfig = Configuration as SitecoreChildrenConfiguration;
Func<IEnumerable<Item>> getItems = () =>
ItemManager.GetChildren(scContext.Item, SecurityCheck.Enable, ChildListOptions.None);
if (_activator == null)
{
_activator = Mapper.Utilities.GetActivator(
typeof (LazyItemEnumerable<>),
new[] {GenericType},
getItems,
scConfig.IsLazy,
scConfig.InferType,
scContext.Service);
}
return _activator(getItems,
scConfig.IsLazy,
scConfig.InferType,
scContext.Service);
}
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:30,代码来源:SitecoreChildrenMapper.cs
示例7: MapToProperty
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
if (scContext != null)
{
return scContext.Item;
}
return null;
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:9,代码来源:SitecoreItemMapper.cs
示例8: MapToCms
/// <summary>
/// Maps data from the .Net property value to the CMS value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>The value to write</returns>
public override void MapToCms(AbstractDataMappingContext mappingContext)
{
var scConfig = Configuration as SitecoreFieldConfiguration;
var scContext = mappingContext as SitecoreDataMappingContext ;
var field = Utilities.GetField(scContext.Item, scConfig.FieldId, scConfig.FieldName);
object value = Configuration.PropertyInfo.GetValue(mappingContext.Object, null);
SetField(field, value, scConfig, scContext);
}
开发者ID:jelleovermars,项目名称:Glass.Mapper,代码行数:15,代码来源:AbstractSitecoreFieldMapper.cs
示例9: MapToProperty
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
var scConfig = Configuration as SitecoreChildrenConfiguration;
if (scContext != null && scConfig != null)
{
return new ChildrenCast(scContext.Service, scContext.Item, scConfig.IsLazy, scConfig.InferType);
}
return null;
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:10,代码来源:SitecoreChildrenCastMapper.cs
示例10: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext"></param>
/// <returns></returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var umbContext = mappingContext as UmbracoDataMappingContext;
var umbConfig = Configuration as UmbracoParentConfiguration;
return umbContext.Service.CreateType(
umbConfig.PropertyInfo.PropertyType,
umbContext.Service.ContentService.GetById(umbContext.Content.ParentId),
umbConfig.IsLazy,
umbConfig.InferType);
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:16,代码来源:UmbracoParentMapper.cs
示例11: MapPropertyToCms
public override void MapPropertyToCms(AbstractDataMappingContext mappingContext)
{
var scConfig = Configuration as SitecoreFieldConfiguration;
if ((scConfig.Setting & SitecoreFieldSettings.PageEditorOnly) == SitecoreFieldSettings.PageEditorOnly)
{
return;
}
base.MapPropertyToCms(mappingContext);
}
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:11,代码来源:AbstractSitecoreFieldMapper.cs
示例12: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
var scConfig = Configuration as SitecoreParentConfiguration;
return scContext.Service.CreateType(
scConfig.PropertyInfo.PropertyType,
scContext.Item.Parent,
scConfig.IsLazy,
scConfig.InferType);
}
开发者ID:uv20,项目名称:Glass.Mapper,代码行数:16,代码来源:SitecoreParentMapper.cs
示例13: MapToProperty
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
var scConfig = Configuration as SitecoreSelfConfiguration;
if (scContext != null && scConfig != null)
{
return scContext.Service.CreateType(scConfig.PropertyInfo.PropertyType, scContext.Item, scConfig.IsLazy, scConfig.InferType, null);
}
return null;
}
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:11,代码来源:SitecoreSelfMapper.cs
示例14: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scConfig = Configuration as SitecoreFieldConfiguration;
var scContext = mappingContext as SitecoreDataMappingContext;
var field = Utilities.GetField(scContext.Item, scConfig.FieldId, scConfig.FieldName);
if (field == null)
return null;
return GetField(field, scConfig, scContext);
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:17,代码来源:AbstractSitecoreFieldMapper.cs
示例15: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext"></param>
/// <returns></returns>
/// <exception cref="System.NotSupportedException">The type {0} on {0}.{1} is not supported by UmbracoIdMapper.Formatted
/// (umbConfig.PropertyInfo.ReflectedType.FullName,
/// umbConfig.PropertyInfo.Name)</exception>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
UmbracoDataMappingContext context = mappingContext as UmbracoDataMappingContext;
var node = context.Content;
var umbConfig = Configuration as UmbracoIdConfiguration;
if (umbConfig.PropertyInfo.PropertyType == typeof(int))
return node.Id;
if (umbConfig.PropertyInfo.PropertyType == typeof(Guid))
return node.Key;
throw new NotSupportedException("The type {0} on {0}.{1} is not supported by UmbracoIdMapper".Formatted
(umbConfig.PropertyInfo.ReflectedType.FullName,
umbConfig.PropertyInfo.Name));
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:24,代码来源:UmbracoIdMapper.cs
示例16: MapToProperty
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var config = Configuration as UmbracoDelegateConfiguration;
var context = mappingContext as UmbracoDataMappingContext;
if (config == null)
{
throw new ArgumentException("A delegate property configuration was expected");
}
if (context == null)
{
throw new ArgumentException("A sitecore data mapping context was expected");
}
return config.MapToPropertyAction == null
? null
: config.MapToPropertyAction(context);
}
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:18,代码来源:UmbracoDelegateMapper.cs
示例17: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
var scConfig = Configuration as SitecoreChildrenConfiguration;
Type genericType = Utilities.GetGenericArgument(Configuration.PropertyInfo.PropertyType);
Func<IEnumerable<Item>> getItems = () => scContext.Item.Children;
return Utilities.CreateGenericType(
typeof (LazyItemEnumerable<>),
new[] {genericType},
getItems,
scConfig.IsLazy,
scConfig.InferType,
scContext.Service
);
}
开发者ID:jelleovermars,项目名称:Glass.Mapper,代码行数:24,代码来源:SitecoreChildrenMapper.cs
示例18: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
/// <exception cref="System.NotSupportedException">The type {0} on {0}.{1} is not supported by SitecoreIdMapper.Formatted
/// (scConfig.PropertyInfo.ReflectedType.FullName,
/// scConfig.PropertyInfo.Name)</exception>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
SitecoreDataMappingContext context = (SitecoreDataMappingContext)mappingContext;
var item = context.Item;
var scConfig = Configuration;
if (scConfig.PropertyInfo.PropertyType == typeof(Guid))
return item.ID.Guid;
else if (scConfig.PropertyInfo.PropertyType == typeof(ID))
return item.ID;
else
{
throw new NotSupportedException("The type {0} on {0}.{1} is not supported by SitecoreIdMapper".Formatted
(scConfig.PropertyInfo.ReflectedType.FullName,
scConfig.PropertyInfo.Name));
}
}
开发者ID:smithc,项目名称:Glass.Mapper,代码行数:28,代码来源:SitecoreIdMapper.cs
示例19: MapToProperty
/// <summary>
/// Maps data from the CMS value to the .Net property value
/// </summary>
/// <param name="mappingContext">The mapping context.</param>
/// <returns>System.Object.</returns>
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scConfig = Configuration as SitecoreLinkedConfiguration;
var scContext = mappingContext as SitecoreDataMappingContext;
Type genericType = Mapper.Utilities.GetGenericArgument(scConfig.PropertyInfo.PropertyType);
var item = scContext.Item;
var linkDb = global::Sitecore.Globals.LinkDatabase;
//ME - i am not sure this is correct but there is an odd behaviour of references
// languges come back as invariant, going with default language in this scenario
var references = new Func<IEnumerable<Item>>(() =>{
var itemLinks = linkDb.GetReferences(item);
var items = itemLinks.Select(x => x.GetTargetItem());
return Utilities.GetLanguageItems(items, LanguageManager.DefaultLanguage, scContext.Service.ItemVersionHandler);
});
var getItems = new Func<IEnumerable<Item>>(() =>
{
switch (scConfig.Option)
{
case SitecoreLinkedOptions.All:
var itemLinks1 = references();
var itemLinks2 = linkDb.GetReferrers(item);
return itemLinks1.Union(itemLinks2.Select(x => x.GetSourceItem()));
case SitecoreLinkedOptions.References:
return references();
case SitecoreLinkedOptions.Referrers:
var itemLinks4 = linkDb.GetReferrers(item);
return itemLinks4.Select(x => x.GetSourceItem());
default:
return new List<Item>();
}
});
return scContext.Service.CreateTypes(genericType, getItems, scConfig.IsLazy, scConfig.InferType);
}
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:46,代码来源:SitecoreLinkedMapper.cs
示例20: MapToCms
public override void MapToCms(AbstractDataMappingContext mappingContext)
{
var config = Configuration as SitecoreDelegateConfiguration;
var context = mappingContext as SitecoreDataMappingContext;
if (config == null)
{
throw new ArgumentException("A delegate property configuration was expected");
}
if (context == null)
{
throw new ArgumentException("A sitecore data mapping context was expected");
}
if (config.MapToCmsAction == null)
{
return;
}
config.MapToCmsAction(context);
}
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:21,代码来源:SitecoreDelegateMapper.cs
注:本文中的AbstractDataMappingContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论