Moving interfaces for services to Umbraco.Core.
Adding xml extensions for Content to generate xml for the xml cache. Adding test for xml generation.
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -138,5 +133,13 @@ namespace Umbraco.Core
|
||||
if (this.IsReady)
|
||||
throw new Exception("ApplicationContext has already been initialized.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current DatabaseContext
|
||||
/// </summary>
|
||||
public DatabaseContext DatabaseContext
|
||||
{
|
||||
get { return DatabaseContext.Current; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
@@ -41,6 +43,44 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Possibly add a ToXml method, which will generate valid xml for the current Content object
|
||||
/// <summary>
|
||||
/// Creates the xml representation for the <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
|
||||
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
|
||||
public static XElement ToXml(this IContent content)
|
||||
{
|
||||
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
|
||||
var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
|
||||
|
||||
var xml = new XElement(nodeName,
|
||||
new XAttribute("id", content.Id),
|
||||
new XAttribute("parentID", content.Level > 1 ? content.ParentId : -1),
|
||||
new XAttribute("level", content.Level),
|
||||
new XAttribute("writerID", content.Writer.Id),
|
||||
new XAttribute("creatorID", content.Creator.Id),
|
||||
new XAttribute("nodeType", content.ContentType.Id),
|
||||
new XAttribute("template", content.Template),//Template name versus Id
|
||||
new XAttribute("sortOrder", content.SortOrder),
|
||||
new XAttribute("createDate", content.CreateDate),
|
||||
new XAttribute("updateDate", content.UpdateDate),
|
||||
new XAttribute("nodeName", content.Name),
|
||||
new XAttribute("urlName", content.UrlName),//Format Url ?
|
||||
new XAttribute("writerName", content.Writer.Name),
|
||||
new XAttribute("creatorName", content.Creator.Name),
|
||||
new XAttribute("path", content.Path));
|
||||
|
||||
foreach (var property in content.Properties)
|
||||
{
|
||||
if (property == null) continue;
|
||||
|
||||
xml.Add(property.ToXml());
|
||||
|
||||
if (property.Alias == "umbracoUrlName" && property.Value.ToString().Trim() != string.Empty)
|
||||
xml.SetAttributeValue("urlName", property.Value);
|
||||
}
|
||||
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,12 @@ namespace Umbraco.Core.Models
|
||||
[IgnoreDataMember]
|
||||
internal DataTypeDatabaseType DataTypeDatabaseType { get { return _propertyType.DataTypeDatabaseType; } }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the PropertyType, which this Property is based on
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
internal PropertyType PropertyType { get { return _propertyType; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the version id for the Property
|
||||
/// </summary>
|
||||
|
||||
26
src/Umbraco.Core/Models/PropertyExtensions.cs
Normal file
26
src/Umbraco.Core/Models/PropertyExtensions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public static class PropertyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the xml representation for the <see cref="Property"/> object
|
||||
/// </summary>
|
||||
/// <param name="property"><see cref="Property"/> to generate xml for</param>
|
||||
/// <returns>Xml of the property and its value</returns>
|
||||
public static XElement ToXml(this Property property)
|
||||
{
|
||||
string nodeName = property.Alias.ToUmbracoAlias();
|
||||
|
||||
var xd = new XmlDocument();
|
||||
XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");
|
||||
xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
|
||||
|
||||
var element = xmlNode.GetXElement();
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ namespace Umbraco.Core.Models
|
||||
internal Guid DataTypeControlId
|
||||
{
|
||||
get { return _dataTypeControlId; }
|
||||
private set
|
||||
set
|
||||
{
|
||||
_dataTypeControlId = value;
|
||||
OnPropertyChanged(DataTypeControlIdSelector);
|
||||
@@ -140,7 +140,7 @@ namespace Umbraco.Core.Models
|
||||
internal DataTypeDatabaseType DataTypeDatabaseType
|
||||
{
|
||||
get { return _dataTypeDatabaseType; }
|
||||
private set
|
||||
set
|
||||
{
|
||||
_dataTypeDatabaseType = value;
|
||||
OnPropertyChanged(DataTypeDatabaseTypeSelector);
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Umbraco.Core.Models
|
||||
/// Resolves the IDataType for a PropertyType.
|
||||
/// </summary>
|
||||
/// <param name="propertyType">PropertyType that references a DataType</param>
|
||||
/// <param name="propertyId">Id of the Property which references this DataType through its PropertyType</param>
|
||||
/// <returns><see cref="IDataType"/></returns>
|
||||
/// <remarks>
|
||||
/// This extension method is left internal because we don't want to take
|
||||
@@ -15,11 +16,12 @@ namespace Umbraco.Core.Models
|
||||
/// be replaced by PropertyEditors. It is however needed to generate xml
|
||||
/// for a property/propertytype when publishing.
|
||||
/// </remarks>
|
||||
internal static IDataType DataType(this PropertyType propertyType)
|
||||
internal static IDataType DataType(this PropertyType propertyType, int propertyId)
|
||||
{
|
||||
Mandate.ParameterNotNull(propertyType, "propertyType");
|
||||
var dataType = DataTypesResolver.Current.GetById(propertyType.DataTypeControlId);
|
||||
dataType.DataTypeDefinitionId = propertyType.DataTypeId;
|
||||
dataType.Data.PropertyId = propertyId;
|
||||
return dataType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +195,19 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
//Create the PropertyData for this version - cmsPropertyData
|
||||
var propertyFactory = new PropertyFactory(entity.ContentType, entity.Version, entity.Id);
|
||||
var propertyDataDtos = propertyFactory.BuildDto(entity.Properties);
|
||||
var keyDictionary = new Dictionary<int, int>();
|
||||
|
||||
//Add Properties
|
||||
foreach (var propertyDataDto in propertyDataDtos)
|
||||
{
|
||||
Database.Insert(propertyDataDto);
|
||||
var primaryKey = Convert.ToInt32(Database.Insert(propertyDataDto));
|
||||
keyDictionary.Add(propertyDataDto.PropertyTypeId, primaryKey);
|
||||
}
|
||||
|
||||
//Update Properties with its newly set Id
|
||||
foreach (var property in entity.Properties)
|
||||
{
|
||||
property.Id = keyDictionary[property.PropertyTypeId];
|
||||
}
|
||||
|
||||
((ICanBeDirty)entity).ResetDirtyProperties();
|
||||
|
||||
@@ -111,6 +111,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var propertyTypeDto = propertyFactory.BuildPropertyTypeDto(propertyGroup.Id, propertyType);
|
||||
var primaryKey = Convert.ToInt32(Database.Insert(propertyTypeDto));
|
||||
propertyType.Id = primaryKey;//Set Id on PropertyType
|
||||
|
||||
//Update the current PropertyType with correct ControlId and DatabaseType
|
||||
var dataTypeDto = Database.FirstOrDefault<DataTypeDto>("WHERE nodeId = @Id", new { Id = propertyTypeDto.DataTypeId });
|
||||
propertyType.DataTypeControlId = dataTypeDto.ControlId;
|
||||
propertyType.DataTypeDatabaseType = dataTypeDto.DbType.EnumParse<DataTypeDatabaseType>(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
foreach (var contentTypeDto in list)
|
||||
{
|
||||
bool result = contentType.AddContentType(Get(contentTypeDto.ParentId));
|
||||
//Do something if adding fails? (Should hopefully not be possible unless someone create a circular reference)
|
||||
//Do something if adding fails? (Should hopefully not be possible unless someone created a circular reference)
|
||||
}
|
||||
|
||||
((ICanBeDirty)contentType).ResetDirtyProperties();
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.Publishing
|
||||
namespace Umbraco.Core.Publishing
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class for the implementation of an <see cref="IPublishingStrategy"/>, which provides the events used for publishing/unpublishing.
|
||||
/// </summary>
|
||||
public abstract class BasePublishingStrategy : IPublishingStrategy
|
||||
{
|
||||
public abstract bool Publish(IContent content, int userId);
|
||||
@@ -11,15 +14,10 @@ namespace Umbraco.Web.Publishing
|
||||
public abstract bool UnPublish(IContent content, int userId);
|
||||
public abstract bool UnPublish(IEnumerable<IContent> content, int userId);
|
||||
|
||||
/// <summary>
|
||||
/// The publishing event handler used for publish and unpublish events
|
||||
/// </summary>
|
||||
public delegate void PublishingEventHandler(IContent sender, PublishingEventArgs e);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before publish
|
||||
/// </summary>
|
||||
public static event PublishingEventHandler Publishing;
|
||||
public static event EventHandler<PublishingEventArgs> Publishing;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="Publishing"/> event
|
||||
@@ -35,7 +33,7 @@ namespace Umbraco.Web.Publishing
|
||||
/// <summary>
|
||||
/// Occurs after publish
|
||||
/// </summary>
|
||||
public static event PublishingEventHandler Published;
|
||||
public static event EventHandler<PublishingEventArgs> Published;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="Published"/> event
|
||||
@@ -51,7 +49,7 @@ namespace Umbraco.Web.Publishing
|
||||
/// <summary>
|
||||
/// Occurs before unpublish
|
||||
/// </summary>
|
||||
public static event PublishingEventHandler UnPublishing;
|
||||
public static event EventHandler<PublishingEventArgs> UnPublishing;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="UnPublishing"/> event
|
||||
@@ -67,7 +65,7 @@ namespace Umbraco.Web.Publishing
|
||||
/// <summary>
|
||||
/// Occurs after unpublish
|
||||
/// </summary>
|
||||
public static event PublishingEventHandler UnPublished;
|
||||
public static event EventHandler<PublishingEventArgs> UnPublished;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="UnPublished"/> event
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Publishing
|
||||
namespace Umbraco.Core.Publishing
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the Publishing Strategy
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ContentService, which is an easy access to operations involving <see cref="IContent"/>
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ContentTypeService, which is an easy access to operations involving <see cref="IContentType"/>
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the DataType Service, which is an easy access to operations involving <see cref="IDataType"/> and <see cref="IDataTypeDefinition"/>
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the File Service, which is an easy access to operations involving <see cref="IFile"/> objects like Scripts, Stylesheets and Templates
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the Localization Service, which is an easy access to operations involving Languages and Dictionary
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ContentService, which is an easy access to operations involving <see cref="IMacro"/>
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the Media Service, which is an easy access to operations involving <see cref="IMedia"/>
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Marker interface for services, which is used to store difference services in a list or dictionary
|
||||
@@ -1,6 +1,6 @@
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the UserService, which is an easy access to operations involving <see cref="IProfile"/> and eventually Users and Members.
|
||||
@@ -104,6 +104,7 @@
|
||||
<Compile Include="Models\Membership\Profile.cs" />
|
||||
<Compile Include="Models\Membership\User.cs" />
|
||||
<Compile Include="Models\Membership\UserProfile.cs" />
|
||||
<Compile Include="Models\PropertyExtensions.cs" />
|
||||
<Compile Include="Models\PropertyTypeExtensions.cs" />
|
||||
<Compile Include="Models\Rdbms\ContentType2ContentTypeDto.cs" />
|
||||
<Compile Include="Models\Rdbms\PropertyTypeGroupDto.cs" />
|
||||
@@ -376,6 +377,8 @@
|
||||
<Compile Include="ObjectResolution\Resolution.cs" />
|
||||
<Compile Include="ObjectResolution\ResolverBase.cs" />
|
||||
<Compile Include="ObjectResolution\SingleObjectResolverBase.cs" />
|
||||
<Compile Include="Publishing\BasePublishingStrategy.cs" />
|
||||
<Compile Include="Publishing\IPublishingStrategy.cs" />
|
||||
<Compile Include="RenderingEngine.cs" />
|
||||
<Compile Include="Serialization\AbstractSerializationService.cs" />
|
||||
<Compile Include="Serialization\Formatter.cs" />
|
||||
@@ -387,6 +390,15 @@
|
||||
<Compile Include="Serialization\ServiceStackJsonSerializer.cs" />
|
||||
<Compile Include="Serialization\ServiceStackXmlSerializer.cs" />
|
||||
<Compile Include="Serialization\StreamedResult.cs" />
|
||||
<Compile Include="Services\IContentService.cs" />
|
||||
<Compile Include="Services\IContentTypeService.cs" />
|
||||
<Compile Include="Services\IDataTypeService.cs" />
|
||||
<Compile Include="Services\IFileService.cs" />
|
||||
<Compile Include="Services\ILocalizationService.cs" />
|
||||
<Compile Include="Services\IMacroService.cs" />
|
||||
<Compile Include="Services\IMediaService.cs" />
|
||||
<Compile Include="Services\IService.cs" />
|
||||
<Compile Include="Services\IUserService.cs" />
|
||||
<Compile Include="TypeExtensions.cs" />
|
||||
<Compile Include="ReadLock.cs" />
|
||||
<Compile Include="TypeFinder.cs" />
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for xml objects
|
||||
/// </summary>
|
||||
internal static class XmlExtensions
|
||||
{
|
||||
|
||||
public static T AttributeValue<T>(this XmlNode xml, string attributeName)
|
||||
{
|
||||
if (xml == null) throw new ArgumentNullException("xml");
|
||||
@@ -26,5 +25,22 @@ namespace Umbraco.Core
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public static XElement GetXElement(this XmlNode node)
|
||||
{
|
||||
XDocument xDoc = new XDocument();
|
||||
using (XmlWriter xmlWriter = xDoc.CreateWriter())
|
||||
node.WriteTo(xmlWriter);
|
||||
return xDoc.Root;
|
||||
}
|
||||
|
||||
public static XmlNode GetXmlNode(this XElement element)
|
||||
{
|
||||
using (XmlReader xmlReader = element.CreateReader())
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load(xmlReader);
|
||||
return xmlDoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,11 @@
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
|
||||
<connectionStrings>
|
||||
<appSettings>
|
||||
<add key="umbracoDbDSN" value="datalayer=SQLCE4Umbraco.SqlCEHelper,SQLCE4Umbraco;data source=|DataDirectory|\test.sdf" />
|
||||
</appSettings>
|
||||
|
||||
<connectionStrings>
|
||||
<add name="umbracoDbDSN" connectionString="Datasource=|DataDirectory|test.sdf" providerName="System.Data.SqlServerCe.4.0"/>
|
||||
</connectionStrings>
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using umbraco.editorControls.tinyMCE3;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
@@ -19,6 +23,19 @@ namespace Umbraco.Tests.Services
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
//this ensures its reset
|
||||
PluginManager.Current = new PluginManager();
|
||||
|
||||
//for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
|
||||
PluginManager.Current.AssembliesToScan = new[]
|
||||
{
|
||||
typeof(IDataType).Assembly,
|
||||
typeof(tinyMCE3dataType).Assembly
|
||||
};
|
||||
|
||||
DataTypesResolver.Current = new DataTypesResolver(
|
||||
PluginManager.Current.ResolveDataTypes());
|
||||
|
||||
base.Initialize();
|
||||
|
||||
CreateTestData();
|
||||
@@ -27,6 +44,8 @@ namespace Umbraco.Tests.Services
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
TestHelper.ClearDatabase();
|
||||
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
@@ -549,6 +568,26 @@ namespace Umbraco.Tests.Services
|
||||
Assert.AreEqual(subpage2.Name, rollback.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Generate_Xml_Representation_Of_Content()
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MockedContentTypes.CreateTextpageContentType();
|
||||
ServiceContext.ContentTypeService.Save(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Root Home", -1);
|
||||
ServiceContext.ContentService.Save(content, 0);
|
||||
|
||||
var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
|
||||
|
||||
// Act
|
||||
XElement element = content.ToXml();
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Name.LocalName, Is.EqualTo(nodeName));
|
||||
}
|
||||
|
||||
public void CreateTestData()
|
||||
{
|
||||
//NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested.
|
||||
|
||||
@@ -26,15 +26,5 @@ namespace Umbraco.Web
|
||||
var configPath = http.Request.PhysicalApplicationPath + "\\web.config";
|
||||
File.SetLastWriteTimeUtc(configPath, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the DatabaseContext to the ApplicationContext
|
||||
/// </summary>
|
||||
/// <param name="appContext"></param>
|
||||
/// <returns></returns>
|
||||
public static DatabaseContext DatabaseContext(this ApplicationContext appContext)
|
||||
{
|
||||
return Umbraco.Core.DatabaseContext.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Publishing;
|
||||
|
||||
namespace Umbraco.Web.Publishing
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
@@ -10,6 +9,8 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Publishing;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Publishing;
|
||||
using Content = Umbraco.Core.Models.Content;
|
||||
|
||||
@@ -20,7 +21,6 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class ContentService : IContentService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IPublishingStrategy _publishingStrategy;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IUserService _userService;
|
||||
@@ -40,7 +40,6 @@ namespace Umbraco.Web.Services
|
||||
|
||||
public ContentService(IUnitOfWorkProvider provider, IPublishingStrategy publishingStrategy, IUserService userService)
|
||||
{
|
||||
_provider = provider;
|
||||
_publishingStrategy = publishingStrategy;
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
_userService = userService;
|
||||
|
||||
@@ -5,6 +5,7 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
@@ -13,7 +14,6 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class ContentTypeService : IContentTypeService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
@@ -26,7 +26,6 @@ namespace Umbraco.Web.Services
|
||||
{
|
||||
_contentService = contentService;
|
||||
_mediaService = mediaService;
|
||||
_provider = provider;
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
@@ -16,7 +17,6 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class DataTypeService : IDataTypeService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DataTypeService() : this(new PetaPocoUnitOfWorkProvider())
|
||||
@@ -25,8 +25,7 @@ namespace Umbraco.Web.Services
|
||||
|
||||
public DataTypeService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
_unitOfWork = _provider.GetUnitOfWork();
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
@@ -11,7 +12,6 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class FileService : IFileService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public FileService() : this(new FileUnitOfWorkProvider())
|
||||
@@ -20,7 +20,6 @@ namespace Umbraco.Web.Services
|
||||
|
||||
public FileService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
@@ -15,7 +16,6 @@ namespace Umbraco.Web.Services
|
||||
public class LocalizationService : ILocalizationService
|
||||
{
|
||||
private static readonly Guid RootParentId = new Guid("41c7638d-f529-4bff-853e-59a0c2fb1bde");
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public LocalizationService() : this(new PetaPocoUnitOfWorkProvider())
|
||||
@@ -24,7 +24,6 @@ namespace Umbraco.Web.Services
|
||||
|
||||
public LocalizationService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
@@ -13,7 +14,6 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class MacroService : IMacroService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public MacroService()
|
||||
@@ -23,8 +23,7 @@ namespace Umbraco.Web.Services
|
||||
|
||||
public MacroService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
_unitOfWork = _provider.GetUnitOfWork();
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
EnsureMacroCache();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
@@ -12,7 +13,6 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class MediaService : IMediaService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public MediaService() : this(new PetaPocoUnitOfWorkProvider())
|
||||
@@ -21,7 +21,6 @@ namespace Umbraco.Web.Services
|
||||
|
||||
public MediaService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Publishing;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
@@ -13,32 +14,33 @@ namespace Umbraco.Web.Services
|
||||
/// </summary>
|
||||
public class ServiceContext
|
||||
{
|
||||
internal ServiceContext(HttpContextBase httpContext)
|
||||
private readonly ConcurrentDictionary<string, IService> _cache = new ConcurrentDictionary<string, IService>();
|
||||
private readonly HttpContextBase _httpContext;
|
||||
|
||||
public ServiceContext() : this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public ServiceContext(HttpContextBase httpContext)
|
||||
{
|
||||
_httpContext = httpContext;
|
||||
|
||||
if (_cache.IsEmpty)
|
||||
{
|
||||
BuildServiceCache();
|
||||
}
|
||||
BuildServiceCache();
|
||||
}
|
||||
|
||||
public static ServiceContext Current { get; internal set; }
|
||||
|
||||
private readonly HttpContextBase _httpContext;
|
||||
|
||||
private readonly ConcurrentDictionary<string, IService> _cache = new ConcurrentDictionary<string, IService>();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the various services and adds them to the internal cache
|
||||
/// </summary>
|
||||
private void BuildServiceCache()
|
||||
{
|
||||
if (_cache.IsEmpty == false) return;//Only proceed to build cache if cache is empty
|
||||
|
||||
var provider = new PetaPocoUnitOfWorkProvider();
|
||||
var fileProvider = new FileUnitOfWorkProvider();
|
||||
var publishingStrategy = new PublishingStrategy();
|
||||
|
||||
var userService = new UserService(_httpContext);
|
||||
var userService = new UserService(provider, _httpContext);
|
||||
|
||||
var contentService = new ContentService(provider, publishingStrategy, userService);
|
||||
_cache.AddOrUpdate(typeof (IContentService).Name, contentService, (x, y) => contentService);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Umbraco.Web.Services
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the ServiceFactory, which provides access to the various services in
|
||||
@@ -6,7 +8,7 @@
|
||||
/// </summary>
|
||||
public static class ServiceFactory
|
||||
{
|
||||
private static readonly ServiceContext ServiceContext = new ServiceContext(null);
|
||||
private static readonly ServiceContext ServiceContext = new ServiceContext();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IContentService"/>
|
||||
|
||||
@@ -4,6 +4,8 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
@@ -14,9 +16,13 @@ namespace Umbraco.Web.Services
|
||||
public class UserService : IUserService
|
||||
{
|
||||
private readonly HttpContextBase _httpContext;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UserService(HttpContextBase httpContext)
|
||||
public UserService(IUnitOfWorkProvider provider) : this(provider, null) { }
|
||||
|
||||
public UserService(IUnitOfWorkProvider provider, HttpContextBase httpContext)
|
||||
{
|
||||
_unitOfWork = provider.GetUnitOfWork();
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
@@ -28,9 +34,16 @@ namespace Umbraco.Web.Services
|
||||
/// <returns><see cref="IProfile"/> containing the Name and Id of the logged in BackOffice User</returns>
|
||||
public IProfile GetCurrentBackOfficeUser()
|
||||
{
|
||||
var cookie = _httpContext.Request.Cookies["UMB_UCONTEXT"];
|
||||
Mandate.That(_httpContext != null,
|
||||
() =>
|
||||
new ArgumentException(
|
||||
"The HttpContext which is used to retrieve information about the currently logged in backoffice user was null and can therefor not be used",
|
||||
"HttpContextBase"));
|
||||
if (_httpContext == null) return null;
|
||||
|
||||
var cookie = _httpContext.Request.Cookies["UMB_UCONTEXT"];
|
||||
Mandate.That(cookie != null, () => new ArgumentException("The Cookie containing the UserContext Guid Id was null", "Cookie"));
|
||||
if (cookie == null) return null;
|
||||
|
||||
string contextId = cookie.Value;
|
||||
string cacheKey = string.Concat("UmbracoUserContext", contextId);
|
||||
|
||||
@@ -307,8 +307,6 @@
|
||||
<Compile Include="Mvc\UmbracoPageResult.cs" />
|
||||
<Compile Include="PropertyEditors\RteMacroRenderingPropertyEditorValueConverter.cs" />
|
||||
<Compile Include="PublishedMediaStoreResolver.cs" />
|
||||
<Compile Include="Publishing\BasePublishingStrategy.cs" />
|
||||
<Compile Include="Publishing\IPublishingStrategy.cs" />
|
||||
<Compile Include="Publishing\PublishingStrategy.cs" />
|
||||
<Compile Include="RenderFieldCaseType.cs" />
|
||||
<Compile Include="RenderFieldEncodingType.cs" />
|
||||
@@ -319,15 +317,6 @@
|
||||
<Compile Include="Services\ContentTypeService.cs" />
|
||||
<Compile Include="Services\DataTypeService.cs" />
|
||||
<Compile Include="Services\FileService.cs" />
|
||||
<Compile Include="Services\IContentService.cs" />
|
||||
<Compile Include="Services\IContentTypeService.cs" />
|
||||
<Compile Include="Services\IDataTypeService.cs" />
|
||||
<Compile Include="Services\IFileService.cs" />
|
||||
<Compile Include="Services\ILocalizationService.cs" />
|
||||
<Compile Include="Services\IMacroService.cs" />
|
||||
<Compile Include="Services\IMediaService.cs" />
|
||||
<Compile Include="Services\IService.cs" />
|
||||
<Compile Include="Services\IUserService.cs" />
|
||||
<Compile Include="Services\LocalizationService.cs" />
|
||||
<Compile Include="Services\MacroService.cs" />
|
||||
<Compile Include="Services\MediaService.cs" />
|
||||
|
||||
Reference in New Issue
Block a user