/// <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>( UndoableUnitBase <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) { OwnerKey = ownerKey }; OnExecuting(eventArgs); if (eventArgs.Cancel) { return(UnitResult.Cancelled); } redoableDictionary.Remove(ownerKey); if (!repeatableDictionary.TryGetValue(ownerKey, out UnitCollection <IInternalUnit> repeatableUnits)) { repeatableUnits = new UnitCollection <IInternalUnit>(); repeatableDictionary[ownerKey] = repeatableUnits; } repeatableUnits.AddLast(unit); if (!undoableDictionary.TryGetValue(ownerKey, out UnitCollection <IUndoableUnit> undoableUnits)) { undoableUnits = new UnitCollection <IUndoableUnit>(); undoableDictionary[ownerKey] = undoableUnits; } undoableUnits.AddLast(unit); UnitResult result = unit.PerformUnit(argument, UnitMode.FirstTime); TrimIfRequired(ownerKey); OnExecuted(new UndoServiceEventArgs(unit)); return(result); }
UnitResult PerformUnit <T>(UndoableUnitBase <T> unit, T argument) { var eventArgs = new CancellableUndoServiceEventArgs(unit); OnExecuting(eventArgs); if (eventArgs.Cancel) { return(UnitResult.Cancelled); } globallyRedoableUnits.Clear(); globallyRepeatableUnits.AddLast(unit); globallyUndoableUnits.AddLast(unit); UnitResult result = unit.PerformUnit(argument, UnitMode.FirstTime); TrimIfRequired(); OnExecuted(new UndoServiceEventArgs(unit)); return(result); }