2021-04-22 20:25:25 +10:00
using System ;
2021-02-18 11:06:02 +01:00
using Umbraco.Cms.Core ;
using Umbraco.Cms.Core.Cache ;
using Umbraco.Cms.Core.PublishedCache ;
2016-05-27 14:26:28 +02:00
2021-02-18 11:06:02 +01:00
namespace Umbraco.Cms.Infrastructure.PublishedCache
2016-05-27 14:26:28 +02:00
{
2017-10-31 12:48:24 +01:00
// implements published snapshot
2021-07-06 07:55:05 +02:00
public class PublishedSnapshot : IPublishedSnapshot , IDisposable
2016-05-27 14:26:28 +02:00
{
2017-10-31 12:48:24 +01:00
private readonly PublishedSnapshotService _service ;
2016-06-09 18:45:16 +02:00
private bool _defaultPreview ;
2017-10-31 12:48:24 +01:00
private PublishedSnapshotElements _elements ;
2016-05-27 14:26:28 +02:00
#region Constructors
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
public PublishedSnapshot ( IPublishedSnapshotService service , bool defaultPreview )
2016-05-27 14:26:28 +02:00
{
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
_service = service as PublishedSnapshotService ;
2016-05-27 14:26:28 +02:00
_defaultPreview = defaultPreview ;
}
2017-10-31 12:48:24 +01:00
public class PublishedSnapshotElements : IDisposable
2016-05-27 14:26:28 +02:00
{
2021-04-22 20:25:25 +10:00
#pragma warning disable IDE1006 // Naming Styles
2016-05-27 14:26:28 +02:00
public ContentCache ContentCache ;
public MediaCache MediaCache ;
public MemberCache MemberCache ;
public DomainCache DomainCache ;
2019-01-17 11:01:23 +01:00
public IAppCache SnapshotCache ;
public IAppCache ElementsCache ;
2021-04-22 20:25:25 +10:00
#pragma warning restore IDE1006 // Naming Styles
2016-05-27 14:26:28 +02:00
public void Dispose ( )
{
ContentCache . Dispose ( ) ;
MediaCache . Dispose ( ) ;
2021-04-20 17:56:55 +10:00
MemberCache . Dispose ( ) ;
2016-05-27 14:26:28 +02:00
}
}
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
private PublishedSnapshotElements Elements
{
get
{
if ( _service = = null )
{
throw new InvalidOperationException ( $"The {typeof(PublishedSnapshot)} cannot be used when the {typeof(IPublishedSnapshotService)} is not the default type {typeof(PublishedSnapshotService)}" ) ;
}
return _elements ? ? = _service . GetElements ( _defaultPreview ) ;
}
}
2016-05-27 14:26:28 +02:00
public void Resync ( )
{
2017-10-31 12:48:24 +01:00
// no lock - published snapshots are single-thread
2016-05-30 19:54:36 +02:00
_elements ? . Dispose ( ) ;
2016-05-27 14:26:28 +02:00
_elements = null ;
}
#endregion
#region Caches
2019-01-17 11:01:23 +01:00
public IAppCache SnapshotCache = > Elements . SnapshotCache ;
2016-05-27 14:26:28 +02:00
2019-01-17 11:01:23 +01:00
public IAppCache ElementsCache = > Elements . ElementsCache ;
2016-05-27 14:26:28 +02:00
#endregion
2017-10-31 12:48:24 +01:00
#region IPublishedSnapshot
2016-05-27 14:26:28 +02:00
2017-10-31 12:50:30 +01:00
public IPublishedContentCache Content = > Elements . ContentCache ;
2016-05-27 14:26:28 +02:00
2017-10-31 12:50:30 +01:00
public IPublishedMediaCache Media = > Elements . MediaCache ;
2016-05-27 14:26:28 +02:00
2017-10-31 12:50:30 +01:00
public IPublishedMemberCache Members = > Elements . MemberCache ;
2016-05-27 14:26:28 +02:00
2017-10-31 12:50:30 +01:00
public IDomainCache Domains = > Elements . DomainCache ;
2016-05-27 14:26:28 +02:00
2016-06-09 18:45:16 +02:00
public IDisposable ForcedPreview ( bool preview , Action < bool > callback = null )
{
return new ForcedPreviewObject ( this , preview , callback ) ;
}
2019-02-15 10:42:02 +11:00
private class ForcedPreviewObject : DisposableObjectSlim
2016-06-09 18:45:16 +02:00
{
2018-04-27 11:38:50 +10:00
private readonly PublishedSnapshot _publishedSnapshot ;
2016-06-09 18:45:16 +02:00
private readonly bool _origPreview ;
private readonly Action < bool > _callback ;
2018-04-27 11:38:50 +10:00
public ForcedPreviewObject ( PublishedSnapshot publishedShapshot , bool preview , Action < bool > callback )
2016-06-09 18:45:16 +02:00
{
2018-04-27 11:38:50 +10:00
_publishedSnapshot = publishedShapshot ;
2016-06-09 18:45:16 +02:00
_callback = callback ;
// save and force
2017-10-31 12:48:24 +01:00
_origPreview = publishedShapshot . _defaultPreview ;
publishedShapshot . _defaultPreview = preview ;
2016-06-09 18:45:16 +02:00
}
protected override void DisposeResources ( )
{
// restore
2018-04-27 11:38:50 +10:00
_publishedSnapshot . _defaultPreview = _origPreview ;
2016-06-09 18:45:16 +02:00
_callback ? . Invoke ( _origPreview ) ;
}
}
2016-05-27 14:26:28 +02:00
#endregion
#region IDisposable
private bool _disposed ;
public void Dispose ( )
{
if ( _disposed ) return ;
_disposed = true ;
2016-05-30 19:54:36 +02:00
_elements ? . Dispose ( ) ;
2016-05-27 14:26:28 +02:00
}
#endregion
}
}