Fixes IPublishedShapshot and friends
This commit is contained in:
@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var xmlStore = new XmlStore(() => _xml, null, null, null);
|
||||
var cacheProvider = new StaticCacheProvider();
|
||||
var domainCache = new DomainCache(ServiceContext.DomainService, ServiceContext.LocalizationService);
|
||||
var publishedShapshot = new Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedShapshot(
|
||||
var publishedShapshot = new Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedSnapshot(
|
||||
new PublishedContentCache(xmlStore, domainCache, cacheProvider, globalSettings, new SiteDomainHelper(), ContentTypesCache, null, null),
|
||||
new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, cacheProvider, ContentTypesCache),
|
||||
new PublishedMemberCache(null, cacheProvider, Current.Services.MemberService, ContentTypesCache),
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Umbraco.Tests.Published
|
||||
var cacheMock = new Mock<IPublishedContentCache>();
|
||||
var cacheContent = new Dictionary<int, IPublishedContent>();
|
||||
cacheMock.Setup(x => x.GetById(It.IsAny<int>())).Returns<int>(id => cacheContent.TryGetValue(id, out IPublishedContent content) ? content : null);
|
||||
var publishedSnapshotMock = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshotMock = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshotMock.Setup(x => x.Content).Returns(cacheMock.Object);
|
||||
var publishedSnapshotAccessorMock = new Mock<IPublishedSnapshotAccessor>();
|
||||
publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot).Returns(publishedSnapshotMock.Object);
|
||||
@@ -164,7 +164,7 @@ namespace Umbraco.Tests.Published
|
||||
var cacheMock = new Mock<IPublishedContentCache>();
|
||||
var cacheContent = new Dictionary<int, IPublishedContent>();
|
||||
cacheMock.Setup(x => x.GetById(It.IsAny<int>())).Returns<int>(id => cacheContent.TryGetValue(id, out IPublishedContent content) ? content : null);
|
||||
var publishedSnapshotMock = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshotMock = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshotMock.Setup(x => x.Content).Returns(cacheMock.Object);
|
||||
var publishedSnapshotAccessorMock = new Mock<IPublishedSnapshotAccessor>();
|
||||
publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot).Returns(publishedSnapshotMock.Object);
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Tests.Published
|
||||
});
|
||||
|
||||
var contentCache = new Mock<IPublishedContentCache>();
|
||||
var publishedSnapshot = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshot = new Mock<IPublishedSnapshot>();
|
||||
|
||||
// mocked published snapshot returns a content cache
|
||||
publishedSnapshot
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Umbraco.Tests.Published
|
||||
var elementsCache = new DictionaryCacheProvider();
|
||||
var snapshotCache = new DictionaryCacheProvider();
|
||||
|
||||
var publishedSnapshot = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshot = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshot.Setup(x => x.SnapshotCache).Returns(snapshotCache);
|
||||
publishedSnapshot.Setup(x => x.ElementsCache).Returns(elementsCache);
|
||||
|
||||
|
||||
@@ -197,13 +197,13 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.AreEqual(2, result[1].Id);
|
||||
}
|
||||
|
||||
private static SolidPublishedShapshot CreatePublishedSnapshot()
|
||||
private static SolidPublishedSnapshot CreatePublishedSnapshot()
|
||||
{
|
||||
var dataTypeService = new TestObjects.TestDataTypeService(
|
||||
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
|
||||
|
||||
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
|
||||
var caches = new SolidPublishedShapshot();
|
||||
var caches = new SolidPublishedSnapshot();
|
||||
var cache = caches.InnerContentCache;
|
||||
|
||||
var props = new[]
|
||||
|
||||
@@ -1,347 +1,347 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
class SolidPublishedShapshot : IPublishedShapshot
|
||||
{
|
||||
public readonly SolidPublishedContentCache InnerContentCache = new SolidPublishedContentCache();
|
||||
public readonly SolidPublishedContentCache InnerMediaCache = new SolidPublishedContentCache();
|
||||
|
||||
public IPublishedContentCache Content => InnerContentCache;
|
||||
|
||||
public IPublishedMediaCache Media => InnerMediaCache;
|
||||
|
||||
public IPublishedMemberCache Members => null;
|
||||
|
||||
public IDomainCache Domains => null;
|
||||
|
||||
public IDisposable ForcedPreview(bool forcedPreview, Action<bool> callback = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Resync()
|
||||
{ }
|
||||
|
||||
public ICacheProvider SnapshotCache => null;
|
||||
|
||||
public ICacheProvider ElementsCache => null;
|
||||
}
|
||||
|
||||
class SolidPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache
|
||||
{
|
||||
private readonly Dictionary<int, IPublishedContent> _content = new Dictionary<int, IPublishedContent>();
|
||||
|
||||
public SolidPublishedContentCache()
|
||||
: base(false)
|
||||
{ }
|
||||
|
||||
public void Add(SolidPublishedContent content)
|
||||
{
|
||||
_content[content.Id] = content.CreateModel();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_content.Clear();
|
||||
}
|
||||
|
||||
public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetRouteById(bool preview, int contentId, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetRouteById(int contentId, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, int contentId)
|
||||
{
|
||||
return _content.ContainsKey(contentId) ? _content[contentId] : null;
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Guid contentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
return _content.ContainsKey(contentId);
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetAtRoot(bool preview)
|
||||
{
|
||||
return _content.Values.Where(x => x.Parent == null);
|
||||
}
|
||||
|
||||
public override IPublishedContent GetSingleByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool HasContent(bool preview)
|
||||
{
|
||||
return _content.Count > 0;
|
||||
}
|
||||
|
||||
public override PublishedContentType GetContentType(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override PublishedContentType GetContentType(string alias)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetByContentType(PublishedContentType contentType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
class SolidPublishedContent : IPublishedContent
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public SolidPublishedContent(PublishedContentType contentType)
|
||||
{
|
||||
// initialize boring stuff
|
||||
TemplateId = 0;
|
||||
WriterName = CreatorName = string.Empty;
|
||||
WriterId = CreatorId = 0;
|
||||
CreateDate = UpdateDate = DateTime.Now;
|
||||
Version = Guid.Empty;
|
||||
IsDraft = false;
|
||||
|
||||
ContentType = contentType;
|
||||
DocumentTypeAlias = contentType.Alias;
|
||||
DocumentTypeId = contentType.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Content
|
||||
|
||||
public int Id { get; set; }
|
||||
public Guid Key { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
class SolidPublishedSnapshot : IPublishedSnapshot
|
||||
{
|
||||
public readonly SolidPublishedContentCache InnerContentCache = new SolidPublishedContentCache();
|
||||
public readonly SolidPublishedContentCache InnerMediaCache = new SolidPublishedContentCache();
|
||||
|
||||
public IPublishedContentCache Content => InnerContentCache;
|
||||
|
||||
public IPublishedMediaCache Media => InnerMediaCache;
|
||||
|
||||
public IPublishedMemberCache Members => null;
|
||||
|
||||
public IDomainCache Domains => null;
|
||||
|
||||
public IDisposable ForcedPreview(bool forcedPreview, Action<bool> callback = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Resync()
|
||||
{ }
|
||||
|
||||
public ICacheProvider SnapshotCache => null;
|
||||
|
||||
public ICacheProvider ElementsCache => null;
|
||||
}
|
||||
|
||||
class SolidPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache
|
||||
{
|
||||
private readonly Dictionary<int, IPublishedContent> _content = new Dictionary<int, IPublishedContent>();
|
||||
|
||||
public SolidPublishedContentCache()
|
||||
: base(false)
|
||||
{ }
|
||||
|
||||
public void Add(SolidPublishedContent content)
|
||||
{
|
||||
_content[content.Id] = content.CreateModel();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_content.Clear();
|
||||
}
|
||||
|
||||
public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetRouteById(bool preview, int contentId, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetRouteById(int contentId, string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, int contentId)
|
||||
{
|
||||
return _content.ContainsKey(contentId) ? _content[contentId] : null;
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Guid contentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
return _content.ContainsKey(contentId);
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetAtRoot(bool preview)
|
||||
{
|
||||
return _content.Values.Where(x => x.Parent == null);
|
||||
}
|
||||
|
||||
public override IPublishedContent GetSingleByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool HasContent(bool preview)
|
||||
{
|
||||
return _content.Count > 0;
|
||||
}
|
||||
|
||||
public override PublishedContentType GetContentType(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override PublishedContentType GetContentType(string alias)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedContent> GetByContentType(PublishedContentType contentType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
class SolidPublishedContent : IPublishedContent
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public SolidPublishedContent(PublishedContentType contentType)
|
||||
{
|
||||
// initialize boring stuff
|
||||
TemplateId = 0;
|
||||
WriterName = CreatorName = string.Empty;
|
||||
WriterId = CreatorId = 0;
|
||||
CreateDate = UpdateDate = DateTime.Now;
|
||||
Version = Guid.Empty;
|
||||
IsDraft = false;
|
||||
|
||||
ContentType = contentType;
|
||||
DocumentTypeAlias = contentType.Alias;
|
||||
DocumentTypeId = contentType.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Content
|
||||
|
||||
public int Id { get; set; }
|
||||
public Guid Key { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IReadOnlyDictionary<string, PublishedCultureName> CultureNames => throw new NotSupportedException();
|
||||
public string UrlName { get; set; }
|
||||
public string DocumentTypeAlias { get; private set; }
|
||||
public int DocumentTypeId { get; private set; }
|
||||
public string WriterName { get; set; }
|
||||
public string CreatorName { get; set; }
|
||||
public int WriterId { get; set; }
|
||||
public int CreatorId { get; set; }
|
||||
public string Path { get; set; }
|
||||
public DateTime CreateDate { get; set; }
|
||||
public DateTime UpdateDate { get; set; }
|
||||
public Guid Version { get; set; }
|
||||
public int Level { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
public PublishedItemType ItemType { get { return PublishedItemType.Content; } }
|
||||
public bool IsDraft { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tree
|
||||
|
||||
public int ParentId { get; set; }
|
||||
public IEnumerable<int> ChildIds { get; set; }
|
||||
|
||||
public IPublishedContent Parent { get; set; }
|
||||
public IEnumerable<IPublishedContent> Children { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContentType
|
||||
|
||||
public PublishedContentType ContentType { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public IEnumerable<IPublishedProperty> Properties { get; set; }
|
||||
|
||||
public IPublishedProperty GetProperty(string alias)
|
||||
{
|
||||
return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias));
|
||||
}
|
||||
|
||||
public IPublishedProperty GetProperty(string alias, bool recurse)
|
||||
{
|
||||
var property = GetProperty(alias);
|
||||
if (recurse == false) return property;
|
||||
|
||||
IPublishedContent content = this;
|
||||
while (content != null && (property == null || property.HasValue() == false))
|
||||
{
|
||||
content = content.Parent;
|
||||
property = content == null ? null : content.GetProperty(alias);
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
public object this[string alias]
|
||||
{
|
||||
get
|
||||
{
|
||||
var property = GetProperty(alias);
|
||||
return property == null || property.HasValue() == false ? null : property.GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class SolidPublishedProperty : IPublishedProperty
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
public object SolidSourceValue { get; set; }
|
||||
public object SolidValue { get; set; }
|
||||
public bool SolidHasValue { get; set; }
|
||||
public object SolidXPathValue { get; set; }
|
||||
|
||||
public object GetSourceValue(string culture = null, string segment = null) => SolidSourceValue;
|
||||
public object GetValue(string culture = null, string segment = null) => SolidValue;
|
||||
public object GetXPathValue(string culture = null, string segment = null) => SolidXPathValue;
|
||||
public bool HasValue(string culture = null, string segment = null) => SolidHasValue;
|
||||
}
|
||||
|
||||
[PublishedModel("ContentType2")]
|
||||
internal class ContentType2 : PublishedContentModel
|
||||
{
|
||||
#region Plumbing
|
||||
|
||||
public ContentType2(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
public int Prop1 => this.Value<int>("prop1");
|
||||
}
|
||||
|
||||
[PublishedModel("ContentType2Sub")]
|
||||
internal class ContentType2Sub : ContentType2
|
||||
{
|
||||
#region Plumbing
|
||||
|
||||
public ContentType2Sub(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class PublishedContentStrong1 : PublishedContentModel
|
||||
{
|
||||
public PublishedContentStrong1(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
public int StrongValue => this.Value<int>("strongValue");
|
||||
}
|
||||
|
||||
class PublishedContentStrong1Sub : PublishedContentStrong1
|
||||
{
|
||||
public PublishedContentStrong1Sub(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
public int AnotherValue => this.Value<int>("anotherValue");
|
||||
}
|
||||
|
||||
class PublishedContentStrong2 : PublishedContentModel
|
||||
{
|
||||
public PublishedContentStrong2(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
public int StrongValue => this.Value<int>("strongValue");
|
||||
}
|
||||
|
||||
class AutoPublishedContentType : PublishedContentType
|
||||
{
|
||||
private static readonly PublishedPropertyType Default;
|
||||
|
||||
static AutoPublishedContentType()
|
||||
{
|
||||
var dataTypeService = new TestObjects.TestDataTypeService(
|
||||
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 666 });
|
||||
|
||||
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
|
||||
Default = factory.CreatePropertyType("*", 666);
|
||||
}
|
||||
|
||||
public AutoPublishedContentType(int id, string alias, IEnumerable<PublishedPropertyType> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.InvariantNeutral)
|
||||
{ }
|
||||
|
||||
public AutoPublishedContentType(int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.InvariantNeutral)
|
||||
{ }
|
||||
|
||||
public override PublishedPropertyType GetPropertyType(string alias)
|
||||
{
|
||||
var propertyType = base.GetPropertyType(alias);
|
||||
return propertyType ?? Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IReadOnlyDictionary<string, PublishedCultureName> CultureNames => throw new NotSupportedException();
|
||||
public string UrlName { get; set; }
|
||||
public string DocumentTypeAlias { get; private set; }
|
||||
public int DocumentTypeId { get; private set; }
|
||||
public string WriterName { get; set; }
|
||||
public string CreatorName { get; set; }
|
||||
public int WriterId { get; set; }
|
||||
public int CreatorId { get; set; }
|
||||
public string Path { get; set; }
|
||||
public DateTime CreateDate { get; set; }
|
||||
public DateTime UpdateDate { get; set; }
|
||||
public Guid Version { get; set; }
|
||||
public int Level { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
public PublishedItemType ItemType { get { return PublishedItemType.Content; } }
|
||||
public bool IsDraft { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tree
|
||||
|
||||
public int ParentId { get; set; }
|
||||
public IEnumerable<int> ChildIds { get; set; }
|
||||
|
||||
public IPublishedContent Parent { get; set; }
|
||||
public IEnumerable<IPublishedContent> Children { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContentType
|
||||
|
||||
public PublishedContentType ContentType { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public IEnumerable<IPublishedProperty> Properties { get; set; }
|
||||
|
||||
public IPublishedProperty GetProperty(string alias)
|
||||
{
|
||||
return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias));
|
||||
}
|
||||
|
||||
public IPublishedProperty GetProperty(string alias, bool recurse)
|
||||
{
|
||||
var property = GetProperty(alias);
|
||||
if (recurse == false) return property;
|
||||
|
||||
IPublishedContent content = this;
|
||||
while (content != null && (property == null || property.HasValue() == false))
|
||||
{
|
||||
content = content.Parent;
|
||||
property = content == null ? null : content.GetProperty(alias);
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
public object this[string alias]
|
||||
{
|
||||
get
|
||||
{
|
||||
var property = GetProperty(alias);
|
||||
return property == null || property.HasValue() == false ? null : property.GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class SolidPublishedProperty : IPublishedProperty
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
public object SolidSourceValue { get; set; }
|
||||
public object SolidValue { get; set; }
|
||||
public bool SolidHasValue { get; set; }
|
||||
public object SolidXPathValue { get; set; }
|
||||
|
||||
public object GetSourceValue(string culture = null, string segment = null) => SolidSourceValue;
|
||||
public object GetValue(string culture = null, string segment = null) => SolidValue;
|
||||
public object GetXPathValue(string culture = null, string segment = null) => SolidXPathValue;
|
||||
public bool HasValue(string culture = null, string segment = null) => SolidHasValue;
|
||||
}
|
||||
|
||||
[PublishedModel("ContentType2")]
|
||||
internal class ContentType2 : PublishedContentModel
|
||||
{
|
||||
#region Plumbing
|
||||
|
||||
public ContentType2(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
public int Prop1 => this.Value<int>("prop1");
|
||||
}
|
||||
|
||||
[PublishedModel("ContentType2Sub")]
|
||||
internal class ContentType2Sub : ContentType2
|
||||
{
|
||||
#region Plumbing
|
||||
|
||||
public ContentType2Sub(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class PublishedContentStrong1 : PublishedContentModel
|
||||
{
|
||||
public PublishedContentStrong1(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
public int StrongValue => this.Value<int>("strongValue");
|
||||
}
|
||||
|
||||
class PublishedContentStrong1Sub : PublishedContentStrong1
|
||||
{
|
||||
public PublishedContentStrong1Sub(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
public int AnotherValue => this.Value<int>("anotherValue");
|
||||
}
|
||||
|
||||
class PublishedContentStrong2 : PublishedContentModel
|
||||
{
|
||||
public PublishedContentStrong2(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
public int StrongValue => this.Value<int>("strongValue");
|
||||
}
|
||||
|
||||
class AutoPublishedContentType : PublishedContentType
|
||||
{
|
||||
private static readonly PublishedPropertyType Default;
|
||||
|
||||
static AutoPublishedContentType()
|
||||
{
|
||||
var dataTypeService = new TestObjects.TestDataTypeService(
|
||||
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 666 });
|
||||
|
||||
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
|
||||
Default = factory.CreatePropertyType("*", 666);
|
||||
}
|
||||
|
||||
public AutoPublishedContentType(int id, string alias, IEnumerable<PublishedPropertyType> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.InvariantNeutral)
|
||||
{ }
|
||||
|
||||
public AutoPublishedContentType(int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.InvariantNeutral)
|
||||
{ }
|
||||
|
||||
public override PublishedPropertyType GetPropertyType(string alias)
|
||||
{
|
||||
var propertyType = base.GetPropertyType(alias);
|
||||
return propertyType ?? Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
//var routingContext = GetRoutingContext("/test", 1111);
|
||||
var umbracoContext = GetUmbracoContext("/test", 0);
|
||||
var cache = umbracoContext.PublishedShapshot.Content as PublishedContentCache;
|
||||
var cache = umbracoContext.PublishedSnapshot.Content as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
|
||||
|
||||
// fixme not sure?
|
||||
|
||||
@@ -5,6 +5,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -99,7 +100,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(1178, "/home/sub1/custom-sub-2/")]
|
||||
[TestCase(1175, "/home/sub-2/")]
|
||||
[TestCase(1172, "/test-page/")]
|
||||
public void Get_Nice_Url_Not_Hiding_Top_Level(int nodeId, string niceUrlMatch)
|
||||
public void Get_Url_Not_Hiding_Top_Level(int nodeId, string niceUrlMatch)
|
||||
{
|
||||
var globalSettings = Mock.Get(TestObjects.GetGlobalSettings()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.UseDirectoryUrls).Returns(true);
|
||||
@@ -129,7 +130,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(1178, "/sub1/custom-sub-2/")]
|
||||
[TestCase(1175, "/sub-2/")]
|
||||
[TestCase(1172, "/test-page/")] // not hidden because not first root
|
||||
public void Get_Nice_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch)
|
||||
public void Get_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch)
|
||||
{
|
||||
var globalSettings = Mock.Get(TestObjects.GetGlobalSettings()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.UseDirectoryUrls).Returns(true);
|
||||
@@ -176,7 +177,7 @@ namespace Umbraco.Tests.Routing
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Nice_Url_Unpublished()
|
||||
public void Get_Url_Unpublished()
|
||||
{
|
||||
var globalSettings = Mock.Get(TestObjects.GetGlobalSettings()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.UseDirectoryUrls).Returns(true);
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(10011, "http://domain2.com", false, "http://domain1.com/1001-1/")]
|
||||
[TestCase(1001, "https://domain1.com", false, "/")]
|
||||
[TestCase(10011, "https://domain1.com", false, "/1001-1/")]
|
||||
public void Get_Nice_Url_SimpleDomain(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
public void Get_Url_SimpleDomain(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
var request = Mock.Get(settings.RequestHandler);
|
||||
@@ -207,7 +207,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(10011, "http://domain2.com", false, "http://domain1.com/foo/1001-1/")]
|
||||
[TestCase(1001, "https://domain1.com", false, "http://domain1.com/foo/")]
|
||||
[TestCase(10011, "https://domain1.com", false, "http://domain1.com/foo/1001-1/")]
|
||||
public void Get_Nice_Url_SimpleWithSchemeAndPath(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
public void Get_Url_SimpleWithSchemeAndPath(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
var request = Mock.Get(settings.RequestHandler);
|
||||
@@ -235,7 +235,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(10011, "http://domain1.com", false, "/")]
|
||||
[TestCase(100111, "http://domain1.com", false, "/1001-1-1/")]
|
||||
[TestCase(1002, "http://domain1.com", false, "/1002/")]
|
||||
public void Get_Nice_Url_DeepDomain(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
public void Get_Url_DeepDomain(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
var request = Mock.Get(settings.RequestHandler);
|
||||
@@ -269,7 +269,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(1003, "http://domain3.com", false, "/")]
|
||||
[TestCase(10031, "http://domain3.com", false, "/en/")]
|
||||
[TestCase(100321, "http://domain3.com", false, "/fr/1003-2-1/")]
|
||||
public void Get_Nice_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
public void Get_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
var request = Mock.Get(settings.RequestHandler);
|
||||
@@ -293,7 +293,7 @@ namespace Umbraco.Tests.Routing
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Nice_Url_DomainsAndCache()
|
||||
public void Get_Url_DomainsAndCache()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
var request = Mock.Get(settings.RequestHandler);
|
||||
@@ -360,7 +360,7 @@ namespace Umbraco.Tests.Routing
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Nice_Url_Relative_Or_Absolute()
|
||||
public void Get_Url_Relative_Or_Absolute()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
var requestMock = Mock.Get(settings.RequestHandler);
|
||||
@@ -394,7 +394,7 @@ namespace Umbraco.Tests.Routing
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Nice_Url_Alternate()
|
||||
public void Get_Url_Alternate()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
webSecurity.Setup(x => x.UserHasSectionAccess(It.IsAny<string>(), It.IsAny<IUser>()))
|
||||
.Returns(() => true);
|
||||
|
||||
var publishedSnapshot = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshot = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of<IPublishedMemberCache>());
|
||||
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
|
||||
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedSnapshot.Object);
|
||||
|
||||
@@ -4,6 +4,6 @@ namespace Umbraco.Tests.TestHelpers.Stubs
|
||||
{
|
||||
public class TestPublishedSnapshotAccessor : IPublishedSnapshotAccessor
|
||||
{
|
||||
public IPublishedShapshot PublishedSnapshot { get; set; }
|
||||
public IPublishedSnapshot PublishedSnapshot { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
var httpContext = Mock.Of<HttpContextBase>();
|
||||
|
||||
var publishedSnapshotMock = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshotMock = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshotMock.Setup(x => x.Members).Returns(Mock.Of<IPublishedMemberCache>());
|
||||
var publishedSnapshot = publishedSnapshotMock.Object;
|
||||
var publishedSnapshotServiceMock = new Mock<IPublishedSnapshotService>();
|
||||
|
||||
@@ -343,20 +343,23 @@ namespace Umbraco.Tests.TestHelpers
|
||||
}
|
||||
}
|
||||
|
||||
protected UmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable<IUrlProvider> urlProviders = null, IGlobalSettings globalSettings = null)
|
||||
protected UmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable<IUrlProvider> urlProviders = null, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null)
|
||||
{
|
||||
// ensure we have a PublishedCachesService
|
||||
var service = PublishedSnapshotService as PublishedSnapshotService;
|
||||
var service = snapshotService ?? PublishedSnapshotService as PublishedSnapshotService;
|
||||
if (service == null)
|
||||
throw new Exception("Not a proper XmlPublishedCache.PublishedCachesService.");
|
||||
|
||||
// re-initialize PublishedCacheService content with an Xml source with proper template id
|
||||
service.XmlStore.GetXmlDocument = () =>
|
||||
if (service is PublishedSnapshotService)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(GetXmlContent(templateId));
|
||||
return doc;
|
||||
};
|
||||
// re-initialize PublishedCacheService content with an Xml source with proper template id
|
||||
((PublishedSnapshotService)service).XmlStore.GetXmlDocument = () =>
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(GetXmlContent(templateId));
|
||||
return doc;
|
||||
};
|
||||
}
|
||||
|
||||
var httpContext = GetHttpContextFactory(url, routeData).HttpContext;
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@
|
||||
<Compile Include="Migrations\MigrationTests.cs" />
|
||||
<Compile Include="Models\PathValidationTests.cs" />
|
||||
<Compile Include="Models\VariationTests.cs" />
|
||||
<Compile Include="PublishedContent\SolidPublishedSnapshot.cs" />
|
||||
<Compile Include="Published\PublishedSnapshotTestObjects.cs" />
|
||||
<Compile Include="Published\ModelTypeTests.cs" />
|
||||
<Compile Include="Published\NestedContentTests.cs" />
|
||||
@@ -375,7 +376,6 @@
|
||||
<Compile Include="Persistence\SyntaxProvider\SqlCeSyntaxProviderTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentDataTableTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentTestBase.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentTestElements.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedMediaTests.cs" />
|
||||
<Compile Include="Misc\HashCodeCombinerTests.cs" />
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Can_Lookup_Content()
|
||||
{
|
||||
var publishedSnapshot = new Mock<IPublishedShapshot>();
|
||||
var publishedSnapshot = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of<IPublishedMemberCache>());
|
||||
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
|
||||
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedSnapshot.Object);
|
||||
|
||||
@@ -432,7 +432,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
|
||||
var ctx = new UmbracoContext(
|
||||
GetHttpContextFactory(url, routeData).HttpContext,
|
||||
http,
|
||||
_service,
|
||||
new WebSecurity(http, Current.Services.UserService, globalSettings),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Umbraco.Web.Composing
|
||||
public static DistributedCache DistributedCache
|
||||
=> Container.GetInstance<DistributedCache>();
|
||||
|
||||
public static IPublishedShapshot PublishedSnapshot
|
||||
public static IPublishedSnapshot PublishedSnapshot
|
||||
=> Container.GetInstance<IPublishedSnapshotAccessor>().PublishedSnapshot;
|
||||
|
||||
public static EventMessages EventMessages
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// </summary>
|
||||
/// <remarks>A published snapshot is a point-in-time capture of the current state of
|
||||
/// everything that is "published".</remarks>
|
||||
public interface IPublishedShapshot
|
||||
public interface IPublishedSnapshot
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IPublishedContentCache"/>.
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the "current" <see cref="IPublishedShapshot"/>.
|
||||
/// Provides access to the "current" <see cref="IPublishedSnapshot"/>.
|
||||
/// </summary>
|
||||
public interface IPublishedSnapshotAccessor
|
||||
{
|
||||
IPublishedShapshot PublishedSnapshot { get; set; }
|
||||
IPublishedSnapshot PublishedSnapshot { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using Umbraco.Web.Cache;
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates and manages <see cref="IPublishedShapshot"/> instances.
|
||||
/// Creates and manages <see cref="IPublishedSnapshot"/> instances.
|
||||
/// </summary>
|
||||
public interface IPublishedSnapshotService : IDisposable
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// <remarks>If <paramref name="previewToken"/> is null, the snapshot is not previewing, else it
|
||||
/// is previewing, and what is or is not visible in preview depends on the content of the token,
|
||||
/// which is not specified and depends on the actual published snapshot service implementation.</remarks>
|
||||
IPublishedShapshot CreatePublishedSnapshot(string previewToken);
|
||||
IPublishedSnapshot CreatePublishedSnapshot(string previewToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published snapshot accessor.
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
private CacheValues GetCacheValues(PropertyCacheLevel cacheLevel)
|
||||
{
|
||||
CacheValues cacheValues;
|
||||
PublishedShapshot publishedSnapshot;
|
||||
PublishedSnapshot publishedSnapshot;
|
||||
ICacheProvider cache;
|
||||
switch (cacheLevel)
|
||||
{
|
||||
@@ -115,7 +115,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// elements cache (if we don't want to pollute the elements cache with short-lived
|
||||
// data) depending on settings
|
||||
// for members, always cache in the snapshot cache - never pollute elements cache
|
||||
publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
publishedSnapshot = (PublishedSnapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
cache = publishedSnapshot == null
|
||||
? null
|
||||
: ((_isPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (_isMember == false)
|
||||
@@ -125,7 +125,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
break;
|
||||
case PropertyCacheLevel.Snapshot:
|
||||
// cache within the snapshot cache
|
||||
publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
publishedSnapshot = (PublishedSnapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
cache = publishedSnapshot?.SnapshotCache;
|
||||
cacheValues = GetCacheValues(cache);
|
||||
break;
|
||||
|
||||
@@ -102,10 +102,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// this is for tests purposes
|
||||
// args are: current published snapshot (may be null), previewing, content id - returns: content
|
||||
|
||||
internal static Func<IPublishedShapshot, bool, int, IPublishedContent> GetContentByIdFunc { get; set; }
|
||||
internal static Func<IPublishedSnapshot, bool, int, IPublishedContent> GetContentByIdFunc { get; set; }
|
||||
= (publishedShapshot, previewing, id) => publishedShapshot.Content.GetById(previewing, id);
|
||||
|
||||
internal static Func<IPublishedShapshot, bool, int, IPublishedContent> GetMediaByIdFunc { get; set; }
|
||||
internal static Func<IPublishedSnapshot, bool, int, IPublishedContent> GetMediaByIdFunc { get; set; }
|
||||
= (publishedShapshot, previewing, id) => publishedShapshot.Media.GetById(previewing, id);
|
||||
|
||||
private IPublishedContent GetContentById(bool previewing, int id)
|
||||
@@ -289,7 +289,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// beware what you use that one for - you don't want to cache its result
|
||||
private ICacheProvider GetAppropriateCache()
|
||||
{
|
||||
var publishedSnapshot = (PublishedShapshot)_publishedSnapshotAccessor.PublishedSnapshot;
|
||||
var publishedSnapshot = (PublishedSnapshot)_publishedSnapshotAccessor.PublishedSnapshot;
|
||||
var cache = publishedSnapshot == null
|
||||
? null
|
||||
: ((IsPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (ItemType != PublishedItemType.Member)
|
||||
@@ -300,7 +300,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
private ICacheProvider GetCurrentSnapshotCache()
|
||||
{
|
||||
var publishedSnapshot = (PublishedShapshot)_publishedSnapshotAccessor.PublishedSnapshot;
|
||||
var publishedSnapshot = (PublishedSnapshot)_publishedSnapshotAccessor.PublishedSnapshot;
|
||||
return publishedSnapshot?.SnapshotCache;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using Umbraco.Core.Cache;
|
||||
namespace Umbraco.Web.PublishedCache.NuCache
|
||||
{
|
||||
// implements published snapshot
|
||||
internal class PublishedShapshot : IPublishedShapshot, IDisposable
|
||||
internal class PublishedSnapshot : IPublishedSnapshot, IDisposable
|
||||
{
|
||||
private readonly PublishedSnapshotService _service;
|
||||
private bool _defaultPreview;
|
||||
@@ -13,7 +13,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
#region Constructors
|
||||
|
||||
public PublishedShapshot(PublishedSnapshotService service, bool defaultPreview)
|
||||
public PublishedSnapshot(PublishedSnapshotService service, bool defaultPreview)
|
||||
{
|
||||
_service = service;
|
||||
_defaultPreview = defaultPreview;
|
||||
@@ -72,13 +72,13 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
private class ForcedPreviewObject : DisposableObject
|
||||
{
|
||||
private readonly PublishedShapshot _publishedShapshot;
|
||||
private readonly PublishedSnapshot _publishedSnapshot;
|
||||
private readonly bool _origPreview;
|
||||
private readonly Action<bool> _callback;
|
||||
|
||||
public ForcedPreviewObject(PublishedShapshot publishedShapshot, bool preview, Action<bool> callback)
|
||||
public ForcedPreviewObject(PublishedSnapshot publishedShapshot, bool preview, Action<bool> callback)
|
||||
{
|
||||
_publishedShapshot = publishedShapshot;
|
||||
_publishedSnapshot = publishedShapshot;
|
||||
_callback = callback;
|
||||
|
||||
// save and force
|
||||
@@ -89,7 +89,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
// restore
|
||||
_publishedShapshot._defaultPreview = _origPreview;
|
||||
_publishedSnapshot._defaultPreview = _origPreview;
|
||||
_callback?.Invoke(_origPreview);
|
||||
}
|
||||
}
|
||||
@@ -533,7 +533,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
}
|
||||
|
||||
if (draftChanged || publishedChanged)
|
||||
((PublishedShapshot)CurrentPublishedShapshot).Resync();
|
||||
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
|
||||
}
|
||||
|
||||
private void NotifyLocked(IEnumerable<ContentCacheRefresher.JsonPayload> payloads, out bool draftChanged, out bool publishedChanged)
|
||||
@@ -630,7 +630,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
}
|
||||
|
||||
if (anythingChanged)
|
||||
((PublishedShapshot)CurrentPublishedShapshot).Resync();
|
||||
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
|
||||
}
|
||||
|
||||
private void NotifyLocked(IEnumerable<MediaCacheRefresher.JsonPayload> payloads, out bool anythingChanged)
|
||||
@@ -719,7 +719,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
Notify<IContentType>(_contentStore, payloads, RefreshContentTypesLocked);
|
||||
Notify<IMediaType>(_mediaStore, payloads, RefreshMediaTypesLocked);
|
||||
|
||||
((PublishedShapshot)CurrentPublishedShapshot).Resync();
|
||||
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
|
||||
}
|
||||
|
||||
private void Notify<T>(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action<IEnumerable<int>, IEnumerable<int>, IEnumerable<int>, IEnumerable<int>> action)
|
||||
@@ -796,7 +796,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
}
|
||||
}
|
||||
|
||||
((PublishedShapshot)CurrentPublishedShapshot).Resync();
|
||||
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
|
||||
}
|
||||
|
||||
public override void Notify(DomainCacheRefresher.JsonPayload[] payloads)
|
||||
@@ -945,17 +945,17 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
private long _contentGen, _mediaGen, _domainGen;
|
||||
private ICacheProvider _elementsCache;
|
||||
|
||||
public override IPublishedShapshot CreatePublishedSnapshot(string previewToken)
|
||||
public override IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
|
||||
{
|
||||
// no cache, no joy
|
||||
if (_isReady == false)
|
||||
throw new InvalidOperationException("The published snapshot service has not properly initialized.");
|
||||
|
||||
var preview = previewToken.IsNullOrWhiteSpace() == false;
|
||||
return new PublishedShapshot(this, preview);
|
||||
return new PublishedSnapshot(this, preview);
|
||||
}
|
||||
|
||||
public PublishedShapshot.PublishedSnapshotElements GetElements(bool previewDefault)
|
||||
public PublishedSnapshot.PublishedSnapshotElements GetElements(bool previewDefault)
|
||||
{
|
||||
// note: using ObjectCacheRuntimeCacheProvider for elements and snapshot caches
|
||||
// is not recommended because it creates an inner MemoryCache which is a heavy
|
||||
@@ -996,7 +996,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// a MaxValue to make sure this one runs last, and it should be ok
|
||||
scopeContext.Enlist("Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.Resync", () => this, (completed, svc) =>
|
||||
{
|
||||
((PublishedShapshot)svc.CurrentPublishedShapshot).Resync();
|
||||
((PublishedSnapshot)svc.CurrentPublishedSnapshot).Resync();
|
||||
}, int.MaxValue);
|
||||
}
|
||||
|
||||
@@ -1017,7 +1017,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
var domainCache = new DomainCache(domainSnap);
|
||||
var domainHelper = new DomainHelper(domainCache, _siteDomainHelper);
|
||||
|
||||
return new PublishedShapshot.PublishedSnapshotElements
|
||||
return new PublishedSnapshot.PublishedSnapshotElements
|
||||
{
|
||||
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainHelper, _globalSettings, _serviceContext.LocalizationService),
|
||||
MediaCache = new MediaCache(previewDefault, mediaSnap, snapshotCache, elementsCache),
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
// note: NOT setting _publishedSnapshotAccessor.PublishedSnapshot here because it is the
|
||||
// responsibility of the caller to manage what the 'current' facade is
|
||||
public abstract IPublishedShapshot CreatePublishedSnapshot(string previewToken);
|
||||
public abstract IPublishedSnapshot CreatePublishedSnapshot(string previewToken);
|
||||
|
||||
protected IPublishedShapshot CurrentPublishedShapshot => PublishedSnapshotAccessor.PublishedSnapshot;
|
||||
protected IPublishedSnapshot CurrentPublishedSnapshot => PublishedSnapshotAccessor.PublishedSnapshot;
|
||||
|
||||
public abstract bool EnsureEnvironment(out IEnumerable<string> errors);
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace Umbraco.Web.PublishedCache
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
public IPublishedShapshot PublishedSnapshot
|
||||
public IPublishedSnapshot PublishedSnapshot
|
||||
{
|
||||
get
|
||||
{
|
||||
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
|
||||
if (umbracoContext == null) throw new Exception("The IUmbracoContextAccessor could not provide an UmbracoContext.");
|
||||
return umbracoContext.PublishedShapshot;
|
||||
return umbracoContext.PublishedSnapshot;
|
||||
}
|
||||
|
||||
set
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// <summary>
|
||||
/// Implements a published snapshot.
|
||||
/// </summary>
|
||||
class PublishedShapshot : IPublishedShapshot
|
||||
class PublishedSnapshot : IPublishedSnapshot
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedShapshot"/> class with a content cache
|
||||
/// Initializes a new instance of the <see cref="PublishedSnapshot"/> class with a content cache
|
||||
/// and a media cache.
|
||||
/// </summary>
|
||||
public PublishedShapshot(
|
||||
public PublishedSnapshot(
|
||||
PublishedContentCache contentCache,
|
||||
PublishedMediaCache mediaCache,
|
||||
PublishedMemberCache memberCache,
|
||||
@@ -139,7 +139,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
#region Caches
|
||||
|
||||
public override IPublishedShapshot CreatePublishedSnapshot(string previewToken)
|
||||
public override 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
|
||||
@@ -148,7 +148,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
var domainCache = new DomainCache(_domainService, _localizationService);
|
||||
|
||||
return new PublishedShapshot(
|
||||
return new PublishedSnapshot(
|
||||
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _siteDomainHelper, _contentTypeCache, _routesCache, previewToken),
|
||||
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache),
|
||||
new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache),
|
||||
|
||||
@@ -1250,7 +1250,7 @@ ORDER BY umbracoNode.level, umbracoNode.sortOrder";
|
||||
|
||||
private void ResyncCurrentPublishedSnapshot(XmlDocument xml)
|
||||
{
|
||||
var publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
var publishedSnapshot = (PublishedSnapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
if (publishedSnapshot == null) return;
|
||||
((PublishedContentCache) publishedSnapshot.Content).Resync(xml);
|
||||
((PublishedMediaCache) publishedSnapshot.Media).Resync();
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
if (node != null)
|
||||
{
|
||||
var d = DomainHelper.FindWildcardDomainInPath(frequest.UmbracoContext.PublishedShapshot.Domains.GetAll(true), node.Path, null);
|
||||
var d = DomainHelper.FindWildcardDomainInPath(frequest.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), node.Path, null);
|
||||
if (d != null)
|
||||
errorCulture = d.Culture;
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace Umbraco.Web.Routing
|
||||
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Uri=\"{request.Uri}\"");
|
||||
|
||||
// try to find a domain matching the current request
|
||||
var domainAndUri = DomainHelper.DomainForUri(request.UmbracoContext.PublishedShapshot.Domains.GetAll(false), request.Uri);
|
||||
var domainAndUri = DomainHelper.DomainForUri(request.UmbracoContext.PublishedSnapshot.Domains.GetAll(false), request.Uri);
|
||||
|
||||
// handle domain - always has a contentId and a culture
|
||||
if (domainAndUri != null)
|
||||
@@ -311,7 +311,7 @@ namespace Umbraco.Web.Routing
|
||||
var nodePath = request.PublishedContent.Path;
|
||||
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Path=\"{nodePath}\"");
|
||||
var rootNodeId = request.HasDomain ? request.Domain.ContentId : (int?)null;
|
||||
var domain = DomainHelper.FindWildcardDomainInPath(request.UmbracoContext.PublishedShapshot.Domains.GetAll(true), nodePath, rootNodeId);
|
||||
var domain = DomainHelper.FindWildcardDomainInPath(request.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), nodePath, rootNodeId);
|
||||
|
||||
// always has a contentId and a culture
|
||||
if (domain != null)
|
||||
@@ -602,14 +602,14 @@ namespace Umbraco.Web.Routing
|
||||
var loginPageId = publicAccessAttempt.Result.LoginNodeId;
|
||||
|
||||
if (loginPageId != request.PublishedContent.Id)
|
||||
request.PublishedContent = request.UmbracoContext.PublishedShapshot.Content.GetById(loginPageId);
|
||||
request.PublishedContent = request.UmbracoContext.PublishedSnapshot.Content.GetById(loginPageId);
|
||||
}
|
||||
else if (_services.PublicAccessService.HasAccess(request.PublishedContent.Id, _services.ContentService, GetRolesForLogin(membershipHelper.CurrentUserName)) == false)
|
||||
{
|
||||
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Current member has not access, redirect to error page");
|
||||
var errorPageId = publicAccessAttempt.Result.NoAccessNodeId;
|
||||
if (errorPageId != request.PublishedContent.Id)
|
||||
request.PublishedContent = request.UmbracoContext.PublishedShapshot.Content.GetById(errorPageId);
|
||||
request.PublishedContent = request.UmbracoContext.PublishedSnapshot.Content.GetById(errorPageId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Umbraco.Web.Security
|
||||
_umbracoContext = umbracoContext;
|
||||
_membershipProvider = membershipProvider;
|
||||
_roleProvider = roleProvider;
|
||||
_memberCache = umbracoContext.PublishedShapshot.Members;
|
||||
_memberCache = umbracoContext.PublishedSnapshot.Members;
|
||||
|
||||
// helpers are *not* instanciated by the container so we have to
|
||||
// get our dependencies injected manually, through properties.
|
||||
|
||||
@@ -342,6 +342,7 @@
|
||||
<Compile Include="PropertyEditors\ValueConverters\MemberPickerValueConverter.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\MultiNodeTreePickerValueConverter.cs" />
|
||||
<Compile Include="PropertyEditors\ValueListUniqueValueValidator.cs" />
|
||||
<Compile Include="PublishedCache\IPublishedSnapshot.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\BTree.ContentDataSerializer.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\BTree.ContentNodeKitSerializer.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\BTree.DictionaryOfCultureVariationSerializer.cs" />
|
||||
@@ -351,13 +352,13 @@
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\PropertyData.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\SerializerBase.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\NuCacheComponent.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PublishedSnapshot.cs" />
|
||||
<Compile Include="PublishedCache\PublishedElement.cs" />
|
||||
<Compile Include="PublishedCache\PublishedElementPropertyBase.cs" />
|
||||
<Compile Include="Models\Trees\DisableUser.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\ContentPickerValueConverter.cs" />
|
||||
<Compile Include="PublishedCache\PublishedSnapshotServiceBase.cs" />
|
||||
<Compile Include="PublishedCache\IDomainCache.cs" />
|
||||
<Compile Include="PublishedCache\IPublishedShapshot.cs" />
|
||||
<Compile Include="PublishedCache\IPublishedSnapshotAccessor.cs" />
|
||||
<Compile Include="PublishedCache\IPublishedSnapshotService.cs" />
|
||||
<Compile Include="PublishedCache\IPublishedMemberCache.cs" />
|
||||
@@ -371,7 +372,6 @@
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\ContentSourceDto.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\Database.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DomainCache.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PublishedShapshot.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PublishedSnapshotService.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\MediaCache.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\MemberCache.cs" />
|
||||
@@ -389,7 +389,7 @@
|
||||
<Compile Include="PublishedCache\PublishedContentTypeCache.cs" />
|
||||
<Compile Include="PublishedCache\UmbracoContextPublishedSnapshotAccessor.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\DomainCache.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\PublishedShapshot.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\PublishedSnapshot.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\PublishedSnapshotService.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\PreviewContent.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\PublishedMemberCache.cs" />
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Web
|
||||
public class UmbracoContext : DisposableObject, IDisposeOnRequestEnd
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly Lazy<IPublishedShapshot> _publishedSnapshot;
|
||||
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
|
||||
private DomainHelper _domainHelper;
|
||||
private string _previewToken;
|
||||
private bool? _previewing;
|
||||
@@ -125,7 +125,7 @@ namespace Umbraco.Web
|
||||
Security = webSecurity;
|
||||
|
||||
// beware - we cannot expect a current user here, so detecting preview mode must be a lazy thing
|
||||
_publishedSnapshot = new Lazy<IPublishedShapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken));
|
||||
_publishedSnapshot = new Lazy<IPublishedSnapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken));
|
||||
|
||||
// set the urls...
|
||||
// NOTE: The request will not be available during app startup so we can only set this to an absolute URL of localhost, this
|
||||
@@ -178,7 +178,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Gets the published snapshot.
|
||||
/// </summary>
|
||||
public IPublishedShapshot PublishedShapshot => _publishedSnapshot.Value;
|
||||
public IPublishedSnapshot PublishedSnapshot => _publishedSnapshot.Value;
|
||||
|
||||
// for unit tests
|
||||
internal bool HasPublishedSnapshot => _publishedSnapshot.IsValueCreated;
|
||||
@@ -186,12 +186,12 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Gets the published content cache.
|
||||
/// </summary>
|
||||
public IPublishedContentCache ContentCache => PublishedShapshot.Content;
|
||||
public IPublishedContentCache ContentCache => PublishedSnapshot.Content;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published media cache.
|
||||
/// </summary>
|
||||
public IPublishedMediaCache MediaCache => PublishedShapshot.Media;
|
||||
public IPublishedMediaCache MediaCache => PublishedSnapshot.Media;
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating whether the current request is a front-end umbraco request
|
||||
@@ -227,7 +227,7 @@ namespace Umbraco.Web
|
||||
internal DomainHelper GetDomainHelper(ISiteDomainHelper siteDomainHelper)
|
||||
{
|
||||
if (_domainHelper == null)
|
||||
_domainHelper = new DomainHelper(PublishedShapshot.Domains, siteDomainHelper);
|
||||
_domainHelper = new DomainHelper(PublishedSnapshot.Domains, siteDomainHelper);
|
||||
return _domainHelper;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ namespace Umbraco.Web
|
||||
internal IDisposable ForcedPreview(bool preview)
|
||||
{
|
||||
InPreviewMode = preview;
|
||||
return PublishedShapshot.ForcedPreview(preview, orig => InPreviewMode = orig);
|
||||
return PublishedSnapshot.ForcedPreview(preview, orig => InPreviewMode = orig);
|
||||
}
|
||||
|
||||
private HttpRequestBase GetRequestFromContext()
|
||||
|
||||
Reference in New Issue
Block a user