Files
Umbraco-CMS/tests/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs

223 lines
9.0 KiB
C#
Raw Normal View History

2020-12-10 18:09:32 +11:00
using System.Collections.Generic;
2016-05-26 19:20:33 +02:00
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Runtime;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Core.Web;
namespace Umbraco.Tests.LegacyXmlPublishedCache
{
/// <summary>
2017-10-31 12:48:24 +01:00
/// Implements a published snapshot service.
/// </summary>
internal class XmlPublishedSnapshotService : IPublishedSnapshotService
{
private readonly XmlStore _xmlStore;
private readonly RoutesCache _routesCache;
2018-02-09 14:34:28 +01:00
private readonly IPublishedContentTypeFactory _publishedContentTypeFactory;
private readonly PublishedContentTypeCache _contentTypeCache;
private readonly IDomainService _domainService;
private readonly IMediaService _mediaService;
2016-07-20 12:44:15 +02:00
private readonly IUserService _userService;
2019-01-17 11:01:23 +01:00
private readonly IAppCache _requestCache;
2020-09-08 13:03:43 +02:00
private readonly GlobalSettings _globalSettings;
2018-04-30 21:29:49 +02:00
private readonly IDefaultCultureAccessor _defaultCultureAccessor;
private readonly IEntityXmlSerializer _entitySerializer;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
#region Constructors
2016-05-26 19:20:33 +02:00
// used in WebBootManager + tests
public XmlPublishedSnapshotService(
ServiceContext serviceContext,
2017-10-17 17:43:15 +02:00
IPublishedContentTypeFactory publishedContentTypeFactory,
2017-05-30 19:41:37 +02:00
IScopeProvider scopeProvider,
2019-01-17 11:01:23 +01:00
IAppCache requestCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentRepository documentRepository,
IMediaRepository mediaRepository,
IMemberRepository memberRepository,
2018-04-30 21:29:49 +02:00
IDefaultCultureAccessor defaultCultureAccessor,
ILoggerFactory loggerFactory,
2020-09-08 13:03:43 +02:00
GlobalSettings globalSettings,
IHostingEnvironment hostingEnvironment,
IApplicationShutdownRegistry hostingLifetime,
IShortStringHelper shortStringHelper,
IEntityXmlSerializer entitySerializer,
MainDom mainDom,
bool testing = false,
bool enableRepositoryEvents = true)
: this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache,
publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor,
2017-12-14 17:04:44 +01:00
documentRepository, mediaRepository, memberRepository,
2018-04-30 21:29:49 +02:00
defaultCultureAccessor,
loggerFactory, globalSettings, hostingEnvironment, hostingLifetime, shortStringHelper, entitySerializer, null, mainDom, testing, enableRepositoryEvents)
{
_umbracoContextAccessor = umbracoContextAccessor;
}
2016-05-26 19:20:33 +02:00
// used in some tests
internal XmlPublishedSnapshotService(
ServiceContext serviceContext,
2017-10-17 17:43:15 +02:00
IPublishedContentTypeFactory publishedContentTypeFactory,
2017-05-30 19:41:37 +02:00
IScopeProvider scopeProvider,
2019-01-17 11:01:23 +01:00
IAppCache requestCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentRepository documentRepository,
IMediaRepository mediaRepository,
IMemberRepository memberRepository,
2018-04-30 21:29:49 +02:00
IDefaultCultureAccessor defaultCultureAccessor,
ILoggerFactory loggerFactory,
2020-09-08 13:03:43 +02:00
GlobalSettings globalSettings,
IHostingEnvironment hostingEnvironment,
IApplicationShutdownRegistry hostingLifetime,
IShortStringHelper shortStringHelper,
IEntityXmlSerializer entitySerializer,
2017-07-20 11:21:28 +02:00
PublishedContentTypeCache contentTypeCache,
MainDom mainDom,
bool testing,
bool enableRepositoryEvents)
{
_routesCache = new RoutesCache();
2018-02-09 14:34:28 +01:00
_publishedContentTypeFactory = publishedContentTypeFactory;
_contentTypeCache = contentTypeCache
?? new PublishedContentTypeCache(serviceContext.ContentTypeService, serviceContext.MediaTypeService, serviceContext.MemberTypeService, publishedContentTypeFactory, loggerFactory.CreateLogger<PublishedContentTypeCache>());
_xmlStore = new XmlStore(serviceContext.ContentTypeService, serviceContext.ContentService, scopeProvider, _routesCache,
_contentTypeCache, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents,
documentRepository, mediaRepository, memberRepository, entitySerializer, hostingEnvironment, hostingLifetime, shortStringHelper);
_domainService = serviceContext.DomainService;
_mediaService = serviceContext.MediaService;
2016-07-20 12:44:15 +02:00
_userService = serviceContext.UserService;
2018-04-30 21:29:49 +02:00
_defaultCultureAccessor = defaultCultureAccessor;
_variationContextAccessor = variationContextAccessor;
_requestCache = requestCache;
_umbracoContextAccessor = umbracoContextAccessor;
_globalSettings = globalSettings;
_entitySerializer = entitySerializer;
}
public void Dispose()
{
_xmlStore.Dispose();
}
#endregion
public IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
{
// use _requestCache to store recursive properties lookup, etc. both in content
// and media cache. Life span should be the current request. Or, ideally
// the current caches, but that would mean creating an extra cache (StaticCache
// probably) so better use RequestCache.
2018-04-30 21:29:49 +02:00
var domainCache = new DomainCache(_domainService, _defaultCultureAccessor);
2018-04-27 11:38:50 +10:00
return new PublishedSnapshot(
2020-12-10 18:09:32 +11:00
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _contentTypeCache, _routesCache, _variationContextAccessor, previewToken),
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache, _entitySerializer, _umbracoContextAccessor, _variationContextAccessor),
Published members cleanup (#10159) * Getting new netcore PublicAccessChecker in place * Adds full test coverage for PublicAccessChecker * remove PublicAccessComposer * adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller * Implements the required methods on IMemberManager, removes old migrated code * Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops * adds note * adds note * Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling. * Changes name to IUmbracoEndpointBuilder * adds note * Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect * fixing build * Updates user manager to correctly validate password hashing and injects the IBackOfficeUserPasswordChecker * Merges PR * Fixes up build and notes * Implements security stamp and email confirmed for members, cleans up a bunch of repo/service level member groups stuff, shares user store code between members and users and fixes the user identity object so we arent' tracking both groups and roles. * Security stamp for members is now working * Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware. * adds note * removes unused filter, fixes build * fixes WebPath and tests * Looks up entities in one query * remove usings * Fix test, remove stylesheet * Set status code before we write to response to avoid error * Ensures that users and members are validated when logging in. Shares more code between users and members. * merge changes * oops * Reducing and removing published member cache * Fixes RepositoryCacheKeys to ensure the keys are normalized * oops didn't mean to commit this * Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy * oops didn't mean to comit this * bah, far out this keeps getting recommitted. sorry * cannot inject IPublishedMemberCache and cannot have IPublishedMember * splits out files, fixes build * fix tests * removes membership provider classes * removes membership provider classes * updates the identity map definition * reverts commented out lines * reverts commented out lines Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-22 21:21:43 +10:00
new PublishedMemberCache(_contentTypeCache, _variationContextAccessor),
domainCache);
}
#region Xml specific
/// <summary>
/// Gets the underlying XML store.
/// </summary>
public XmlStore XmlStore => _xmlStore;
/// <summary>
/// Gets the underlying RoutesCache.
/// </summary>
public RoutesCache RoutesCache => _routesCache;
public bool VerifyContentAndPreviewXml()
{
return XmlStore.VerifyContentAndPreviewXml();
}
public void RebuildContentAndPreviewXml()
{
XmlStore.RebuildContentAndPreviewXml();
}
public bool VerifyMediaXml()
{
return XmlStore.VerifyMediaXml();
}
public void RebuildMediaXml()
{
XmlStore.RebuildMediaXml();
}
public bool VerifyMemberXml()
{
return XmlStore.VerifyMemberXml();
}
public void RebuildMemberXml()
{
XmlStore.RebuildMemberXml();
}
#endregion
#region Change management
public void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged)
{
_xmlStore.Notify(payloads, out draftChanged, out publishedChanged);
}
public void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged)
{
foreach (var payload in payloads)
PublishedMediaCache.ClearCache(payload.Id);
anythingChanged = true;
}
public void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads)
{
_xmlStore.Notify(payloads);
if (payloads.Any(x => x.ItemType == typeof(IContentType).Name))
_routesCache.Clear();
}
public void Notify(DataTypeCacheRefresher.JsonPayload[] payloads)
{
2018-02-09 14:34:28 +01:00
_publishedContentTypeFactory.NotifyDataTypeChanges(payloads.Select(x => x.Id).ToArray());
_xmlStore.Notify(payloads);
}
public void Notify(DomainCacheRefresher.JsonPayload[] payloads)
{
_routesCache.Clear();
}
#endregion
public void Rebuild(int groupSize = 5000, IReadOnlyCollection<int> contentTypeIds = null, IReadOnlyCollection<int> mediaTypeIds = null, IReadOnlyCollection<int> memberTypeIds = null) { }
public Task CollectAsync() => Task.CompletedTask;
}
}