Files
Umbraco-CMS/src/Umbraco.Web/PublishedCache/NuCache/PublishedMember.cs

117 lines
5.0 KiB
C#
Raw Normal View History

2016-05-27 14:26:28 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
namespace Umbraco.Web.PublishedCache.NuCache
{
// note
// the whole PublishedMember thing should be refactored because as soon as a member
// is wrapped on in a model, the inner IMember and all associated properties are lost
2017-07-12 14:09:31 +02:00
internal class PublishedMember : PublishedContent //, IPublishedMember
2016-05-27 14:26:28 +02:00
{
private readonly IMember _member;
private PublishedMember(IMember member, ContentNode contentNode, ContentData contentData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedVariationContextAccessor variationContextAccessor)
: base(contentNode, contentData, publishedSnapshotAccessor, variationContextAccessor)
2016-05-27 14:26:28 +02:00
{
_member = member;
}
public static IPublishedContent Create(IMember member, PublishedContentType contentType, bool previewing, IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedVariationContextAccessor variationContextAccessor)
2016-05-27 14:26:28 +02:00
{
var d = new ContentData
{
Name = member.Name,
Published = previewing,
TemplateId = -1,
VersionDate = member.UpdateDate,
WriterId = member.CreatorId, // what else?
Properties = GetPropertyValues(contentType, member)
};
var n = new ContentNode(member.Id, member.Key,
contentType,
member.Level, member.Path, member.SortOrder,
member.ParentId,
member.CreateDate, member.CreatorId);
return new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
2016-05-27 14:26:28 +02:00
}
2017-12-07 13:22:32 +01:00
private static Dictionary<string, PropertyData[]> GetPropertyValues(PublishedContentType contentType, IMember member)
2016-05-27 14:26:28 +02:00
{
2017-10-31 12:48:24 +01:00
// see node in PublishedSnapshotService
2016-05-27 14:26:28 +02:00
// we do not (want to) support ConvertDbToXml/String
//var propertyEditorResolver = PropertyEditorResolver.Current;
2017-12-07 13:22:32 +01:00
// see note in MemberType.Variations
// we don't want to support variations on members
2016-05-27 14:26:28 +02:00
var properties = member
.Properties
//.Select(property =>
//{
// var e = propertyEditorResolver.GetByAlias(property.PropertyType.PropertyEditorAlias);
// var v = e == null
// ? property.Value
// : e.ValueEditor.ConvertDbToString(property, property.PropertyType, ApplicationContext.Current.Services.DataTypeService);
// return new KeyValuePair<string, object>(property.Alias, v);
//})
//.ToDictionary(x => x.Key, x => x.Value);
2017-12-07 13:22:32 +01:00
.ToDictionary(x => x.Alias, x => new[] { new PropertyData { Value = x.GetValue() } }, StringComparer.OrdinalIgnoreCase);
2016-05-27 14:26:28 +02:00
2016-06-03 10:57:54 +02:00
// see also PublishedContentType
2016-05-27 14:26:28 +02:00
AddIf(contentType, properties, "Email", member.Email);
AddIf(contentType, properties, "Username", member.Username);
2016-06-03 10:57:54 +02:00
AddIf(contentType, properties, "PasswordQuestion", member.PasswordQuestion);
AddIf(contentType, properties, "Comments", member.Comments);
AddIf(contentType, properties, "IsApproved", member.IsApproved);
AddIf(contentType, properties, "IsLockedOut", member.IsLockedOut);
AddIf(contentType, properties, "LastLockoutDate", member.LastLockoutDate);
AddIf(contentType, properties, "CreateDate", member.CreateDate);
AddIf(contentType, properties, "LastLoginDate", member.LastLoginDate);
AddIf(contentType, properties, "LastPasswordChangeDate", member.LastPasswordChangeDate);
2016-05-27 14:26:28 +02:00
return properties;
}
2017-12-07 13:22:32 +01:00
private static void AddIf(PublishedContentType contentType, IDictionary<string, PropertyData[]> properties, string alias, object value)
2016-05-27 14:26:28 +02:00
{
var propertyType = contentType.GetPropertyType(alias);
if (propertyType == null || propertyType.IsUserProperty) return;
2017-12-07 13:22:32 +01:00
properties[alias] = new[] { new PropertyData { Value = value } };
2016-05-27 14:26:28 +02:00
}
#region IPublishedMember
2017-07-12 14:09:31 +02:00
public IMember Member => _member;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public string Email => _member.Email;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public string UserName => _member.Username;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public string PasswordQuestion => _member.PasswordQuestion;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public string Comments => _member.Comments;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public bool IsApproved => _member.IsApproved;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public bool IsLockedOut => _member.IsLockedOut;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public DateTime LastLockoutDate => _member.LastLockoutDate;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public DateTime CreationDate => _member.CreateDate;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public DateTime LastLoginDate => _member.LastLoginDate;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public DateTime LastActivityDate => _member.LastLoginDate;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public DateTime LastPasswordChangedDate => _member.LastPasswordChangeDate;
2016-05-27 14:26:28 +02:00
#endregion
}
}