public virtual void Execute(IPropertyCommand <string, string> command) { if (null == command.GetState() && null == command.Content) { command.SetState("SHIP_GRP_CREATED"); return; } if ("SHIP_GRP_CREATED" == command.GetState() && "Approve" == command.Content) { command.SetState("SHIP_GRP_APPROVED"); return; } if ("SHIP_GRP_APPROVED" == command.GetState() && "Complete" == command.Content) { command.SetState("SHIP_GRP_COMPLETED"); return; } if ("SHIP_GRP_CREATED" == command.GetState() && "Reject" == command.Content) { command.SetState("SHIP_GRP_REJECTED"); return; } if ("SHIP_GRP_CREATED" == command.GetState() && "Cancel" == command.Content) { command.SetState("SHIP_GRP_CANCELLED"); return; } throw new ArgumentException(String.Format("State: {0}, command: {1}", command.GetState, command.Content)); }
public virtual void Execute(IPropertyCommand <string, string> command) { if (null == command.GetState() && null == command.Content) { command.SetState("Drafted"); return; } if ("Drafted" == command.GetState() && "Complete" == command.Content) { command.SetState("Completed"); return; } if ("Drafted" == command.GetState() && "Void" == command.Content) { command.SetState("Voided"); return; } if ("Completed" == command.GetState() && "Close" == command.Content) { command.SetState("Closed"); return; } if ("Completed" == command.GetState() && "Reverse" == command.Content) { command.SetState("Reversed"); return; } throw new ArgumentException(String.Format("State: {0}, command: {1}", command.GetState, command.Content)); }
public void Execute(IPropertyCommand <DocumentAction, string> command) { var currentState = command.GetState(); var trigger = command.Content != null ? command.Content.Name : null; if (command.OuterCommandType == CommandType.Create) { if (String.IsNullOrWhiteSpace(currentState)) { currentState = DocumentStatus.Initial; } if (trigger == null) { trigger = DocumentActionName.Draft; } } //TODO 这样才是线程安全的,但是效率不高,需要改进: var stateMachine = BuildStateMachine(() => currentState, command.SetState); stateMachine.Fire(trigger); //_currentDocumentStatus = currentState; //_stateMachine.Fire(trigger); //command.SetState(_currentDocumentStatus); }
public void Execute(IPropertyCommand <string, string> command) { var currentState = command.GetState(); var trigger = command.Content; if (command.OuterCommandType == CommandType.Create) { if (String.IsNullOrWhiteSpace(currentState)) { currentState = DocumentStatusIds.Initial; } if (trigger == null) { trigger = DocumentAction.Draft; } } var stateMachine = BuildStateMachine(() => currentState, command.SetState); stateMachine.Fire(trigger); }
public virtual void Execute(IPropertyCommand <string, string> command) { if (null == command.GetState() && null == command.Content) { command.SetState("Drafted"); return; } if ("Drafted" == command.GetState() && "Void" == command.Content) { command.SetState("Voided"); return; } if ("Drafted" == command.GetState() && "Complete" == command.Content && ((IMovementState)command.Context).IsInTransit == false) { command.SetState("Completed"); return; } if ("Drafted" == command.GetState() && "Complete" == command.Content && ((IMovementState)command.Context).IsInTransit == true) { command.SetState("InProgress"); return; } if ("InProgress" == command.GetState() && "Confirm" == command.Content) { command.SetState("Complete"); return; } if ("Completed" == command.GetState() && "Close" == command.Content) { command.SetState("Closed"); return; } if ("Completed" == command.GetState() && "Reverse" == command.Content && ((IMovementState)command.Context).IsInTransit == false) { command.SetState("Reversed"); return; } throw new ArgumentException(String.Format("State: {0}, command: {1}", command.GetState, command.Content)); }