コード例 #1
0
        public override bool WaitingFor(IActionCase actionCase)
        {
            bool ret = false;

            if (actionCase is TimeInterval)
            {
                TimeInterval receivedValue = (TimeInterval)actionCase;
                if (Id == receivedValue.Id)
                {
                    ret = true;
                }
            }
            return(ret);
        }
コード例 #2
0
        public override bool WaitingFor(IActionCase actionCase)
        {
            bool ret = false;

            if (actionCase is ActionBase)
            {
                ActionBase receivedValue = (ActionBase)actionCase;
                if (ActionId == receivedValue.Id)
                {
                    Action = receivedValue;
                    ret    = true;
                }
            }
            return(ret);
        }
コード例 #3
0
ファイル: SessionClient.cs プロジェクト: jimzrt/hyper
        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);
            }
        }
コード例 #4
0
        internal ActionHandlerResult TryHandle(IActionCase actionCase)
        {
            ActionHandlerResult ret = null;

            if (Token.IsStateActive)
            {
                if (ActionUnits.Count > 0)
                {
                    ActionUnit ou = ActionUnits.FirstOrDefault(x => x.TryHandle(actionCase));
                    ret = Handle(ou);
                    if (ou != null && ou.TimeoutMs > 0)
                    {
                        Token.Reset(ou.TimeoutMs);
                    }
                }
            }
            return(ret);
        }
コード例 #5
0
ファイル: CommandHandler.cs プロジェクト: jimzrt/hyper
        public override bool WaitingFor(IActionCase actionCase)
        {
            bool ret = false;

            if (actionCase is CustomDataFrame)
            {
                CustomDataFrame receivedValue = (CustomDataFrame)actionCase;
                if (Substituted == BoolFlag.NotSpecified ||
                    Substituted == BoolFlag.True && receivedValue.IsSubstituted ||
                    Substituted == BoolFlag.False && !receivedValue.IsSubstituted)
                {
                    byte[] payload = receivedValue.Data;
                    ret = IsExpectedData(payload);
                    if (ret)
                    {
                        DataFrame = receivedValue;
                    }
                }
            }
            //"{0}: {1} - {2}"._DLOG(ret, actionCase.ToString(), mMask.GetHex());
            return(ret);
        }
コード例 #6
0
ファイル: ActionHandler.cs プロジェクト: jimzrt/hyper
 public virtual bool WaitingFor(IActionCase actionCase)
 {
     return(false);
 }
コード例 #7
0
ファイル: SessionClient.cs プロジェクト: jimzrt/hyper
        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);
                }
            }
        }
コード例 #8
0
 public virtual bool TryHandle(IActionCase actionCase)
 {
     return(ActionHandler != null && ActionHandler.State != HandlerStates.Handled && ActionHandler.WaitingFor(actionCase));
 }