Exemple #1
0
        public Attempt <OperationResult <MoveOperationStatusType> > Move(IDataType toMove, int parentId)
        {
            var evtMsgs  = EventMessagesFactory.Get();
            var moveInfo = new List <MoveEventInfo <IDataType> >();

            using (var scope = ScopeProvider.CreateScope())
            {
                var moveEventInfo = new MoveEventInfo <IDataType>(toMove, toMove.Path, parentId);

                var movingDataTypeNotification = new DataTypeMovingNotification(moveEventInfo, evtMsgs);
                if (scope.Notifications.PublishCancelable(movingDataTypeNotification))
                {
                    scope.Complete();
                    return(OperationResult.Attempt.Fail(MoveOperationStatusType.FailedCancelledByEvent, evtMsgs));
                }

                try
                {
                    EntityContainer container = null;
                    if (parentId > 0)
                    {
                        container = _dataTypeContainerRepository.Get(parentId);
                        if (container == null)
                        {
                            throw new DataOperationException <MoveOperationStatusType>(MoveOperationStatusType.FailedParentNotFound); // causes rollback
                        }
                    }
                    moveInfo.AddRange(_dataTypeRepository.Move(toMove, container));

                    scope.Notifications.Publish(new DataTypeMovedNotification(moveEventInfo, evtMsgs).WithStateFrom(movingDataTypeNotification));

                    scope.Complete();
                }
                catch (DataOperationException <MoveOperationStatusType> ex)
                {
                    scope.Complete(); // TODO: what are we doing here exactly?
                    return(OperationResult.Attempt.Fail(ex.Operation, evtMsgs));
                }
            }

            return(OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, evtMsgs));
        }
Exemple #2
0
        public Attempt <OperationResult <MoveOperationStatusType> > Move(IDataType toMove, int parentId)
        {
            var evtMsgs  = EventMessagesFactory.Get();
            var moveInfo = new List <MoveEventInfo <IDataType> >();

            using (var scope = ScopeProvider.CreateScope())
            {
                var moveEventInfo = new MoveEventInfo <IDataType>(toMove, toMove.Path, parentId);
                var moveEventArgs = new MoveEventArgs <IDataType>(evtMsgs, moveEventInfo);
                if (scope.Events.DispatchCancelable(Moving, this, moveEventArgs))
                {
                    scope.Complete();
                    return(OperationResult.Attempt.Fail(MoveOperationStatusType.FailedCancelledByEvent, evtMsgs));
                }

                try
                {
                    EntityContainer container = null;
                    if (parentId > 0)
                    {
                        container = _dataTypeContainerRepository.Get(parentId);
                        if (container == null)
                        {
                            throw new DataOperationException <MoveOperationStatusType>(MoveOperationStatusType.FailedParentNotFound); // causes rollback
                        }
                    }
                    moveInfo.AddRange(_dataTypeRepository.Move(toMove, container));

                    moveEventArgs.MoveInfoCollection = moveInfo;
                    moveEventArgs.CanCancel          = false;
                    scope.Events.Dispatch(Moved, this, moveEventArgs);
                    scope.Complete();
                }
                catch (DataOperationException <MoveOperationStatusType> ex)
                {
                    scope.Complete(); // fixme what are we doing here exactly?
                    return(OperationResult.Attempt.Fail(ex.Operation, evtMsgs));
                }
            }

            return(OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, evtMsgs));
        }