Initial commit of changing all IsRaisedEventCancelled to use the event manager and inside of a uow

This commit is contained in:
Shannon
2017-01-23 20:48:51 +11:00
parent a3150b7d4e
commit ac4de99f30
26 changed files with 642 additions and 683 deletions

View File

@@ -173,7 +173,7 @@ namespace Umbraco.Core
return new ServiceContext(
new RepositoryFactory(ApplicationCache, ProfilingLogger.Logger, dbContext.SqlSyntax, UmbracoConfig.For.UmbracoSettings()),
new PetaPocoUnitOfWorkProvider(scopeProvider),
new FileUnitOfWorkProvider(),
new FileUnitOfWorkProvider(scopeProvider),
new PublishingStrategy(msgFactory, ProfilingLogger.Logger),
ApplicationCache,
ProfilingLogger.Logger,

View File

@@ -284,7 +284,7 @@ namespace Umbraco.Core.Persistence.Repositories
var missingRoles = roleNames.Except(existingRoles);
var missingGroups = missingRoles.Select(x => new MemberGroup {Name = x}).ToArray();
if (SavingMemberGroup.IsRaisedEventCancelled(new SaveEventArgs<IMemberGroup>(missingGroups), this))
if (SavingMemberGroup.IsRaisedEventCancelled(new SaveEventArgs<IMemberGroup>(missingGroups), this, UnitOfWork.EventManager))
{
return;
}

View File

@@ -102,7 +102,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
if (_isolatedCache != null) return _isolatedCache;
var scope = ((PetaPocoUnitOfWork) UnitOfWork).Scope; // fixme cast!
var scope = ((ScopeUnitOfWork) UnitOfWork).Scope; // fixme cast!
IsolatedRuntimeCache provider;
switch (scope.RepositoryCacheMode)
{
@@ -164,7 +164,7 @@ namespace Umbraco.Core.Persistence.Repositories
return _cachePolicy = NoRepositoryCachePolicy<TEntity, TId>.Instance;
_cachePolicy = CreateCachePolicy(IsolatedCache);
var scope = ((PetaPocoUnitOfWork) UnitOfWork).Scope; // fixme cast!
var scope = ((ScopeUnitOfWork) UnitOfWork).Scope; // fixme cast!
switch (scope.RepositoryCacheMode)
{
case RepositoryCacheMode.Default:

View File

@@ -3,73 +3,26 @@ using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Scoping;
using IsolationLevel = System.Data.IsolationLevel;
namespace Umbraco.Core.Persistence.UnitOfWork
{
/// <summary>
/// Represents the Unit of Work implementation for working with files
/// </summary>
internal class FileUnitOfWork : IUnitOfWork
internal class FileUnitOfWork : ScopeUnitOfWork
{
private Guid _key;
private readonly Queue<Operation> _operations = new Queue<Operation>();
public FileUnitOfWork()
public FileUnitOfWork(IScopeProvider scopeProvider, IsolationLevel isolationLevel = IsolationLevel.Unspecified) : base(scopeProvider, isolationLevel)
{
_key = Guid.NewGuid();
}
#region Implementation of IUnitOfWork
/// <summary>
/// Registers an <see cref="IEntity" /> instance to be added through this <see cref="UnitOfWork" />
/// </summary>
/// <param name="entity">The <see cref="IEntity" /></param>
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
public void RegisterAdded(IEntity entity, IUnitOfWorkRepository repository)
{
_operations.Enqueue(
new Operation
{
Entity = entity,
Repository = repository,
Type = TransactionType.Insert
});
}
/// <summary>
/// Registers an <see cref="IEntity" /> instance to be changed through this <see cref="UnitOfWork" />
/// </summary>
/// <param name="entity">The <see cref="IEntity" /></param>
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
public void RegisterChanged(IEntity entity, IUnitOfWorkRepository repository)
{
_operations.Enqueue(
new Operation
{
Entity = entity,
Repository = repository,
Type = TransactionType.Update
});
}
/// <summary>
/// Registers an <see cref="IEntity" /> instance to be removed through this <see cref="UnitOfWork" />
/// </summary>
/// <param name="entity">The <see cref="IEntity" /></param>
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
public void RegisterRemoved(IEntity entity, IUnitOfWorkRepository repository)
{
_operations.Enqueue(
new Operation
{
Entity = entity,
Repository = repository,
Type = TransactionType.Delete
});
}
public void Commit()
public override void Commit()
{
//NOTE: I'm leaving this in here for reference, but this is useless, transaction scope + Files doesn't do anything,
// the closest you can get is transactional NTFS, but that requires distributed transaction coordinator and some other libs/wrappers,
@@ -81,9 +34,9 @@ namespace Umbraco.Core.Persistence.UnitOfWork
// scope.Complete();
//}
while (_operations.Count > 0)
while (Operations.Count > 0)
{
var operation = _operations.Dequeue();
var operation = Operations.Dequeue();
switch (operation.Type)
{
case TransactionType.Insert:
@@ -99,44 +52,16 @@ namespace Umbraco.Core.Persistence.UnitOfWork
}
// Clear everything
_operations.Clear();
Operations.Clear();
_key = Guid.NewGuid();
}
public object Key
public override object Key
{
get { return _key; }
}
#endregion
#region Operation
/// <summary>
/// Provides a snapshot of an entity and the repository reference it belongs to.
/// </summary>
private sealed class Operation
{
/// <summary>
/// Gets or sets the entity.
/// </summary>
/// <value>The entity.</value>
public IEntity Entity { get; set; }
/// <summary>
/// Gets or sets the repository.
/// </summary>
/// <value>The repository.</value>
public IUnitOfWorkRepository Repository { get; set; }
/// <summary>
/// Gets or sets the type of operation.
/// </summary>
/// <value>The type of operation.</value>
public TransactionType Type { get; set; }
}
#endregion
}
}

View File

@@ -1,17 +1,26 @@
namespace Umbraco.Core.Persistence.UnitOfWork
using Umbraco.Core.Logging;
using Umbraco.Core.Scoping;
namespace Umbraco.Core.Persistence.UnitOfWork
{
/// <summary>
/// Represents a Unit of Work Provider for creating a <see cref="FileUnitOfWork"/>
/// </summary>
public class FileUnitOfWorkProvider : IUnitOfWorkProvider
public class FileUnitOfWorkProvider : ScopeUnitOfWorkProvider
{
#region Implementation of IUnitOfWorkProvider
public IUnitOfWork GetUnitOfWork()
public FileUnitOfWorkProvider()
: this(new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, LoggerResolver.Current.Logger)))
{
return new FileUnitOfWork();
}
#endregion
public FileUnitOfWorkProvider(IScopeProvider scopeProvider) : base(scopeProvider)
{
}
public override IScopeUnitOfWork GetUnitOfWork()
{
return new FileUnitOfWork(Provider);
}
}
}

View File

@@ -1,98 +1,44 @@
using System;
using System.Data;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Scoping;
namespace Umbraco.Core.Persistence.UnitOfWork
{
/// <summary>
/// Represents a Unit of Work Provider for creating a <see cref="PetaPocoUnitOfWork"/>
/// Represents a Unit of Work Provider for creating a <see cref="ScopeUnitOfWork"/>
/// </summary>
public class PetaPocoUnitOfWorkProvider : IScopeUnitOfWorkProvider
public class PetaPocoUnitOfWorkProvider : ScopeUnitOfWorkProvider
{
private readonly IScopeProvider _scopeProvider;
[Obsolete("Use the constructor specifying an ILogger instead")]
public PetaPocoUnitOfWorkProvider()
: this(new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, LoggerResolver.Current.Logger)))
{
}
: base(new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, LoggerResolver.Current.Logger)))
{ }
[Obsolete("Use the constructor specifying an ILogger instead")]
public PetaPocoUnitOfWorkProvider(string connectionString, string providerName)
: this(new ScopeProvider(new DefaultDatabaseFactory(connectionString, providerName, LoggerResolver.Current.Logger)))
: base(new ScopeProvider(new DefaultDatabaseFactory(connectionString, providerName, LoggerResolver.Current.Logger)))
{ }
/// <summary>
/// Parameterless constructor uses defaults
/// Constructor
/// </summary>
public PetaPocoUnitOfWorkProvider(ILogger logger)
: this(new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, logger)))
{
}
: base(new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, logger)))
{ }
/// <summary>
/// Constructor accepting custom connectino string and provider name
/// Constructor accepting custom connection string and provider name
/// </summary>
/// <param name="logger"></param>
/// <param name="connectionString">Connection String to use with Database</param>
/// <param name="providerName">Database Provider for the Connection String</param>
public PetaPocoUnitOfWorkProvider(ILogger logger, string connectionString, string providerName)
: this(new ScopeProvider(new DefaultDatabaseFactory(connectionString, providerName, logger)))
: base(new ScopeProvider(new DefaultDatabaseFactory(connectionString, providerName, logger)))
{ }
/// <summary>
/// Constructor accepting a <see cref="IScopeProvider"/> instance
/// </summary>
/// <param name="scopeProvider"></param>
public PetaPocoUnitOfWorkProvider(IScopeProvider scopeProvider)
public PetaPocoUnitOfWorkProvider(IScopeProvider scopeProvider) : base(scopeProvider)
{
Mandate.ParameterNotNull(scopeProvider, "scopeProvider");
_scopeProvider = scopeProvider;
}
#region Implementation of IUnitOfWorkProvider
//explicit implementation
IDatabaseUnitOfWork IDatabaseUnitOfWorkProvider.GetUnitOfWork()
{
return new PetaPocoUnitOfWork(_scopeProvider);
}
/// <summary>
/// Creates a Unit of work with a new UmbracoDatabase instance for the work item/transaction.
/// </summary>
/// <returns></returns>
/// <remarks>
/// Each PetaPoco UOW uses it's own Database object, not the shared Database object that comes from
/// the ApplicationContext.Current.DatabaseContext.Database. This is because each transaction should use it's own Database
/// and we Dispose of this Database object when the UOW is disposed.
/// </remarks>
public IScopeUnitOfWork GetUnitOfWork()
{
return new PetaPocoUnitOfWork(_scopeProvider);
}
/// <summary>
/// Creates a Unit of work with a new UmbracoDatabase instance for the work item/transaction.
/// </summary>
/// <returns></returns>
/// <remarks>
/// Each PetaPoco UOW uses it's own Database object, not the shared Database object that comes from
/// the ApplicationContext.Current.DatabaseContext.Database. This is because each transaction should use it's own Database
/// and we Dispose of this Database object when the UOW is disposed.
/// </remarks>
public IScopeUnitOfWork GetUnitOfWork(IsolationLevel isolationLevel)
{
return new PetaPocoUnitOfWork(_scopeProvider, isolationLevel);
}
#endregion
}
}

View File

@@ -8,9 +8,9 @@ using Umbraco.Core.Scoping;
namespace Umbraco.Core.Persistence.UnitOfWork
{
/// <summary>
/// Represents the Unit of Work implementation for PetaPoco
/// Represents the Unit of Work implementation for a Scope
/// </summary>
internal class PetaPocoUnitOfWork : DisposableObject, IScopeUnitOfWork
internal class ScopeUnitOfWork : DisposableObject, IScopeUnitOfWork
{
private readonly Queue<Operation> _operations = new Queue<Operation>();
private readonly IsolationLevel _isolationLevel;
@@ -32,7 +32,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork
/// <remarks>
/// This should normally not be used directly and should be created with the UnitOfWorkProvider
/// </remarks>
internal PetaPocoUnitOfWork(IScopeProvider scopeProvider, IsolationLevel isolationLevel = IsolationLevel.Unspecified)
internal ScopeUnitOfWork(IScopeProvider scopeProvider, IsolationLevel isolationLevel = IsolationLevel.Unspecified)
{
_scopeProvider = scopeProvider;
_isolationLevel = isolationLevel;
@@ -94,7 +94,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork
/// Unlike a typical unit of work, this UOW will let you commit more than once since a new transaction is creaed per
/// Commit() call instead of having one Transaction per UOW.
/// </remarks>
public void Commit()
public virtual void Commit()
{
Commit(null);
}
@@ -141,7 +141,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork
_key = Guid.NewGuid();
}
public object Key
public virtual object Key
{
get { return _key; }
}
@@ -161,12 +161,17 @@ namespace Umbraco.Core.Persistence.UnitOfWork
get { return Scope.Events; }
}
protected Queue<Operation> Operations
{
get { return _operations; }
}
#region Operation
/// <summary>
/// Provides a snapshot of an entity and the repository reference it belongs to.
/// </summary>
private sealed class Operation
protected sealed class Operation
{
/// <summary>
/// Gets or sets the entity.

View File

@@ -0,0 +1,54 @@
using System.Data;
using Umbraco.Core.Scoping;
namespace Umbraco.Core.Persistence.UnitOfWork
{
public abstract class ScopeUnitOfWorkProvider : IScopeUnitOfWorkProvider
{
public IScopeProvider Provider { get; private set; }
/// <summary>
/// Constructor accepting a <see cref="IScopeProvider"/> instance
/// </summary>
/// <param name="scopeProvider"></param>
protected ScopeUnitOfWorkProvider(IScopeProvider scopeProvider)
{
Mandate.ParameterNotNull(scopeProvider, "scopeProvider");
Provider = scopeProvider;
}
//explicit implementation
IDatabaseUnitOfWork IDatabaseUnitOfWorkProvider.GetUnitOfWork()
{
return new ScopeUnitOfWork(Provider);
}
/// <summary>
/// Creates a Unit of work with a new UmbracoDatabase instance for the work item/transaction.
/// </summary>
/// <returns></returns>
/// <remarks>
/// Each PetaPoco UOW uses it's own Database object, not the shared Database object that comes from
/// the ApplicationContext.Current.DatabaseContext.Database. This is because each transaction should use it's own Database
/// and we Dispose of this Database object when the UOW is disposed.
/// </remarks>
public virtual IScopeUnitOfWork GetUnitOfWork()
{
return new ScopeUnitOfWork(Provider);
}
/// <summary>
/// Creates a Unit of work with a new UmbracoDatabase instance for the work item/transaction.
/// </summary>
/// <returns></returns>
/// <remarks>
/// Each PetaPoco UOW uses it's own Database object, not the shared Database object that comes from
/// the ApplicationContext.Current.DatabaseContext.Database. This is because each transaction should use it's own Database
/// and we Dispose of this Database object when the UOW is disposed.
/// </remarks>
public IScopeUnitOfWork GetUnitOfWork(IsolationLevel isolationLevel)
{
return new ScopeUnitOfWork(Provider, isolationLevel);
}
}
}

View File

@@ -177,11 +177,7 @@ namespace Umbraco.Core.Services
Created.RaiseEvent(new NewEventArgs<IContent>(content, false, contentTypeAlias, parentId), this, uow.EventManager);
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
{
auditRepo.AddOrUpdate(new AuditItem(content.Id, string.Format("Content '{0}' was created", name), AuditType.New, content.CreatorId));
uow.Commit();
}
Audit(AuditType.New, string.Format("Content '{0}' was created", name), content.CreatorId, content.Id);
return content;
}

View File

@@ -719,12 +719,13 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user saving the ContentType</param>
public void Save(IContentType contentType, int userId = 0)
{
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(contentType), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(contentType), this, uow.EventManager))
return;
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
{
ValidateLocked(contentType); // throws if invalid
@@ -749,12 +750,13 @@ namespace Umbraco.Core.Services
{
var asArray = contentTypes.ToArray();
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(asArray), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(asArray), this, uow.EventManager))
return;
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
{
// all-or-nothing, validate them all first
@@ -786,12 +788,13 @@ namespace Umbraco.Core.Services
/// <remarks>Deleting a <see cref="IContentType"/> will delete all the <see cref="IContent"/> objects based on this <see cref="IContentType"/></remarks>
public void Delete(IContentType contentType, int userId = 0)
{
if (DeletingContentType.IsRaisedEventCancelled(new DeleteEventArgs<IContentType>(contentType), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (DeletingContentType.IsRaisedEventCancelled(new DeleteEventArgs<IContentType>(contentType), this, uow.EventManager))
return;
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
{
//TODO: This needs to change, if we are deleting a content type, we should just delete the data,
@@ -830,12 +833,13 @@ namespace Umbraco.Core.Services
{
var asArray = contentTypes.ToArray();
if (DeletingContentType.IsRaisedEventCancelled(new DeleteEventArgs<IContentType>(asArray), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (DeletingContentType.IsRaisedEventCancelled(new DeleteEventArgs<IContentType>(asArray), this, uow.EventManager))
return;
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
{
var deletedContentTypes = new List<IContentType>();
@@ -1173,12 +1177,13 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional Id of the user saving the MediaType</param>
public void Save(IMediaType mediaType, int userId = 0)
{
if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(mediaType), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(mediaType), this, uow.EventManager))
return;
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
{
ValidateLocked(mediaType); // throws if invalid
@@ -1204,12 +1209,13 @@ namespace Umbraco.Core.Services
{
var asArray = mediaTypes.ToArray();
if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(asArray), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(asArray), this, uow.EventManager))
return;
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
{
// all-or-nothing, validate them all first
@@ -1242,13 +1248,15 @@ namespace Umbraco.Core.Services
/// <remarks>Deleting a <see cref="IMediaType"/> will delete all the <see cref="IMedia"/> objects based on this <see cref="IMediaType"/></remarks>
public void Delete(IMediaType mediaType, int userId = 0)
{
if (DeletingMediaType.IsRaisedEventCancelled(new DeleteEventArgs<IMediaType>(mediaType), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (DeletingMediaType.IsRaisedEventCancelled(new DeleteEventArgs<IMediaType>(mediaType), this, uow.EventManager))
return;
_mediaService.DeleteMediaOfType(mediaType.Id, userId);
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
{
var deletedMediaTypes = new List<IMediaType>() {mediaType};
@@ -1274,16 +1282,18 @@ namespace Umbraco.Core.Services
{
var asArray = mediaTypes.ToArray();
if (DeletingMediaType.IsRaisedEventCancelled(new DeleteEventArgs<IMediaType>(asArray), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
if (DeletingMediaType.IsRaisedEventCancelled(new DeleteEventArgs<IMediaType>(asArray), this, uow.EventManager))
return;
foreach (var mediaType in asArray)
{
_mediaService.DeleteMediaOfType(mediaType.Id);
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
{
var deletedMediaTypes = new List<IMediaType>();

View File

@@ -361,10 +361,11 @@ namespace Umbraco.Core.Services
/// <param name="userId">Id of the user issueing the save</param>
public void Save(IDataTypeDefinition dataTypeDefinition, int userId = 0)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
var uow = UowProvider.GetUnitOfWork();
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this, uow.EventManager))
return;
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
{
dataTypeDefinition.CreatorId = userId;
@@ -394,14 +395,15 @@ namespace Umbraco.Core.Services
/// <param name="userId">Id of the user issueing the save</param>
/// <param name="raiseEvents">Boolean indicating whether or not to raise events</param>
public void Save(IEnumerable<IDataTypeDefinition> dataTypeDefinitions, int userId, bool raiseEvents)
{
using (var uow = UowProvider.GetUnitOfWork())
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinitions), this))
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinitions), this, uow.EventManager))
return;
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
{
foreach (var dataTypeDefinition in dataTypeDefinitions)
@@ -417,6 +419,7 @@ namespace Umbraco.Core.Services
Audit(AuditType.Save, string.Format("Save DataTypeDefinition performed by user"), userId, -1);
}
}
/// <summary>
/// Saves a list of PreValues for a given DataTypeDefinition
@@ -501,14 +504,15 @@ namespace Umbraco.Core.Services
/// <param name="userId"></param>
public void SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary<string, PreValue> values, int userId = 0)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
using (var uow = UowProvider.GetUnitOfWork())
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this, uow.EventManager))
return;
// if preValues contain the data type, override the data type definition accordingly
if (values != null && values.ContainsKey(Constants.PropertyEditors.PreValueKeys.DataValueType))
dataTypeDefinition.DatabaseType = PropertyValueEditor.GetDatabaseType(values[Constants.PropertyEditors.PreValueKeys.DataValueType].Value);
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
{
dataTypeDefinition.CreatorId = userId;
@@ -526,6 +530,7 @@ namespace Umbraco.Core.Services
Audit(AuditType.Save, string.Format("Save DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
}
}
/// <summary>
/// Deletes an <see cref="IDataTypeDefinition"/>
@@ -538,10 +543,11 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional Id of the user issueing the deletion</param>
public void Delete(IDataTypeDefinition dataTypeDefinition, int userId = 0)
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
using (var uow = UowProvider.GetUnitOfWork())
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition), this, uow.EventManager))
return;
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
{
repository.Delete(dataTypeDefinition);
@@ -553,6 +559,7 @@ namespace Umbraco.Core.Services
Audit(AuditType.Delete, string.Format("Delete DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
}
}
/// <summary>
/// Gets the <see cref="IDataType"/> specified by it's unique ID

View File

@@ -20,13 +20,13 @@ namespace Umbraco.Core.Services
/// </summary>
public class FileService : ScopeRepositoryService, IFileService
{
private readonly IUnitOfWorkProvider _fileUowProvider;
private readonly IScopeUnitOfWorkProvider _fileUowProvider;
private const string PartialViewHeader = "@inherits Umbraco.Web.Mvc.UmbracoTemplatePage";
private const string PartialViewMacroHeader = "@inherits Umbraco.Web.Macros.PartialViewMacroPage";
public FileService(
IUnitOfWorkProvider fileProvider,
IScopeUnitOfWorkProvider fileProvider,
IDatabaseUnitOfWorkProvider dataProvider,
RepositoryFactory repositoryFactory,
ILogger logger,
@@ -71,10 +71,11 @@ namespace Umbraco.Core.Services
/// <param name="userId"></param>
public void SaveStylesheet(Stylesheet stylesheet, int userId = 0)
{
if (SavingStylesheet.IsRaisedEventCancelled(new SaveEventArgs<Stylesheet>(stylesheet), this))
using (var uow = _fileUowProvider.GetUnitOfWork())
{
if (SavingStylesheet.IsRaisedEventCancelled(new SaveEventArgs<Stylesheet>(stylesheet), this, uow.EventManager))
return;
var uow = _fileUowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateStylesheetRepository(uow, UowProvider.GetUnitOfWork()))
{
repository.AddOrUpdate(stylesheet);
@@ -85,6 +86,7 @@ namespace Umbraco.Core.Services
Audit(AuditType.Save, string.Format("Save Stylesheet performed by user"), userId, -1);
}
}
/// <summary>
/// Deletes a stylesheet by its name
@@ -99,7 +101,7 @@ namespace Umbraco.Core.Services
var stylesheet = repository.Get(path);
if (stylesheet == null) return;
if (DeletingStylesheet.IsRaisedEventCancelled(new DeleteEventArgs<Stylesheet>(stylesheet), this))
if (DeletingStylesheet.IsRaisedEventCancelled(new DeleteEventArgs<Stylesheet>(stylesheet), this, uow.EventManager))
return;
repository.Delete(stylesheet);
@@ -161,12 +163,12 @@ namespace Umbraco.Core.Services
/// <param name="userId"></param>
public void SaveScript(Script script, int userId = 0)
{
if (SavingScript.IsRaisedEventCancelled(new SaveEventArgs<Script>(script), this))
return;
var uow = _fileUowProvider.GetUnitOfWork();
using (var uow = _fileUowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
{
if (SavingScript.IsRaisedEventCancelled(new SaveEventArgs<Script>(script), this, uow.EventManager))
return;
repository.AddOrUpdate(script);
uow.Commit();
@@ -183,13 +185,13 @@ namespace Umbraco.Core.Services
/// <param name="userId"></param>
public void DeleteScript(string path, int userId = 0)
{
var uow = _fileUowProvider.GetUnitOfWork();
using (var uow = _fileUowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
{
var script = repository.Get(path);
if (script == null) return;
if (DeletingScript.IsRaisedEventCancelled(new DeleteEventArgs<Script>(script), this))
if (DeletingScript.IsRaisedEventCancelled(new DeleteEventArgs<Script>(script), this, uow.EventManager))
return; ;
repository.Delete(script);
@@ -452,12 +454,12 @@ namespace Umbraco.Core.Services
/// <param name="userId"></param>
public void SaveTemplate(ITemplate template, int userId = 0)
{
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(template), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
{
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(template), this, uow.EventManager))
return;
repository.AddOrUpdate(template);
uow.Commit();
@@ -474,12 +476,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user</param>
public void SaveTemplate(IEnumerable<ITemplate> templates, int userId = 0)
{
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(templates), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
{
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(templates), this, uow.EventManager))
return;
foreach (var template in templates)
{
repository.AddOrUpdate(template);
@@ -527,7 +529,7 @@ namespace Umbraco.Core.Services
var template = repository.Get(alias);
if (template == null) return;
if (DeletingTemplate.IsRaisedEventCancelled(new DeleteEventArgs<ITemplate>(template), this))
if (DeletingTemplate.IsRaisedEventCancelled(new DeleteEventArgs<ITemplate>(template), this, uow.EventManager))
return;
repository.Delete(template);
@@ -813,7 +815,7 @@ namespace Umbraco.Core.Services
if (partialView == null)
return true;
if (DeletingPartialView.IsRaisedEventCancelled(new DeleteEventArgs<IPartialView>(partialView), this))
if (DeletingPartialView.IsRaisedEventCancelled(new DeleteEventArgs<IPartialView>(partialView), this, uow.EventManager))
return false;
repository.Delete(partialView);
@@ -840,12 +842,12 @@ namespace Umbraco.Core.Services
private Attempt<IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = 0)
{
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<IPartialView>(partialView), this))
return Attempt<IPartialView>.Fail();
var uow = _fileUowProvider.GetUnitOfWork();
using (var uow = _fileUowProvider.GetUnitOfWork())
using (var repository = GetPartialViewRepository(partialViewType, uow))
{
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<IPartialView>(partialView), this, uow.EventManager))
return Attempt<IPartialView>.Fail();
repository.AddOrUpdate(partialView);
uow.Commit();
}

View File

@@ -88,7 +88,7 @@ namespace Umbraco.Core.Services
item.Translations = translations;
}
if (SavingDictionaryItem.IsRaisedEventCancelled(new SaveEventArgs<IDictionaryItem>(item), this))
if (SavingDictionaryItem.IsRaisedEventCancelled(new SaveEventArgs<IDictionaryItem>(item), this, uow.EventManager))
return item;
repository.AddOrUpdate(item);
@@ -220,12 +220,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user saving the dictionary item</param>
public void Save(IDictionaryItem dictionaryItem, int userId = 0)
{
if (SavingDictionaryItem.IsRaisedEventCancelled(new SaveEventArgs<IDictionaryItem>(dictionaryItem), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateDictionaryRepository(uow))
{
if (SavingDictionaryItem.IsRaisedEventCancelled(new SaveEventArgs<IDictionaryItem>(dictionaryItem), this, uow.EventManager))
return;
repository.AddOrUpdate(dictionaryItem);
uow.Commit();
//ensure the lazy Language callback is assigned
@@ -245,12 +245,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user deleting the dictionary item</param>
public void Delete(IDictionaryItem dictionaryItem, int userId = 0)
{
if (DeletingDictionaryItem.IsRaisedEventCancelled(new DeleteEventArgs<IDictionaryItem>(dictionaryItem), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateDictionaryRepository(uow))
{
if (DeletingDictionaryItem.IsRaisedEventCancelled(new DeleteEventArgs<IDictionaryItem>(dictionaryItem), this, uow.EventManager))
return;
//NOTE: The recursive delete is done in the repository
repository.Delete(dictionaryItem);
uow.Commit();
@@ -320,12 +320,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user saving the language</param>
public void Save(ILanguage language, int userId = 0)
{
if (SavingLanguage.IsRaisedEventCancelled(new SaveEventArgs<ILanguage>(language), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateLanguageRepository(uow))
{
if (SavingLanguage.IsRaisedEventCancelled(new SaveEventArgs<ILanguage>(language), this, uow.EventManager))
return;
repository.AddOrUpdate(language);
uow.Commit();
}
@@ -342,12 +342,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user deleting the language</param>
public void Delete(ILanguage language, int userId = 0)
{
if (DeletingLanguage.IsRaisedEventCancelled(new DeleteEventArgs<ILanguage>(language), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateLanguageRepository(uow))
{
if (DeletingLanguage.IsRaisedEventCancelled(new DeleteEventArgs<ILanguage>(language), this, uow.EventManager))
return;
//NOTE: There isn't any constraints in the db, so possible references aren't deleted
repository.Delete(language);
uow.Commit();

View File

@@ -139,12 +139,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional id of the user deleting the macro</param>
public void Delete(IMacro macro, int userId = 0)
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMacro>(macro), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMacroRepository(uow))
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMacro>(macro), this, uow.EventManager))
return;
repository.Delete(macro);
uow.Commit();
@@ -161,12 +161,12 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional Id of the user deleting the macro</param>
public void Save(IMacro macro, int userId = 0)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMacro>(macro), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMacroRepository(uow))
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMacro>(macro), this, uow.EventManager))
return;
repository.AddOrUpdate(macro);
uow.Commit();

View File

@@ -67,7 +67,9 @@ namespace Umbraco.Core.Services
var parent = GetById(media.ParentId);
media.Path = string.Concat(parent.IfNotNull(x => x.Path, media.ParentId.ToString()), ",", media.Id);
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parentId), this))
using (var uow = UowProvider.GetUnitOfWork())
{
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parentId), this, uow.EventManager))
{
media.WasCancelled = true;
return media;
@@ -82,6 +84,9 @@ namespace Umbraco.Core.Services
return media;
}
}
/// <summary>
/// Creates an <see cref="IMedia"/> object using the alias of the <see cref="IMediaType"/>
/// that this Media should based on.
@@ -104,7 +109,9 @@ namespace Umbraco.Core.Services
var media = new Models.Media(name, parent, mediaType);
media.Path = string.Concat(parent.Path, ",", media.Id);
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parent), this))
using (var uow = UowProvider.GetUnitOfWork())
{
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parent), this, uow.EventManager))
{
media.WasCancelled = true;
return media;
@@ -118,6 +125,7 @@ namespace Umbraco.Core.Services
return media;
}
}
/// <summary>
/// Creates an <see cref="IMedia"/> object using the alias of the <see cref="IMediaType"/>
@@ -137,21 +145,22 @@ namespace Umbraco.Core.Services
var mediaType = FindMediaTypeByAlias(mediaTypeAlias);
var media = new Models.Media(name, parentId, mediaType);
var uow = UowProvider.GetUnitOfWork();
//NOTE: I really hate the notion of these Creating/Created events - they are so inconsistent, I've only just found
// out that in these 'WithIdentity' methods, the Saving/Saved events were not fired, wtf. Anyways, they're added now.
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parentId), this))
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parentId), this, uow.EventManager))
{
media.WasCancelled = true;
return media;
}
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(media), this))
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(media), this, uow.EventManager))
{
media.WasCancelled = true;
return media;
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
{
media.CreatorId = userId;
@@ -196,21 +205,22 @@ namespace Umbraco.Core.Services
var mediaType = FindMediaTypeByAlias(mediaTypeAlias);
var media = new Models.Media(name, parent, mediaType);
var uow = UowProvider.GetUnitOfWork();
//NOTE: I really hate the notion of these Creating/Created events - they are so inconsistent, I've only just found
// out that in these 'WithIdentity' methods, the Saving/Saved events were not fired, wtf. Anyways, they're added now.
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parent), this))
if (Creating.IsRaisedEventCancelled(new NewEventArgs<IMedia>(media, mediaTypeAlias, parent), this, uow.EventManager))
{
media.WasCancelled = true;
return media;
}
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(media), this))
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(media), this, uow.EventManager))
{
media.WasCancelled = true;
return media;
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
{
media.CreatorId = userId;
@@ -934,7 +944,7 @@ namespace Umbraco.Core.Services
files = ((MediaRepository)repository).GetFilesInRecycleBinForUploadField();
if (EmptyingRecycleBin.IsRaisedEventCancelled(new RecycleBinEventArgs(nodeObjectType, entities, files), this))
if (EmptyingRecycleBin.IsRaisedEventCancelled(new RecycleBinEventArgs(nodeObjectType, entities, files), this, uow.EventManager))
return;
success = repository.EmptyRecycleBin();
@@ -969,7 +979,7 @@ namespace Umbraco.Core.Services
var query = Query<IMedia>.Builder.Where(x => x.ContentTypeId == mediaTypeId);
var contents = repository.GetByQuery(query).ToArray();
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMedia>(contents), this))
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMedia>(contents), this, uow.EventManager))
return;
foreach (var content in contents.OrderByDescending(x => x.ParentId))
@@ -1164,13 +1174,15 @@ namespace Umbraco.Core.Services
public bool Sort(IEnumerable<IMedia> items, int userId = 0, bool raiseEvents = true)
{
var asArray = items.ToArray();
var uow = UowProvider.GetUnitOfWork();
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(asArray), this))
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(asArray), this, uow.EventManager))
return false;
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
{
int i = 0;

View File

@@ -62,18 +62,17 @@ namespace Umbraco.Core.Services
}
public void Save(IMemberGroup memberGroup, bool raiseEvents = true)
{
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMemberGroup>(memberGroup), this))
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMemberGroup>(memberGroup), this, uow.EventManager))
{
return;
}
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
{
repository.AddOrUpdate(memberGroup);
uow.Commit();
}
@@ -84,12 +83,11 @@ namespace Umbraco.Core.Services
public void Delete(IMemberGroup memberGroup)
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberGroup>(memberGroup), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberGroup>(memberGroup), this, uow.EventManager))
return;
repository.Delete(memberGroup);
uow.Commit();
}

View File

@@ -230,7 +230,7 @@ namespace Umbraco.Core.Services
var query = Query<IMember>.Builder.Where(x => x.ContentTypeId == memberTypeId);
var members = repository.GetByQuery(query).ToArray();
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMember>(members), this))
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMember>(members), this, uow.EventManager))
return;
foreach (var member in members)
@@ -853,15 +853,15 @@ namespace Umbraco.Core.Services
var member = new Member(name, email.ToLower().Trim(), username, passwordValue, memberType);
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(member), this))
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(member), this, uow.EventManager))
{
member.WasCancelled = true;
return member;
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
{
repository.AddOrUpdate(member);
//insert the xml
repository.AddOrUpdateContentXml(member, m => _entitySerializer.Serialize(_dataTypeService, m));
@@ -945,12 +945,12 @@ namespace Umbraco.Core.Services
/// <param name="member"><see cref="IMember"/> to Delete</param>
public void Delete(IMember member)
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMember>(member), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMember>(member), this, uow.EventManager))
return;
repository.Delete(member);
uow.Commit();
@@ -969,18 +969,17 @@ namespace Umbraco.Core.Services
/// <param name="raiseEvents">Optional parameter to raise events.
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
public void Save(IMember entity, bool raiseEvents = true)
{
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(entity), this))
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(entity), this, uow.EventManager))
{
return;
}
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
{
repository.AddOrUpdate(entity);
repository.AddOrUpdateContentXml(entity, m => _entitySerializer.Serialize(_dataTypeService, m));
// generate preview for blame history?
@@ -1006,16 +1005,17 @@ namespace Umbraco.Core.Services
{
var asArray = entities.ToArray();
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(asArray), this))
return;
}
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMember>(asArray), this, uow.EventManager))
return;
}
foreach (var member in asArray)
{
repository.AddOrUpdate(member);

View File

@@ -75,20 +75,19 @@ namespace Umbraco.Core.Services
public void Save(IMemberType memberType, int userId = 0)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMemberType>(memberType), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMemberType>(memberType), this, uow.EventManager))
return;
memberType.CreatorId = userId;
repository.AddOrUpdate(memberType);
uow.Commit();
}
UpdateContentXmlStructure(memberType);
}
Saved.RaiseEvent(new SaveEventArgs<IMemberType>(memberType, false), this);
@@ -98,14 +97,13 @@ namespace Umbraco.Core.Services
{
var asArray = memberTypes.ToArray();
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMemberType>(asArray), this))
return;
using (new WriteLock(Locker))
{
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMemberType>(asArray), this, uow.EventManager))
return;
foreach (var memberType in asArray)
{
memberType.CreatorId = userId;
@@ -123,14 +121,14 @@ namespace Umbraco.Core.Services
public void Delete(IMemberType memberType, int userId = 0)
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberType>(memberType), this))
using (new WriteLock(Locker))
using (var uow = UowProvider.GetUnitOfWork())
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberType>(memberType), this, uow.EventManager))
return;
using (new WriteLock(Locker))
{
_memberService.DeleteMembersOfType(memberType.Id);
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
{
repository.Delete(memberType);
@@ -145,17 +143,17 @@ namespace Umbraco.Core.Services
{
var asArray = memberTypes.ToArray();
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberType>(asArray), this))
using (new WriteLock(Locker))
using (var uow = UowProvider.GetUnitOfWork())
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberType>(asArray), this, uow.EventManager))
return;
using (new WriteLock(Locker))
{
foreach (var contentType in asArray)
{
_memberService.DeleteMembersOfType(contentType.Id);
}
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
{
foreach (var memberType in asArray)

View File

@@ -397,12 +397,13 @@ namespace Umbraco.Core.Services
Save(relationType);
var relation = new Relation(parent.Id, child.Id, relationType);
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this))
return relation;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
{
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this, uow.EventManager))
return relation;
repository.AddOrUpdate(relation);
uow.Commit();
}
@@ -425,12 +426,13 @@ namespace Umbraco.Core.Services
throw new ArgumentNullException(string.Format("No RelationType with Alias '{0}' exists.", relationTypeAlias));
var relation = new Relation(parent.Id, child.Id, relationType);
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this))
return relation;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
{
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this, uow.EventManager))
return relation;
repository.AddOrUpdate(relation);
uow.Commit();
}
@@ -545,12 +547,11 @@ namespace Umbraco.Core.Services
/// <param name="relation">Relation to save</param>
public void Save(IRelation relation)
{
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
{
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this, uow.EventManager))
return;
repository.AddOrUpdate(relation);
uow.Commit();
}
@@ -564,12 +565,11 @@ namespace Umbraco.Core.Services
/// <param name="relationType">RelationType to Save</param>
public void Save(IRelationType relationType)
{
if (SavingRelationType.IsRaisedEventCancelled(new SaveEventArgs<IRelationType>(relationType), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateRelationTypeRepository(uow))
{
if (SavingRelationType.IsRaisedEventCancelled(new SaveEventArgs<IRelationType>(relationType), this, uow.EventManager))
return;
repository.AddOrUpdate(relationType);
uow.Commit();
}
@@ -583,12 +583,11 @@ namespace Umbraco.Core.Services
/// <param name="relation">Relation to Delete</param>
public void Delete(IRelation relation)
{
if (DeletingRelation.IsRaisedEventCancelled(new DeleteEventArgs<IRelation>(relation), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
{
if (DeletingRelation.IsRaisedEventCancelled(new DeleteEventArgs<IRelation>(relation), this, uow.EventManager))
return;
repository.Delete(relation);
uow.Commit();
}
@@ -602,12 +601,11 @@ namespace Umbraco.Core.Services
/// <param name="relationType">RelationType to Delete</param>
public void Delete(IRelationType relationType)
{
if (DeletingRelationType.IsRaisedEventCancelled(new DeleteEventArgs<IRelationType>(relationType), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateRelationTypeRepository(uow))
{
if (DeletingRelationType.IsRaisedEventCancelled(new DeleteEventArgs<IRelationType>(relationType), this, uow.EventManager))
return;
repository.Delete(relationType);
uow.Commit();
}

View File

@@ -162,7 +162,7 @@ namespace Umbraco.Core.Services
public ServiceContext(
RepositoryFactory repositoryFactory,
IScopeUnitOfWorkProvider dbUnitOfWorkProvider,
IUnitOfWorkProvider fileUnitOfWorkProvider,
IScopeUnitOfWorkProvider fileUnitOfWorkProvider,
BasePublishingStrategy publishingStrategy,
CacheHelper cache,
ILogger logger,
@@ -188,7 +188,7 @@ namespace Umbraco.Core.Services
/// </summary>
private void BuildServiceCache(
IScopeUnitOfWorkProvider dbUnitOfWorkProvider,
IUnitOfWorkProvider fileUnitOfWorkProvider,
IScopeUnitOfWorkProvider fileUnitOfWorkProvider,
BasePublishingStrategy publishingStrategy,
CacheHelper cache,
RepositoryFactory repositoryFactory,

View File

@@ -151,7 +151,7 @@ namespace Umbraco.Core.Services
user.AddAllowedSection("content");
user.AddAllowedSection("media");
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(user), this))
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(user), this, uow.EventManager))
return user;
repository.AddOrUpdate(user);
@@ -284,12 +284,11 @@ namespace Umbraco.Core.Services
}
else
{
if (DeletingUser.IsRaisedEventCancelled(new DeleteEventArgs<IUser>(user), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateUserRepository(uow))
{
if (DeletingUser.IsRaisedEventCancelled(new DeleteEventArgs<IUser>(user), this, uow.EventManager))
return;
repository.Delete(user);
uow.Commit();
}
@@ -306,15 +305,14 @@ namespace Umbraco.Core.Services
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
public void Save(IUser entity, bool raiseEvents = true)
{
if (raiseEvents)
{
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(entity), this))
return;
}
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateUserRepository(uow))
{
if (raiseEvents)
{
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(entity), this, uow.EventManager))
return;
}
repository.AddOrUpdate(entity);
try
{
@@ -342,15 +340,14 @@ namespace Umbraco.Core.Services
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
public void Save(IEnumerable<IUser> entities, bool raiseEvents = true)
{
if (raiseEvents)
{
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(entities), this))
return;
}
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateUserRepository(uow))
{
if (raiseEvents)
{
if (SavingUser.IsRaisedEventCancelled(new SaveEventArgs<IUser>(entities), this, uow.EventManager))
return;
}
foreach (var member in entities)
{
repository.AddOrUpdate(member);
@@ -651,15 +648,14 @@ namespace Umbraco.Core.Services
/// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param>
public void SaveUserType(IUserType userType, bool raiseEvents = true)
{
if (raiseEvents)
{
if (SavingUserType.IsRaisedEventCancelled(new SaveEventArgs<IUserType>(userType), this))
return;
}
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
{
if (raiseEvents)
{
if (SavingUserType.IsRaisedEventCancelled(new SaveEventArgs<IUserType>(userType), this, uow.EventManager))
return;
}
repository.AddOrUpdate(userType);
uow.Commit();
}
@@ -674,12 +670,11 @@ namespace Umbraco.Core.Services
/// <param name="userType">UserType to delete</param>
public void DeleteUserType(IUserType userType)
{
if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs<IUserType>(userType), this))
return;
var uow = UowProvider.GetUnitOfWork();
using (var uow = UowProvider.GetUnitOfWork())
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
{
if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs<IUserType>(userType), this, uow.EventManager))
return;
repository.Delete(userType);
uow.Commit();
}

View File

@@ -512,6 +512,7 @@
<Compile Include="Persistence\Repositories\TaskTypeRepository.cs" />
<Compile Include="Persistence\UnitOfWork\IScopeUnitOfWork.cs" />
<Compile Include="Persistence\UnitOfWork\IScopeUnitOfWorkProvider.cs" />
<Compile Include="Persistence\UnitOfWork\ScopeUnitOfWorkProvider.cs" />
<Compile Include="PropertyEditors\DecimalValidator.cs" />
<Compile Include="PropertyEditors\PropertyEditorValueTypes.cs" />
<Compile Include="PropertyEditors\ValueConverters\GridValueConverter.cs" />
@@ -1116,7 +1117,7 @@
<Compile Include="Persistence\UnitOfWork\IUnitOfWork.cs" />
<Compile Include="Persistence\UnitOfWork\IUnitOfWorkProvider.cs" />
<Compile Include="Persistence\UnitOfWork\IUnitOfWorkRepository.cs" />
<Compile Include="Persistence\UnitOfWork\PetaPocoUnitOfWork.cs" />
<Compile Include="Persistence\UnitOfWork\ScopeUnitOfWork.cs" />
<Compile Include="Persistence\UnitOfWork\PetaPocoUnitOfWorkProvider.cs" />
<Compile Include="Profiling\IProfiler.cs" />
<Compile Include="Profiling\LogProfiler.cs" />

View File

@@ -50,9 +50,10 @@ namespace Umbraco.Tests.Persistence
//disable cache
var cacheHelper = CacheHelper.CreateDisabledCacheHelper();
var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, _logger);
var scopeProvider = new ScopeProvider(dbFactory);
var dbContext = new DatabaseContext(
new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, _logger)),
scopeProvider,
_logger, SqlSyntaxProvider, Constants.DatabaseProviders.SqlCe);
var repositoryFactory = new RepositoryFactory(cacheHelper, _logger, SqlSyntaxProvider, SettingsForTests.GenerateMockSettings());
@@ -62,7 +63,7 @@ namespace Umbraco.Tests.Persistence
//assign the db context
dbContext,
//assign the service context
new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(_logger), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, _logger), cacheHelper, _logger, evtMsgs),
new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(scopeProvider), new FileUnitOfWorkProvider(scopeProvider), new PublishingStrategy(evtMsgs, _logger), cacheHelper, _logger, evtMsgs),
cacheHelper,
new ProfilingLogger(_logger, Mock.Of<IProfiler>()))
{

View File

@@ -103,7 +103,7 @@ namespace Umbraco.Tests.TestHelpers
//assign the db context
new DatabaseContext(scopeProvider, Logger, SqlSyntax, GetDbProviderName()),
//assign the service context
new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(scopeProvider), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, Logger), CacheHelper, Logger, evtMsgs),
new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(scopeProvider), new FileUnitOfWorkProvider(scopeProvider), new PublishingStrategy(evtMsgs, Logger), CacheHelper, Logger, evtMsgs),
CacheHelper,
ProfilingLogger)
{

View File

@@ -162,12 +162,14 @@ namespace Umbraco.Tests.TestHelpers
var sqlSyntax = new SqlCeSyntaxProvider();
var repoFactory = new RepositoryFactory(CacheHelper, Logger, sqlSyntax, SettingsForTests.GenerateMockSettings());
var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, Logger);
var scopeProvider = new ScopeProvider(dbFactory);
var evtMsgs = new TransientMessagesFactory();
var applicationContext = new ApplicationContext(
//assign the db context
new DatabaseContext(new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, Logger)), Logger, sqlSyntax, Constants.DatabaseProviders.SqlCe),
new DatabaseContext(scopeProvider, Logger, sqlSyntax, Constants.DatabaseProviders.SqlCe),
//assign the service context
new ServiceContext(repoFactory, new PetaPocoUnitOfWorkProvider(Logger), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, Logger), CacheHelper, Logger, evtMsgs),
new ServiceContext(repoFactory, new PetaPocoUnitOfWorkProvider(scopeProvider), new FileUnitOfWorkProvider(scopeProvider), new PublishingStrategy(evtMsgs, Logger), CacheHelper, Logger, evtMsgs),
CacheHelper,
ProfilingLogger)
{

View File

@@ -96,7 +96,7 @@ namespace Umbraco.Web
return new ServiceContext(
new RepositoryFactory(ApplicationCache, ProfilingLogger.Logger, dbContext.SqlSyntax, UmbracoConfig.For.UmbracoSettings()),
new PetaPocoUnitOfWorkProvider(scopeProvider),
new FileUnitOfWorkProvider(),
new FileUnitOfWorkProvider(scopeProvider),
new PublishingStrategy(evtMsgs, ProfilingLogger.Logger),
ApplicationCache,
ProfilingLogger.Logger,