Пример #1
0
 public static void Start(WFInstance obj, Zetbox.Basic.Workflow.WFDefinition workflow)
 {
     if (workflow != null)
     {
         Logging.Log.InfoFormat("Starting workflow {0}", workflow.Name);
         obj.Workflow = workflow;
         foreach (var stateDef in workflow.StateDefinitions.Where(s => s.IsStartState))
         {
             StateActions.CreateState(obj, stateDef);
         }
         obj.Recalculate("IsActive");
     }
 }
Пример #2
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();
            }
        }