Fixes build and fixes how published media cache gets root nodes - if people have done this in the past it would have been horrible for site performance
This commit is contained in:
@@ -408,7 +408,7 @@ namespace Umbraco.Tests.Mvc
|
||||
var ctx = new UmbracoContext(
|
||||
GetHttpContextFactory(url, routeData).HttpContext,
|
||||
appCtx,
|
||||
new PublishedCaches(cache, new PublishedMediaCache()),
|
||||
new PublishedCaches(cache, new PublishedMediaCache(appCtx)),
|
||||
new WebSecurity(http, appCtx));
|
||||
|
||||
//if (setSingleton)
|
||||
|
||||
@@ -92,9 +92,9 @@ namespace Umbraco.Tests.PublishedCache
|
||||
|
||||
_umbracoContext = new UmbracoContext(
|
||||
_httpContextFactory.HttpContext,
|
||||
ApplicationContext.Current,
|
||||
new PublishedCaches(cache, new PublishedMediaCache()),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext.Current));
|
||||
ApplicationContext,
|
||||
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));
|
||||
|
||||
_cache = _umbracoContext.ContentCache;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Tests.PublishedCache
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot2.Id);
|
||||
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx);
|
||||
var roots = cache.GetAtRoot();
|
||||
Assert.AreEqual(2, roots.Count());
|
||||
Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));
|
||||
@@ -126,6 +126,8 @@ namespace Umbraco.Tests.PublishedCache
|
||||
[Test]
|
||||
public void Convert_From_Search_Result()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var result = new SearchResult()
|
||||
{
|
||||
Id = 1234,
|
||||
@@ -144,7 +146,7 @@ namespace Umbraco.Tests.PublishedCache
|
||||
result.Fields.Add("updateDate", "2012-07-16T10:34:09");
|
||||
result.Fields.Add("writerName", "Shannon");
|
||||
|
||||
var store = new PublishedMediaCache();
|
||||
var store = new PublishedMediaCache(ctx.Application);
|
||||
var doc = store.ConvertFromSearchResult(result);
|
||||
|
||||
DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
@@ -154,9 +156,11 @@ namespace Umbraco.Tests.PublishedCache
|
||||
[Test]
|
||||
public void Convert_From_XPath_Navigator()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var xmlDoc = GetMediaXml();
|
||||
var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
|
||||
var cache = new PublishedMediaCache();
|
||||
var cache = new PublishedMediaCache(ctx.Application);
|
||||
var doc = cache.ConvertFromXPathNavigator(navigator);
|
||||
|
||||
DoAssert(doc, 2000, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon2", 22, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
});
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(new PublishedCaches(
|
||||
new PublishedContentCache(), new PublishedMediaCache()));
|
||||
new PublishedContentCache(), new PublishedMediaCache(ApplicationContext)));
|
||||
|
||||
if (PublishedContentModelFactoryResolver.HasCurrent == false)
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
internal static IPublishedContent GetNode(int id, UmbracoContext umbracoContext)
|
||||
{
|
||||
var ctx = umbracoContext;
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx);
|
||||
var doc = cache.GetById(id);
|
||||
Assert.IsNotNull(doc);
|
||||
return doc;
|
||||
@@ -113,7 +113,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -142,7 +142,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//ensure it is found
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
@@ -182,7 +182,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -204,7 +204,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -226,7 +226,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -248,7 +248,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
@@ -267,7 +267,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
@@ -442,7 +442,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
</node>");
|
||||
var node = xml.DescendantsAndSelf("node").Single(x => (int) x.Attribute("id") == nodeId);
|
||||
|
||||
var publishedMedia = new PublishedMediaCache();
|
||||
var publishedMedia = new PublishedMediaCache(ApplicationContext);
|
||||
|
||||
var nav = node.CreateNavigator();
|
||||
|
||||
@@ -483,7 +483,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
</Image>");
|
||||
var node = xml.DescendantsAndSelf("Image").Single(x => (int)x.Attribute("id") == nodeId);
|
||||
|
||||
var publishedMedia = new PublishedMediaCache();
|
||||
var publishedMedia = new PublishedMediaCache(ApplicationContext);
|
||||
|
||||
var nav = node.CreateNavigator();
|
||||
|
||||
@@ -502,7 +502,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var errorXml = new XElement("error", string.Format("No media is maching '{0}'", 1234));
|
||||
var nav = errorXml.CreateNavigator();
|
||||
|
||||
var publishedMedia = new PublishedMediaCache();
|
||||
var publishedMedia = new PublishedMediaCache(ApplicationContext);
|
||||
var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/"), 1234);
|
||||
|
||||
Assert.IsNull(converted);
|
||||
|
||||
@@ -356,7 +356,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var ctx = new UmbracoContext(
|
||||
httpContext,
|
||||
ApplicationContext,
|
||||
new PublishedCaches(cache, new PublishedMediaCache()),
|
||||
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
|
||||
new WebSecurity(httpContext, ApplicationContext));
|
||||
|
||||
if (setSingleton)
|
||||
|
||||
@@ -18,8 +18,6 @@ using Umbraco.Core.Xml;
|
||||
using Umbraco.Web.Models;
|
||||
using UmbracoExamine;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic;
|
||||
using ContentType = umbraco.cms.businesslogic.ContentType;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
@@ -31,21 +29,30 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// </remarks>
|
||||
internal class PublishedMediaCache : IPublishedMediaCache
|
||||
{
|
||||
public PublishedMediaCache()
|
||||
{
|
||||
}
|
||||
public PublishedMediaCache(ApplicationContext applicationContext)
|
||||
{
|
||||
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
|
||||
_applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generally used for unit testing to use an explicit examine searcher
|
||||
/// </summary>
|
||||
/// <param name="applicationContext"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <param name="indexProvider"></param>
|
||||
internal PublishedMediaCache(BaseSearchProvider searchProvider, BaseIndexProvider indexProvider)
|
||||
internal PublishedMediaCache(ApplicationContext applicationContext, BaseSearchProvider searchProvider, BaseIndexProvider indexProvider)
|
||||
{
|
||||
_searchProvider = searchProvider;
|
||||
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
|
||||
if (searchProvider == null) throw new ArgumentNullException("searchProvider");
|
||||
if (indexProvider == null) throw new ArgumentNullException("indexProvider");
|
||||
|
||||
_applicationContext = applicationContext;
|
||||
_searchProvider = searchProvider;
|
||||
_indexProvider = indexProvider;
|
||||
}
|
||||
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
private readonly BaseSearchProvider _searchProvider;
|
||||
private readonly BaseIndexProvider _indexProvider;
|
||||
|
||||
@@ -56,17 +63,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
public virtual IEnumerable<IPublishedContent> GetAtRoot(UmbracoContext umbracoContext, bool preview)
|
||||
{
|
||||
var rootMedia = global::umbraco.cms.businesslogic.media.Media.GetRootMedias();
|
||||
var result = new List<IPublishedContent>();
|
||||
//TODO: need to get a ConvertFromMedia method but we'll just use this for now.
|
||||
foreach (var media in rootMedia
|
||||
.Select(m => global::umbraco.library.GetMedia(m.Id, true))
|
||||
.Where(media => media != null && media.Current != null))
|
||||
{
|
||||
media.MoveNext();
|
||||
result.Add(ConvertFromXPathNavigator(media.Current));
|
||||
}
|
||||
return result;
|
||||
//TODO: We should be able to look these ids first in Examine!
|
||||
|
||||
var rootMedia = _applicationContext.Services.MediaService.GetRootMedia();
|
||||
return rootMedia.Select(m => GetUmbracoMedia(m.Id));
|
||||
}
|
||||
|
||||
public virtual IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars)
|
||||
@@ -96,7 +96,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
public bool XPathNavigatorIsNavigable { get { return false; } }
|
||||
|
||||
public virtual bool HasContent(UmbracoContext context, bool preview) { throw new NotImplementedException(); }
|
||||
public virtual bool HasContent(UmbracoContext context, bool preview) { throw new NotImplementedException(); }
|
||||
|
||||
private ExamineManager GetExamineManagerSafe()
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Web.Standalone
|
||||
|
||||
var caches = new PublishedCaches(
|
||||
new PublishedCache.XmlPublishedCache.PublishedContentCache(),
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache());
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache(ApplicationContext.Current));
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(caches);
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ namespace Umbraco.Web
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(new PublishedCaches(
|
||||
new PublishedCache.XmlPublishedCache.PublishedContentCache(),
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache()));
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache(ApplicationContext)));
|
||||
|
||||
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector),
|
||||
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
||||
|
||||
@@ -528,8 +528,10 @@ namespace umbraco
|
||||
if (media == null) return null;
|
||||
var serializer = new EntityXmlSerializer();
|
||||
var serialized = serializer.Serialize(
|
||||
ApplicationContext.Current.Services.MediaService, ApplicationContext.Current.Services.DataTypeService,
|
||||
ApplicationContext.Current.Services.UserService, media, deep);
|
||||
ApplicationContext.Current.Services.MediaService,
|
||||
ApplicationContext.Current.Services.DataTypeService,
|
||||
media,
|
||||
deep);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user