Added events.Service and xmlhelper.service

This commit is contained in:
perploug
2013-08-12 15:06:12 +02:00
committed by Per Ploug Krogslund
parent 3e3f12bf63
commit e825c08901
982 changed files with 162678 additions and 162678 deletions

View File

@@ -1,49 +1,49 @@
using System;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a base generic ContentPropertyBasic from a Property
/// </summary>
/// <typeparam name="T"></typeparam>
internal class ContentPropertyBasicConverter<T> : TypeConverter<Property, T>
where T : ContentPropertyBasic, new()
{
protected override T ConvertCore(Property property)
{
var editor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId);
if (editor == null)
{
//TODO: Remove this check as we shouldn't support this at all!
var legacyEditor = DataTypesResolver.Current.GetById(property.PropertyType.DataTypeId);
if (legacyEditor == null)
{
throw new NullReferenceException("The property editor with id " + property.PropertyType.DataTypeId + " does not exist");
}
var legacyResult = new T
{
Id = property.Id,
Value = property.Value == null ? "" : property.Value.ToString(),
Alias = property.Alias
};
return legacyResult;
}
var result = new T
{
Id = property.Id,
Value = editor.ValueEditor.SerializeValue(property.Value),
Alias = property.Alias
};
result.PropertyEditor = editor;
return result;
}
}
using System;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a base generic ContentPropertyBasic from a Property
/// </summary>
/// <typeparam name="T"></typeparam>
internal class ContentPropertyBasicConverter<T> : TypeConverter<Property, T>
where T : ContentPropertyBasic, new()
{
protected override T ConvertCore(Property property)
{
var editor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId);
if (editor == null)
{
//TODO: Remove this check as we shouldn't support this at all!
var legacyEditor = DataTypesResolver.Current.GetById(property.PropertyType.DataTypeId);
if (legacyEditor == null)
{
throw new NullReferenceException("The property editor with id " + property.PropertyType.DataTypeId + " does not exist");
}
var legacyResult = new T
{
Id = property.Id,
Value = property.Value == null ? "" : property.Value.ToString(),
Alias = property.Alias
};
return legacyResult;
}
var result = new T
{
Id = property.Id,
Value = editor.ValueEditor.SerializeValue(property.Value),
Alias = property.Alias
};
result.PropertyEditor = editor;
return result;
}
}
}

View File

@@ -1,44 +1,44 @@
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a ContentPropertyDto from a Property
/// </summary>
internal class ContentPropertyDisplayConverter : ContentPropertyBasicConverter<ContentPropertyDisplay>
{
private readonly ApplicationContext _applicationContext;
public ContentPropertyDisplayConverter(ApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}
protected override ContentPropertyDisplay ConvertCore(Property originalProp)
{
var display = base.ConvertCore(originalProp);
//set the display properties after mapping
display.Alias = originalProp.Alias;
display.Description = originalProp.PropertyType.Description;
display.Label = originalProp.PropertyType.Name;
display.Config = _applicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(originalProp.PropertyType.DataTypeDefinitionId);
if (display.PropertyEditor == null)
{
//if there is no property editor it means that it is a legacy data type
// we cannot support editing with that so we'll just render the readonly value view.
display.View = GlobalSettings.Path.EnsureEndsWith('/') +
"views/propertyeditors/umbraco/readonlyvalue/readonlyvalue.html";
}
else
{
display.View = display.PropertyEditor.ValueEditor.View;
}
return display;
}
}
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a ContentPropertyDto from a Property
/// </summary>
internal class ContentPropertyDisplayConverter : ContentPropertyBasicConverter<ContentPropertyDisplay>
{
private readonly ApplicationContext _applicationContext;
public ContentPropertyDisplayConverter(ApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}
protected override ContentPropertyDisplay ConvertCore(Property originalProp)
{
var display = base.ConvertCore(originalProp);
//set the display properties after mapping
display.Alias = originalProp.Alias;
display.Description = originalProp.PropertyType.Description;
display.Label = originalProp.PropertyType.Name;
display.Config = _applicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(originalProp.PropertyType.DataTypeDefinitionId);
if (display.PropertyEditor == null)
{
//if there is no property editor it means that it is a legacy data type
// we cannot support editing with that so we'll just render the readonly value view.
display.View = GlobalSettings.Path.EnsureEndsWith('/') +
"views/propertyeditors/umbraco/readonlyvalue/readonlyvalue.html";
}
else
{
display.View = display.PropertyEditor.ValueEditor.View;
}
return display;
}
}
}

View File

@@ -1,35 +1,35 @@
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a ContentPropertyDto from a Property
/// </summary>
internal class ContentPropertyDtoConverter : ContentPropertyBasicConverter<ContentPropertyDto>
{
private readonly ApplicationContext _applicationContext;
public ContentPropertyDtoConverter(ApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}
protected override ContentPropertyDto ConvertCore(Property originalProperty)
{
var propertyDto = base.ConvertCore(originalProperty);
propertyDto.IsRequired = originalProperty.PropertyType.Mandatory;
propertyDto.ValidationRegExp = originalProperty.PropertyType.ValidationRegExp;
propertyDto.Alias = originalProperty.Alias;
propertyDto.Description = originalProperty.PropertyType.Description;
propertyDto.Label = originalProperty.PropertyType.Name;
propertyDto.DataType = _applicationContext.Services.DataTypeService.GetDataTypeDefinitionById(originalProperty.PropertyType.DataTypeDefinitionId);
propertyDto.PropertyEditor = PropertyEditorResolver.Current.GetById(originalProperty.PropertyType.DataTypeId);
return propertyDto;
}
}
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates a ContentPropertyDto from a Property
/// </summary>
internal class ContentPropertyDtoConverter : ContentPropertyBasicConverter<ContentPropertyDto>
{
private readonly ApplicationContext _applicationContext;
public ContentPropertyDtoConverter(ApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}
protected override ContentPropertyDto ConvertCore(Property originalProperty)
{
var propertyDto = base.ConvertCore(originalProperty);
propertyDto.IsRequired = originalProperty.PropertyType.Mandatory;
propertyDto.ValidationRegExp = originalProperty.PropertyType.ValidationRegExp;
propertyDto.Alias = originalProperty.Alias;
propertyDto.Description = originalProperty.PropertyType.Description;
propertyDto.Label = originalProperty.PropertyType.Name;
propertyDto.DataType = _applicationContext.Services.DataTypeService.GetDataTypeDefinitionById(originalProperty.PropertyType.DataTypeDefinitionId);
propertyDto.PropertyEditor = PropertyEditorResolver.Current.GetById(originalProperty.PropertyType.DataTypeId);
return propertyDto;
}
}
}

View File

@@ -1,36 +1,36 @@
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// A mapper which declares how to map content properties. These mappings are shared among media (and probably members) which is
/// why they are in their own mapper
/// </summary>
internal class ContentPropertyModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
//FROM Property TO ContentPropertyBasic
config.CreateMap<PropertyGroup, Tab<ContentPropertyDisplay>>()
.ForMember(tab => tab.Label, expression => expression.MapFrom(@group => @group.Name))
.ForMember(tab => tab.IsActive, expression => expression.UseValue(true))
.ForMember(tab => tab.Properties, expression => expression.Ignore());
//FROM Property TO ContentPropertyBasic
config.CreateMap<Property, ContentPropertyBasic>()
.ConvertUsing<ContentPropertyBasicConverter<ContentPropertyBasic>>();
//FROM Property TO ContentPropertyDto
config.CreateMap<Property, ContentPropertyDto>()
.ConvertUsing(new ContentPropertyDtoConverter(applicationContext));
//FROM Property TO ContentPropertyDisplay
config.CreateMap<Property, ContentPropertyDisplay>()
.ConvertUsing(new ContentPropertyDisplayConverter(applicationContext));
}
}
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// A mapper which declares how to map content properties. These mappings are shared among media (and probably members) which is
/// why they are in their own mapper
/// </summary>
internal class ContentPropertyModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
//FROM Property TO ContentPropertyBasic
config.CreateMap<PropertyGroup, Tab<ContentPropertyDisplay>>()
.ForMember(tab => tab.Label, expression => expression.MapFrom(@group => @group.Name))
.ForMember(tab => tab.IsActive, expression => expression.UseValue(true))
.ForMember(tab => tab.Properties, expression => expression.Ignore());
//FROM Property TO ContentPropertyBasic
config.CreateMap<Property, ContentPropertyBasic>()
.ConvertUsing<ContentPropertyBasicConverter<ContentPropertyBasic>>();
//FROM Property TO ContentPropertyDto
config.CreateMap<Property, ContentPropertyDto>()
.ConvertUsing(new ContentPropertyDtoConverter(applicationContext));
//FROM Property TO ContentPropertyDisplay
config.CreateMap<Property, ContentPropertyDisplay>()
.ConvertUsing(new ContentPropertyDisplayConverter(applicationContext));
}
}
}

View File

@@ -1,18 +1,18 @@
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Maps the Creator for content
/// </summary>
internal class CreatorResolver : ValueResolver<IContent, UserBasic>
{
protected override UserBasic ResolveCore(IContent source)
{
return Mapper.Map<IProfile, UserBasic>(source.GetWriterProfile());
}
}
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Maps the Creator for content
/// </summary>
internal class CreatorResolver : ValueResolver<IContent, UserBasic>
{
protected override UserBasic ResolveCore(IContent source)
{
return Mapper.Map<IProfile, UserBasic>(source.GetWriterProfile());
}
}
}

View File

@@ -1,20 +1,20 @@
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Defines mappings for content/media (and i'm sure one day member) type mappings
/// </summary>
internal class ContentTypeModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<IMediaType, ContentTypeBasic>();
config.CreateMap<IContentType, ContentTypeBasic>();
}
}
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Defines mappings for content/media (and i'm sure one day member) type mappings
/// </summary>
internal class ContentTypeModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<IMediaType, ContentTypeBasic>();
config.CreateMap<IContentType, ContentTypeBasic>();
}
}
}

View File

@@ -1,20 +1,20 @@
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Maps the Owner for IContentBase
/// </summary>
/// <typeparam name="TPersisted"></typeparam>
internal class OwnerResolver<TPersisted> : ValueResolver<TPersisted, UserBasic>
where TPersisted : IContentBase
{
protected override UserBasic ResolveCore(TPersisted source)
{
return Mapper.Map<IProfile, UserBasic>(source.GetCreatorProfile());
}
}
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Maps the Owner for IContentBase
/// </summary>
/// <typeparam name="TPersisted"></typeparam>
internal class OwnerResolver<TPersisted> : ValueResolver<TPersisted, UserBasic>
where TPersisted : IContentBase
{
protected override UserBasic ResolveCore(TPersisted source)
{
return Mapper.Map<IProfile, UserBasic>(source.GetCreatorProfile());
}
}
}

View File

@@ -1,16 +1,16 @@
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class SectionModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<Section, Core.Models.Section>()
.ReverseMap(); //backwards too!
}
}
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class SectionModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<Section, Core.Models.Section>()
.ReverseMap(); //backwards too!
}
}
}

View File

@@ -1,68 +1,68 @@
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates the tabs collection with properties assigned for display models
/// </summary>
internal class TabsAndPropertiesResolver : ValueResolver<IContentBase, IEnumerable<Tab<ContentPropertyDisplay>>>
{
protected override IEnumerable<Tab<ContentPropertyDisplay>> ResolveCore(IContentBase content)
{
var aggregateTabs = new List<Tab<ContentPropertyDisplay>>();
//now we need to aggregate the tabs and properties since we might have duplicate tabs (based on aliases) because
// of how content composition works.
foreach (var propertyGroups in content.PropertyGroups.GroupBy(x => x.Name))
{
var aggregateProperties = new List<ContentPropertyDisplay>();
//there will always be one group with a null parent id (the top-most)
//then we'll iterate over all of the groups and ensure the properties are
//added in order so that when they render they are rendered with highest leve
//parent properties first.
int? currentParentId = null;
for (var i = 0; i < propertyGroups.Count(); i++)
{
var current = propertyGroups.Single(x => x.ParentId == currentParentId);
aggregateProperties.AddRange(
Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(
content.GetPropertiesForGroup(current)));
currentParentId = current.Id;
}
//then we'll just use the root group's data to make the composite tab
var rootGroup = propertyGroups.Single(x => x.ParentId == null);
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = rootGroup.Id,
Alias = rootGroup.Name,
Label = rootGroup.Name,
Properties = aggregateProperties,
IsActive = false
});
}
//now add the generic properties tab for any properties that don't belong to a tab
var orphanProperties = content.GetNonGroupedProperties();
//now add the generic properties tab
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = 0,
Label = "Generic properties",
Alias = "Generic properties",
Properties = Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(orphanProperties)
});
//set the first tab to active
aggregateTabs.First().IsActive = true;
return aggregateTabs;
}
}
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates the tabs collection with properties assigned for display models
/// </summary>
internal class TabsAndPropertiesResolver : ValueResolver<IContentBase, IEnumerable<Tab<ContentPropertyDisplay>>>
{
protected override IEnumerable<Tab<ContentPropertyDisplay>> ResolveCore(IContentBase content)
{
var aggregateTabs = new List<Tab<ContentPropertyDisplay>>();
//now we need to aggregate the tabs and properties since we might have duplicate tabs (based on aliases) because
// of how content composition works.
foreach (var propertyGroups in content.PropertyGroups.GroupBy(x => x.Name))
{
var aggregateProperties = new List<ContentPropertyDisplay>();
//there will always be one group with a null parent id (the top-most)
//then we'll iterate over all of the groups and ensure the properties are
//added in order so that when they render they are rendered with highest leve
//parent properties first.
int? currentParentId = null;
for (var i = 0; i < propertyGroups.Count(); i++)
{
var current = propertyGroups.Single(x => x.ParentId == currentParentId);
aggregateProperties.AddRange(
Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(
content.GetPropertiesForGroup(current)));
currentParentId = current.Id;
}
//then we'll just use the root group's data to make the composite tab
var rootGroup = propertyGroups.Single(x => x.ParentId == null);
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = rootGroup.Id,
Alias = rootGroup.Name,
Label = rootGroup.Name,
Properties = aggregateProperties,
IsActive = false
});
}
//now add the generic properties tab for any properties that don't belong to a tab
var orphanProperties = content.GetNonGroupedProperties();
//now add the generic properties tab
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = 0,
Label = "Generic properties",
Alias = "Generic properties",
Properties = Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(orphanProperties)
});
//set the first tab to active
aggregateTabs.First().IsActive = true;
return aggregateTabs;
}
}
}

View File

@@ -1,47 +1,47 @@
using System;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models.Mapping;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class UserModelMapper : MapperConfiguration
{
#region Mapper config
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<IUser, UserDetail>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))
.ForMember(
detail => detail.EmailHash,
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()));
config.CreateMap<IProfile, UserBasic>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));
}
#endregion
private static int GetIntId(object id)
{
var result = id.TryConvertTo<int>();
if (result.Success == false)
{
throw new InvalidOperationException(
"Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
}
return result.Result;
}
public UserDetail ToUserDetail(IUser user)
{
return Mapper.Map<UserDetail>(user);
}
public UserBasic ToUserBasic(IProfile profile)
{
return Mapper.Map<UserBasic>(profile);
}
}
using System;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models.Mapping;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class UserModelMapper : MapperConfiguration
{
#region Mapper config
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<IUser, UserDetail>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))
.ForMember(
detail => detail.EmailHash,
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()));
config.CreateMap<IProfile, UserBasic>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));
}
#endregion
private static int GetIntId(object id)
{
var result = id.TryConvertTo<int>();
if (result.Success == false)
{
throw new InvalidOperationException(
"Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
}
return result.Result;
}
public UserDetail ToUserDetail(IUser user)
{
return Mapper.Map<UserDetail>(user);
}
public UserBasic ToUserBasic(IProfile profile)
{
return Mapper.Map<UserBasic>(profile);
}
}
}