Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
 public void SetElevatedMode(bool elevatedMode)
 {
     if (!_identityResolver.GetCurrent().IsAdmininistrator())
     {
         throw new System.Security.SecurityException("You have no rights to enter elevated mode");
     }
     if (_elevatedMode != elevatedMode)
     {
         _elevatedMode = elevatedMode;
         var temp = IsElevatedModeChanged;
         if (temp != null)
         {
             temp(this, EventArgs.Empty);
         }
     }
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public static void AddLogEntry(WFInstance obj, string formatString)
        {
            if (!string.IsNullOrEmpty(formatString))
            {
                var      ctx             = obj.Context;
                Identity identity        = null;
                var      currentIdentity = _idResolver.GetCurrent();
                if (currentIdentity != null)
                {
                    identity = ctx.Find <Identity>(currentIdentity.ID);
                }

                var msg = formatString
                          .Replace("{User}", (identity ?? (object)string.Empty).ToString())
                          .Replace("{Date}", DateTime.Today.ToShortDateString())
                          .Replace("{Time}", DateTime.Now.ToShortTimeString());
                Logging.Log.InfoFormat("Adding WF-Logentry: {0}", msg);
                var logEntry = ctx.Create <LogEntry>();
                logEntry.Message  = msg;
                logEntry.Identity = identity;
                obj.LogEntries.Add(logEntry);
            }
        }