public void RemoveStateListener(IStateListener listener) { lock ( _syncLock ) { _stateListeners.Remove(listener); } }
public static void DisposeStateListener(IStateListener Listener) { if (StateListeners != null) { StateListeners.Remove(Listener); } }
/// <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); } }
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); } }
public void Unsubscribe(IStateListener listener) { if (_listeners == null) { return; } _listeners.RemoveAll(x => x.TryGetTarget(out var target) && target == listener); }
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); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void UnregisterDeviceStateListener(IStateListener listener) { LoggingUtils.PrintFunction(); lock (m_updateLockMutex) { m_registeredDeviceStateListeners.Remove(listener); } }
public static void RegisterStateListener(IStateListener Listener) { if (StateListeners == null) { StateListeners = new List <IStateListener>(); } if (!StateListeners.Contains(Listener)) { StateListeners.Add(Listener); } }
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); } }
/// <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 static void DisposeStateListener(this IStateListener Listener) { PlayController.DisposeStateListener(Listener); }
public static void RegisterStateListener(this IStateListener Listener) { PlayController.RegisterStateListener(Listener); }
/// <summary> /// Remove a listener from the state machine messaging. /// </summary> /// <param name="listener"></param> public void RemoveListener(IStateListener <StateType> listener) { listeners.Remove(listener); }
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); } }
public void Subscribe(IStateListener listener) { _stateListeners.Add(listener); }
public void UnregisterListener(IStateListener listener) { listeners.Remove(listener); }
public void UnsubscribeStateListener(IStateListener listener) { _stateListeners.TryRemove(listener); }
public void AddListener(IStateListener listener) { this.listeners.Add(listener); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void UnregisterDeviceStateListener (IStateListener listener) { LoggingUtils.PrintFunction (); lock (m_updateLockMutex) { m_registeredDeviceStateListeners.Remove (listener); } }
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); } }
/// <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); }
public void SetStateListener(IStateListener stateListener) { this.stateListener = stateListener; }
public void RegisterListener(IStateListener listener) { listeners.Add(listener); }
public void RemoveListener(IStateListener listener) { this.listeners.Remove(listener); }
public void AddStateListener(IStateListener listener) { stateListeners.Add(listener); }
public void SubscribeStateListener(IStateListener listener) { _stateListeners.TryAdd(listener); }
public void RemoveStateListener(IStateListener listener) { stateListeners.Remove(listener); }
public static void AddListener(IStateListener<EventsLogChanged> listener) { Listeners.Add(listener); }
public static void AddListener(IStateListener <EventsLogChanged> listener) { Listeners.Add(listener); }