示例#1
0
        public static void Execute(StateChangeDefinition obj, Zetbox.Basic.Workflow.State current)
        {
            var identity = _idResolver.GetCurrent();

            Logging.Log.InfoFormat("Executing workflow StateChange [{0}].{1}", current, obj.Name);

            var nextStates = obj.NextStates.ToList();

            // call invocation
            if (_invocationExec.HasValidInvocation(obj))
            {
                Logging.Log.DebugFormat("  calling invocation [{0}].{1}", obj.ImplementorName, obj.MemberName);
                nextStates = _invocationExec.CallInvocation <List <StateDefinition> >(obj, typeof(StateChangeInvocationPrototype), obj, current, identity);
            }

            Logging.Log.InfoFormat("  nextStates.Count = {0}", nextStates.Count);

            var stateEnds = true;

            if (nextStates == null || nextStates.Count == 0)
            {
                // workflow branch ends here
                Logging.Log.Info("No next states, workflow will end");
            }
            else
            {
                // change current state
                foreach (var stateDef in nextStates)
                {
                    if (stateDef == current.StateDefinition)
                    {
                        Logging.Log.Info("Staying in current state");
                        stateEnds = false;
                    }
                    else
                    {
                        StateActions.CreateState(current.Instance, stateDef);
                    }
                }
            }

            // set on left
            if (stateEnds)
            {
                current.LeftOn = DateTime.Now;
                current.Persons.Clear();
                current.Groups.Clear();
                current.ScheduledActions.Clear();
            }
        }
示例#2
0
        public static void Execute(Action obj, ParameterizedActionDefinition paramedAction, State current)
        {
            if (current == null)
            {
                throw new ArgumentException("current");
            }
            var identity = _idResolver.GetCurrent();

            Logging.Log.InfoFormat("Executing workflow action [{0}].{1}", current, obj.Name);

            // call invocation
            if (_invocationExec.HasValidInvocation(obj))
            {
                Logging.Log.DebugFormat("  calling invocation [{0}].{1}", obj.ImplementorName, obj.MemberName);
                var result = _invocationExec.CallInvocation <bool>(obj, typeof(ActionInvocationPrototype), obj, paramedAction, current, identity);
                if (result == false)
                {
                    Logging.Log.Info("  -> returned false, exiting");
                    return;
                }
            }

            // Add logfile entry
            current.Instance.AddLogEntry(obj.LogMessageFormat);

            // find and execute state change
            var stateChangeList = current.StateDefinition.StateChanges.Where(sc => sc.InvokedByActions.Contains(paramedAction)).ToList();

            if (stateChangeList.Count == 0)
            {
                // Action does not invoke a state change
            }
            else if (stateChangeList.Count > 1)
            {
                // this is an error
                throw new NotSupportedException(string.Format("Action {0} invokes more than one state change logic. This is not supported", obj));
            }
            else
            {
                var stateChange = stateChangeList.Single();
                stateChange.Execute(current);
            }
        }