本文整理汇总了C#中AbstractDataMappingContext类的典型用法代码示例。如果您正苦于以下问题:C# AbstractDataMappingContext类的具体用法?C# AbstractDataMappingContext怎么用?C# AbstractDataMappingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractDataMappingContext类属于命名空间,在下文中一共展示了AbstractDataMappingContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
示例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);
}
}
示例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));
}
}
示例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
);
}
示例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));
}
}
示例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);
}
示例7: MapToProperty
public override object MapToProperty(AbstractDataMappingContext mappingContext)
{
var scContext = mappingContext as SitecoreDataMappingContext;
if (scContext != null)
{
return scContext.Item;
}
return null;
}
示例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);
}
示例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;
}
示例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);
}
示例11: MapPropertyToCms
public override void MapPropertyToCms(AbstractDataMappingContext mappingContext)
{
var scConfig = Configuration as SitecoreFieldConfiguration;
if ((scConfig.Setting & SitecoreFieldSettings.PageEditorOnly) == SitecoreFieldSettings.PageEditorOnly)
{
return;
}
base.MapPropertyToCms(mappingContext);
}
示例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);
}
示例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;
}
示例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);
}
示例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));
}