diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index 9406fb015e..bfc5579750 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Services /// /// internal ServiceContext(IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider, IUnitOfWorkProvider fileUnitOfWorkProvider, IPublishingStrategy publishingStrategy) - { + { BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy, //this needs to be lazy because when we create the service context it's generally before the //resolvers have been initialized! diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index d3b7c20c06..7f3a4f97c3 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -279,6 +279,7 @@ + diff --git a/src/Umbraco.Tests/UmbracoExamine/ContentServiceTest.cs b/src/Umbraco.Tests/UmbracoExamine/ContentServiceTest.cs new file mode 100644 index 0000000000..679c91e489 --- /dev/null +++ b/src/Umbraco.Tests/UmbracoExamine/ContentServiceTest.cs @@ -0,0 +1,26 @@ +using System.Linq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Tests.TestHelpers; +using UmbracoExamine.DataServices; + +namespace Umbraco.Tests.UmbracoExamine +{ + [TestFixture] + public class ContentServiceTest : BaseDatabaseFactoryTest + { + + [Test] + public void Get_All_User_Property_Names() + { + var contentService = new UmbracoContentService(ApplicationContext); + var db = DatabaseContext.Database; + + var result = contentService.GetAllUserPropertyNames(); + + Assert.IsTrue(result.Select(x => x).ContainsAll(new[] { "contents", "umbracoBytes", "umbracoExtension", "umbracoFile", "umbracoHeight", "umbracoWidth" })); + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/UmbracoExamine/TestContentService.cs b/src/Umbraco.Tests/UmbracoExamine/TestContentService.cs index 9e34a738e2..0078c94a59 100644 --- a/src/Umbraco.Tests/UmbracoExamine/TestContentService.cs +++ b/src/Umbraco.Tests/UmbracoExamine/TestContentService.cs @@ -3,12 +3,14 @@ using System.Linq; using System.Text.RegularExpressions; using System.Xml.Linq; using System.Xml.XPath; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.Repositories; using UmbracoExamine; using UmbracoExamine.DataServices; namespace Umbraco.Tests.UmbracoExamine { - /// + /// /// A mock data service used to return content from the XML data file created with CWS /// public class TestContentService : IContentService diff --git a/src/UmbracoExamine/DataServices/UmbracoContentService.cs b/src/UmbracoExamine/DataServices/UmbracoContentService.cs index de84f02047..c80556856b 100644 --- a/src/UmbracoExamine/DataServices/UmbracoContentService.cs +++ b/src/UmbracoExamine/DataServices/UmbracoContentService.cs @@ -6,6 +6,8 @@ using System.Text; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Services; using umbraco; using System.Xml.Linq; @@ -25,17 +27,19 @@ namespace UmbracoExamine.DataServices public class UmbracoContentService : IContentService { - private readonly ServiceContext _services; + private readonly ApplicationContext _applicationContext; + [SecuritySafeCritical] public UmbracoContentService() - : this(ApplicationContext.Current.Services) + : this(ApplicationContext.Current) { } - public UmbracoContentService(ServiceContext services) + [SecuritySafeCritical] + public UmbracoContentService(ApplicationContext applicationContext) { - _services = services; + _applicationContext = applicationContext; } /// @@ -74,7 +78,7 @@ namespace UmbracoExamine.DataServices public XDocument GetLatestContentByXPath(string xpath) { var xmlContent = XDocument.Parse(""); - foreach (var c in _services.ContentService.GetRootContent()) + foreach (var c in _applicationContext.Services.ContentService.GetRootContent()) { xmlContent.Root.Add(c.ToXml()); } @@ -115,39 +119,18 @@ namespace UmbracoExamine.DataServices /// [SecuritySafeCritical] public IEnumerable GetAllUserPropertyNames() - { - //TODO: this is how umb codebase 4.0 does this... convert to new data layer - - var aliases = new List(); - var fieldSql = "select distinct alias from cmsPropertyType order by alias"; + { try { - using (var dr = Application.SqlHelper.ExecuteReader(fieldSql)) - { - while (dr.Read()) - { - aliases.Add(dr.GetString("alias")); - } - } + var result = _applicationContext.DatabaseContext.Database.Fetch("select distinct alias from cmsPropertyType order by alias"); + return result.Select(r => r.Alias.ToString()).Cast().ToList(); } catch (Exception ex) { - if (ex is SqlHelperException || ex is SqlException) - { - //if this happens, it could be due to wrong connection string, or something else. - //we don't want to crash the app because of this so we'll actually swallow this - //exception... Unfortunately logging probably won't work in this situation either :( - - LogHelper.Error("EXCEPTION OCCURRED reading GetAllUserPropertyNames", ex); - } - else - { - throw; - } - } - - return aliases; - } + LogHelper.Error("EXCEPTION OCCURRED reading GetAllUserPropertyNames", ex); + return Enumerable.Empty(); + } + } /// /// Returns a list of all system field names in Umbraco diff --git a/src/UmbracoExamine/UmbracoExamine.csproj b/src/UmbracoExamine/UmbracoExamine.csproj index c9a697ddbb..1545dfd5ff 100644 --- a/src/UmbracoExamine/UmbracoExamine.csproj +++ b/src/UmbracoExamine/UmbracoExamine.csproj @@ -92,6 +92,7 @@ False ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll +