Exemple #1
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;
            }
        }
Exemple #2
0
 public void OnHandleToken(ActionToken actionToken)
 {
     RunningActions.ForEach(action =>
     {
         if (action.Token == actionToken)
         {
             ActionCaseConsumer.Add(action);
         }
         return(false);
     });
 }
Exemple #3
0
 public void Cancel(Type actionType)
 {
     RunningActions.ForEach(type =>
     {
         if (type.GetType() == actionType)
         {
             type.Token.SetCancelling();
             ActionCaseConsumer.Add(type);
         }
         return(false);
     });
 }
Exemple #4
0
 public void TokenExpired(ActionToken actionToken)
 {
     RunningActions.ForEach(action =>
     {
         if (action.Token == actionToken)
         {
             action.Token.SetExpiring();
             ActionCaseConsumer.Add(action);
         }
         return(false);
     });
 }
Exemple #5
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);
         });
     }
 }
Exemple #6
0
 private void TryHandleDataFrame(CustomDataFrame actionCase, List <ActionHandlerResult> ahResults)
 {
     lock (_actionStateLock)
     {
         RunningActions.ForEach(x =>
         {
             if (!actionCase.IsHandled)
             {
                 var ahr = x.TryHandle(actionCase);
                 if (ahr != null)
                 {
                     ahResults.Add(ahr);
                 }
             }
             return(false);
         });
     }
 }
Exemple #7
0
        private void HandleActionCaseInner(IActionCase actionCase)
        {
            var customDataFrame = actionCase as CustomDataFrame;
            var timeInterval    = actionCase as TimeInterval;
            var action          = actionCase as ActionBase;

            if (customDataFrame != null)
            {
                CustomDataFrame dataFrameOri = customDataFrame;
                var             ahResults    = new List <ActionHandlerResult>();
                Dictionary <SubstituteIncomingFlags, CustomDataFrame> substitutedDataFrames = new Dictionary <SubstituteIncomingFlags, CustomDataFrame>();
                var dataFrame = SubstituteIncoming(dataFrameOri, ahResults, substitutedDataFrames);
                if (dataFrame != null)
                {
                    TryHandleDataFrame(dataFrame, ahResults);
                    if (dataFrame.Parent != null)
                    {
                        TryHandleDataFrame(dataFrame.Parent, ahResults);
                    }
                    ProcessSubstituteManagers(dataFrame, ahResults, substitutedDataFrames);
                    foreach (var ahResult in ahResults)
                    {
                        ProcessNext(ahResult);
                        if (ahResult.Parent != null)
                        {
                            ProcessCompleted(ahResult.Parent);
                        }
                    }
                }
            }
            else if (timeInterval != null)
            {
                if (timeInterval.ParentAction != null)
                {
                    ProcessNext(timeInterval.ParentAction.TryHandle(actionCase));
                    if (timeInterval.ParentAction != null)
                    {
                        ProcessCompleted(timeInterval.ParentAction);
                    }
                }
            }
            else if (action != null)
            {
                if (action.Token.IsStateFinished)
                {
                    ProcessCompleted(action);
                    if (action.IsExclusive)
                    {
                        _isExclusiveBusy = false;
                        var pendingAction = PendingExclusiveActions.Dequeue();
                        if (pendingAction != null)
                        {
                            _actionCaseConsumer.Add(pendingAction);
                        }
                    }
                    RunningActions.ForEach(x =>
                    {
                        if (x.ParentAction == action)
                        {
                            if (x.ParentAction.Token.State == ActionStates.Expired || x.ParentAction.Token.State == ActionStates.Cancelled)
                            {
                                x.Token.SetCancelling();
                                var ahResult = x.TryHandleStopped();
                                ProcessNext(ahResult);
                                x.Token.SetCancelled();
                                ProcessCompleted(x);
                            }
                            else
                            {
                                x.Token.SetCancelled();
                                ProcessCompleted(x);
                            }
                        }
                        return(false);
                    });
                    if (action.ParentAction != null && action.ParentAction.Token.IsStateActive)
                    {
                        var ahResult = action.ParentAction.TryHandle(action);
                        ProcessNext(ahResult);
                        action.ParentAction.FixStates();
                        ProcessCompleted(action.ParentAction);
                    }
                }
                else
                {
                    if (action.Token.State == ActionStates.None)
                    {
                        var actionStartSignal = action.Token.StartSignal;
                        action.SessionId = SessionId;
                        if (action.IsSequenceNumberRequired)
                        {
                            action.SequenceNumber = NextFuncId();
                        }
                        action = SubstituteAction(action);
                        if (action.IsExclusive)
                        {
                            if (!SuppressDebugOutput)
                            {
                                "{0:X2} (W){1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe());
                            }
                            if (_isExclusiveBusy)
                            {
                                PendingExclusiveActions.Enqueue(action);
                                return;
                            }
                            else
                            {
                                _isExclusiveBusy = true;
                            }
                            //CheckPoint.Pass(action);
                        }

                        var ahResult = action.Start();

                        if (_actionChangeCallback != null)
                        {
                            _actionChangeCallback(action.Token);
                        }

                        if (action.IsFirstPriority)
                        {
                            RunningActions.AddFirst(action);
                        }
                        else
                        {
                            RunningActions.AddLast(action);
                        }
                        if (!SuppressDebugOutput)
                        {
                            "{0:X2} {1}"._DLOG(SessionId, action.GetName() + action.AboutMeSafe());
                        }

                        ProcessNext(ahResult);
                        if (action.Token.TimeoutMs > 0)
                        {
                            TimeoutManager.AddTimer(action.Token);
                        }
                        if (actionStartSignal != null && !isDisposing)
                        {
                            actionStartSignal.Set();
                        }
                    }
                    else if (action.Token.Result.State == ActionStates.Cancelling)
                    {
                        var ahResult = action.TryHandleStopped();
                        ProcessNext(ahResult);
                    }
                    else if (action.Token.Result.State == ActionStates.Expiring)
                    {
                        var ahResult = action.TryHandleStopped();
                        ProcessNext(ahResult);
                    }
                    action.FixStates();
                    ProcessCompleted(action);
                }
            }
        }