Пример #1
0
        /// <summary>
        /// レスポンスを送ります。
        /// </summary>
        private void SendResponse(int id, IPbResponse response,
                                  bool isOutLog = true)
        {
            if (response == null)
            {
                return;
            }

            var sendData = new PbSendData(response);

            SendDataInternal(id, true, sendData, isOutLog);
        }
Пример #2
0
        /// <summary>
        /// リクエストかコマンドを処理します。
        /// </summary>
        private void HandleRequestOrCommand(int id, object message)
        {
            HandlerInfo handlerInfo = null;
            IPbResponse response    = null;

            // コマンドを処理するハンドラオブジェクトを取得します。
            lock (this.handlerDic)
            {
                if (!this.handlerDic.TryGetValue(message.GetType(), out handlerInfo))
                {
                    Log.Error(this,
                              "{0}: 適切なハンドラが見つかりませんでした。",
                              message.GetType());
                    return;
                }
            }

            // ログを出力したくない場合もあります。
            if (handlerInfo.IsOutLog)
            {
                Log.Debug(this,
                          "{0}を受信しました。", message.GetType());
            }

            if (handlerInfo.Handler != null)
            {
                try
                {
                    // レスポンスはnullのことがありますが、
                    // それは合法です。
                    response = handlerInfo.Handler(message);
                }
                catch (Exception ex)
                {
                    Log.ErrorException(this, ex,
                                       "受信データの処理ハンドラでエラーが発生しました。");

                    response = new PbResponse <PbDummy>()
                    {
                        ErrorCode = PbErrorCode.HandlerException,
                    };
                }
            }

            // もしリクエストなら、レスポンスを返します。
            if (handlerInfo.IsRequestHandler)
            {
                // responseはnullのことがあります。
                SendResponse(id, response);
            }
        }
Пример #3
0
 /// <summary>
 /// レスポンスハンドラを呼び出します。
 /// </summary>
 public abstract void OnResponseReceived(IPbResponse response);
Пример #4
0
 /// <summary>
 /// レスポンスハンドラを呼び出します。
 /// </summary>
 public abstract void OnResponseReceived(IPbResponse response);