Esempio n. 1
0
        public ActionToken ExecuteAsync(IActionItem actionCase)
        {
            var         action = actionCase as ActionBase;
            ActionToken ret    = null;

            if (action != null)
            {
                if (!SuppressDebugOutput)
                {
                    "{0:X2} (E){1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe());
                }
                if (action.Token != null)
                {
                    action.Token.HandleMe = (x) => OnHandleToken(x);
                    action.Token.LogEntryPointClassLineNumber = GetLineNumberInTheEntryPointClass(LogEntryPointClass);
                    action.Token.StartSignal = _actionStartSignal;
                }
                ret = action.Token;
                ActionCaseConsumer.Add(action);
                if (!isDisposing)
                {
                    //_actionStartSignal.WaitOne(1000);
                    if (!SuppressDebugOutput)
                    {
                        "{0:X2} (R){1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe());
                    }
                }
            }
            return(ret);
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    isDisposing = true;
                    // TODO: dispose managed state (managed objects).
                    _actionStartSignal.Set();
                    _actionStartSignal.Close();
                    CallbackBufferBlock.Stop();
                    TimeoutManager.Stop();
                    ActionCaseConsumer.Stop();
                    RunningActions.ForEach(action =>
                    {
                        action.Token.SetCancelled();
                        action.Token.SetCompletedSignal();
                        return(false);
                    });
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Esempio n. 3
0
 public void OnHandleToken(ActionToken actionToken)
 {
     RunningActions.ForEach(action =>
     {
         if (action.Token == actionToken)
         {
             ActionCaseConsumer.Add(action);
         }
         return(false);
     });
 }
Esempio n. 4
0
 public void RunComponents()
 {
     TimeoutManager.Start(this);
     CallbackBufferBlock.Start("CallbackBufferBlock", action =>
     {
         if (action.CompletedCallback != null)
         {
             action.CompletedCallback(action);
         }
     });
     ActionCaseConsumer.Start("ActionCaseConsumer", HandleActionCaseInner);
 }
Esempio n. 5
0
 public void Cancel(Type actionType)
 {
     RunningActions.ForEach(type =>
     {
         if (type.GetType() == actionType)
         {
             type.Token.SetCancelling();
             ActionCaseConsumer.Add(type);
         }
         return(false);
     });
 }
Esempio n. 6
0
 public void TokenExpired(ActionToken actionToken)
 {
     RunningActions.ForEach(action =>
     {
         if (action.Token == actionToken)
         {
             action.Token.SetExpiring();
             ActionCaseConsumer.Add(action);
         }
         return(false);
     });
 }
Esempio n. 7
0
 public void Cancel(ActionToken actionToken)
 {
     if (actionToken != null && !actionToken.IsStateFinished)
     {
         RunningActions.ForEach(action =>
         {
             if (action.Token == actionToken)
             {
                 action.Token.SetCancelling();
                 ActionCaseConsumer.Add(action);
             }
             return(false);
         });
     }
 }
Esempio n. 8
0
        public void HandleActionCase(IActionCase actionCase)
        {
            var dataFrame    = actionCase as CustomDataFrame;
            var timeInterval = actionCase as TimeInterval;

            if (dataFrame != null && !dataFrame.IsOutcome && !dataFrame.IsHandled)
            {
                if (IsHandleFrameEnabled)
                {
                    ActionCaseConsumer.Add(dataFrame);
                }
            }

            if (timeInterval != null && !timeInterval.IsHandled)
            {
                ActionCaseConsumer.Add(timeInterval);
            }
        }
Esempio n. 9
0
        public void ProcessNext(ActionHandlerResult ahResult)
        {
            if (ahResult != null && ahResult.NextActions != null)
            {
                var sendFrames    = ahResult.NextActions.Where(x => x is CommandMessage);
                var timeIntervals = ahResult.NextActions.Where(x => x is TimeInterval);
                var actions       = ahResult.NextActions.Where(x => x is ActionBase);
                if (sendFrames.Any())
                {
                    if (SendFramesCallback != null)
                    {
                        var isTransmitted = SendFramesCallback(ahResult);
                        if (isTransmitted)
                        {
                            ahResult.Parent.FixStates();
                        }
                        else
                        {
                            ahResult.Parent.Token.SetFailed();
                        }
                        if (ahResult.Parent.Token.IsStateFinished)
                        {
                            ActionCaseConsumer.Add(ahResult.Parent);
                        }
                    }
                }

                if (timeIntervals.Any())
                {
                    foreach (TimeInterval item in timeIntervals)
                    {
                        TimeoutManager.AddTimer(item);
                    }
                }

                if (actions.Any())
                {
                    foreach (ActionBase item in actions)
                    {
                        ActionCaseConsumer.Add(item);
                    }
                }
            }
        }
Esempio n. 10
0
        private void ProcessCompleted(ActionBase action)
        {
            if (action.Token.IsStateFinished)
            {
                if (RunningActions.Remove(action))
                {
                    action.Token.Name = action.Name + ": " + action.AboutMeSafe();
                    if (_actionChangeCallback != null)
                    {
                        _actionChangeCallback(action.Token);
                    }

                    action.Token.SetCompletedSignal();
                    if (!SuppressDebugOutput)
                    {
                        "{0:X2} {1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe());
                    }
                    CallbackBufferBlock.Add(action);
                    ActionCaseConsumer.Add(action);
                }
            }
        }