Esempio n. 1
0
        /// <summary>Executes the specified unit.</summary>
        /// <param name="unit">The command to execute.</param>
        /// <param name="argument">The argument passed to the unit on execution.</param>
        /// <param name="ownerKey">An object identifying the owner of the unit.</param>
        public UnitResult PerformUnit <T>(UnitBase <T> unit, T argument, object ownerKey)
        {
            //AssertArg.IsNotNull(unit, nameof(unit));
            if (unit == null)
            {
                throw new ArgumentNullException(nameof(unit));
            }

            if (ownerKey == null)
            {
                return(PerformUnit(unit, argument));
            }

            var eventArgs = new CancellableUndoServiceEventArgs(unit);

            OnExecuting(eventArgs);

            if (eventArgs.Cancel)
            {
                return(UnitResult.Cancelled);
            }

            /* Clear the undoable units for this context. */
            undoableDictionary.Remove(ownerKey);
            redoableDictionary.Remove(ownerKey);

            if (!repeatableDictionary.TryGetValue(ownerKey,
                                                  out UnitCollection <IInternalUnit> repeatableUnits))
            {
                repeatableUnits = new UnitCollection <IInternalUnit>();
                repeatableDictionary[ownerKey] = repeatableUnits;
            }
            repeatableUnits.AddLast(unit);

            var result = unit.PerformUnit(argument, UnitMode.FirstTime);

            TrimIfRequired(ownerKey);

            OnExecuted(new UndoServiceEventArgs(unit));
            return(result);
        }
Esempio n. 2
0
        UnitResult PerformUnit <T>(UnitBase <T> unit, T argument)
        {
            var eventArgs = new CancellableUndoServiceEventArgs(unit);

            OnExecuting(eventArgs);

            if (eventArgs.Cancel)
            {
                return(UnitResult.Cancelled);
            }

            globallyRedoableUnits.Clear();
            globallyUndoableUnits.Clear();

            globallyRepeatableUnits.AddLast(unit);

            UnitResult result = unit.PerformUnit(argument, UnitMode.FirstTime);

            TrimIfRequired();

            OnExecuted(new UndoServiceEventArgs(unit));
            return(result);
        }