diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs
index 4ffcd9f2b7..3e626ca922 100644
--- a/src/Umbraco.Core/ApplicationContext.cs
+++ b/src/Umbraco.Core/ApplicationContext.cs
@@ -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.");
}
+
+ ///
+ /// Gets the current DatabaseContext
+ ///
+ public DatabaseContext DatabaseContext
+ {
+ get { return DatabaseContext.Current; }
+ }
}
}
diff --git a/src/Umbraco.Core/Models/ContentExtensions.cs b/src/Umbraco.Core/Models/ContentExtensions.cs
index 369c03c2f2..39a63b5093 100644
--- a/src/Umbraco.Core/Models/ContentExtensions.cs
+++ b/src/Umbraco.Core/Models/ContentExtensions.cs
@@ -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
+ ///
+ /// Creates the xml representation for the object
+ ///
+ /// to generate xml for
+ /// Xml representation of the passed in
+ 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;
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs
index b45096b1f2..c4965d7fa2 100644
--- a/src/Umbraco.Core/Models/Property.cs
+++ b/src/Umbraco.Core/Models/Property.cs
@@ -61,6 +61,12 @@ namespace Umbraco.Core.Models
[IgnoreDataMember]
internal DataTypeDatabaseType DataTypeDatabaseType { get { return _propertyType.DataTypeDatabaseType; } }
+ ///
+ /// Returns the PropertyType, which this Property is based on
+ ///
+ [IgnoreDataMember]
+ internal PropertyType PropertyType { get { return _propertyType; } }
+
///
/// Gets or Sets the version id for the Property
///
diff --git a/src/Umbraco.Core/Models/PropertyExtensions.cs b/src/Umbraco.Core/Models/PropertyExtensions.cs
new file mode 100644
index 0000000000..8f978673c9
--- /dev/null
+++ b/src/Umbraco.Core/Models/PropertyExtensions.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Xml;
+using System.Xml.Linq;
+
+namespace Umbraco.Core.Models
+{
+ public static class PropertyExtensions
+ {
+ ///
+ /// Creates the xml representation for the object
+ ///
+ /// to generate xml for
+ /// Xml of the property and its value
+ 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs
index 5f085d4afc..7a1213820e 100644
--- a/src/Umbraco.Core/Models/PropertyType.cs
+++ b/src/Umbraco.Core/Models/PropertyType.cs
@@ -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);
diff --git a/src/Umbraco.Core/Models/PropertyTypeExtensions.cs b/src/Umbraco.Core/Models/PropertyTypeExtensions.cs
index 727b065ade..97c803deb7 100644
--- a/src/Umbraco.Core/Models/PropertyTypeExtensions.cs
+++ b/src/Umbraco.Core/Models/PropertyTypeExtensions.cs
@@ -8,6 +8,7 @@ namespace Umbraco.Core.Models
/// Resolves the IDataType for a PropertyType.
///
/// PropertyType that references a DataType
+ /// Id of the Property which references this DataType through its PropertyType
///
///
/// 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.
///
- 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;
}
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
index 3f94b40663..a182cdf524 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
@@ -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();
+
//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();
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs
index 1e58ef09cd..314de2e2da 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs
@@ -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("WHERE nodeId = @Id", new { Id = propertyTypeDto.DataTypeId });
+ propertyType.DataTypeControlId = dataTypeDto.ControlId;
+ propertyType.DataTypeDatabaseType = dataTypeDto.DbType.EnumParse(true);
}
}
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
index cd3313fdd4..07a2c71380 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
@@ -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();
diff --git a/src/Umbraco.Web/Publishing/BasePublishingStrategy.cs b/src/Umbraco.Core/Publishing/BasePublishingStrategy.cs
similarity index 79%
rename from src/Umbraco.Web/Publishing/BasePublishingStrategy.cs
rename to src/Umbraco.Core/Publishing/BasePublishingStrategy.cs
index 87a62f6883..3bc9afd7f1 100644
--- a/src/Umbraco.Web/Publishing/BasePublishingStrategy.cs
+++ b/src/Umbraco.Core/Publishing/BasePublishingStrategy.cs
@@ -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
{
+ ///
+ /// Abstract class for the implementation of an , which provides the events used for publishing/unpublishing.
+ ///
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 content, int userId);
- ///
- /// The publishing event handler used for publish and unpublish events
- ///
- public delegate void PublishingEventHandler(IContent sender, PublishingEventArgs e);
-
///
/// Occurs before publish
///
- public static event PublishingEventHandler Publishing;
+ public static event EventHandler Publishing;
///
/// Raises the event
@@ -35,7 +33,7 @@ namespace Umbraco.Web.Publishing
///
/// Occurs after publish
///
- public static event PublishingEventHandler Published;
+ public static event EventHandler Published;
///
/// Raises the event
@@ -51,7 +49,7 @@ namespace Umbraco.Web.Publishing
///
/// Occurs before unpublish
///
- public static event PublishingEventHandler UnPublishing;
+ public static event EventHandler UnPublishing;
///
/// Raises the event
@@ -67,7 +65,7 @@ namespace Umbraco.Web.Publishing
///
/// Occurs after unpublish
///
- public static event PublishingEventHandler UnPublished;
+ public static event EventHandler UnPublished;
///
/// Raises the event
diff --git a/src/Umbraco.Web/Publishing/IPublishingStrategy.cs b/src/Umbraco.Core/Publishing/IPublishingStrategy.cs
similarity index 96%
rename from src/Umbraco.Web/Publishing/IPublishingStrategy.cs
rename to src/Umbraco.Core/Publishing/IPublishingStrategy.cs
index 4e5b4057d3..c2861eac8b 100644
--- a/src/Umbraco.Web/Publishing/IPublishingStrategy.cs
+++ b/src/Umbraco.Core/Publishing/IPublishingStrategy.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Publishing
+namespace Umbraco.Core.Publishing
{
///
/// Defines the Publishing Strategy
diff --git a/src/Umbraco.Web/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs
similarity index 97%
rename from src/Umbraco.Web/Services/IContentService.cs
rename to src/Umbraco.Core/Services/IContentService.cs
index 7b9359e2ab..28b2c9fdb7 100644
--- a/src/Umbraco.Web/Services/IContentService.cs
+++ b/src/Umbraco.Core/Services/IContentService.cs
@@ -1,8 +1,8 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the ContentService, which is an easy access to operations involving
diff --git a/src/Umbraco.Web/Services/IContentTypeService.cs b/src/Umbraco.Core/Services/IContentTypeService.cs
similarity index 96%
rename from src/Umbraco.Web/Services/IContentTypeService.cs
rename to src/Umbraco.Core/Services/IContentTypeService.cs
index 35601b2f69..f1881fea0c 100644
--- a/src/Umbraco.Web/Services/IContentTypeService.cs
+++ b/src/Umbraco.Core/Services/IContentTypeService.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the ContentTypeService, which is an easy access to operations involving
diff --git a/src/Umbraco.Web/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs
similarity index 96%
rename from src/Umbraco.Web/Services/IDataTypeService.cs
rename to src/Umbraco.Core/Services/IDataTypeService.cs
index c09033a84c..9ad1d85a1d 100644
--- a/src/Umbraco.Web/Services/IDataTypeService.cs
+++ b/src/Umbraco.Core/Services/IDataTypeService.cs
@@ -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
{
///
/// Defines the DataType Service, which is an easy access to operations involving and
diff --git a/src/Umbraco.Web/Services/IFileService.cs b/src/Umbraco.Core/Services/IFileService.cs
similarity index 95%
rename from src/Umbraco.Web/Services/IFileService.cs
rename to src/Umbraco.Core/Services/IFileService.cs
index 0856e7b1e6..7e854929ef 100644
--- a/src/Umbraco.Web/Services/IFileService.cs
+++ b/src/Umbraco.Core/Services/IFileService.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the File Service, which is an easy access to operations involving objects like Scripts, Stylesheets and Templates
diff --git a/src/Umbraco.Web/Services/ILocalizationService.cs b/src/Umbraco.Core/Services/ILocalizationService.cs
similarity index 96%
rename from src/Umbraco.Web/Services/ILocalizationService.cs
rename to src/Umbraco.Core/Services/ILocalizationService.cs
index a145277f04..fe29cfa332 100644
--- a/src/Umbraco.Web/Services/ILocalizationService.cs
+++ b/src/Umbraco.Core/Services/ILocalizationService.cs
@@ -1,8 +1,8 @@
-using System;
+using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the Localization Service, which is an easy access to operations involving Languages and Dictionary
diff --git a/src/Umbraco.Web/Services/IMacroService.cs b/src/Umbraco.Core/Services/IMacroService.cs
similarity index 94%
rename from src/Umbraco.Web/Services/IMacroService.cs
rename to src/Umbraco.Core/Services/IMacroService.cs
index 8a5089daba..cb327d3630 100644
--- a/src/Umbraco.Web/Services/IMacroService.cs
+++ b/src/Umbraco.Core/Services/IMacroService.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the ContentService, which is an easy access to operations involving
diff --git a/src/Umbraco.Web/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs
similarity index 96%
rename from src/Umbraco.Web/Services/IMediaService.cs
rename to src/Umbraco.Core/Services/IMediaService.cs
index 0a39e255ae..28b5068535 100644
--- a/src/Umbraco.Web/Services/IMediaService.cs
+++ b/src/Umbraco.Core/Services/IMediaService.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using Umbraco.Core.Models;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the Media Service, which is an easy access to operations involving
diff --git a/src/Umbraco.Web/Services/IService.cs b/src/Umbraco.Core/Services/IService.cs
similarity index 82%
rename from src/Umbraco.Web/Services/IService.cs
rename to src/Umbraco.Core/Services/IService.cs
index 22834401e9..448e09aac4 100644
--- a/src/Umbraco.Web/Services/IService.cs
+++ b/src/Umbraco.Core/Services/IService.cs
@@ -1,4 +1,4 @@
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Marker interface for services, which is used to store difference services in a list or dictionary
diff --git a/src/Umbraco.Web/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs
similarity index 85%
rename from src/Umbraco.Web/Services/IUserService.cs
rename to src/Umbraco.Core/Services/IUserService.cs
index 95c2c2a73d..95c00dd44e 100644
--- a/src/Umbraco.Web/Services/IUserService.cs
+++ b/src/Umbraco.Core/Services/IUserService.cs
@@ -1,6 +1,6 @@
-using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Models.Membership;
-namespace Umbraco.Web.Services
+namespace Umbraco.Core.Services
{
///
/// Defines the UserService, which is an easy access to operations involving and eventually Users and Members.
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index be7079989b..4f8d7cf3f9 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -104,6 +104,7 @@
+
@@ -376,6 +377,8 @@
+
+
@@ -387,6 +390,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/Umbraco.Core/XmlExtensions.cs b/src/Umbraco.Core/XmlExtensions.cs
index ab526f6532..7757d25fda 100644
--- a/src/Umbraco.Core/XmlExtensions.cs
+++ b/src/Umbraco.Core/XmlExtensions.cs
@@ -1,15 +1,14 @@
using System;
using System.Xml;
+using System.Xml.Linq;
namespace Umbraco.Core
{
-
///
/// Extension methods for xml objects
///
internal static class XmlExtensions
{
-
public static T AttributeValue(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;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/App.config b/src/Umbraco.Tests/App.config
index f27ac99042..17540689bc 100644
--- a/src/Umbraco.Tests/App.config
+++ b/src/Umbraco.Tests/App.config
@@ -7,7 +7,11 @@
-
+
+
+
+
+
diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs
index 8ac431eaaf..96cfc45fc4 100644
--- a/src/Umbraco.Tests/Services/ContentServiceTests.cs
+++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs
@@ -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.
diff --git a/src/Umbraco.Web/ApplicationContextExtensions.cs b/src/Umbraco.Web/ApplicationContextExtensions.cs
index d9902147e6..fcbcab1628 100644
--- a/src/Umbraco.Web/ApplicationContextExtensions.cs
+++ b/src/Umbraco.Web/ApplicationContextExtensions.cs
@@ -26,15 +26,5 @@ namespace Umbraco.Web
var configPath = http.Request.PhysicalApplicationPath + "\\web.config";
File.SetLastWriteTimeUtc(configPath, DateTime.UtcNow);
}
-
- ///
- /// Adds the DatabaseContext to the ApplicationContext
- ///
- ///
- ///
- public static DatabaseContext DatabaseContext(this ApplicationContext appContext)
- {
- return Umbraco.Core.DatabaseContext.Current;
- }
}
}
diff --git a/src/Umbraco.Web/Publishing/PublishingStrategy.cs b/src/Umbraco.Web/Publishing/PublishingStrategy.cs
index ef3b0b4d7d..44bfbb6ab4 100644
--- a/src/Umbraco.Web/Publishing/PublishingStrategy.cs
+++ b/src/Umbraco.Web/Publishing/PublishingStrategy.cs
@@ -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
{
diff --git a/src/Umbraco.Web/Services/ContentService.cs b/src/Umbraco.Web/Services/ContentService.cs
index 9f60039354..c259b5c354 100644
--- a/src/Umbraco.Web/Services/ContentService.cs
+++ b/src/Umbraco.Web/Services/ContentService.cs
@@ -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
///
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;
diff --git a/src/Umbraco.Web/Services/ContentTypeService.cs b/src/Umbraco.Web/Services/ContentTypeService.cs
index 6ce4ecb7d8..25e7e250c1 100644
--- a/src/Umbraco.Web/Services/ContentTypeService.cs
+++ b/src/Umbraco.Web/Services/ContentTypeService.cs
@@ -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
///
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();
}
diff --git a/src/Umbraco.Web/Services/DataTypeService.cs b/src/Umbraco.Web/Services/DataTypeService.cs
index aa5468a92a..ac3bbdfe28 100644
--- a/src/Umbraco.Web/Services/DataTypeService.cs
+++ b/src/Umbraco.Web/Services/DataTypeService.cs
@@ -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
///
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();
}
///
diff --git a/src/Umbraco.Web/Services/FileService.cs b/src/Umbraco.Web/Services/FileService.cs
index 0257299d9a..9910be6547 100644
--- a/src/Umbraco.Web/Services/FileService.cs
+++ b/src/Umbraco.Web/Services/FileService.cs
@@ -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
///
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();
}
diff --git a/src/Umbraco.Web/Services/LocalizationService.cs b/src/Umbraco.Web/Services/LocalizationService.cs
index e518516da9..b8d1e9772d 100644
--- a/src/Umbraco.Web/Services/LocalizationService.cs
+++ b/src/Umbraco.Web/Services/LocalizationService.cs
@@ -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();
}
diff --git a/src/Umbraco.Web/Services/MacroService.cs b/src/Umbraco.Web/Services/MacroService.cs
index 075beeadfd..6a1be6ec79 100644
--- a/src/Umbraco.Web/Services/MacroService.cs
+++ b/src/Umbraco.Web/Services/MacroService.cs
@@ -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
///
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();
}
diff --git a/src/Umbraco.Web/Services/MediaService.cs b/src/Umbraco.Web/Services/MediaService.cs
index b06c7f0ee3..bb11314a44 100644
--- a/src/Umbraco.Web/Services/MediaService.cs
+++ b/src/Umbraco.Web/Services/MediaService.cs
@@ -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
///
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();
}
diff --git a/src/Umbraco.Web/Services/ServiceContext.cs b/src/Umbraco.Web/Services/ServiceContext.cs
index bba2e2e87d..3c11085f73 100644
--- a/src/Umbraco.Web/Services/ServiceContext.cs
+++ b/src/Umbraco.Web/Services/ServiceContext.cs
@@ -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
///
public class ServiceContext
{
- internal ServiceContext(HttpContextBase httpContext)
+ private readonly ConcurrentDictionary _cache = new ConcurrentDictionary();
+ 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 _cache = new ConcurrentDictionary();
-
///
/// Builds the various services and adds them to the internal cache
///
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);
diff --git a/src/Umbraco.Web/Services/ServiceFactory.cs b/src/Umbraco.Web/Services/ServiceFactory.cs
index 298df0365d..2bfb82c4fa 100644
--- a/src/Umbraco.Web/Services/ServiceFactory.cs
+++ b/src/Umbraco.Web/Services/ServiceFactory.cs
@@ -1,4 +1,6 @@
-namespace Umbraco.Web.Services
+using Umbraco.Core.Services;
+
+namespace Umbraco.Web.Services
{
///
/// Represents the ServiceFactory, which provides access to the various services in
@@ -6,7 +8,7 @@
///
public static class ServiceFactory
{
- private static readonly ServiceContext ServiceContext = new ServiceContext(null);
+ private static readonly ServiceContext ServiceContext = new ServiceContext();
///
/// Gets the
diff --git a/src/Umbraco.Web/Services/UserService.cs b/src/Umbraco.Web/Services/UserService.cs
index fd37ce92e6..e6e8e3ab51 100644
--- a/src/Umbraco.Web/Services/UserService.cs
+++ b/src/Umbraco.Web/Services/UserService.cs
@@ -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
/// containing the Name and Id of the logged in BackOffice User
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);
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 604d0388e9..c4fbacf117 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -307,8 +307,6 @@
-
-
@@ -319,15 +317,6 @@
-
-
-
-
-
-
-
-
-