diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index b28f4b077a..51628f456a 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -23,81 +23,6 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Services { - // fixme this is some test code, get rid of it all of course - public class SomeService : ScopeRepositoryService - { - // fixme the eventMessagesFactory should die, event messages are scoped! - public SomeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory) - : base(provider, repositoryFactory, logger, eventMessagesFactory) - { } - - public static event TypedEventHandler> StaticDeleting; - - public event TypedEventHandler> InstanceDeleting; - - public void OnStaticDeleting(SomeService sender, DeleteEventArgs args) - { - if (StaticDeleting == null) return; - StaticDeleting(sender, args); - } - - public void OnInstanceDeleting(SomeService sender, DeleteEventArgs args) - { - if (sender.InstanceDeleting == null) return; - sender.InstanceDeleting(sender, args); - } - - public abstract class EventData - { - private readonly TypedEventHandler _eventHandler; - private readonly TSender _sender; - - protected EventData(TypedEventHandler eventHandler, TSender sender) - { - _eventHandler = eventHandler; - _sender = sender; - } - - protected abstract TArgs GetArgs(); - - public void Raise() - { - _eventHandler(_sender, GetArgs()); - } - } - - public class DeletingEvent : EventData> - { - private readonly IContent _content; - - public DeletingEvent(TypedEventHandler> eventHandler, SomeService sender, IContent content) - : base(eventHandler, sender) - { - _content = content; - } - - protected override DeleteEventArgs GetArgs() - { - return new DeleteEventArgs(_content); - } - - // and *there* we could implement some sort of proper comparison between events! - // Shan's EventDefinition only works on names and that's a true mess - } - - public void Dispatch(EventData eventData) - { - eventData.Raise(); - } - - public void DoSomething() - { - IContent content = null; - Dispatch(new DeletingEvent(StaticDeleting, this, content)); - Dispatch(new DeletingEvent(InstanceDeleting, this, content)); - } - } - /// /// Represents the Content Service, which is an easy access to operations involving /// @@ -123,7 +48,7 @@ namespace Umbraco.Core.Services { if (dataTypeService == null) throw new ArgumentNullException("dataTypeService"); if (userService == null) throw new ArgumentNullException("userService"); - _publishingStrategy = new PublishingStrategy(logger); + _publishingStrategy = new PublishingStrategy(eventMessagesFactory, logger); _dataTypeService = dataTypeService; _userService = userService; } @@ -1088,7 +1013,7 @@ namespace Umbraco.Core.Services //see: http://issues.umbraco.org/issue/U4-9336 content.EnsureValidPath(Logger, entity => GetById(entity.ParentId), QuickUpdate); var originalPath = content.Path; - if (uow.Events.DispatchCancelable(Trashing, this, new MoveEventArgs(evtMsgs, new MoveEventInfo(content, originalPath, Constants.System.RecycleBinContent)))) + if (uow.Events.DispatchCancelable(Trashing, this, new MoveEventArgs(evtMsgs, new MoveEventInfo(content, originalPath, Constants.System.RecycleBinContent)), "Trashing")) { return OperationStatus.Cancelled(evtMsgs); } @@ -1123,15 +1048,13 @@ namespace Umbraco.Core.Services descendant.ChangeTrashedState(true, descendant.ParentId); repository.AddOrUpdate(descendant); } - // fixme NEED to happen within the transaction = this is a DISPATCHED event! - //uow.Events.Dispatch(Trashed, Event.User|Event.Commit, this, new MoveEventArgs(false, uow.Messages, moveInfo.ToArray())); - uow.Events.Dispatch(Trashed, this, new MoveEventArgs(false, uow.Messages, moveInfo.ToArray())); - uow.Events.Dispatch(Trashed, this, new MoveEventArgs(false, evtMsgs, moveInfo.ToArray()), "Trashed"); // fixme WHY the event name?! + + uow.Commit(); + + uow.Events.Dispatch(Trashed, this, new MoveEventArgs(false, evtMsgs, moveInfo.ToArray()), "Trashed"); // fixme just writing to DB, no need for an event, ok here Audit(AuditType.Move, "Move Content to Recycle Bin performed by user", userId, content.Id); - - uow.Commit(); } // fixme the WHOLE thing should move to the UOW! @@ -1610,7 +1533,7 @@ namespace Umbraco.Core.Services // what a spectacular mess using (IScope scope = UowProvider.ScopeProvider.CreateScope()) { - if (scope.Events.DispatchCancelable(Moving, this, new MoveEventArgs(new MoveEventInfo(content, content.Path, parentId)))) + if (scope.Events.DispatchCancelable(Moving, this, new MoveEventArgs(new MoveEventInfo(content, content.Path, parentId)), "Moving")) return; //used to track all the moved entities to be given to the event @@ -1619,32 +1542,11 @@ namespace Umbraco.Core.Services //call private method that does the recursive moving PerformMove(content, parentId, userId, moveInfo); - scope.Events.Dispatch(Moved, this, new MoveEventArgs(false, moveInfo.ToArray())); + scope.Events.Dispatch(Moved, this, new MoveEventArgs(false, moveInfo.ToArray()), "Moved"); scope.Complete(); } - // fixme kill this - /* - using (var uow = UowProvider.GetUnitOfWork()) - { - if (Moving.IsRaisedEventCancelled( - new MoveEventArgs( - new MoveEventInfo(content, content.Path, parentId)), this, uow.Events)) - { - return; - } - - //used to track all the moved entities to be given to the event - var moveInfo = new List>(); - - //call private method that does the recursive moving - PerformMove(content, parentId, userId, moveInfo); - - Moved.RaiseEvent(new MoveEventArgs(false, moveInfo.ToArray()), this, uow.Events); - } - */ - Audit(AuditType.Move, "Move Content performed by user", userId, content.Id); } } diff --git a/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs b/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs index 301af78017..68d4791377 100644 --- a/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs +++ b/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.Publishing ServiceContext.ContentTypeService.GetContentType("umbTextpage"), "Sub Sub Sub", mandatorContent.Id); ServiceContext.ContentService.Save(subContent, 0); - IPublishingStrategy2 strategy = new PublishingStrategy(Logger); + IPublishingStrategy2 strategy = new PublishingStrategy(new TransientMessagesFactory(), Logger); //publish root and nodes at it's children level var listToPublish = ServiceContext.ContentService.GetDescendants(_homePage.Id).Concat(new[] { _homePage }); @@ -97,7 +97,7 @@ namespace Umbraco.Tests.Publishing { CreateTestData(); - IPublishingStrategy2 strategy = new PublishingStrategy( Logger); + IPublishingStrategy2 strategy = new PublishingStrategy(new TransientMessagesFactory(), Logger); PublishingStrategy.Publishing +=PublishingStrategyPublishing; @@ -124,7 +124,7 @@ namespace Umbraco.Tests.Publishing { CreateTestData(); - IPublishingStrategy2 strategy = new PublishingStrategy(Logger); + IPublishingStrategy2 strategy = new PublishingStrategy(new TransientMessagesFactory(), Logger); //publish root and nodes at it's children level var result1 = strategy.Publish(_unitOfWork, _homePage, 0); @@ -151,7 +151,7 @@ namespace Umbraco.Tests.Publishing { CreateTestData(); - IPublishingStrategy2 strategy = new PublishingStrategy(Logger); + IPublishingStrategy2 strategy = new PublishingStrategy(new TransientMessagesFactory(), Logger); //publish root and nodes at it's children level var result1 = strategy.Publish(_unitOfWork, _homePage, 0);