/// <summary> /// Handle container saving events /// </summary> /// <param name="notification"></param> public virtual void Handle(EntityContainerSavedNotification notification) { if (_mutexService.IsPaused) { return; } foreach (var folder in notification.SavedEntities) { if (folder.ContainedObjectType == this.itemObjectType.GetGuid()) { UpdateFolder(folder.Id, Path.Combine(rootFolder, this.DefaultFolder), DefaultConfig); } } }
public Attempt <OperationResult <OperationResultType, EntityContainer> > CreateContainer(int parentId, Guid key, string name, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages eventMessages = EventMessagesFactory.Get(); using (IScope scope = ScopeProvider.CreateScope()) { scope.WriteLock(WriteLockIds); // also for containers try { var container = new EntityContainer(ContainedObjectType) { Name = name, ParentId = parentId, CreatorId = userId, Key = key }; var savingNotification = new EntityContainerSavingNotification(container, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) { scope.Complete(); return(OperationResult.Attempt.Cancel(eventMessages, container)); } _containerRepository.Save(container); scope.Complete(); var savedNotification = new EntityContainerSavedNotification(container, eventMessages); savedNotification.WithStateFrom(savingNotification); scope.Notifications.Publish(savedNotification); // TODO: Audit trail ? return(OperationResult.Attempt.Succeed(eventMessages, container)); } catch (Exception ex) { scope.Complete(); return(OperationResult.Attempt.Fail <OperationResultType, EntityContainer>(OperationResultType.FailedCancelledByEvent, eventMessages, ex)); } } }
public Attempt <OperationResult> SaveContainer(EntityContainer container, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages eventMessages = EventMessagesFactory.Get(); Guid containerObjectType = ContainerObjectType; if (container.ContainerObjectType != containerObjectType) { var ex = new InvalidOperationException("Not a container of the proper type."); return(OperationResult.Attempt.Fail(eventMessages, ex)); } if (container.HasIdentity && container.IsPropertyDirty("ParentId")) { var ex = new InvalidOperationException("Cannot save a container with a modified parent, move the container instead."); return(OperationResult.Attempt.Fail(eventMessages, ex)); } using (IScope scope = ScopeProvider.CreateScope()) { var savingNotification = new EntityContainerSavingNotification(container, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) { scope.Complete(); return(OperationResult.Attempt.Cancel(eventMessages)); } scope.WriteLock(WriteLockIds); // also for containers _containerRepository.Save(container); scope.Complete(); var savedNotification = new EntityContainerSavedNotification(container, eventMessages); savedNotification.WithStateFrom(savingNotification); scope.Notifications.Publish(savedNotification); } // TODO: Audit trail ? return(OperationResult.Attempt.Succeed(eventMessages)); }