diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs
index 8dfc2536e9..7381e5ab81 100644
--- a/src/Umbraco.Core/ApplicationContext.cs
+++ b/src/Umbraco.Core/ApplicationContext.cs
@@ -332,7 +332,7 @@ namespace Umbraco.Core
this.ApplicationCache = null;
if (_databaseContext != null) //need to check the internal field here
{
- if (DatabaseContext.IsDatabaseConfigured)
+ if (DatabaseContext.IsDatabaseConfigured && DatabaseContext.Database != null)
{
DatabaseContext.Database.Dispose();
}
diff --git a/src/Umbraco.Core/Cache/CacheKeys.cs b/src/Umbraco.Core/Cache/CacheKeys.cs
index c370b13303..f76ff0439f 100644
--- a/src/Umbraco.Core/Cache/CacheKeys.cs
+++ b/src/Umbraco.Core/Cache/CacheKeys.cs
@@ -48,6 +48,7 @@ namespace Umbraco.Core.Cache
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
public const string LanguageCacheKey = "UmbracoLanguageCache";
+ [Obsolete("This is no longer used and will be removed from the codebase in the future")]
public const string DomainCacheKey = "UmbracoDomainList";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs
index 13d6bd71c9..9133377f5f 100644
--- a/src/Umbraco.Core/Models/Content.cs
+++ b/src/Umbraco.Core/Models/Content.cs
@@ -160,10 +160,7 @@ namespace Umbraco.Core.Models
///
/// Language of the data contained within this Content object.
///
- ///
- /// Left internal until multilingual support is implemented.
- ///
- [DataMember]
+ [Obsolete("This is not used and will be removed from the codebase in future versions")]
public string Language
{
get { return _language; }
diff --git a/src/Umbraco.Core/Models/DeepCloneHelper.cs b/src/Umbraco.Core/Models/DeepCloneHelper.cs
index eb3be9d145..0e0e260c06 100644
--- a/src/Umbraco.Core/Models/DeepCloneHelper.cs
+++ b/src/Umbraco.Core/Models/DeepCloneHelper.cs
@@ -7,25 +7,6 @@ using System.Reflection;
namespace Umbraco.Core.Models
{
- ///
- /// Used to attribute properties that have a setter and are a reference type
- /// that should be ignored for cloning when using the DeepCloneHelper
- ///
- ///
- ///
- /// This attribute must be used:
- /// * when the property is backed by a field but the result of the property is the un-natural data stored in the field
- ///
- /// This attribute should not be used:
- /// * when the property is virtual
- /// * when the setter performs additional required logic other than just setting the underlying field
- ///
- ///
- internal class DoNotCloneAttribute : Attribute
- {
-
- }
-
public static class DeepCloneHelper
{
///
diff --git a/src/Umbraco.Core/Models/DoNotCloneAttribute.cs b/src/Umbraco.Core/Models/DoNotCloneAttribute.cs
new file mode 100644
index 0000000000..a27df59b03
--- /dev/null
+++ b/src/Umbraco.Core/Models/DoNotCloneAttribute.cs
@@ -0,0 +1,23 @@
+using System;
+
+namespace Umbraco.Core.Models
+{
+ ///
+ /// Used to attribute properties that have a setter and are a reference type
+ /// that should be ignored for cloning when using the DeepCloneHelper
+ ///
+ ///
+ ///
+ /// This attribute must be used:
+ /// * when the property is backed by a field but the result of the property is the un-natural data stored in the field
+ ///
+ /// This attribute should not be used:
+ /// * when the property is virtual
+ /// * when the setter performs additional required logic other than just setting the underlying field
+ ///
+ ///
+ internal class DoNotCloneAttribute : Attribute
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/IDomain.cs b/src/Umbraco.Core/Models/IDomain.cs
new file mode 100644
index 0000000000..9fb3e8019d
--- /dev/null
+++ b/src/Umbraco.Core/Models/IDomain.cs
@@ -0,0 +1,12 @@
+using Umbraco.Core.Models.EntityBase;
+
+namespace Umbraco.Core.Models
+{
+ public interface IDomain : IAggregateRoot, IRememberBeingDirty, ICanBeDirty
+ {
+ ILanguage Language { get; set; }
+ string DomainName { get; set; }
+ IContent RootContent { get; set; }
+ bool IsWildcard { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/UmbracoDomain.cs b/src/Umbraco.Core/Models/UmbracoDomain.cs
new file mode 100644
index 0000000000..963535729c
--- /dev/null
+++ b/src/Umbraco.Core/Models/UmbracoDomain.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Reflection;
+using System.Runtime.Serialization;
+using Umbraco.Core.Models.EntityBase;
+
+namespace Umbraco.Core.Models
+{
+ //TODO: Need to custom serialize this
+
+ [Serializable]
+ [DataContract(IsReference = true)]
+ public class UmbracoDomain : Entity, IDomain
+ {
+ public UmbracoDomain(string domainName)
+ {
+ _domainName = domainName;
+ }
+
+ private IContent _content;
+ private ILanguage _language;
+ private string _domainName;
+
+ private static readonly PropertyInfo DefaultLanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.Language);
+ private static readonly PropertyInfo DomainNameSelector = ExpressionHelper.GetPropertyInfo(x => x.DomainName);
+ private static readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo(x => x.RootContent);
+
+ [DataMember]
+ public ILanguage Language
+ {
+ get { return _language; }
+ set
+ {
+ SetPropertyValueAndDetectChanges(o =>
+ {
+ _language = value;
+ return _language;
+ }, _language, DefaultLanguageSelector);
+ }
+ }
+
+ [DataMember]
+ public string DomainName
+ {
+ get { return _domainName; }
+ set
+ {
+ SetPropertyValueAndDetectChanges(o =>
+ {
+ _domainName = value;
+ return _domainName;
+ }, _domainName, DomainNameSelector);
+ }
+ }
+
+ [DataMember]
+ public IContent RootContent
+ {
+ get { return _content; }
+ set
+ {
+ SetPropertyValueAndDetectChanges(o =>
+ {
+ _content = value;
+ return _content;
+ }, _content, ContentSelector);
+ }
+ }
+
+ public bool IsWildcard
+ {
+ get { return string.IsNullOrWhiteSpace(DomainName) || DomainName.StartsWith("*"); }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs b/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs
index 0287a58b78..54c8aa30a8 100644
--- a/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs
+++ b/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs
@@ -6,11 +6,9 @@ namespace Umbraco.Core.Persistence.Factories
{
internal class LanguageFactory
{
- #region Implementation of IEntityFactory
-
public ILanguage BuildEntity(LanguageDto dto)
{
- var lang = new Language(dto.IsoCode){CultureName = dto.CultureName, Id = dto.Id};
+ var lang = new Language(dto.IsoCode) { CultureName = dto.CultureName, Id = dto.Id };
//on initial construction we don't want to have dirty properties tracked
// http://issues.umbraco.org/issue/U4-1946
lang.ResetDirtyProperties(false);
@@ -19,13 +17,11 @@ namespace Umbraco.Core.Persistence.Factories
public LanguageDto BuildDto(ILanguage entity)
{
- var dto = new LanguageDto{ CultureName = entity.CultureName, IsoCode = entity.IsoCode};
+ var dto = new LanguageDto { CultureName = entity.CultureName, IsoCode = entity.IsoCode };
if (entity.HasIdentity)
dto.Id = short.Parse(entity.Id.ToString(CultureInfo.InvariantCulture));
return dto;
}
-
- #endregion
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs b/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs
index 599eae12cb..81a6703324 100644
--- a/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs
+++ b/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs
@@ -10,8 +10,6 @@ namespace Umbraco.Core.Persistence.Factories
///
internal class TaskFactory
{
-
-
public Task BuildEntity(TaskDto dto)
{
var entity = new Task(new TaskType(dto.TaskTypeDto.Alias) { Id = dto.TaskTypeDto.Id })
diff --git a/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs b/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs
new file mode 100644
index 0000000000..a17abebad6
--- /dev/null
+++ b/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs
@@ -0,0 +1,27 @@
+using Umbraco.Core.Models;
+using Umbraco.Core.Models.Rdbms;
+
+namespace Umbraco.Core.Persistence.Factories
+{
+ internal class TaskTypeFactory
+ {
+ public TaskType BuildEntity(TaskTypeDto dto)
+ {
+ var entity = new TaskType(dto.Alias) {Id = dto.Id};
+ //on initial construction we don't want to have dirty properties tracked
+ // http://issues.umbraco.org/issue/U4-1946
+ entity.ResetDirtyProperties(false);
+ return entity;
+ }
+
+ public TaskTypeDto BuildDto(TaskType entity)
+ {
+ var dto = new TaskTypeDto
+ {
+ Id = (byte)entity.Id,
+ Alias = entity.Alias
+ };
+ return dto;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Mappers/DomainMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DomainMapper.cs
new file mode 100644
index 0000000000..15d0852158
--- /dev/null
+++ b/src/Umbraco.Core/Persistence/Mappers/DomainMapper.cs
@@ -0,0 +1,29 @@
+using System.Collections.Concurrent;
+using Umbraco.Core.Models.Rdbms;
+using Umbraco.Core.Persistence.Repositories;
+
+namespace Umbraco.Core.Persistence.Mappers
+{
+ [MapperFor(typeof(DomainRepository.CacheableDomain))]
+ public sealed class DomainMapper : BaseMapper
+ {
+ private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary();
+
+ public DomainMapper()
+ {
+ BuildMap();
+ }
+
+ internal override ConcurrentDictionary PropertyInfoCache
+ {
+ get { return PropertyInfoCacheInstance; }
+ }
+
+ internal override void BuildMap()
+ {
+ CacheMap(src => src.Id, dto => dto.Id);
+ CacheMap(src => src.RootContentId, dto => dto.RootStructureId);
+ CacheMap(src => src.DefaultLanguageId, dto => dto.DefaultLanguage);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs b/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs
index b891bc7ec8..0832aace89 100644
--- a/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs
+++ b/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs
@@ -16,8 +16,6 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary();
- //NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
- // otherwise that would fail because there is no public constructor.
public LanguageMapper()
{
BuildMap();
diff --git a/src/Umbraco.Core/Persistence/Mappers/MapperAttribute.cs b/src/Umbraco.Core/Persistence/Mappers/MapperAttribute.cs
deleted file mode 100644
index b9e033ac88..0000000000
--- a/src/Umbraco.Core/Persistence/Mappers/MapperAttribute.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System;
-
-namespace Umbraco.Core.Persistence.Mappers
-{
- ///
- /// An attribute used to decorate entities in order to associate with a mapper
- ///
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
- internal sealed class MapperAttribute : Attribute
- {
- public Type MapperType { get; private set; }
-
- public MapperAttribute(Type mapperType)
- {
- MapperType = mapperType;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs b/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs
deleted file mode 100644
index 6f43b8e304..0000000000
--- a/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using System;
-using System.Reflection;
-using Umbraco.Core.Models;
-
-namespace Umbraco.Core.Persistence.Mappers
-{
- internal class ModelDtoMapper : IMapper
- {
- public void GetTableInfo(Type t, TableInfo ti)
- { }
-
- public bool MapPropertyToColumn(PropertyInfo pi, ref string columnName, ref bool resultColumn)
- {
- if (pi.DeclaringType == typeof(Content) || pi.DeclaringType == typeof(IContent))
- {
- switch (pi.Name)
- {
- case "Trashed":
- columnName = "[umbracoNode].[trashed]";
- return true;
- case "ParentId":
- columnName = "[umbracoNode].[parentID]";
- return true;
- case "UserId":
- columnName = "[umbracoNode].[nodeUser]";
- return true;
- case "Level":
- columnName = "[umbracoNode].[level]";
- return true;
- case "Path":
- columnName = "[umbracoNode].[path]";
- return true;
- case "SortOrder":
- columnName = "[umbracoNode].[sortOrder]";
- return true;
- case "NodeId":
- columnName = "[umbracoNode].[id]";
- return true;
- case "Published":
- columnName = "[cmsDocument].[published]";
- return true;
- case "Key":
- columnName = "[umbracoNode].[uniqueID]";
- return true;
- case "CreateDate":
- columnName = "[umbracoNode].[createDate]";
- return true;
- case "Name":
- columnName = "[umbracoNode].[text]";
- return true;
- }
- }
-
- if (pi.DeclaringType == typeof(ContentType) || pi.DeclaringType == typeof(IContentType))
- {
- switch (pi.Name)
- {
- case "Alias":
- columnName = "[cmsContentType].[alias]";
- return true;
- case "Icon":
- columnName = "[cmsContentType].[icon]";
- return true;
- case "Thumbnail":
- columnName = "[cmsContentType].[thumbnail]";
- return true;
- case "Description":
- columnName = "[cmsContentType].[description]";
- return true;
- }
- }
-
- return true;
- }
-
- public Func GetFromDbConverter(PropertyInfo pi, Type sourceType)
- {
- return null;
- }
-
- public Func GetToDbConverter(Type sourceType)
- {
- return null;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
index 77228039f9..60951f6086 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
@@ -63,7 +63,7 @@ namespace Umbraco.Core.Persistence.Repositories
.Where(GetBaseWhereClause(), new { Id = id })
.Where(x => x.Newest)
.OrderByDescending(x => x.VersionDate);
-
+
var dto = Database.Fetch(sql).FirstOrDefault();
if (dto == null)
@@ -79,7 +79,7 @@ namespace Umbraco.Core.Persistence.Repositories
var sql = GetBaseQuery(false);
if (ids.Any())
{
- sql.Where("umbracoNode.id in (@ids)", new {ids = ids});
+ sql.Where("umbracoNode.id in (@ids)", new { ids = ids });
}
//we only want the newest ones with this method
@@ -115,7 +115,7 @@ namespace Umbraco.Core.Persistence.Repositories
.On(left => left.NodeId, right => right.NodeId)
.InnerJoin()
.On(left => left.NodeId, right => right.NodeId)
- .Where(x => x.NodeObjectType == NodeObjectTypeId );
+ .Where(x => x.NodeObjectType == NodeObjectTypeId);
return sql;
}
@@ -260,7 +260,7 @@ namespace Umbraco.Core.Persistence.Repositories
.Where(x => x.Newest != true);
var dto = Database.Fetch(sql).FirstOrDefault();
- if(dto == null) return;
+ if (dto == null) return;
using (var transaction = Database.GetTransaction())
{
@@ -311,7 +311,7 @@ namespace Umbraco.Core.Persistence.Repositories
//Ensure unique name on the same level
entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name);
-
+
//Ensure that strings don't contain characters that are invalid in XML
entity.SanitizeEntityPropertiesForXmlStorage();
@@ -332,7 +332,7 @@ namespace Umbraco.Core.Persistence.Repositories
nodeDto.Level = short.Parse(level.ToString(CultureInfo.InvariantCulture));
nodeDto.SortOrder = sortOrder;
var o = Database.IsNew(nodeDto) ? Convert.ToInt32(Database.Insert(nodeDto)) : Database.Update(nodeDto);
-
+
//Update with new correct path
nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId);
Database.Update(nodeDto);
@@ -353,14 +353,14 @@ namespace Umbraco.Core.Persistence.Repositories
if (parentPermissions.Any())
{
var userPermissions = (
- from perm in parentPermissions
- from p in perm.AssignedPermissions
+ from perm in parentPermissions
+ from p in perm.AssignedPermissions
select new EntityPermissionSet.UserPermission(perm.UserId, p)).ToList();
permissionsRepo.ReplaceEntityPermissions(new EntityPermissionSet(entity.Id, userPermissions));
//flag the entity's permissions changed flag so we can track those changes.
//Currently only used for the cache refreshers to detect if we should refresh all user permissions cache.
- ((Content) entity).PermissionsChanged = true;
+ ((Content)entity).PermissionsChanged = true;
}
//Create the Content specific data - cmsContent
@@ -408,8 +408,8 @@ namespace Umbraco.Core.Persistence.Repositories
protected override void PersistUpdatedItem(IContent entity)
{
- var publishedState = ((Content) entity).PublishedState;
-
+ var publishedState = ((Content)entity).PublishedState;
+
//check if we need to make any database changes at all
if (entity.RequiresSaving(publishedState) == false)
{
@@ -444,7 +444,7 @@ namespace Umbraco.Core.Persistence.Repositories
var maxSortOrder =
Database.ExecuteScalar(
"SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
- new {ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId});
+ new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId });
entity.SortOrder = maxSortOrder + 1;
//Question: If we move a node, should we update permissions to inherit from the new parent if the parent has permissions assigned?
@@ -476,7 +476,7 @@ namespace Umbraco.Core.Persistence.Repositories
//If Published state has changed then previous versions should have their publish state reset.
//If state has been changed to unpublished the previous versions publish state should also be reset.
//if (((ICanBeDirty)entity).IsPropertyDirty("Published") && (entity.Published || publishedState == PublishedState.Unpublished))
- if (entity.ShouldClearPublishedFlagForPreviousVersions(publishedState, shouldCreateNewVersion))
+ if (entity.ShouldClearPublishedFlagForPreviousVersions(publishedState, shouldCreateNewVersion))
{
var publishedDocs = Database.Fetch("WHERE nodeId = @Id AND published = @IsPublished", new { Id = entity.Id, IsPublished = true });
foreach (var doc in publishedDocs)
@@ -543,7 +543,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
foreach (var property in entity.Properties)
{
- if(keyDictionary.ContainsKey(property.PropertyTypeId) == false) continue;
+ if (keyDictionary.ContainsKey(property.PropertyTypeId) == false) continue;
property.Id = keyDictionary[property.PropertyTypeId];
}
@@ -618,6 +618,17 @@ namespace Umbraco.Core.Persistence.Repositories
repo.ReplaceEntityPermissions(permissionSet);
}
+ public void ClearPublished(IContent content)
+ {
+ // race cond!
+ var documentDtos = Database.Fetch("WHERE nodeId=@id AND published=@published", new { id = content.Id, published = true });
+ foreach (var documentDto in documentDtos)
+ {
+ documentDto.Published = false;
+ Database.Update(documentDto);
+ }
+ }
+
public IContent GetByLanguage(int id, string language)
{
var sql = GetBaseQuery(false);
@@ -632,7 +643,7 @@ namespace Umbraco.Core.Persistence.Repositories
return GetByVersion(dto.ContentVersionDto.VersionId);
}
-
+
///
/// Assigns a single permission to the current content item for the specified user ids
///
@@ -706,12 +717,12 @@ namespace Umbraco.Core.Persistence.Repositories
var args = new List();
var sbWhere = new StringBuilder("AND (cmsDocument.newest = 1)");
-
+
if (filter.IsNullOrWhiteSpace() == false)
{
sbWhere.Append(" AND (cmsDocument." + SqlSyntax.GetQuotedColumnName("text") + " LIKE @" + args.Count + ")");
args.Add("%" + filter + "%");
- }
+ }
Func> filterCallback = () => new Tuple(sbWhere.ToString(), args.ToArray());
@@ -721,7 +732,7 @@ namespace Umbraco.Core.Persistence.Repositories
filterCallback);
}
-
+
#endregion
#region IRecycleBinRepository members
@@ -800,7 +811,7 @@ namespace Umbraco.Core.Persistence.Repositories
///
///
///
- private IContent CreateContentFromDto(DocumentDto dto,
+ private IContent CreateContentFromDto(DocumentDto dto,
IContentType contentType,
ITemplate template,
Models.PropertyCollection propCollection)
@@ -873,7 +884,7 @@ namespace Umbraco.Core.Persistence.Repositories
var results = dtos.OrderBy(x => x.Text, new SimilarNodeNameComparer());
foreach (var dto in results)
{
- if(id != 0 && id == dto.NodeId) continue;
+ if (id != 0 && id == dto.NodeId) continue;
if (dto.Text.ToLowerInvariant().Equals(currentName.ToLowerInvariant()))
{
@@ -886,5 +897,19 @@ namespace Umbraco.Core.Persistence.Repositories
return currentName;
}
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _contentTypeRepository.Dispose();
+ _templateRepository.Dispose();
+ _tagRepository.Dispose();
+ _contentPreviewRepository.Dispose();
+ _contentXmlRepository.Dispose();
+ }
}
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs
index d2f4b3bebe..15f7f0f878 100644
--- a/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs
@@ -42,7 +42,7 @@ namespace Umbraco.Core.Persistence.Repositories
protected override IDataTypeDefinition PerformGet(int id)
{
- return GetAll(new[] {id}).FirstOrDefault();
+ return GetAll(new[] { id }).FirstOrDefault();
}
protected override IEnumerable PerformGetAll(params int[] ids)
@@ -150,7 +150,7 @@ namespace Umbraco.Core.Persistence.Repositories
//Cannot add a duplicate data type
var exists = Database.ExecuteScalar(@"SELECT COUNT(*) FROM cmsDataType
INNER JOIN umbracoNode ON cmsDataType.nodeId = umbracoNode.id
-WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + "= @name", new {name = entity.Name});
+WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + "= @name", new { name = entity.Name });
if (exists > 0)
{
throw new DuplicateNameException("A data type with the name " + entity.Name + " already exists");
@@ -196,7 +196,7 @@ WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + "= @name", new {na
var exists = Database.ExecuteScalar(@"SELECT COUNT(*) FROM cmsDataType
INNER JOIN umbracoNode ON cmsDataType.nodeId = umbracoNode.id
WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + @"= @name
-AND umbracoNode.id <> @id",
+AND umbracoNode.id <> @id",
new { id = entity.Id, name = entity.Name });
if (exists > 0)
{
@@ -254,7 +254,7 @@ AND umbracoNode.id <> @id",
}
//Delete the pre-values
- Database.Delete("WHERE datatypeNodeId = @Id", new {Id = entity.Id});
+ Database.Delete("WHERE datatypeNodeId = @Id", new { Id = entity.Id });
//Delete Content specific data
Database.Delete("WHERE nodeId = @Id", new { Id = entity.Id });
@@ -329,7 +329,7 @@ AND umbracoNode.id <> @id",
public void AddOrUpdatePreValues(IDataTypeDefinition dataType, IDictionary values)
{
- var currentVals = new DataTypePreValueDto[]{};
+ var currentVals = new DataTypePreValueDto[] { };
if (dataType.HasIdentity)
{
//first just get all pre-values for this data type so we can compare them to see if we need to insert or update or replace
@@ -337,7 +337,7 @@ AND umbracoNode.id <> @id",
.From()
.Where(dto => dto.DataTypeNodeId == dataType.Id)
.OrderBy(dto => dto.SortOrder);
- currentVals = Database.Fetch(sql).ToArray();
+ currentVals = Database.Fetch(sql).ToArray();
}
//already existing, need to be updated
@@ -409,7 +409,7 @@ AND umbracoNode.id <> @id",
//the key will be: "UmbracoPreValDATATYPEID-CSVOFPREVALIDS
var key = GetPrefixedCacheKey(dataTypeId)
- + string.Join(",", collection.FormatAsDictionary().Select(x => x.Value.Id).ToArray());
+ + string.Join(",", collection.FormatAsDictionary().Select(x => x.Value.Id).ToArray());
//store into cache
_cacheHelper.RuntimeCache.InsertCacheItem(key, () => collection,
@@ -429,7 +429,7 @@ AND umbracoNode.id <> @id",
public string Value { get; set; }
public string Alias { get; set; }
public IDataTypeDefinition DataType { get; set; }
- public int SortOrder { get; set; }
+ public int SortOrder { get; set; }
}
///
@@ -476,7 +476,7 @@ AND umbracoNode.id <> @id",
protected override Guid NodeObjectTypeId
{
get { throw new NotImplementedException(); }
- }
+ }
#endregion
protected override void PersistDeletedItem(PreValueEntity entity)
@@ -579,6 +579,17 @@ AND id <> @id",
}
}
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _contentTypeRepository.Dispose();
+ _preValRepository.Dispose();
+ }
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs
index 4c70d339b6..a8dac969d3 100644
--- a/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs
@@ -224,14 +224,18 @@ namespace Umbraco.Core.Persistence.Repositories
public IDictionaryItem Get(Guid uniqueId)
{
- var uniqueIdRepo = new DictionaryByUniqueIdRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax);
- return uniqueIdRepo.Get(uniqueId);
+ using (var uniqueIdRepo = new DictionaryByUniqueIdRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ return uniqueIdRepo.Get(uniqueId);
+ }
}
public IDictionaryItem Get(string key)
{
- var keyRepo = new DictionaryByKeyRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax);
- return keyRepo.Get(key);
+ using (var keyRepo = new DictionaryByKeyRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ return keyRepo.Get(key);
+ }
}
private class DictionaryByUniqueIdRepository : SimpleGetRepository
@@ -315,5 +319,16 @@ namespace Umbraco.Core.Persistence.Repositories
return "cmsDictionary." + SqlSyntax.GetQuotedColumnName("key") + " in (@ids)";
}
}
+
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _languageRepository.Dispose();
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs
new file mode 100644
index 0000000000..2adba8536a
--- /dev/null
+++ b/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs
@@ -0,0 +1,348 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using Umbraco.Core.Cache;
+using Umbraco.Core.Logging;
+using Umbraco.Core.Models;
+using Umbraco.Core.Models.EntityBase;
+using Umbraco.Core.Models.Rdbms;
+using Umbraco.Core.Persistence.Querying;
+using Umbraco.Core.Persistence.SqlSyntax;
+using Umbraco.Core.Persistence.UnitOfWork;
+
+namespace Umbraco.Core.Persistence.Repositories
+{
+ internal class DomainRepository : PetaPocoRepositoryBase, IDomainRepository
+ {
+ private readonly IContentRepository _contentRepository;
+ private readonly ILanguageRepository _languageRepository;
+
+ public DomainRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, IContentRepository contentRepository, ILanguageRepository languageRepository)
+ : base(work, cache, logger, sqlSyntax)
+ {
+ _contentRepository = contentRepository;
+ _languageRepository = languageRepository;
+ }
+
+ ///
+ /// Override the cache, this repo will not perform any cache, the caching is taken care of in the inner repository
+ ///
+ ///
+ /// This is required because IDomain is a deep object and we dont' want to cache it since it contains an ILanguage and an IContent, when these
+ /// are deep cloned the object graph that will be cached will be huge. Instead we'll have an internal repository that caches the simple
+ /// Domain structure and we'll use the other repositories to resolve the entities to attach
+ ///
+ protected override IRuntimeCacheProvider RuntimeCache
+ {
+ get { return new NullCacheProvider(); }
+ }
+
+ protected override IDomain PerformGet(int id)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+ return factory.BuildDomainEntity(repo.Get(id), _contentRepository, _languageRepository);
+ }
+ }
+
+ protected override IEnumerable PerformGetAll(params int[] ids)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+ return factory.BuildDomainEntities(repo.GetAll(ids).ToArray(), _contentRepository, _languageRepository);
+ }
+ }
+
+ protected override IEnumerable PerformGetByQuery(IQuery query)
+ {
+ throw new NotSupportedException("This repository does not support this method");
+ }
+
+ protected override Sql GetBaseQuery(bool isCount)
+ {
+ var sql = new Sql();
+ sql.Select(isCount ? "COUNT(*)" : "*").From(SqlSyntax);
+ return sql;
+ }
+
+ protected override string GetBaseWhereClause()
+ {
+ return "umbracoDomains.id = @Id";
+ }
+
+ protected override void PersistDeletedItem(IDomain entity)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+ repo.PersistDeletedItem(factory.BuildEntity(entity));
+ }
+ }
+
+ protected override IEnumerable GetDeleteClauses()
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override Guid NodeObjectTypeId
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ protected override void PersistNewItem(IDomain entity)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+ var cacheableEntity = factory.BuildEntity(entity);
+ repo.PersistNewItem(cacheableEntity);
+ //re-map the id
+ entity.Id = cacheableEntity.Id;
+ entity.ResetDirtyProperties();
+ }
+ }
+
+ protected override void PersistUpdatedItem(IDomain entity)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+ repo.PersistUpdatedItem(factory.BuildEntity(entity));
+ entity.ResetDirtyProperties();
+ }
+ }
+
+ public bool Exists(string domainName)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var query = new Query().Where(x => x.DomainName.InvariantEquals(domainName));
+ return repo.GetByQuery(query).Any();
+ }
+ }
+
+ public IEnumerable GetAll(bool includeWildcards)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+ return factory.BuildDomainEntities(repo.GetAll().ToArray(), _contentRepository, _languageRepository)
+ .Where(x => includeWildcards || x.IsWildcard == false);
+ }
+ }
+
+ public IEnumerable GetAssignedDomains(int contentId, bool includeWildcards)
+ {
+ using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
+ {
+ var factory = new DomainModelFactory();
+
+ var query = new Query().Where(x => x.RootContentId == contentId);
+
+ return factory.BuildDomainEntities(repo.GetByQuery(query).ToArray(), _contentRepository, _languageRepository)
+ .Where(x => includeWildcards || x.IsWildcard == false);
+ }
+ }
+
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _contentRepository.Dispose();
+ _languageRepository.Dispose();
+ }
+
+ ///
+ /// A simple domain model that is cacheable without a large object graph
+ ///
+ internal class CacheableDomain : Entity, IAggregateRoot
+ {
+ public int? DefaultLanguageId { get; set; }
+ public string DomainName { get; set; }
+ public int? RootContentId { get; set; }
+ }
+
+ ///
+ /// Inner repository responsible for CRUD for domains that allows caching simple data
+ ///
+ private class CachedDomainRepository : PetaPocoRepositoryBase
+ {
+ private readonly DomainRepository _domainRepo;
+
+ public CachedDomainRepository(DomainRepository domainRepo, IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
+ : base(work, cache, logger, sqlSyntax)
+ {
+ _domainRepo = domainRepo;
+ }
+
+ protected override CacheableDomain PerformGet(int id)
+ {
+ var sql = GetBaseQuery(false);
+ sql.Where(GetBaseWhereClause(), new { Id = id });
+
+ var dto = Database.FirstOrDefault(sql);
+ if (dto == null)
+ return null;
+
+ var entity = ConvertFromDto(dto);
+
+ //on initial construction we don't want to have dirty properties tracked
+ // http://issues.umbraco.org/issue/U4-1946
+ ((Entity)entity).ResetDirtyProperties(false);
+
+ return entity;
+ }
+
+ protected override IEnumerable PerformGetAll(params int[] ids)
+ {
+ var sql = GetBaseQuery(false).Where("umbracoDomains.id > 0");
+ if (ids.Any())
+ {
+ sql.Where("umbracoDomains.id in (@ids)", new { ids = ids });
+ }
+
+ return Database.Fetch(sql).Select(ConvertFromDto);
+ }
+
+ protected override IEnumerable PerformGetByQuery(IQuery query)
+ {
+ var sqlClause = GetBaseQuery(false);
+ var translator = new SqlTranslator(sqlClause, query);
+ var sql = translator.Translate();
+ return Database.Fetch(sql).Select(ConvertFromDto);
+ }
+
+ protected override Sql GetBaseQuery(bool isCount)
+ {
+ return _domainRepo.GetBaseQuery(isCount);
+ }
+
+ protected override string GetBaseWhereClause()
+ {
+ return _domainRepo.GetBaseWhereClause();
+ }
+
+ protected override IEnumerable GetDeleteClauses()
+ {
+ var list = new List
+ {
+ "DELETE FROM umbracoDomains WHERE id = @Id"
+ };
+ return list;
+ }
+
+ protected override Guid NodeObjectTypeId
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ protected override void PersistNewItem(CacheableDomain entity)
+ {
+ var exists = Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoDomains WHERE domainName = @domainName", new {domainName = entity.DomainName});
+ if (exists > 0) throw new DuplicateNameException(string.Format("The domain name {0} is already assigned", entity.DomainName));
+
+ entity.AddingEntity();
+
+ var factory = new DomainModelFactory();
+ var dto = factory.BuildDto(entity);
+
+ var id = Convert.ToInt32(Database.Insert(dto));
+ entity.Id = id;
+
+ entity.ResetDirtyProperties();
+ }
+
+ protected override void PersistUpdatedItem(CacheableDomain entity)
+ {
+ entity.UpdatingEntity();
+
+ var factory = new DomainModelFactory();
+ var dto = factory.BuildDto(entity);
+
+ Database.Update(dto);
+
+ entity.ResetDirtyProperties();
+ }
+
+ private CacheableDomain ConvertFromDto(DomainDto dto)
+ {
+ var factory = new DomainModelFactory();
+ var entity = factory.BuildEntity(dto);
+ return entity;
+ }
+ }
+
+ internal class DomainModelFactory
+ {
+ public IEnumerable BuildDomainEntities(CacheableDomain[] cacheableDomains, IContentRepository contentRepository, ILanguageRepository languageRepository)
+ {
+ var contentIds = cacheableDomains.Select(x => x.RootContentId).Where(x => x.HasValue).Select(x => x.Value).Distinct().ToArray();
+ var langIds = cacheableDomains.Select(x => x.DefaultLanguageId).Where(x => x.HasValue).Select(x => x.Value).Distinct().ToArray();
+ var contentItems = contentRepository.GetAll(contentIds);
+ var langItems = languageRepository.GetAll(langIds);
+
+ return cacheableDomains
+ .WhereNotNull()
+ .Select(cacheableDomain => new UmbracoDomain(cacheableDomain.DomainName)
+ {
+ Id = cacheableDomain.Id,
+ //lookup from repo - this will be cached
+ Language = cacheableDomain.DefaultLanguageId.HasValue ? langItems.FirstOrDefault(l => l.Id == cacheableDomain.DefaultLanguageId.Value) : null,
+ //lookup from repo - this will be cached
+ RootContent = cacheableDomain.RootContentId.HasValue ? contentItems.FirstOrDefault(l => l.Id == cacheableDomain.RootContentId.Value) : null,
+ });
+ }
+
+ public IDomain BuildDomainEntity(CacheableDomain cacheableDomain, IContentRepository contentRepository, ILanguageRepository languageRepository)
+ {
+ if (cacheableDomain == null) return null;
+
+ return new UmbracoDomain(cacheableDomain.DomainName)
+ {
+ Id = cacheableDomain.Id,
+ //lookup from repo - this will be cached
+ Language = cacheableDomain.DefaultLanguageId.HasValue ? languageRepository.Get(cacheableDomain.DefaultLanguageId.Value) : null,
+ //lookup from repo - this will be cached
+ RootContent = cacheableDomain.RootContentId.HasValue ? contentRepository.Get(cacheableDomain.RootContentId.Value) : null
+ };
+ }
+
+ public CacheableDomain BuildEntity(IDomain entity)
+ {
+ var domain = new CacheableDomain
+ {
+ Id = entity.Id,
+ DefaultLanguageId = entity.Language == null ? null : (int?)entity.Language.Id,
+ DomainName = entity.DomainName,
+ RootContentId = entity.RootContent == null ? null : (int?)entity.RootContent.Id
+ };
+ //on initial construction we don't want to have dirty properties tracked
+ // http://issues.umbraco.org/issue/U4-1946
+ domain.ResetDirtyProperties(false);
+ return domain;
+ }
+
+ public CacheableDomain BuildEntity(DomainDto dto)
+ {
+ var domain = new CacheableDomain { Id = dto.Id, DefaultLanguageId = dto.DefaultLanguage, DomainName = dto.DomainName, RootContentId = dto.RootStructureId };
+ //on initial construction we don't want to have dirty properties tracked
+ // http://issues.umbraco.org/issue/U4-1946
+ domain.ResetDirtyProperties(false);
+ return domain;
+ }
+
+ public DomainDto BuildDto(CacheableDomain entity)
+ {
+ var dto = new DomainDto { DefaultLanguage = entity.DefaultLanguageId, DomainName = entity.DomainName, Id = entity.Id, RootStructureId = entity.RootContentId };
+ return dto;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs
index ac0fcebbe7..5cb470b7cd 100644
--- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs
@@ -27,6 +27,12 @@ namespace Umbraco.Core.Persistence.Repositories
///
void ReplaceContentPermissions(EntityPermissionSet permissionSet);
+ ///
+ /// Clears the published flag for a content.
+ ///
+ ///
+ void ClearPublished(IContent content);
+
///
/// Gets a specific language version of an
///
diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDomainRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDomainRepository.cs
new file mode 100644
index 0000000000..030251d805
--- /dev/null
+++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDomainRepository.cs
@@ -0,0 +1,12 @@
+using System.Collections.Generic;
+using Umbraco.Core.Models;
+
+namespace Umbraco.Core.Persistence.Repositories
+{
+ public interface IDomainRepository : IRepositoryQueryable
+ {
+ bool Exists(string domainName);
+ IEnumerable GetAll(bool includeWildcards);
+ IEnumerable GetAssignedDomains(int contentId, bool includeWildcards);
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITaskRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITaskRepository.cs
index aac8f09872..d2b4770082 100644
--- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITaskRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/ITaskRepository.cs
@@ -4,15 +4,13 @@ using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
+ public interface ITaskTypeRepository : IRepositoryQueryable
+ {
+
+ }
+
public interface ITaskRepository : IRepositoryQueryable
{
- //IEnumerable GetTasks(Guid? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false);
IEnumerable GetTasks(int? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false);
-
- //IEnumerable GetTasksForItem(int id);
- //IEnumerable GetTasksForItem(Guid uniqueId);
- //IEnumerable GetTasksByType(int typeId);
- //IEnumerable GetTasksByType(string typeAlias);
-
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs b/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs
index 898dae9497..1403d5e6c4 100644
--- a/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs
@@ -51,6 +51,11 @@ namespace Umbraco.Core.Persistence.Repositories
sql.Where("umbracoLanguage.id in (@ids)", new { ids = ids });
}
+ //this needs to be sorted since that is the way legacy worked - default language is the first one!!
+ //even though legacy didn't sort, it should be by id
+ sql.OrderBy(dto => dto.Id, SqlSyntax);
+
+
return Database.Fetch(sql).Select(ConvertFromDto);
}
@@ -70,7 +75,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
var sql = new Sql();
sql.Select(isCount ? "COUNT(*)" : "*")
- .From();
+ .From(SqlSyntax);
return sql;
}
@@ -200,6 +205,9 @@ namespace Umbraco.Core.Persistence.Repositories
}
}
+ ///
+ /// Inner repository for looking up languages by culture name, this deals with caching by a string key
+ ///
private class LanguageByCultureNameRepository : SimpleGetRepository
{
private readonly LanguageRepository _languageRepository;
diff --git a/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs
index e5334bfac2..9f9ac2e3bf 100644
--- a/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs
@@ -217,7 +217,7 @@ namespace Umbraco.Core.Persistence.Repositories
var id = contentTypeId;
var query = Query.Builder.Where(x => x.ContentTypeId == id && x.Trashed == false);
RebuildXmlStructuresProcessQuery(serializer, query, tr, groupSize);
- }
+ }
}
tr.Complete();
@@ -434,7 +434,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
get { return Constants.System.RecycleBinMedia; }
}
-
+
#endregion
///
@@ -581,6 +581,18 @@ namespace Umbraco.Core.Persistence.Repositories
return currentName;
}
-
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _mediaTypeRepository.Dispose();
+ _tagRepository.Dispose();
+ _contentXmlRepository.Dispose();
+ _contentPreviewRepository.Dispose();
+ }
}
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs
index 8c08bf38c2..79d35d99a4 100644
--- a/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs
@@ -782,5 +782,20 @@ namespace Umbraco.Core.Persistence.Repositories
((Entity)member).ResetDirtyProperties(false);
return member;
}
+
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _memberTypeRepository.Dispose();
+ _tagRepository.Dispose();
+ _memberGroupRepository.Dispose();
+ _contentXmlRepository.Dispose();
+ _contentPreviewRepository.Dispose();
+ }
}
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/RelationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/RelationRepository.cs
index c9a6c2f96a..69e0307c09 100644
--- a/src/Umbraco.Core/Persistence/Repositories/RelationRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/RelationRepository.cs
@@ -146,5 +146,16 @@ namespace Umbraco.Core.Persistence.Repositories
}
#endregion
+
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _relationTypeRepository.Dispose();
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs
index 10a9e1fe2c..a6bbff353a 100644
--- a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs
@@ -46,6 +46,14 @@ namespace Umbraco.Core.Persistence.Repositories
get { return _cache; }
}
+ ///
+ /// The runtime cache used for this repo - by standard this is the runtime cache exposed by the CacheHelper but can be overridden
+ ///
+ protected virtual IRuntimeCacheProvider RuntimeCache
+ {
+ get { return _cache.RuntimeCache; }
+ }
+
public static string GetCacheIdKey(object id)
{
return string.Format("{0}{1}", GetCacheTypeKey(), id);
@@ -77,7 +85,7 @@ namespace Umbraco.Core.Persistence.Repositories
///
/// Adds or Updates an entity of type TEntity
///
- /// This method is backed by an cache
+ /// This method is backed by an cache
///
public void AddOrUpdate(TEntity entity)
{
@@ -105,13 +113,13 @@ namespace Umbraco.Core.Persistence.Repositories
protected abstract TEntity PerformGet(TId id);
///
- /// Gets an entity by the passed in Id
+ /// Gets an entity by the passed in Id utilizing the repository's runtime cache
///
///
///
public TEntity Get(TId id)
{
- return RepositoryCache.RuntimeCache.GetCacheItem(
+ return RuntimeCache.GetCacheItem(
GetCacheIdKey(id), () =>
{
var entity = PerformGet(id);
@@ -149,14 +157,14 @@ namespace Umbraco.Core.Persistence.Repositories
if (ids.Any())
{
- var entities = ids.Select(x => RepositoryCache.RuntimeCache.GetCacheItem(GetCacheIdKey(x))).ToArray();
+ var entities = ids.Select(x => RuntimeCache.GetCacheItem(GetCacheIdKey(x))).ToArray();
if (ids.Count().Equals(entities.Count()) && entities.Any(x => x == null) == false)
return entities.Select(x => (TEntity)x);
}
else
{
- var allEntities = RepositoryCache.RuntimeCache.GetCacheItemsByKeySearch(GetCacheTypeKey()).ToArray();
+ var allEntities = RuntimeCache.GetCacheItemsByKeySearch(GetCacheTypeKey()).ToArray();
if (allEntities.Any())
{
@@ -185,7 +193,7 @@ namespace Umbraco.Core.Persistence.Repositories
if (entity != null)
{
var localCopy = entity;
- RepositoryCache.RuntimeCache.InsertCacheItem(GetCacheIdKey(entity.Id), () => localCopy);
+ RuntimeCache.InsertCacheItem(GetCacheIdKey(entity.Id), () => localCopy);
}
}
@@ -213,7 +221,7 @@ namespace Umbraco.Core.Persistence.Repositories
///
public bool Exists(TId id)
{
- var fromCache = RepositoryCache.RuntimeCache.GetCacheItem(GetCacheIdKey(id));
+ var fromCache = RuntimeCache.GetCacheItem(GetCacheIdKey(id));
if (fromCache != null)
{
return true;
@@ -245,13 +253,13 @@ namespace Umbraco.Core.Persistence.Repositories
try
{
PersistNewItem((TEntity)entity);
- RepositoryCache.RuntimeCache.InsertCacheItem(GetCacheIdKey(entity.Id), () => entity);
+ RuntimeCache.InsertCacheItem(GetCacheIdKey(entity.Id), () => entity);
}
catch (Exception)
{
//if an exception is thrown we need to remove the entry from cache, this is ONLY a work around because of the way
// that we cache entities: http://issues.umbraco.org/issue/U4-4259
- RepositoryCache.RuntimeCache.ClearCacheItem(GetCacheIdKey(entity.Id));
+ RuntimeCache.ClearCacheItem(GetCacheIdKey(entity.Id));
throw;
}
@@ -266,14 +274,14 @@ namespace Umbraco.Core.Persistence.Repositories
try
{
PersistUpdatedItem((TEntity)entity);
- RepositoryCache.RuntimeCache.InsertCacheItem(GetCacheIdKey(entity.Id), () => entity);
+ RuntimeCache.InsertCacheItem(GetCacheIdKey(entity.Id), () => entity);
}
catch (Exception)
{
//if an exception is thrown we need to remove the entry from cache, this is ONLY a work around because of the way
// that we cache entities: http://issues.umbraco.org/issue/U4-4259
//RepositoryCache.Delete(typeof(TEntity), entity);
- RepositoryCache.RuntimeCache.ClearCacheItem(GetCacheIdKey(entity.Id));
+ RuntimeCache.ClearCacheItem(GetCacheIdKey(entity.Id));
throw;
}
@@ -286,7 +294,7 @@ namespace Umbraco.Core.Persistence.Repositories
public virtual void PersistDeletedItem(IEntity entity)
{
PersistDeletedItem((TEntity)entity);
- RepositoryCache.RuntimeCache.ClearCacheItem(GetCacheIdKey(entity.Id));
+ RuntimeCache.ClearCacheItem(GetCacheIdKey(entity.Id));
}
#endregion
diff --git a/src/Umbraco.Core/Persistence/Repositories/TaskRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TaskRepository.cs
index c6a569eb9f..f30f945851 100644
--- a/src/Umbraco.Core/Persistence/Repositories/TaskRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/TaskRepository.cs
@@ -40,7 +40,7 @@ namespace Umbraco.Core.Persistence.Repositories
if (ids.Any())
{
- sql.Where("cmsTask.id IN (@ids)", new {ids = ids});
+ sql.Where("cmsTask.id IN (@ids)", new { ids = ids });
}
var factory = new TaskFactory();
@@ -109,10 +109,10 @@ namespace Umbraco.Core.Persistence.Repositories
entity.AddingEntity();
//ensure the task type exists
- var taskType = Database.SingleOrDefault("Where alias = @alias", new {alias = entity.TaskType.Alias});
+ var taskType = Database.SingleOrDefault("Where alias = @alias", new { alias = entity.TaskType.Alias });
if (taskType == null)
{
- var taskTypeId = Convert.ToInt32(Database.Insert(new TaskTypeDto {Alias = entity.TaskType.Alias}));
+ var taskTypeId = Convert.ToInt32(Database.Insert(new TaskTypeDto { Alias = entity.TaskType.Alias }));
entity.TaskType.Id = taskTypeId;
}
else
@@ -141,19 +141,6 @@ namespace Umbraco.Core.Persistence.Repositories
entity.ResetDirtyProperties();
}
- //public IEnumerable GetTasks(Guid? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false)
- //{
- // var sql = GetGetTasksQuery(assignedUser, ownerUser, taskTypeAlias, includeClosed);
- // if (itemId.HasValue)
- // {
- // sql.Where(dto => dto.UniqueId == itemId.Value);
- // }
-
- // var dtos = Database.Fetch(sql);
- // var entities = Mapper.Map>(dtos);
- // return entities;
- //}
-
public IEnumerable GetTasks(int? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false)
{
var sql = GetGetTasksQuery(assignedUser, ownerUser, taskTypeAlias, includeClosed);
@@ -181,11 +168,11 @@ namespace Umbraco.Core.Persistence.Repositories
}
if (ownerUser.HasValue)
{
- sql.Where(dto => dto.UserId == ownerUser.Value);
+ sql.Where(dto => dto.ParentUserId == ownerUser.Value);
}
if (assignedUser.HasValue)
{
- sql.Where(dto => dto.ParentUserId == assignedUser.Value);
+ sql.Where(dto => dto.UserId == assignedUser.Value);
}
return sql;
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/TaskTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TaskTypeRepository.cs
new file mode 100644
index 0000000000..564e949172
--- /dev/null
+++ b/src/Umbraco.Core/Persistence/Repositories/TaskTypeRepository.cs
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Umbraco.Core.Logging;
+using Umbraco.Core.Models;
+using Umbraco.Core.Models.Rdbms;
+using Umbraco.Core.Persistence.Factories;
+using Umbraco.Core.Persistence.Querying;
+using Umbraco.Core.Persistence.SqlSyntax;
+using Umbraco.Core.Persistence.UnitOfWork;
+
+namespace Umbraco.Core.Persistence.Repositories
+{
+ internal class TaskTypeRepository : PetaPocoRepositoryBase, ITaskTypeRepository
+ {
+ public TaskTypeRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
+ : base(work, cache, logger, sqlSyntax)
+ {
+ }
+
+ protected override TaskType PerformGet(int id)
+ {
+ var sql = GetBaseQuery(false);
+ sql.Where(GetBaseWhereClause(), new { Id = id });
+
+ var taskDto = Database.Fetch(sql).FirstOrDefault();
+ if (taskDto == null)
+ return null;
+
+ var factory = new TaskTypeFactory();
+ var entity = factory.BuildEntity(taskDto);
+ return entity;
+ }
+
+ protected override IEnumerable PerformGetAll(params int[] ids)
+ {
+ var sql = GetBaseQuery(false);
+
+ if (ids.Any())
+ {
+ sql.Where("cmsTaskType.id IN (@ids)", new { ids = ids });
+ }
+
+ var factory = new TaskTypeFactory();
+ var dtos = Database.Fetch(sql);
+ return dtos.Select(factory.BuildEntity);
+ }
+
+ protected override IEnumerable PerformGetByQuery(IQuery query)
+ {
+ var sqlClause = GetBaseQuery(false);
+ var translator = new SqlTranslator(sqlClause, query);
+ var sql = translator.Translate();
+
+ var factory = new TaskTypeFactory();
+ var dtos = Database.Fetch(sql);
+ return dtos.Select(factory.BuildEntity);
+ }
+
+ protected override Sql GetBaseQuery(bool isCount)
+ {
+ var sql = new Sql();
+ sql.Select("*").From(SqlSyntax);
+ return sql;
+ }
+
+ protected override string GetBaseWhereClause()
+ {
+ return "cmsTaskType.id = @Id";
+ }
+
+ protected override IEnumerable GetDeleteClauses()
+ {
+ var list = new List
+ {
+ "DELETE FROM cmsTask WHERE taskTypeId = @Id",
+ "DELETE FROM cmsTaskType WHERE id = @Id"
+ };
+ return list;
+ }
+
+ protected override Guid NodeObjectTypeId
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ protected override void PersistNewItem(TaskType entity)
+ {
+ entity.AddingEntity();
+
+ //TODO: Just remove the task type db table or add a unique index to the alias
+
+ //ensure the task type exists
+ var taskType = Database.SingleOrDefault("Where alias = @alias", new { alias = entity.Alias });
+ if (taskType != null)
+ {
+ throw new InvalidOperationException("A task type already exists with the given alias " + entity.Alias);
+ }
+
+ var factory = new TaskTypeFactory();
+ var dto = factory.BuildDto(entity);
+
+ var id = Convert.ToInt32(Database.Insert(dto));
+ entity.Id = id;
+
+ entity.ResetDirtyProperties();
+ }
+
+ protected override void PersistUpdatedItem(TaskType entity)
+ {
+ entity.UpdatingEntity();
+
+ var factory = new TaskTypeFactory();
+ var dto = factory.BuildDto(entity);
+
+ Database.Update(dto);
+
+ entity.ResetDirtyProperties();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs
index e56771fc7d..fb66dc7ade 100644
--- a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs
@@ -374,6 +374,17 @@ namespace Umbraco.Core.Persistence.Repositories
var userFactory = new UserFactory(userType);
return userFactory.BuildEntity(dto);
});
- }
+ }
+
+ ///
+ /// Dispose disposable properties
+ ///
+ ///
+ /// Ensure the unit of work is disposed
+ ///
+ protected override void DisposeResources()
+ {
+ _userTypeRepository.Dispose();
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/RepositoryFactory.cs b/src/Umbraco.Core/Persistence/RepositoryFactory.cs
index fa39f013ca..2afe184b3a 100644
--- a/src/Umbraco.Core/Persistence/RepositoryFactory.cs
+++ b/src/Umbraco.Core/Persistence/RepositoryFactory.cs
@@ -66,7 +66,9 @@ namespace Umbraco.Core.Persistence
public virtual ITaskRepository CreateTaskRepository(IDatabaseUnitOfWork uow)
{
- return new TaskRepository(uow, _cacheHelper, _logger, _sqlSyntax);
+ return new TaskRepository(uow,
+ CacheHelper.CreateDisabledCacheHelper(), //never cache
+ _logger, _sqlSyntax);
}
public virtual IAuditRepository CreateAuditRepository(IDatabaseUnitOfWork uow)
@@ -263,5 +265,16 @@ namespace Umbraco.Core.Persistence
return new EntityRepository(uow);
}
+ public IDomainRepository CreateDomainRepository(IDatabaseUnitOfWork uow)
+ {
+ return new DomainRepository(uow, _cacheHelper, _logger, _sqlSyntax, CreateContentRepository(uow), CreateLanguageRepository(uow));
+ }
+
+ public ITaskTypeRepository CreateTaskTypeRepository(IDatabaseUnitOfWork uow)
+ {
+ return new TaskTypeRepository(uow,
+ CacheHelper.CreateDisabledCacheHelper(), //never cache
+ _logger, _sqlSyntax);
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Publishing/PublishingStrategy.cs b/src/Umbraco.Core/Publishing/PublishingStrategy.cs
index 899567bf8d..1c33f87c5e 100644
--- a/src/Umbraco.Core/Publishing/PublishingStrategy.cs
+++ b/src/Umbraco.Core/Publishing/PublishingStrategy.cs
@@ -303,32 +303,7 @@ namespace Umbraco.Core.Publishing
/// True if the unpublish operation was successfull and not cancelled, otherwise false
public override bool UnPublish(IContent content, int userId)
{
- if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs(content), this))
- {
- LogHelper.Info(
- string.Format("Content '{0}' with Id '{1}' will not be un-published, the event was cancelled.", content.Name, content.Id));
- return false;
- }
-
-
- //If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
- //Otherwise it would remain released == published
- if (content.ReleaseDate.HasValue && content.ReleaseDate.Value <= DateTime.Now)
- {
- content.ReleaseDate = null;
-
- LogHelper.Info(
- string.Format(
- "Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
- content.Name, content.Id));
- }
-
- content.ChangePublishedState(PublishedState.Unpublished);
-
- LogHelper.Info(
- string.Format("Content '{0}' with Id '{1}' has been unpublished.",
- content.Name, content.Id));
- return true;
+ return UnPublishInternal(content, userId).Success;
}
///
@@ -337,43 +312,47 @@ namespace Umbraco.Core.Publishing
/// An enumerable list of
/// Id of the User issueing the unpublish operation
/// A list of publish statuses
- internal IEnumerable> UnPublishInternal(IEnumerable content, int userId)
+ private IEnumerable> UnPublishInternal(IEnumerable content, int userId)
{
- var result = new List>();
+ return content.Select(x => UnPublishInternal(x, userId));
+ }
- //Only update content thats already been published
- foreach (var item in content.Where(x => x.Published == true))
+ private Attempt UnPublishInternal(IContent content, int userId)
+ {
+ // content should (is assumed to ) be the newest version, which may not be published
+ // don't know how to test this, so it's not verified
+ // NOTE
+ // if published != newest, then the published flags need to be reseted by whoever is calling that method
+ // at the moment it's done by the content service
+
+ //Fire UnPublishing event
+ if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs(content), this))
{
- //Fire UnPublishing event
- if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs(item), this))
- {
- LogHelper.Info(
- string.Format("Content '{0}' with Id '{1}' will not be published, the event was cancelled.", item.Name, item.Id));
- result.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedCancelledByEvent)));
- continue;
- }
-
- //If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
- //Otherwise it would remain released == published
- if (item.ReleaseDate.HasValue && item.ReleaseDate.Value <= DateTime.Now)
- {
- item.ReleaseDate = null;
-
- LogHelper.Info(
- string.Format("Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
- item.Name, item.Id));
- }
-
- item.ChangePublishedState(PublishedState.Unpublished);
-
LogHelper.Info(
- string.Format("Content '{0}' with Id '{1}' has been unpublished.",
- item.Name, item.Id));
-
- result.Add(Attempt.Succeed(new PublishStatus(item)));
+ string.Format("Content '{0}' with Id '{1}' will not be unpublished, the event was cancelled.", content.Name, content.Id));
+ return Attempt.Fail(new PublishStatus(content, PublishStatusType.FailedCancelledByEvent));
}
- return result;
+ //If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
+ //Otherwise it would remain released == published
+ if (content.ReleaseDate.HasValue && content.ReleaseDate.Value <= DateTime.Now)
+ {
+ content.ReleaseDate = null;
+
+ LogHelper.Info(
+ string.Format("Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
+ content.Name, content.Id));
+ }
+
+ // if newest is published, unpublish
+ if (content.Published)
+ content.ChangePublishedState(PublishedState.Unpublished);
+
+ LogHelper.Info(
+ string.Format("Content '{0}' with Id '{1}' has been unpublished.",
+ content.Name, content.Id));
+
+ return Attempt.Succeed(new PublishStatus(content));
}
///
diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs
index e5a99cf038..c4181a80a4 100644
--- a/src/Umbraco.Core/Services/ContentService.cs
+++ b/src/Umbraco.Core/Services/ContentService.cs
@@ -27,7 +27,7 @@ namespace Umbraco.Core.Services
///
public class ContentService : RepositoryService, IContentService
{
-
+
private readonly IPublishingStrategy _publishingStrategy;
private readonly EntityXmlSerializer _entitySerializer = new EntityXmlSerializer();
private readonly IDataTypeService _dataTypeService;
@@ -1698,6 +1698,13 @@ namespace Umbraco.Core.Services
/// True if unpublishing succeeded, otherwise False
private bool UnPublishDo(IContent content, bool omitCacheRefresh = false, int userId = 0)
{
+ var newest = GetById(content.Id); // ensure we have the newest version
+ if (content.Version != newest.Version) // but use the original object if it's already the newest version
+ content = newest;
+ var published = content.Published ? content : GetPublishedVersion(content.Id); // get the published version
+ if (published == null)
+ return false; // already unpublished
+
var unpublished = _publishingStrategy.UnPublish(content, userId);
if (unpublished)
{
@@ -1706,6 +1713,9 @@ namespace Umbraco.Core.Services
{
content.WriterId = userId;
repository.AddOrUpdate(content);
+ // is published is not newest, reset the published flag on published version
+ if (published.Version != content.Version)
+ repository.ClearPublished(published);
repository.DeleteContentXml(content);
uow.Commit();
diff --git a/src/Umbraco.Core/Services/DomainService.cs b/src/Umbraco.Core/Services/DomainService.cs
new file mode 100644
index 0000000000..f2ff88e001
--- /dev/null
+++ b/src/Umbraco.Core/Services/DomainService.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Umbraco.Core.Events;
+using Umbraco.Core.Logging;
+using Umbraco.Core.Models;
+using Umbraco.Core.Persistence;
+using Umbraco.Core.Persistence.Querying;
+using Umbraco.Core.Persistence.UnitOfWork;
+
+namespace Umbraco.Core.Services
+{
+ public class DomainService : RepositoryService, IDomainService
+ {
+ public DomainService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger)
+ : base(provider, repositoryFactory, logger)
+ {
+ }
+
+ public bool Exists(string domainName)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ return repo.Exists(domainName);
+ }
+ }
+
+ public void Delete(IDomain domain)
+ {
+ if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs(domain), this))
+ return;
+
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repository = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ repository.Delete(domain);
+ uow.Commit();
+ }
+
+ var args = new DeleteEventArgs(domain, false);
+ Deleted.RaiseEvent(args, this);
+ }
+
+ public IDomain GetByName(string name)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repository = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ return repository.GetByQuery(new Query().Where(x => x.DomainName.InvariantEquals(name))).FirstOrDefault();
+ }
+ }
+
+ public IDomain GetById(int id)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ return repo.Get(id);
+ }
+ }
+
+ public IEnumerable GetAll(bool includeWildcards)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ return repo.GetAll(includeWildcards);
+ }
+ }
+
+ public IEnumerable GetAssignedDomains(int contentId, bool includeWildcards)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ return repo.GetAssignedDomains(contentId, includeWildcards);
+ }
+ }
+
+ public void Save(IDomain domainEntity, bool raiseEvents = true)
+ {
+ if (raiseEvents)
+ {
+ if (Saving.IsRaisedEventCancelled(new SaveEventArgs(domainEntity), this))
+ return;
+ }
+
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repository = RepositoryFactory.CreateDomainRepository(uow))
+ {
+ repository.AddOrUpdate(domainEntity);
+ uow.Commit();
+ }
+
+ if (raiseEvents)
+ Saved.RaiseEvent(new SaveEventArgs(domainEntity, false), this);
+ }
+
+ #region Event Handlers
+ ///
+ /// Occurs before Delete
+ ///
+ public static event TypedEventHandler> Deleting;
+
+ ///
+ /// Occurs after Delete
+ ///
+ public static event TypedEventHandler> Deleted;
+
+ ///
+ /// Occurs before Save
+ ///
+ public static event TypedEventHandler> Saving;
+
+ ///
+ /// Occurs after Save
+ ///
+ public static event TypedEventHandler> Saved;
+
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Services/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/EntityXmlSerializer.cs
index 3e5eb6483b..949b4e61c7 100644
--- a/src/Umbraco.Core/Services/EntityXmlSerializer.cs
+++ b/src/Umbraco.Core/Services/EntityXmlSerializer.cs
@@ -5,6 +5,7 @@ using System.Xml;
using System.Xml.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
+using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Strings;
using umbraco.interfaces;
@@ -177,6 +178,27 @@ namespace Umbraco.Core.Services
return xml;
}
+ public XElement Serialize(Stylesheet stylesheet)
+ {
+ var xml = new XElement("Stylesheet",
+ new XElement("Name", stylesheet.Alias),
+ new XElement("FileName", stylesheet.Path),
+ new XElement("Content", new XCData(stylesheet.Content)));
+
+ var props = new XElement("Properties");
+ xml.Add(props);
+
+ foreach (var prop in stylesheet.Properties)
+ {
+ props.Add(new XElement("Property",
+ new XElement("Name", prop.Name),
+ new XElement("Alias", prop.Alias),
+ new XElement("Value", prop.Value)));
+ }
+
+ return xml;
+ }
+
public XElement Serialize(ILanguage language)
{
var xml = new XElement("Language",
diff --git a/src/Umbraco.Core/Services/IDomainService.cs b/src/Umbraco.Core/Services/IDomainService.cs
new file mode 100644
index 0000000000..7026eca041
--- /dev/null
+++ b/src/Umbraco.Core/Services/IDomainService.cs
@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+using Umbraco.Core.Models;
+
+namespace Umbraco.Core.Services
+{
+ public interface IDomainService : IService
+ {
+ bool Exists(string domainName);
+ void Delete(IDomain domain);
+ IDomain GetByName(string name);
+ IDomain GetById(int id);
+ IEnumerable GetAll(bool includeWildcards);
+ IEnumerable GetAssignedDomains(int contentId, bool includeWildcards);
+ void Save(IDomain domainEntity, bool raiseEvents = true);
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Services/IRelationService.cs b/src/Umbraco.Core/Services/IRelationService.cs
index 9dcc6df615..3719993a75 100644
--- a/src/Umbraco.Core/Services/IRelationService.cs
+++ b/src/Umbraco.Core/Services/IRelationService.cs
@@ -108,6 +108,8 @@ namespace Umbraco.Core.Services
/// An enumerable list of objects
IEnumerable GetByParentOrChildId(int id);
+ IEnumerable GetByParentOrChildId(int id, string relationTypeAlias);
+
///
/// Gets a list of objects by the Name of the
///
diff --git a/src/Umbraco.Core/Services/ITaskService.cs b/src/Umbraco.Core/Services/ITaskService.cs
index 4c9038350d..2586f4ea89 100644
--- a/src/Umbraco.Core/Services/ITaskService.cs
+++ b/src/Umbraco.Core/Services/ITaskService.cs
@@ -4,8 +4,13 @@ using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
- public interface ITaskService
+ public interface ITaskService : IService
{
+ TaskType GetTaskTypeByAlias(string taskTypeAlias);
+ TaskType GetTaskTypeById(int id);
+ void Save(TaskType taskType);
+ void Delete(TaskType taskTypeEntity);
+
//IEnumerable GetTasks(Guid? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false);
IEnumerable GetTasks(int? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false);
@@ -14,5 +19,9 @@ namespace Umbraco.Core.Services
///
///
void Save(Task task);
+ void Delete(Task task);
+
+ IEnumerable GetAllTaskTypes();
+ Task GetTaskById(int id);
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Services/LocalizedTextService.cs b/src/Umbraco.Core/Services/LocalizedTextService.cs
index cdd52d0787..164ed77d50 100644
--- a/src/Umbraco.Core/Services/LocalizedTextService.cs
+++ b/src/Umbraco.Core/Services/LocalizedTextService.cs
@@ -46,10 +46,13 @@ namespace Umbraco.Core.Services
/// Initializes with a source of a dictionary of culture -> areas -> sub dictionary of keys/values
///
///
- public LocalizedTextService(IDictionary>> source)
+ ///
+ public LocalizedTextService(IDictionary>> source, ILogger logger)
{
if (source == null) throw new ArgumentNullException("source");
+ if (logger == null) throw new ArgumentNullException("logger");
_dictionarySource = source;
+ _logger = logger;
}
public string Localize(string key, CultureInfo culture, IDictionary tokens = null)
diff --git a/src/Umbraco.Core/Services/RelationService.cs b/src/Umbraco.Core/Services/RelationService.cs
index becde9c416..db2328047d 100644
--- a/src/Umbraco.Core/Services/RelationService.cs
+++ b/src/Umbraco.Core/Services/RelationService.cs
@@ -203,6 +203,23 @@ namespace Umbraco.Core.Services
}
}
+ public IEnumerable GetByParentOrChildId(int id, string relationTypeAlias)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var relationTypeRepository = RepositoryFactory.CreateRelationTypeRepository(uow))
+ {
+ var rtQuery = new Query().Where(x => x.Alias == relationTypeAlias);
+ var relationType = relationTypeRepository.GetByQuery(rtQuery).FirstOrDefault();
+ if (relationType == null) return Enumerable.Empty();
+
+ using (var relationRepo = RepositoryFactory.CreateRelationRepository(uow))
+ {
+ var query = new Query().Where(x => (x.ChildId == id || x.ParentId == id) && x.RelationTypeId == relationType.Id);
+ return relationRepo.GetByQuery(query);
+ }
+ }
+ }
+
///
/// Gets a list of objects by the Name of the
///
diff --git a/src/Umbraco.Core/Services/SectionService.cs b/src/Umbraco.Core/Services/SectionService.cs
index fd9519bc1c..58026ceb1d 100644
--- a/src/Umbraco.Core/Services/SectionService.cs
+++ b/src/Umbraco.Core/Services/SectionService.cs
@@ -210,7 +210,6 @@ namespace Umbraco.Core.Services
/// The application name.
/// The application alias.
/// The application icon, which has to be located in umbraco/images/tray folder.
- [MethodImpl(MethodImplOptions.Synchronized)]
public void MakeNew(string name, string alias, string icon)
{
MakeNew(name, alias, icon, GetSections().Max(x => x.SortOrder) + 1);
@@ -223,7 +222,6 @@ namespace Umbraco.Core.Services
/// The alias.
/// The icon.
/// The sort order.
- [MethodImpl(MethodImplOptions.Synchronized)]
public void MakeNew(string name, string alias, string icon, int sortOrder)
{
if (GetSections().All(x => x.Alias != alias))
diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs
index c4e2d83796..b635e33e9b 100644
--- a/src/Umbraco.Core/Services/ServiceContext.cs
+++ b/src/Umbraco.Core/Services/ServiceContext.cs
@@ -6,6 +6,7 @@ using Umbraco.Core.IO;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Publishing;
+using umbraco.interfaces;
namespace Umbraco.Core.Services
{
@@ -16,6 +17,8 @@ namespace Umbraco.Core.Services
///
public class ServiceContext
{
+ private Lazy _taskService;
+ private Lazy _domainService;
private Lazy _auditService;
private Lazy _localizedTextService;
private Lazy _tagService;
@@ -39,7 +42,7 @@ namespace Umbraco.Core.Services
private Lazy _notificationService;
///
- /// public ctor - will generally just be used for unit testing
+ /// public ctor - will generally just be used for unit testing all items are optional and if not specified, the defaults will be used
///
///
///
@@ -60,46 +63,52 @@ namespace Umbraco.Core.Services
///
///
///
+ ///
+ ///
public ServiceContext(
- IContentService contentService,
- IMediaService mediaService,
- IContentTypeService contentTypeService,
- IDataTypeService dataTypeService,
- IFileService fileService,
- ILocalizationService localizationService,
- IPackagingService packagingService,
- IEntityService entityService,
- IRelationService relationService,
- IMemberGroupService memberGroupService,
- IMemberTypeService memberTypeService,
- IMemberService memberService,
- IUserService userService,
- ISectionService sectionService,
- IApplicationTreeService treeService,
- ITagService tagService,
- INotificationService notificationService,
- ILocalizedTextService localizedTextService,
- IAuditService auditService)
+ IContentService contentService = null,
+ IMediaService mediaService = null,
+ IContentTypeService contentTypeService = null,
+ IDataTypeService dataTypeService = null,
+ IFileService fileService = null,
+ ILocalizationService localizationService = null,
+ IPackagingService packagingService = null,
+ IEntityService entityService = null,
+ IRelationService relationService = null,
+ IMemberGroupService memberGroupService = null,
+ IMemberTypeService memberTypeService = null,
+ IMemberService memberService = null,
+ IUserService userService = null,
+ ISectionService sectionService = null,
+ IApplicationTreeService treeService = null,
+ ITagService tagService = null,
+ INotificationService notificationService = null,
+ ILocalizedTextService localizedTextService = null,
+ IAuditService auditService = null,
+ IDomainService domainService = null,
+ ITaskService taskService = null)
{
- _auditService = new Lazy(() => auditService);
- _localizedTextService = new Lazy(() => localizedTextService);
- _tagService = new Lazy(() => tagService);
- _contentService = new Lazy(() => contentService);
- _mediaService = new Lazy(() => mediaService);
- _contentTypeService = new Lazy(() => contentTypeService);
- _dataTypeService = new Lazy(() => dataTypeService);
- _fileService = new Lazy(() => fileService);
- _localizationService = new Lazy(() => localizationService);
- _packagingService = new Lazy(() => packagingService);
- _entityService = new Lazy(() => entityService);
- _relationService = new Lazy(() => relationService);
- _sectionService = new Lazy(() => sectionService);
- _memberGroupService = new Lazy(() => memberGroupService);
- _memberTypeService = new Lazy(() => memberTypeService);
- _treeService = new Lazy(() => treeService);
- _memberService = new Lazy(() => memberService);
- _userService = new Lazy(() => userService);
- _notificationService = new Lazy(() => notificationService);
+ if (_auditService != null) _auditService = new Lazy(() => auditService);
+ if (_localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService);
+ if (_tagService != null) _tagService = new Lazy(() => tagService);
+ if (_contentService != null) _contentService = new Lazy(() => contentService);
+ if (_mediaService != null) _mediaService = new Lazy(() => mediaService);
+ if (_contentTypeService != null) _contentTypeService = new Lazy(() => contentTypeService);
+ if (_dataTypeService != null) _dataTypeService = new Lazy(() => dataTypeService);
+ if (_fileService != null) _fileService = new Lazy(() => fileService);
+ if (_localizationService != null) _localizationService = new Lazy(() => localizationService);
+ if (_packagingService != null) _packagingService = new Lazy(() => packagingService);
+ if (_entityService != null) _entityService = new Lazy(() => entityService);
+ if (_relationService != null) _relationService = new Lazy(() => relationService);
+ if (_sectionService != null) _sectionService = new Lazy(() => sectionService);
+ if (_memberGroupService != null) _memberGroupService = new Lazy(() => memberGroupService);
+ if (_memberTypeService != null) _memberTypeService = new Lazy(() => memberTypeService);
+ if (_treeService != null) _treeService = new Lazy(() => treeService);
+ if (_memberService != null) _memberService = new Lazy(() => memberService);
+ if (_userService != null) _userService = new Lazy(() => userService);
+ if (_notificationService != null) _notificationService = new Lazy(() => notificationService);
+ if (_domainService != null) _domainService = new Lazy(() => domainService);
+ if (_taskService != null) _taskService = new Lazy(() => taskService);
}
internal ServiceContext(
@@ -129,6 +138,12 @@ namespace Umbraco.Core.Services
var provider = dbUnitOfWorkProvider;
var fileProvider = fileUnitOfWorkProvider;
+ if (_taskService == null)
+ _taskService = new Lazy(() => new TaskService(provider, repositoryFactory, logger));
+
+ if (_domainService == null)
+ _domainService = new Lazy(() => new DomainService(provider, repositoryFactory, logger));
+
if (_auditService == null)
_auditService = new Lazy(() => new AuditService(provider, repositoryFactory, logger));
@@ -198,6 +213,22 @@ namespace Umbraco.Core.Services
}
+ ///
+ /// Gets the
+ ///
+ public ITaskService TaskService
+ {
+ get { return _taskService.Value; }
+ }
+
+ ///
+ /// Gets the
+ ///
+ public IDomainService DomainService
+ {
+ get { return _domainService.Value; }
+ }
+
///
/// Gets the
///
diff --git a/src/Umbraco.Core/Services/TaskService.cs b/src/Umbraco.Core/Services/TaskService.cs
index 08a641c359..861e49c9fc 100644
--- a/src/Umbraco.Core/Services/TaskService.cs
+++ b/src/Umbraco.Core/Services/TaskService.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Linq.Expressions;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -16,13 +17,50 @@ namespace Umbraco.Core.Services
{
}
- //public IEnumerable GetTasks(Guid? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false)
- //{
- // using (var repo = RepositoryFactory.CreateTaskRepository(UowProvider.GetUnitOfWork()))
- // {
- // return repo.GetTasks(itemId, assignedUser, ownerUser, taskTypeAlias);
- // }
- //}
+ public TaskType GetTaskTypeByAlias(string taskTypeAlias)
+ {
+ using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
+ {
+ return repo.GetByQuery(new Query().Where(type => type.Alias == taskTypeAlias)).FirstOrDefault();
+ }
+ }
+
+ public TaskType GetTaskTypeById(int id)
+ {
+ using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
+ {
+ return repo.Get(id);
+ }
+ }
+
+ public void Save(TaskType taskType)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateTaskTypeRepository(uow))
+ {
+ repo.AddOrUpdate(taskType);
+ uow.Commit();
+ }
+ }
+
+ public void Delete(TaskType taskTypeEntity)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateTaskTypeRepository(uow))
+ {
+ repo.Delete(taskTypeEntity);
+ uow.Commit();
+ }
+ }
+
+ public IEnumerable GetAllTaskTypes()
+ {
+ using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
+ {
+ return repo.GetAll();
+ }
+ }
+
public IEnumerable GetTasks(int? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false)
{
@@ -45,5 +83,23 @@ namespace Umbraco.Core.Services
uow.Commit();
}
}
+
+ public void Delete(Task task)
+ {
+ var uow = UowProvider.GetUnitOfWork();
+ using (var repo = RepositoryFactory.CreateTaskRepository(uow))
+ {
+ repo.Delete(task);
+ uow.Commit();
+ }
+ }
+
+ public Task GetTaskById(int id)
+ {
+ using (var repo = RepositoryFactory.CreateTaskRepository(UowProvider.GetUnitOfWork()))
+ {
+ return repo.Get(id);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index ab608bb089..7ab46ed973 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -84,10 +84,16 @@
+
+ ..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Extensions.dll
+
..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll
False
+
+ ..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll
+
@@ -300,12 +306,20 @@
+
+
+
+
+
+
+
+
@@ -316,7 +330,9 @@
+
+
diff --git a/src/Umbraco.Core/packages.config b/src/Umbraco.Core/packages.config
index 0a7e3b962b..7e5c37bd94 100644
--- a/src/Umbraco.Core/packages.config
+++ b/src/Umbraco.Core/packages.config
@@ -10,7 +10,7 @@
-
+
diff --git a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs
index e8fccc48f8..f784dc3bea 100644
--- a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs
+++ b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs
@@ -25,10 +25,10 @@ namespace Umbraco.Tests.Migrations.Upgrades
{
private ContentRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository)
{
- var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, Mock.Of(), Mock.Of(), Mock.Of());
- var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider);
- contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, templateRepository);
- var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, contentTypeRepository, templateRepository, tagRepository);
+ var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, Mock.Of(), Mock.Of(), Mock.Of());
+ var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax);
+ contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, templateRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, contentTypeRepository, templateRepository, tagRepository);
return repository;
}
diff --git a/src/Umbraco.Tests/MockTests.cs b/src/Umbraco.Tests/MockTests.cs
index 68a01810fa..e7fdfea54d 100644
--- a/src/Umbraco.Tests/MockTests.cs
+++ b/src/Umbraco.Tests/MockTests.cs
@@ -13,6 +13,7 @@ using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Profiling;
using Umbraco.Core.Services;
using Moq;
+using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
namespace Umbraco.Tests
@@ -31,40 +32,7 @@ namespace Umbraco.Tests
[Test]
public void Can_Create_Service_Context()
{
- var svcCtx = new ServiceContext(
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new PackagingService(
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), Mock.Of(), Mock.Of()),
- new Mock().Object),
- new Mock().Object,
- new RelationService(
- new Mock().Object,
- new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), Mock.Of(), Mock.Of()),
- new Mock().Object),
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- Mock.Of(),
- Mock.Of());
+ var svcCtx = MockHelper.GetMockedServiceContext();
Assert.Pass();
}
@@ -80,40 +48,7 @@ namespace Umbraco.Tests
{
var appCtx = new ApplicationContext(
new DatabaseContext(new Mock().Object, Mock.Of(), Mock.Of(), "test"),
- new ServiceContext(
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new PackagingService(
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), Mock.Of(), Mock.Of()),
- new Mock().Object),
- new Mock().Object,
- new RelationService(
- new Mock().Object,
- new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), Mock.Of(), Mock.Of()),
- new Mock().Object),
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- new Mock().Object,
- Mock.Of(),
- Mock.Of()),
+ MockHelper.GetMockedServiceContext(),
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of(), Mock.Of()));
@@ -146,6 +81,7 @@ namespace Umbraco.Tests
var umbCtx = UmbracoContext.EnsureContext(
new Mock().Object,
appCtx,
+ Mock.Of(),
true);
Assert.AreEqual(umbCtx, UmbracoContext.Current);
diff --git a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs
index f5ffee1ce3..9c76cbefe0 100644
--- a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs
+++ b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs
@@ -6,7 +6,15 @@ using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Xml;
+using Moq;
using NUnit.Framework;
+using Umbraco.Core.Configuration.UmbracoSettings;
+using Umbraco.Core.Logging;
+using Umbraco.Core.Persistence;
+using Umbraco.Core.Persistence.SqlSyntax;
+using Umbraco.Core.Persistence.UnitOfWork;
+using Umbraco.Core.Profiling;
+using Umbraco.Core.Services;
using Umbraco.Web.Security;
using umbraco.BusinessLogic;
using Umbraco.Core;
@@ -366,11 +374,56 @@ namespace Umbraco.Tests.Mvc
#region Test helpers
+ ServiceContext GetServiceContext(IUmbracoSettingsSection umbracoSettings, ILogger logger)
+ {
+ var svcCtx = new ServiceContext(
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new PackagingService(
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), logger, Mock.Of(), umbracoSettings),
+ new Mock().Object),
+ new Mock().Object,
+ new RelationService(
+ new Mock().Object,
+ new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), logger, Mock.Of(), umbracoSettings),
+ logger,
+ new Mock().Object),
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ new Mock().Object,
+ Mock.Of(),
+ Mock.Of(),
+ Mock.Of());
+ return svcCtx;
+ }
+
ViewContext GetViewContext()
{
- var umbracoContext = GetUmbracoContext("/dang", 0);
+ var settings = SettingsForTests.GetDefault();
+ var logger = Mock.Of();
+ var umbracoContext = GetUmbracoContext(
+ logger, settings,
+ "/dang", 0);
- var urlProvider = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() });
+ var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider() });
var routingContext = new RoutingContext(
umbracoContext,
Enumerable.Empty(),
@@ -389,7 +442,7 @@ namespace Umbraco.Tests.Mvc
return context;
}
- protected UmbracoContext GetUmbracoContext(string url, int templateId, RouteData routeData = null, bool setSingleton = false)
+ protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false)
{
var cache = new PublishedContentCache();
@@ -403,7 +456,14 @@ namespace Umbraco.Tests.Mvc
//PublishedContentCache.UnitTesting = true;
// ApplicationContext.Current = new ApplicationContext(false) { IsReady = true };
- var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper()) { IsReady = true };
+ var svcCtx = GetServiceContext(umbracoSettings, logger);
+
+ var appCtx = new ApplicationContext(
+ new DatabaseContext(Mock.Of(), logger, Mock.Of(), "test"),
+ svcCtx,
+ CacheHelper.CreateDisabledCacheHelper(),
+ new ProfilingLogger(logger, Mock.Of())) { IsReady = true };
+
var http = GetHttpContextFactory(url, routeData).HttpContext;
var ctx = new UmbracoContext(
GetHttpContextFactory(url, routeData).HttpContext,
diff --git a/src/Umbraco.Tests/Persistence/Querying/ContentTypeSqlMappingTests.cs b/src/Umbraco.Tests/Persistence/Querying/ContentTypeSqlMappingTests.cs
index c8b4a54b96..e5c74e4faa 100644
--- a/src/Umbraco.Tests/Persistence/Querying/ContentTypeSqlMappingTests.cs
+++ b/src/Umbraco.Tests/Persistence/Querying/ContentTypeSqlMappingTests.cs
@@ -58,7 +58,7 @@ namespace Umbraco.Tests.Persistence.Querying
IDictionary> allAssociatedTemplates;
IDictionary> allParentContentTypeIds;
var contentTypes = ContentTypeRepository.ContentTypeQueryMapper.MapContentTypes(
- new[] {99997, 99998}, DatabaseContext.Database, SqlSyntaxProvider, out allAssociatedTemplates, out allParentContentTypeIds)
+ new[] {99997, 99998}, DatabaseContext.Database, SqlSyntax, out allAssociatedTemplates, out allParentContentTypeIds)
.ToArray();
var contentType1 = contentTypes.SingleOrDefault(x => x.Id == 99997);
@@ -111,7 +111,7 @@ namespace Umbraco.Tests.Persistence.Querying
IDictionary> allParentContentTypeIds;
var contentTypes = ContentTypeRepository.ContentTypeQueryMapper.MapMediaTypes(
- new[] { 99997, 99998 }, DatabaseContext.Database, SqlSyntaxProvider, out allParentContentTypeIds)
+ new[] { 99997, 99998 }, DatabaseContext.Database, SqlSyntax, out allParentContentTypeIds)
.ToArray();
var contentType1 = contentTypes.SingleOrDefault(x => x.Id == 99997);
@@ -172,7 +172,7 @@ namespace Umbraco.Tests.Persistence.Querying
IDictionary allPropTypeCollection;
IDictionary allPropGroupCollection;
- ContentTypeRepository.ContentTypeQueryMapper.MapGroupsAndProperties(new[] { 99999 }, DatabaseContext.Database, SqlSyntaxProvider, out allPropTypeCollection, out allPropGroupCollection);
+ ContentTypeRepository.ContentTypeQueryMapper.MapGroupsAndProperties(new[] { 99999 }, DatabaseContext.Database, SqlSyntax, out allPropTypeCollection, out allPropGroupCollection);
var propGroupCollection = allPropGroupCollection[99999];
var propTypeCollection = allPropTypeCollection[99999];
diff --git a/src/Umbraco.Tests/Persistence/Repositories/AuditRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/AuditRepositoryTest.cs
index c3cefc1e35..08012a24c4 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/AuditRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/AuditRepositoryTest.cs
@@ -1,10 +1,22 @@
+using System;
+using System.Collections.Generic;
using System.Linq;
+using System.Xml.Linq;
using NUnit.Framework;
+using umbraco;
+using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
+using Umbraco.Core.Persistence;
+
+using Umbraco.Core.Persistence.Mappers;
+using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Tests.TestHelpers;
+using umbraco.editorControls.tinyMCE3;
+using umbraco.interfaces;
+using Umbraco.Core.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Tests.Persistence.Repositories
{
@@ -17,7 +29,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
- using (var repo = new AuditRepository(unitOfWork, CacheHelper, Logger, SqlSyntaxProvider))
+ using (var repo = new AuditRepository(unitOfWork, CacheHelper, Logger, SqlSyntax))
{
repo.AddOrUpdate(new AuditItem(-1, "This is a System audit trail", AuditType.System, 0));
unitOfWork.Commit();
diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
index 9dcd1a60ce..3d004a5022 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
@@ -41,10 +41,10 @@ namespace Umbraco.Tests.Persistence.Repositories
private ContentRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository)
{
- var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, Mock.Of(), Mock.Of(), Mock.Of());
- var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider);
- contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, templateRepository);
- var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, contentTypeRepository, templateRepository, tagRepository);
+ var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, Mock.Of(), Mock.Of(), Mock.Of());
+ var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax);
+ contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, templateRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, contentTypeRepository, templateRepository, tagRepository);
return repository;
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs
index 79061564cc..058dd0330e 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs
@@ -39,17 +39,17 @@ namespace Umbraco.Tests.Persistence.Repositories
private ContentRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository)
{
- var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, Mock.Of(), Mock.Of(), Mock.Of());
- var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider);
- contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, templateRepository);
- var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, contentTypeRepository, templateRepository, tagRepository);
+ var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, Mock.Of(), Mock.Of(), Mock.Of());
+ var tagRepository = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax);
+ contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, templateRepository);
+ var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, contentTypeRepository, templateRepository, tagRepository);
return repository;
}
private ContentTypeRepository CreateRepository(IDatabaseUnitOfWork unitOfWork)
{
- var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, Mock.Of(), Mock.Of(), Mock.Of());
- var contentTypeRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntaxProvider, templateRepository);
+ var templateRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, Mock.Of