Beispiel #1
0
        /// <summary>
        /// 通信完成消息处理方法
        /// </summary>
        /// <param name="session"></param>
        /// <param name="notify"></param>
        public void OnNotifyProc(SessionCompletedNotify notify, SessionHandler session)
        {
            if (!_isRun)
            {
                return;
            }

            this.Invoke(new Action(() =>
            {
                switch (notify)
                {
                case SessionCompletedNotify.OnConnected:
                    this.InitSessionAppTokens(session);
                    break;

                case SessionCompletedNotify.OnSend:
                    this.OnTransmit(session);
                    break;

                case SessionCompletedNotify.OnRecv:
                    this.OnReceive(session);
                    break;

                case SessionCompletedNotify.OnReceived:
                    this.OnReceiveComplete(session);
                    break;

                case SessionCompletedNotify.OnClosed:
                    this.OnClosed(session);
                    break;
                }
            }));
        }
        /// <summary>
        /// 通信完成消息处理方法
        /// </summary>
        /// <param name="session"></param>
        /// <param name="notify"></param>
        private void OnNotifyProc(SessionCompletedNotify notify, SessionProviderContext session)
        {
            if (SynchronizationContext == null)
            {
                NotifyProc(null);
            }
            else
            {
                SynchronizationContext.Send(NotifyProc, null);
            }

            void NotifyProc(object @object)
            {
                try
                {
                    switch (notify)
                    {
                    case SessionCompletedNotify.OnConnected:
                        //先分配好工作类型,等待工作指令分配新的工作类型
                        session.AppTokens = new object[SysConstants.INDEX_COUNT]
                        {
                            ConnectionWorkType.NONE,    //未经验证的状态
                            null
                        };
                        break;

                    case SessionCompletedNotify.OnSend:
                        //耗时操作会导致性能严重降低
                        this.OnTransmitHandlerEvent?.Invoke(session);
                        break;

                    case SessionCompletedNotify.OnRecv:
                        //耗时操作会导致性能严重降低
                        this.OnReceiveHandlerEvent?.Invoke(session);
                        break;

                    case SessionCompletedNotify.OnReceived:
                        this.OnReceiveComplete(session);
                        break;

                    case SessionCompletedNotify.OnClosed:
                        this.OnClosed(session);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteErrorByCurrentMethod(ex);
                }
            }
        }
Beispiel #3
0
        private void OnNotifyProc(SessionCompletedNotify notify, SessionHandler session)
        {
            switch (notify)
            {
            case SessionCompletedNotify.OnConnected:
                this.InitSessionAppToken(session);
                break;

            case SessionCompletedNotify.OnSend:
                break;

            case SessionCompletedNotify.OnRecv:
                break;

            case SessionCompletedNotify.OnReceived:
                this.OnMessage(session);
                break;

            case SessionCompletedNotify.OnClosed:
                this.SessionClosed(session);
                break;
            }
        }