public void RemoveStateListener(IStateListener listener)
 {
     lock ( _syncLock )
     {
         _stateListeners.Remove(listener);
     }
 }
Exemple #2
0
 public static void DisposeStateListener(IStateListener Listener)
 {
     if (StateListeners != null)
     {
         StateListeners.Remove(Listener);
     }
 }
Exemple #3
0
 /// <summary>
 /// Add a listener to the state machine messaging.
 /// </summary>
 /// <param name="listener"></param>
 public void AddListener(IStateListener <StateType> listener)
 {
     if (!listeners.Contains(listener))
     {
         listeners.Add(listener);
     }
 }
Exemple #4
0
 public void RemoveListener(IStateListener listener)
 {
     if (listeners.Contains(listener))
     {
         listeners.Remove(listener);
     }
 }
 public void AddStateListener(IStateListener listener)
 {
     _logger.Debug("Adding state listener");
     lock ( _syncLock )
     {
         _stateListeners.Add(listener);
     }
 }
Exemple #6
0
        public void Unsubscribe(IStateListener listener)
        {
            if (_listeners == null)
            {
                return;
            }

            _listeners.RemoveAll(x => x.TryGetTarget(out var target) && target == listener);
        }
Exemple #7
0
        public void Subscribe(IStateListener listener)
        {
            if (_listeners == null)
            {
                _listeners = new List <WeakReference <IStateListener> >();
            }

            _listeners.Add(new WeakReference <IStateListener>(listener));
        }
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (listener == null)
        {
            listener = animator.GetComponent<IStateListener>();
        }

        listener.StateEntered(StateName);
    }
Exemple #9
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void UnregisterDeviceStateListener(IStateListener listener)
        {
            LoggingUtils.PrintFunction();

            lock (m_updateLockMutex)
            {
                m_registeredDeviceStateListeners.Remove(listener);
            }
        }
Exemple #10
0
 public static void RegisterStateListener(IStateListener Listener)
 {
     if (StateListeners == null)
     {
         StateListeners = new List <IStateListener>();
     }
     if (!StateListeners.Contains(Listener))
     {
         StateListeners.Add(Listener);
     }
 }
Exemple #11
0
        private static async Task InvokeListenerOnAfterExecutionState(StateExecutionContext stateExecutionContext,
                                                                      IStateListener stateListener, StateExecutionResult stateExecutionResult, CancellationToken cancellationToken = default)
        {
            if (null == stateListener)
            {
                return;
            }

            Log.Verbose("State has been processed [{state}] listener [after state] [{workflowInstanceID}]",
                        stateExecutionContext.StateConfiguration.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

            try
            {
                await stateListener.AfterExecutionState(stateExecutionContext, stateExecutionResult, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new WorkflowException(string.Format(CultureInfo.InvariantCulture,
                                                          "An error has occurred during execution of an state [{0}] listener [after state] for workflow instance [{1}]",
                                                          stateExecutionContext.StateConfiguration.Code,
                                                          stateExecutionContext.WorkflowContext.WorkflowInstance.Id), ex);
            }
        }
Exemple #12
0
 /// <summary>
 /// Adds a status listener to this recognizer. The status listener is called whenever the status of the recognizer
 /// changes. This method can be called in any state.
 /// </summary>
 /// <param name="stateListener">stateListener the listener to add</param>
 public void AddStateListener(IStateListener stateListener)
 {
     _stateListeners.Add(stateListener);
 }
 public void RemoveStateListener(IStateListener listener)
 {
    lock ( _syncLock )
    {
       _stateListeners.Remove(listener);
    }
 }
 public void AddStateListener(IStateListener listener)
 {
     _logger.Debug("Adding state listener");
     lock ( _syncLock )
     {
        _stateListeners.Add(listener);
     }
 }
Exemple #15
0
 public static void DisposeStateListener(this IStateListener Listener)
 {
     PlayController.DisposeStateListener(Listener);
 }
Exemple #16
0
 public static void RegisterStateListener(this IStateListener Listener)
 {
     PlayController.RegisterStateListener(Listener);
 }
Exemple #17
0
 /// <summary>
 /// Remove a listener from the state machine messaging.
 /// </summary>
 /// <param name="listener"></param>
 public void RemoveListener(IStateListener <StateType> listener)
 {
     listeners.Remove(listener);
 }
Exemple #18
0
        public async Task <StateExecutionResult> Process(StateExecutionContext stateExecutionContext, CancellationToken cancellationToken = default)
        {
            // 1. log starting
            // 2. listener --> before processing
            // 3. run activities
            //    3.1. execute all synchronous activities
            //    3.2. TODO: schedule all asynchronous activities
            // 4. listener --> after activities
            // 5. if state is final --> report and exit
            // 6. evaluate non-delayed transitions
            //    6.1. coded transitions
            //    6.2. compiled conditions
            // 7. schedule all delayed transitions
            // 8. log finishing

            IStateListener       stateListener        = null;
            StateExecutionResult stateExecutionResult = null;
            var workflowInstance = stateExecutionContext.WorkflowContext.WorkflowInstance;

            try
            {
                Log.Verbose("Starting processing state [{type}::{state}] [{workflowInstanceId}]", stateExecutionContext.StateConfiguration.Type,
                            stateExecutionContext.StateConfiguration.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

                workflowInstance.CurrentStateCode     = stateExecutionContext.StateConfiguration.Code;
                workflowInstance.CurrentStateProgress = StateExecutionProgress.Started;
                await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);

                stateListener = GetStateListener(stateExecutionContext.WorkflowContext);
                workflowInstance.CurrentStateProgress = StateExecutionProgress.BeforeActivities;
                await InvokeListenerOnBeforeExecutingState(stateExecutionContext, stateListener, cancellationToken).ConfigureAwait(false);

                var activityExecutionResult = await ExecuteSynchronousActivities(stateExecutionContext, cancellationToken).ConfigureAwait(false);

                if (activityExecutionResult.Status.IsFailed())
                {
                    workflowInstance.CurrentStateProgress = StateExecutionProgress.Completed;

                    if (!string.IsNullOrEmpty(activityExecutionResult.TransitionToUse))
                    {
                        var transitionConfiguration = stateExecutionContext.StateConfiguration.Transitions.FirstOrDefault(tc =>
                                                                                                                          string.Equals(tc.MoveToState, activityExecutionResult.TransitionToUse, StringComparison.OrdinalIgnoreCase));

                        if (null == transitionConfiguration)
                        {
                            throw new WorkflowException(string.Format(CultureInfo.InvariantCulture,
                                                                      "Cannot not find transition [{0}] for failed activity in status [{1}], [workflow ID={2:D}]",
                                                                      activityExecutionResult.TransitionToUse,
                                                                      stateExecutionContext.StateConfiguration.Code,
                                                                      stateExecutionContext.WorkflowContext.WorkflowInstance.Id));
                        }

                        Log.Verbose("[{type}::{state}] has been failed, transitioning to custom {failureState} [{workflowInstanceId}]",
                                    stateExecutionContext.StateConfiguration.Type, stateExecutionContext.StateConfiguration.Code,
                                    transitionConfiguration.MoveToState, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

                        // stateExecutionResult is being used later in the final block
                        stateExecutionResult = new StateExecutionResult(StateExecutionStatus.Failed, new StateExecutionTransition(StateTypeConfiguration.Application, transitionConfiguration));
                        return(stateExecutionResult);
                    }

                    Log.Verbose("[{type}::{state}] has been failed [{workflowInstanceId}]", stateExecutionContext.StateConfiguration.Type,
                                stateExecutionContext.StateConfiguration.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

                    // stateExecutionResult is being used later in the final block
                    stateExecutionResult = new StateExecutionResult(StateExecutionStatus.Failed, new StateExecutionTransition(StateTypeConfiguration.Failed, null));
                    return(stateExecutionResult);
                }

                workflowInstance.CurrentStateProgress = StateExecutionProgress.AfterActivitiesProcessed;
                await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);
                await InvokeListenerOnAfterExecutionActivities(stateExecutionContext, stateListener, cancellationToken).ConfigureAwait(false);

                if (stateExecutionContext.StateConfiguration.Type == StateTypeConfiguration.Failed ||
                    stateExecutionContext.StateConfiguration.Type == StateTypeConfiguration.Final)
                {
                    Log.Verbose("[{type}::{state}] has been completed [{workflowInstanceId}]", stateExecutionContext.StateConfiguration.Type,
                                stateExecutionContext.StateConfiguration.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

                    workflowInstance.CurrentStateProgress = StateExecutionProgress.Completed;
                    await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);

                    // stateExecutionResult is being used later in the final block
                    stateExecutionResult = new StateExecutionResult(StateExecutionStatus.Finished, new StateExecutionTransition(StateTypeConfiguration.Undefined, null));
                    return(stateExecutionResult);
                }

                workflowInstance.CurrentStateProgress = StateExecutionProgress.BeforeTransitions;
                await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);

                var stateExecutionTransition = await EvaluateNonDelayTransitions(stateExecutionContext, cancellationToken).ConfigureAwait(false);

                var delayedStateExecutionTransitions = GetDelayedTransitions(stateExecutionContext);

                if (stateExecutionTransition.NextStateType == StateTypeConfiguration.Undefined && null == delayedStateExecutionTransitions)
                {
                    throw new WorkflowException(string.Format(CultureInfo.InvariantCulture,
                                                              "Cannot evaluate transition(s) for non final state [{0}], [workflow ID={1:D}]",
                                                              stateExecutionContext.StateConfiguration.Code,
                                                              stateExecutionContext.WorkflowContext.WorkflowInstance.Id));
                }

                if (null != delayedStateExecutionTransitions)
                {
                    await ScheduleDelayedTransitions(stateExecutionContext, delayedStateExecutionTransitions, cancellationToken)
                    .ConfigureAwait(false);
                }

                workflowInstance.CurrentStateProgress = StateExecutionProgress.Completed;
                await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);

                stateExecutionResult = new StateExecutionResult(StateExecutionStatus.Completed, stateExecutionTransition);
                return(stateExecutionResult);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "An error has occurred during processing state [{type}::{state}] [{workflowInstanceId}]",
                          stateExecutionContext.StateConfiguration.Type, stateExecutionContext.StateConfiguration.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

                workflowInstance.CurrentStateProgress = StateExecutionProgress.Completed;
                if (stateExecutionContext.StateConfiguration.Type == StateTypeConfiguration.Failed)
                {
                    stateExecutionResult = new StateExecutionResult(StateExecutionStatus.Failed, new StateExecutionTransition(StateTypeConfiguration.Undefined, null));
                    await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);

                    return(stateExecutionResult);
                }

                stateExecutionResult = new StateExecutionResult(StateExecutionStatus.Failed, new StateExecutionTransition(StateTypeConfiguration.Failed, null));
                await _workflowEngine.SaveWorkflowInstance(workflowInstance, cancellationToken).ConfigureAwait(false);

                return(stateExecutionResult);
            }
            finally
            {
                await InvokeListenerOnAfterExecutionState(stateExecutionContext, stateListener, stateExecutionResult, cancellationToken).ConfigureAwait(false);

                Log.Debug("Finished processing state [{type}::{code}], {status}, {nextState} [{workflowInstanceId}]",
                          stateExecutionContext.StateConfiguration.Type, stateExecutionContext.StateConfiguration.Code,
                          stateExecutionResult?.Status, stateExecutionResult?.Transition.TransitionConfiguration?.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);
            }
        }
Exemple #19
0
 public void Subscribe(IStateListener listener)
 {
     _stateListeners.Add(listener);
 }
 public void UnregisterListener(IStateListener listener)
 {
     listeners.Remove(listener);
 }
Exemple #21
0
 public void UnsubscribeStateListener(IStateListener listener)
 {
     _stateListeners.TryRemove(listener);
 }
Exemple #22
0
 public void AddListener(IStateListener listener)
 {
     this.listeners.Add(listener);
 }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public static void UnregisterDeviceStateListener (IStateListener listener)
    {
      LoggingUtils.PrintFunction ();

      lock (m_updateLockMutex)
      {
        m_registeredDeviceStateListeners.Remove (listener);
      }
    }
Exemple #24
0
        private static async Task InvokeListenerOnBeforeExecutingState(StateExecutionContext stateExecutionContext, IStateListener stateListener, CancellationToken cancellationToken = default)
        {
            if (null == stateListener)
            {
                return;
            }

            Log.Verbose("State processing {state} listener [before activities] [{workflowInstanceId}]",
                        stateExecutionContext.StateConfiguration.Code, stateExecutionContext.WorkflowContext.WorkflowInstance.Id);

            try
            {
                await stateListener.BeforeExecutingState(stateExecutionContext, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new WorkflowException(string.Format(CultureInfo.InvariantCulture,
                                                          "An error has occurred during execution of an state [{0}] listener [before activities] for workflow instance [{1}]",
                                                          stateExecutionContext.StateConfiguration.Code,
                                                          stateExecutionContext.WorkflowContext.WorkflowInstance.Id), ex);
            }
        }
Exemple #25
0
 /// <summary>
 /// Removes a previously added state listener. This method can be called in any state.
 /// </summary>
 /// <param name="stateListener">stateListener the state listener to remove</param>
 public void RemoveStateListener(IStateListener stateListener)
 {
     _stateListeners.Remove(stateListener);
 }
Exemple #26
0
 public void SetStateListener(IStateListener stateListener)
 {
     this.stateListener = stateListener;
 }
 public void RegisterListener(IStateListener listener)
 {
     listeners.Add(listener);
 }
Exemple #28
0
 public void RemoveListener(IStateListener listener)
 {
     this.listeners.Remove(listener);
 }
Exemple #29
0
 public void AddStateListener(IStateListener listener)
 {
     stateListeners.Add(listener);
 }
Exemple #30
0
 public void SubscribeStateListener(IStateListener listener)
 {
     _stateListeners.TryAdd(listener);
 }
Exemple #31
0
 public void RemoveStateListener(IStateListener listener)
 {
     stateListeners.Remove(listener);
 }
Exemple #32
0
 public static void AddListener(IStateListener<EventsLogChanged> listener)
 {
     Listeners.Add(listener);
 }
Exemple #33
0
 public static void AddListener(IStateListener <EventsLogChanged> listener)
 {
     Listeners.Add(listener);
 }