Renamed the project to Umbraco.PublishedCache.NuCache - and move non NuCache related stuff to abstractions and infrastructure.
This commit is contained in:
111
src/Umbraco.Abstractions/PublishedCache/PublishedCacheBase.cs
Normal file
111
src/Umbraco.Abstractions/PublishedCache/PublishedCacheBase.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Xml;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
public abstract class PublishedCacheBase : IPublishedCache
|
||||
{
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
|
||||
public PublishedCacheBase(IVariationContextAccessor variationContextAccessor)
|
||||
{
|
||||
_variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
|
||||
}
|
||||
public bool PreviewDefault { get; }
|
||||
|
||||
protected PublishedCacheBase(bool previewDefault)
|
||||
{
|
||||
PreviewDefault = previewDefault;
|
||||
}
|
||||
|
||||
public abstract IPublishedContent GetById(bool preview, int contentId);
|
||||
|
||||
public IPublishedContent GetById(int contentId)
|
||||
=> GetById(PreviewDefault, contentId);
|
||||
|
||||
public abstract IPublishedContent GetById(bool preview, Guid contentId);
|
||||
|
||||
public IPublishedContent GetById(Guid contentId)
|
||||
=> GetById(PreviewDefault, contentId);
|
||||
|
||||
public abstract IPublishedContent GetById(bool preview, Udi contentId);
|
||||
|
||||
public IPublishedContent GetById(Udi contentId)
|
||||
=> GetById(PreviewDefault, contentId);
|
||||
|
||||
public abstract bool HasById(bool preview, int contentId);
|
||||
|
||||
public bool HasById(int contentId)
|
||||
=> HasById(PreviewDefault, contentId);
|
||||
|
||||
public abstract IEnumerable<IPublishedContent> GetAtRoot(bool preview, string culture = null);
|
||||
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(string culture = null)
|
||||
{
|
||||
return GetAtRoot(PreviewDefault, culture);
|
||||
}
|
||||
|
||||
public abstract IPublishedContent GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars);
|
||||
|
||||
public IPublishedContent GetSingleByXPath(string xpath, XPathVariable[] vars)
|
||||
{
|
||||
return GetSingleByXPath(PreviewDefault, xpath, vars);
|
||||
}
|
||||
|
||||
public abstract IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, XPathVariable[] vars);
|
||||
|
||||
public IPublishedContent GetSingleByXPath(XPathExpression xpath, XPathVariable[] vars)
|
||||
{
|
||||
return GetSingleByXPath(PreviewDefault, xpath, vars);
|
||||
}
|
||||
|
||||
public abstract IEnumerable<IPublishedContent> GetByXPath(bool preview, string xpath, XPathVariable[] vars);
|
||||
|
||||
public IEnumerable<IPublishedContent> GetByXPath(string xpath, XPathVariable[] vars)
|
||||
{
|
||||
return GetByXPath(PreviewDefault, xpath, vars);
|
||||
}
|
||||
|
||||
public abstract IEnumerable<IPublishedContent> GetByXPath(bool preview, XPathExpression xpath, XPathVariable[] vars);
|
||||
|
||||
public IEnumerable<IPublishedContent> GetByXPath(XPathExpression xpath, XPathVariable[] vars)
|
||||
{
|
||||
return GetByXPath(PreviewDefault, xpath, vars);
|
||||
}
|
||||
|
||||
public abstract XPathNavigator CreateNavigator(bool preview);
|
||||
|
||||
public XPathNavigator CreateNavigator()
|
||||
{
|
||||
return CreateNavigator(PreviewDefault);
|
||||
}
|
||||
|
||||
public abstract XPathNavigator CreateNodeNavigator(int id, bool preview);
|
||||
|
||||
public abstract bool HasContent(bool preview);
|
||||
|
||||
public bool HasContent()
|
||||
{
|
||||
return HasContent(PreviewDefault);
|
||||
}
|
||||
|
||||
public abstract IPublishedContentType GetContentType(int id);
|
||||
|
||||
public abstract IPublishedContentType GetContentType(string alias);
|
||||
|
||||
public virtual IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
|
||||
{
|
||||
// this is probably not super-efficient, but works
|
||||
// some cache implementation may want to override it, though
|
||||
return GetAtRoot()
|
||||
.SelectMany(x => x.DescendantsOrSelf(_variationContextAccessor))
|
||||
.Where(x => x.ContentType.Id == contentType.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
158
src/Umbraco.Abstractions/PublishedCache/PublishedMember.cs
Normal file
158
src/Umbraco.Abstractions/PublishedCache/PublishedMember.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Exposes a member object as IPublishedContent
|
||||
/// </summary>
|
||||
public sealed class PublishedMember : PublishedContentBase
|
||||
{
|
||||
private readonly IMember _member;
|
||||
private readonly IMembershipUser _membershipUser;
|
||||
private readonly IPublishedProperty[] _properties;
|
||||
private readonly IPublishedContentType _publishedMemberType;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public PublishedMember(
|
||||
IMember member,
|
||||
IPublishedContentType publishedMemberType,
|
||||
IUserService userService,
|
||||
IVariationContextAccessor variationContextAccessor) : base(variationContextAccessor)
|
||||
{
|
||||
_member = member ?? throw new ArgumentNullException(nameof(member));
|
||||
_membershipUser = member;
|
||||
_publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
|
||||
// RawValueProperty is used for two things here
|
||||
// - for the 'map properties' thing that we should really get rid of
|
||||
// - for populating properties that every member should always have, and that we force-create
|
||||
// if they are not part of the member type properties - in which case they are created as
|
||||
// simple raw properties - which are completely invariant
|
||||
|
||||
var properties = new List<IPublishedProperty>();
|
||||
foreach (var propertyType in _publishedMemberType.PropertyTypes)
|
||||
{
|
||||
var property = _member.Properties[propertyType.Alias];
|
||||
if (property == null) continue;
|
||||
|
||||
properties.Add(new RawValueProperty(propertyType, this, property.GetValue()));
|
||||
}
|
||||
EnsureMemberProperties(properties);
|
||||
_properties = properties.ToArray();
|
||||
}
|
||||
|
||||
#region Membership provider member properties
|
||||
|
||||
public string Email => _membershipUser.Email;
|
||||
|
||||
public string UserName => _membershipUser.Username;
|
||||
|
||||
public string Comments => _membershipUser.Comments;
|
||||
|
||||
public bool IsApproved => _membershipUser.IsApproved;
|
||||
|
||||
public bool IsLockedOut => _membershipUser.IsLockedOut;
|
||||
|
||||
public DateTime LastLockoutDate => _membershipUser.LastLockoutDate;
|
||||
|
||||
public DateTime CreationDate => _membershipUser.CreateDate;
|
||||
|
||||
public DateTime LastLoginDate => _membershipUser.LastLoginDate;
|
||||
|
||||
public DateTime LastActivityDate => _membershipUser.LastLoginDate;
|
||||
|
||||
public DateTime LastPasswordChangeDate => _membershipUser.LastPasswordChangeDate;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPublishedContent
|
||||
|
||||
public override PublishedItemType ItemType => PublishedItemType.Member;
|
||||
|
||||
public override bool IsDraft(string culture = null) => false;
|
||||
|
||||
public override bool IsPublished(string culture = null) => true;
|
||||
|
||||
public override IPublishedContent Parent => null;
|
||||
|
||||
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
|
||||
|
||||
public override IEnumerable<IPublishedContent> ChildrenForAllCultures => Enumerable.Empty<IPublishedContent>();
|
||||
|
||||
public override IEnumerable<IPublishedProperty> Properties => _properties;
|
||||
|
||||
public override IPublishedProperty GetProperty(string alias)
|
||||
{
|
||||
return _properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
|
||||
}
|
||||
|
||||
private void EnsureMemberProperties(List<IPublishedProperty> properties)
|
||||
{
|
||||
var aliases = properties.Select(x => x.Alias).ToList();
|
||||
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.Email), Email);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.Username), UserName);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.Comments), Comments);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.IsApproved), IsApproved);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.IsLockedOut), IsLockedOut);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.LastLockoutDate), LastLockoutDate);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.CreateDate), CreateDate);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.LastLoginDate), LastLoginDate);
|
||||
EnsureMemberProperty(properties, aliases, nameof(IMember.LastPasswordChangeDate), LastPasswordChangeDate);
|
||||
}
|
||||
|
||||
private void EnsureMemberProperty(List<IPublishedProperty> properties, List<string> aliases, string alias, object value)
|
||||
{
|
||||
// if the property already has a value, nothing to do
|
||||
if (aliases.Contains(alias)) return;
|
||||
|
||||
// if not a property type, ignore
|
||||
var propertyType = ContentType.GetPropertyType(alias);
|
||||
if (propertyType == null) return;
|
||||
|
||||
// create a raw-value property
|
||||
// note: throws if propertyType variations is not InvariantNeutral
|
||||
var property = new RawValueProperty(propertyType, this, value);
|
||||
properties.Add(property);
|
||||
}
|
||||
|
||||
public override IPublishedContentType ContentType => _publishedMemberType;
|
||||
|
||||
public override int Id => _member.Id;
|
||||
|
||||
public override Guid Key => _member.Key;
|
||||
|
||||
public override int? TemplateId => throw new NotSupportedException();
|
||||
|
||||
public override int SortOrder => 0;
|
||||
|
||||
public override string Name => _member.Name;
|
||||
|
||||
public override IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => throw new NotSupportedException();
|
||||
|
||||
public override string UrlSegment => throw new NotSupportedException();
|
||||
|
||||
public override int WriterId => _member.CreatorId;
|
||||
|
||||
public override int CreatorId => _member.CreatorId;
|
||||
|
||||
public override string Path => _member.Path;
|
||||
|
||||
public override DateTime CreateDate => _member.CreateDate;
|
||||
|
||||
public override DateTime UpdateDate => _member.UpdateDate;
|
||||
|
||||
public override int Level => _member.Level;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.Cache;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
public abstract class PublishedSnapshotServiceBase : IPublishedSnapshotService
|
||||
{
|
||||
protected PublishedSnapshotServiceBase(IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
|
||||
{
|
||||
PublishedSnapshotAccessor = publishedSnapshotAccessor;
|
||||
VariationContextAccessor = variationContextAccessor;
|
||||
}
|
||||
|
||||
public IPublishedSnapshotAccessor PublishedSnapshotAccessor { get; }
|
||||
public IVariationContextAccessor VariationContextAccessor { get; }
|
||||
|
||||
// note: NOT setting _publishedSnapshotAccessor.PublishedSnapshot here because it is the
|
||||
// responsibility of the caller to manage what the 'current' facade is
|
||||
public abstract IPublishedSnapshot CreatePublishedSnapshot(string previewToken);
|
||||
|
||||
protected IPublishedSnapshot CurrentPublishedSnapshot => PublishedSnapshotAccessor.PublishedSnapshot;
|
||||
|
||||
public abstract bool EnsureEnvironment(out IEnumerable<string> errors);
|
||||
|
||||
public abstract string EnterPreview(IUser user, int contentId);
|
||||
public abstract void RefreshPreview(string previewToken, int contentId);
|
||||
public abstract void ExitPreview(string previewToken);
|
||||
public abstract void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged);
|
||||
public abstract void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged);
|
||||
public abstract void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads);
|
||||
public abstract void Notify(DataTypeCacheRefresher.JsonPayload[] payloads);
|
||||
public abstract void Notify(DomainCacheRefresher.JsonPayload[] payloads);
|
||||
|
||||
public virtual void Rebuild()
|
||||
{ }
|
||||
|
||||
public virtual void Dispose()
|
||||
{ }
|
||||
|
||||
public abstract string GetStatus();
|
||||
|
||||
public virtual string StatusUrl => "views/dashboard/settings/publishedsnapshotcache.html";
|
||||
|
||||
public virtual void Collect()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user