示例#1
0
 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));
 }
示例#2
0
 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);
        }
        private static void _initializeTypeProperties(Type type, Dictionary <string, IPropertyCommand> list)
        {
            // Load the IPropertyCommands from the parent Type
            Type parent = type.BaseType;

            if (parent != typeof(System.Object))
            {
                foreach (KeyValuePair <string, IPropertyCommand> item in _getTypePropertyMap(parent))
                {
                    list.Add(item.Key, item.Value);
                }
                parent = parent.BaseType;
            }

            foreach (Type nestType in type.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public))
            {
#if !(XBOX || XBOX360)
                if (nestType.FindInterfaces(delegate(Type typeObj, Object criteriaObj)
                {
                    if (typeObj.ToString() == criteriaObj.ToString())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                                            , typeof(IPropertyCommand).FullName).Length != 0)
                {
                    foreach (ScriptablePropertyAttribute attr in nestType.GetCustomAttributes(typeof(ScriptablePropertyAttribute), true))
                    {
                        IPropertyCommand propertyCommand = (IPropertyCommand)Activator.CreateInstance(nestType);
                        list.Add(attr.ScriptPropertyName, propertyCommand);
                    }
                }
#else
                foreach (Type iface in nestType.GetInterfaces())
                {
                    if (iface.FullName == typeof(IPropertyCommand).FullName)
                    {
                        foreach (ScriptablePropertyAttribute attr in nestType.GetCustomAttributes(typeof(ScriptablePropertyAttribute), true))
                        {
                            IPropertyCommand propertyCommand = (IPropertyCommand)Activator.CreateInstance(nestType);
                            list.Add(attr.ScriptPropertyName, propertyCommand);
                        }
                    }
                }
#endif
            }
        }
        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);
        }
示例#6
0
 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));
 }
 public PropertyController(IPropertyQuery propertyQuery, IPropertyCommand propertyCommand)
 {
     this.propertyQuery   = propertyQuery;
     this.propertyCommand = propertyCommand;
 }