From f9fd8b67b17f00e3dee5ce87c870baf46938c9ed Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 20 Jul 2016 12:44:15 +0200 Subject: [PATCH] Fix build after merge --- .../ContainerLazyManyObjectsResolver.cs | 14 +-- .../PublishedContentCacheTests.cs | 2 +- .../PublishedMediaCacheTests.cs | 8 +- .../PublishedContent/PublishedMediaTests.cs | 20 ++--- src/Umbraco.Web.UI/umbraco/config/lang/en.xml | 6 +- .../umbraco/config/lang/en_us.xml | 6 +- .../Editors/PackageInstallController.cs | 33 +++---- .../XmlDataIntegrityHealthCheck.cs | 85 +++++-------------- .../HealthCheck/HealthCheckController.cs | 10 ++- .../HealthCheck/HealthCheckResolver.cs | 52 +++++------- .../HealthCheck/IHealthCheckResolver.cs | 2 +- .../XmlPublishedCache/FacadeService.cs | 4 +- .../PublishedContentCache.cs | 4 +- src/Umbraco.Web/WebBootManager.cs | 4 +- .../WebServices/XmlDataIntegrityController.cs | 1 - 15 files changed, 98 insertions(+), 153 deletions(-) diff --git a/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs b/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs index 795cf62d20..8b71508f2b 100644 --- a/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs +++ b/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs @@ -6,7 +6,6 @@ using Umbraco.Core.Logging; namespace Umbraco.Core.ObjectResolution { - /// /// A lazy many objects resolver that uses IoC /// @@ -18,12 +17,12 @@ namespace Umbraco.Core.ObjectResolution { protected IServiceContainer Container; private object _locker = new object(); - private bool _isInitialized = false; + private bool _isInitialized; internal ContainerLazyManyObjectsResolver(IServiceContainer container, ILogger logger, Func> typeListProducerList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) : base(logger, typeListProducerList, scope) { - if (container == null) throw new ArgumentNullException("container"); + if (container == null) throw new ArgumentNullException(nameof(container)); Container = container; //Register ourselves in the case that a resolver instance should be injected someplace @@ -43,14 +42,9 @@ namespace Umbraco.Core.ObjectResolution LazyInitializer.EnsureInitialized(ref Container, ref _isInitialized, ref _locker, () => { foreach (var type in InstanceTypes) - { Container.Register(type, GetLifetime(LifetimeScope)); - } - if (afterRegistered != null) - { - afterRegistered(Container); - } + afterRegistered?.Invoke(Container); return Container; }); @@ -82,7 +76,7 @@ namespace Umbraco.Core.ObjectResolution return new PerRequestLifeTime(); case ObjectLifetimeScope.Application: return new PerContainerLifetime(); - case ObjectLifetimeScope.Transient: + //case ObjectLifetimeScope.Transient: default: return null; } diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index f8ffcb34b0..704278f059 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -64,7 +64,7 @@ namespace Umbraco.Tests.Cache.PublishedCache var domainCache = new DomainCache(ServiceContext.DomainService); var facade = new Facade( new PublishedContentCache(xmlStore, domainCache, cacheProvider, ContentTypesCache, null, null), - new PublishedMediaCache(xmlStore, ServiceContext.MediaService, cacheProvider, ContentTypesCache), + new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, cacheProvider, ContentTypesCache), new PublishedMemberCache(null, cacheProvider, ApplicationContext.Services.MemberService, ContentTypesCache), domainCache); var facadeService = new Mock(); diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs index 0d15d58aa5..e6f344cd15 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs @@ -49,7 +49,7 @@ namespace Umbraco.Tests.Cache.PublishedCache var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot2.Id); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(new XmlStore((XmlDocument) null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(new XmlStore((XmlDocument) null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache); var roots = cache.GetAtRoot(); Assert.AreEqual(2, roots.Count()); Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id})); @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Cache.PublishedCache //var publishedMedia = PublishedMediaTests.GetNode(mRoot.Id, GetUmbracoContext("/test", 1234)); var umbracoContext = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), umbracoContext.Application.Services.MediaService, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), umbracoContext.Application.Services.MediaService, umbracoContext.Application.Services.UserService, new StaticCacheProvider(), ContentTypesCache); var publishedMedia = cache.GetById(mRoot.Id); Assert.IsNotNull(publishedMedia); @@ -179,7 +179,7 @@ namespace Umbraco.Tests.Cache.PublishedCache result.Fields.Add("creatorID", "0"); result.Fields.Add("creatorName", "Shannon"); - var store = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); + var store = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache); var doc = store.CreateFromCacheValues(store.ConvertFromSearchResult(result)); DoAssert(doc, 1234, key, 0, 0, "/media/test.jpg", "Image", 0, "Shannon", "Shannon", 0, 0, "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2); @@ -195,7 +195,7 @@ namespace Umbraco.Tests.Cache.PublishedCache var xmlDoc = GetMediaXml(); ((XmlElement)xmlDoc.DocumentElement.FirstChild).SetAttribute("key", key.ToString()); var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator(); - var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache); var doc = cache.CreateFromCacheValues(cache.ConvertFromXPathNavigator(navigator, true)); DoAssert(doc, 2000, key, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index ccdb7b19af..df5e2842f2 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -62,7 +62,7 @@ namespace Umbraco.Tests.PublishedContent /// internal IPublishedContent GetNode(int id, UmbracoContext umbracoContext) { - var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), umbracoContext.Application.Services.MediaService, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), umbracoContext.Application.Services.MediaService, umbracoContext.Application.Services.UserService, new StaticCacheProvider(), ContentTypesCache); var doc = cache.GetById(id); Assert.IsNotNull(doc); return doc; @@ -116,7 +116,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //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); @@ -148,7 +148,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //ensure it is found var publishedMedia = cache.GetById(3113); @@ -192,7 +192,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //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); @@ -217,7 +217,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //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); @@ -242,7 +242,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //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); @@ -267,7 +267,7 @@ namespace Umbraco.Tests.PublishedContent var ctx = GetUmbracoContext("/test", 1234); var searcher = indexer.GetSearcher(); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //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); @@ -289,7 +289,7 @@ namespace Umbraco.Tests.PublishedContent var ctx = GetUmbracoContext("/test", 1234); var searcher = indexer.GetSearcher(); - var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); + var cache = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //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); @@ -462,7 +462,7 @@ namespace Umbraco.Tests.PublishedContent "); var node = xml.DescendantsAndSelf("Image").Single(x => (int)x.Attribute("id") == nodeId); - var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); + var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache); var nav = node.CreateNavigator(); @@ -482,7 +482,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(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); + var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache); var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/"), 1234); Assert.IsNull(converted); diff --git a/src/Umbraco.Web.UI/umbraco/config/lang/en.xml b/src/Umbraco.Web.UI/umbraco/config/lang/en.xml index 7ed001cb33..234454c660 100644 --- a/src/Umbraco.Web.UI/umbraco/config/lang/en.xml +++ b/src/Umbraco.Web.UI/umbraco/config/lang/en.xml @@ -1327,9 +1327,9 @@ To manage your website, simply open the Umbraco back office and start adding con '%0%' in config file '%1%'.]]> There was an error, check log for full error: %0%. - Total XML: %0%, Total: %1% - Total XML: %0%, Total: %1% - Total XML: %0%, Total published: %1% + Members: %0% + Media: %0% + Content: %0% Certificate validation error: '%0%' Error pinging the URL %0% - '%1%' diff --git a/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml b/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml index 86d90f73d0..ce6f4fbbb1 100644 --- a/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml +++ b/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml @@ -1331,9 +1331,9 @@ To manage your website, simply open the Umbraco back office and start adding con '%0%' in config file '%1%'.]]> There was an error, check log for full error: %0%. - Total XML: %0%, Total: %1% - Total XML: %0%, Total: %1% - Total XML: %0%, Total published: %1% + Members: %0% + Media: %0% + Content: %0% Certificate validation error: '%0%' Error pinging the URL %0% - '%1%' diff --git a/src/Umbraco.Web/Editors/PackageInstallController.cs b/src/Umbraco.Web/Editors/PackageInstallController.cs index 5fb8e8a683..ad4d94a667 100644 --- a/src/Umbraco.Web/Editors/PackageInstallController.cs +++ b/src/Umbraco.Web/Editors/PackageInstallController.cs @@ -89,7 +89,7 @@ namespace Umbraco.Web.Editors if (pack == null) throw new ArgumentNullException("pack"); var refreshCache = false; - + //Uninstall templates foreach (var item in pack.Data.Templates.ToArray()) { @@ -112,7 +112,7 @@ namespace Umbraco.Web.Editors if (macro != null) { Services.MacroService.Delete(macro); - } + } pack.Data.Macros.Remove(nId.ToString()); } @@ -152,7 +152,7 @@ namespace Umbraco.Web.Editors if (di != null) { Services.LocalizationService.Delete(di); - } + } pack.Data.DictionaryItems.Remove(nId.ToString()); } @@ -165,14 +165,14 @@ namespace Umbraco.Web.Editors if (dtd != null) { Services.DataTypeService.Delete(dtd); - } + } pack.Data.DataTypes.Remove(nId.ToString()); } pack.Save(); // uninstall actions - //TODO: We should probably report errors to the UI!! + //TODO: We should probably report errors to the UI!! // This never happened before though, but we should do something now if (pack.Data.Actions.IsNullOrWhiteSpace() == false) { @@ -214,19 +214,14 @@ namespace Umbraco.Web.Editors if (File.Exists(filePath)) { File.Delete(filePath); - + } } pack.Data.Files.Remove(file); } pack.Save(); pack.Delete(Security.GetUserId()); - - //TODO: Legacy - probably not needed - if (refreshCache) - { - library.RefreshContent(); - } + TreeDefinitionCollection.Instance.ReRegisterTrees(); _Legacy.Actions.Action.ReRegisterActionsAndHandlers(); } @@ -317,7 +312,7 @@ namespace Umbraco.Web.Editors model.UmbracoVersion = ins.RequirementsType == RequirementsType.Strict ? string.Format("{0}.{1}.{2}", ins.RequirementsMajor, ins.RequirementsMinor, ins.RequirementsPatch) : string.Empty; - + //now we need to check for version comparison model.IsCompatible = true; if (ins.RequirementsType == RequirementsType.Strict) @@ -397,7 +392,7 @@ namespace Umbraco.Web.Editors { //TODO: Currently it has to be here, it's not ideal but that's the way it is right now var packageTempDir = IOHelper.MapPath(SystemDirectories.Data); - + //ensure it's there Directory.CreateDirectory(packageTempDir); @@ -413,14 +408,14 @@ namespace Umbraco.Web.Editors PopulateFromPackageData(model); var validate = ValidateInstalledInternal(model.Name, model.Version); - + if (validate == false) { //this package is already installed throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( - Services.TextService.Localize("packager/packageAlreadyInstalled"))); + Services.TextService.Localize("packager/packageAlreadyInstalled"))); } - + } else { @@ -429,7 +424,7 @@ namespace Umbraco.Web.Editors Services.TextService.Localize("media/disallowedFileType"), SpeechBubbleIcon.Warning)); } - + } return model; @@ -451,7 +446,7 @@ namespace Umbraco.Web.Editors //our repo guid using (var our = Repository.getByGuid("65194810-1f85-11dd-bd0b-0800200c9a66")) { - path = our.fetch(packageGuid, Security.CurrentUser.Id); + path = our.fetch(packageGuid, Security.CurrentUser.Id); } } diff --git a/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/XmlDataIntegrityHealthCheck.cs b/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/XmlDataIntegrityHealthCheck.cs index 5f009a7b7c..4ece3a6557 100644 --- a/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/XmlDataIntegrityHealthCheck.cs +++ b/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/XmlDataIntegrityHealthCheck.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Generic; -using Umbraco.Core; -using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence; -using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Services; +using Umbraco.Web.PublishedCache; namespace Umbraco.Web.HealthCheck.Checks.DataIntegrity { @@ -19,22 +16,21 @@ namespace Umbraco.Web.HealthCheck.Checks.DataIntegrity public class XmlDataIntegrityHealthCheck : HealthCheck { private readonly ILocalizedTextService _textService; + private readonly PublishedCache.XmlPublishedCache.FacadeService _facadeService; private const string CheckContentXmlTableAction = "checkContentXmlTable"; private const string CheckMediaXmlTableAction = "checkMediaXmlTable"; private const string CheckMembersXmlTableAction = "checkMembersXmlTable"; - public XmlDataIntegrityHealthCheck(HealthCheckContext healthCheckContext) : base(healthCheckContext) + public XmlDataIntegrityHealthCheck(HealthCheckContext healthCheckContext, IFacadeService facadeService) + : base(healthCheckContext) { - _sqlSyntax = HealthCheckContext.ApplicationContext.DatabaseContext.SqlSyntax; - _services = HealthCheckContext.ApplicationContext.Services; - _database = HealthCheckContext.ApplicationContext.DatabaseContext.Database; _textService = healthCheckContext.ApplicationContext.Services.TextService; - } - private readonly ISqlSyntaxProvider _sqlSyntax; - private readonly ServiceContext _services; - private readonly UmbracoDatabase _database; + _facadeService = facadeService as PublishedCache.XmlPublishedCache.FacadeService; + if (_facadeService == null) + throw new NotSupportedException("Unsupported IFacadeService, only the Xml one is supported."); + } /// /// Get the status for this health check @@ -56,13 +52,13 @@ namespace Umbraco.Web.HealthCheck.Checks.DataIntegrity switch (action.Alias) { case CheckContentXmlTableAction: - _services.ContentService.RebuildXmlStructures(); + _facadeService.RebuildContentAndPreviewXml(); return CheckContent(); case CheckMediaXmlTableAction: - _services.MediaService.RebuildXmlStructures(); + _facadeService.RebuildMediaXml(); return CheckMedia(); case CheckMembersXmlTableAction: - _services.MemberService.RebuildXmlStructures(); + _facadeService.RebuildMemberXml(); return CheckMembers(); default: throw new ArgumentOutOfRangeException(); @@ -71,67 +67,28 @@ namespace Umbraco.Web.HealthCheck.Checks.DataIntegrity private HealthCheckStatus CheckMembers() { - var total = _services.MemberService.Count(); - var memberObjectType = Guid.Parse(Constants.ObjectTypes.Member); - var subQuery = _database.Sql() - .Select("Count(*)") - .From() - .InnerJoin() - .On(left => left.NodeId, right => right.NodeId) - .Where(dto => dto.NodeObjectType == memberObjectType); - var totalXml = _database.ExecuteScalar(subQuery); - - var actions = new List(); - if (totalXml != total) - actions.Add(new HealthCheckAction(CheckMembersXmlTableAction, Id)); - - return new HealthCheckStatus(_textService.Localize("healthcheck/xmlDataIntegrityCheckMembers", new[] { totalXml.ToString(), total.ToString() })) - { - ResultType = totalXml == total ? StatusResultType.Success : StatusResultType.Error, - Actions = actions - }; + return Check(_facadeService.VerifyMemberXml(), CheckMembersXmlTableAction, "healthcheck/xmlDataIntegrityCheckMembers"); } private HealthCheckStatus CheckMedia() { - var total = _services.MediaService.Count(); - var mediaObjectType = Guid.Parse(Constants.ObjectTypes.Media); - var subQuery = _database.Sql() - .Select("Count(*)") - .From() - .InnerJoin() - .On(left => left.NodeId, right => right.NodeId) - .Where(dto => dto.NodeObjectType == mediaObjectType); - var totalXml = _database.ExecuteScalar(subQuery); - - var actions = new List(); - if (totalXml != total) - actions.Add(new HealthCheckAction(CheckMediaXmlTableAction, Id)); - - return new HealthCheckStatus(_textService.Localize("healthcheck/xmlDataIntegrityCheckMedia", new[] { totalXml.ToString(), total.ToString() })) - { - ResultType = totalXml == total ? StatusResultType.Success : StatusResultType.Error, - Actions = actions - }; + return Check(_facadeService.VerifyMediaXml(), CheckMediaXmlTableAction, "healthcheck/xmlDataIntegrityCheckMedia"); } private HealthCheckStatus CheckContent() { - var total = _services.ContentService.CountPublished(); - var subQuery = _database.Sql() - .Select("DISTINCT cmsContentXml.nodeId") - .From() - .InnerJoin() - .On(left => left.NodeId, right => right.NodeId); - var totalXml = _database.ExecuteScalar("SELECT COUNT(*) FROM (" + subQuery.SQL + ") as tmp"); + return Check(_facadeService.VerifyContentAndPreviewXml(), CheckContentXmlTableAction, "healthcheck/xmlDataIntegrityCheckContent"); + } + private HealthCheckStatus Check(bool ok, string action, string text) + { var actions = new List(); - if (totalXml != total) - actions.Add(new HealthCheckAction(CheckContentXmlTableAction, Id)); + if (ok == false) + actions.Add(new HealthCheckAction(action, Id)); - return new HealthCheckStatus(_textService.Localize("healthcheck/xmlDataIntegrityCheckContent", new[] { totalXml.ToString(), total.ToString() })) + return new HealthCheckStatus(_textService.Localize(text, new[] { ok ? "ok" : "not ok" })) { - ResultType = totalXml == total ? StatusResultType.Success : StatusResultType.Error, + ResultType = ok ? StatusResultType.Success : StatusResultType.Error, Actions = actions }; } diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckController.cs b/src/Umbraco.Web/HealthCheck/HealthCheckController.cs index 919df88962..3a3230179a 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckController.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Web; using System.Web.Http; using Umbraco.Web.Editors; @@ -29,7 +30,8 @@ namespace Umbraco.Web.HealthCheck /// Returns a collection of anonymous objects representing each group. public object GetAllHealthChecks() { - var groups = _healthCheckResolver.HealthChecks + var context = new HealthCheckContext(new HttpContextWrapper(HttpContext.Current), UmbracoContext.Current); + var groups = _healthCheckResolver.GetHealthChecks(context) .GroupBy(x => x.Group) .OrderBy(x => x.Key); var healthCheckGroups = new List(); @@ -50,7 +52,8 @@ namespace Umbraco.Web.HealthCheck public object GetStatus(Guid id) { - var check = _healthCheckResolver.HealthChecks.FirstOrDefault(x => x.Id == id); + var context = new HealthCheckContext(new HttpContextWrapper(HttpContext.Current), UmbracoContext.Current); + var check = _healthCheckResolver.GetHealthChecks(context).FirstOrDefault(x => x.Id == id); if (check == null) throw new InvalidOperationException("No health check found with ID " + id); return check.GetStatus(); @@ -59,7 +62,8 @@ namespace Umbraco.Web.HealthCheck [HttpPost] public HealthCheckStatus ExecuteAction(HealthCheckAction action) { - var check = _healthCheckResolver.HealthChecks.FirstOrDefault(x => x.Id == action.HealthCheckId); + var context = new HealthCheckContext(new HttpContextWrapper(HttpContext.Current), UmbracoContext.Current); + var check = _healthCheckResolver.GetHealthChecks(context).FirstOrDefault(x => x.Id == action.HealthCheckId); if (check == null) throw new InvalidOperationException("No health check found with id " + action.HealthCheckId); return check.ExecuteAction(action); diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckResolver.cs b/src/Umbraco.Web/HealthCheck/HealthCheckResolver.cs index d3e2dc794d..7377de41f8 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckResolver.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckResolver.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Web; +using LightInject; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; @@ -12,41 +14,33 @@ namespace Umbraco.Web.HealthCheck /// /// Each instance scoped to the lifespan of the http request /// - internal class HealthCheckResolver : LazyManyObjectsResolverBase, IHealthCheckResolver + internal class HealthCheckResolver : ContainerLazyManyObjectsResolver, IHealthCheckResolver { - public HealthCheckResolver(ILogger logger, Func> lazyTypeList) - : base(new HealthCheckServiceProvider(), logger, lazyTypeList, ObjectLifetimeScope.HttpRequest) + public HealthCheckResolver(IServiceContainer container, ILogger logger, Func> types) + : base(container, logger, types, ObjectLifetimeScope.HttpRequest) + { } + + protected override IEnumerable CreateValues(ObjectLifetimeScope scope) { + EnsureTypesRegisterred(scope, container => + { + // resolve ctor dependency from GetInstance() runtimeArguments, if possible - 'factory' is + // the container, 'info' describes the ctor argument, and 'args' contains the args that + // were passed to GetInstance() - use first arg if it is the right type, + // + // for HealthCheckContext + container.RegisterConstructorDependency((factory, info, args) => args.Length > 0 ? args[0] as HealthCheckContext : null); + }); + + return InstanceTypes.Select(x => (HealthCheck) Container.GetInstance(x, new object[] { _healthCheckContext })); } - /// - /// Returns all health check instances - /// - public IEnumerable HealthChecks => Values; + private HealthCheckContext _healthCheckContext; - /// - /// This will ctor the HealthCheck instances - /// - /// - /// This is like a super crappy DI - in v8 we have real DI - /// - private class HealthCheckServiceProvider : IServiceProvider + public IEnumerable GetHealthChecks(HealthCheckContext context) { - public object GetService(Type serviceType) - { - var normalArgs = new[] { typeof(HealthCheckContext) }; - var found = serviceType.GetConstructor(normalArgs); - if (found != null) - { - return found.Invoke(new object[] - { - new HealthCheckContext(new HttpContextWrapper(HttpContext.Current), UmbracoContext.Current) - }); - } - - //use normal ctor - return Activator.CreateInstance(serviceType); - } + _healthCheckContext = context; + return Values; } } } diff --git a/src/Umbraco.Web/HealthCheck/IHealthCheckResolver.cs b/src/Umbraco.Web/HealthCheck/IHealthCheckResolver.cs index 795b61198e..65afa67740 100644 --- a/src/Umbraco.Web/HealthCheck/IHealthCheckResolver.cs +++ b/src/Umbraco.Web/HealthCheck/IHealthCheckResolver.cs @@ -4,6 +4,6 @@ namespace Umbraco.Web.HealthCheck { public interface IHealthCheckResolver { - IEnumerable HealthChecks { get; } + IEnumerable GetHealthChecks(HealthCheckContext context); } } \ No newline at end of file diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs index 3bf3ab9b87..273daa860c 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs @@ -22,6 +22,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache private readonly IDomainService _domainService; private readonly IMemberService _memberService; private readonly IMediaService _mediaService; + private readonly IUserService _userService; private readonly ICacheProvider _requestCache; #region Constructors @@ -60,6 +61,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache _domainService = serviceContext.DomainService; _memberService = serviceContext.MemberService; _mediaService = serviceContext.MediaService; + _userService = serviceContext.UserService; _requestCache = requestCache; } @@ -84,7 +86,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache return new Facade( new PublishedContentCache(_xmlStore, domainCache, _requestCache, _contentTypeCache, _routesCache, previewToken), - new PublishedMediaCache(_xmlStore, _mediaService, _requestCache, _contentTypeCache), + new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache), new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache), domainCache); } diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs index fb6a191b1e..48300bca3b 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs @@ -267,13 +267,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache private IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing, ICacheProvider cacheProvider) { - return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing); // fixme cacheProvider, _contentTypeCache + return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, cacheProvider, _contentTypeCache); } private IEnumerable ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing, ICacheProvider cacheProvider) { return xmlNodes.Cast() - .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing)); // fixme cacheProvider, _contentTypeCache + .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, cacheProvider, _contentTypeCache)); } #endregion diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 8fef4716e5..a23a1c9732 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -517,8 +517,8 @@ namespace Umbraco.Web CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver(Container, typeof(DefaultCultureDictionaryFactory)); - HealthCheckResolver.Current = new HealthCheckResolver(ProfilingLogger.Logger, - () => PluginManager.ResolveTypes()); + HealthCheckResolver.Current = new HealthCheckResolver(Container, ProfilingLogger.Logger, + () => PluginManager.ResolveTypes()); // fixme XML cache vs NuCache?! } /// diff --git a/src/Umbraco.Web/WebServices/XmlDataIntegrityController.cs b/src/Umbraco.Web/WebServices/XmlDataIntegrityController.cs index 94f5428f43..1f68dc7391 100644 --- a/src/Umbraco.Web/WebServices/XmlDataIntegrityController.cs +++ b/src/Umbraco.Web/WebServices/XmlDataIntegrityController.cs @@ -21,7 +21,6 @@ namespace Umbraco.Web.WebServices _facadeService = facadeService as FacadeService; if (_facadeService == null) throw new NotSupportedException("Unsupported IFacadeService, only the Xml one is supported."); - } [HttpPost]