コード例 #1
0
ファイル: JsonRpcResponse.cs プロジェクト: ilahsa/bai_pro
 public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, int originalErrorCode) : this(rpcErrorCode, null, null, originalErrorCode)
 {
     _rpcErrorCode      = rpcErrorCode;
     _respBody          = null;
     _exception         = null;
     _originalErrorCode = originalErrorCode;
 }
コード例 #2
0
        private async Task <LspMessage> ReadMessage()
        {
            int    contentLength = GetContentLength();
            string msgString     = await ReadString(contentLength).ConfigureAwait(false);

            JObject msgJson = JObject.Parse(msgString);

            if (msgJson.TryGetValue("method", out JToken methodToken))
            {
                string method = ((JValue)methodToken).Value.ToString();
                if (msgJson.TryGetValue("id", out JToken idToken))
                {
                    string requestId = ((JValue)idToken).Value.ToString();
                    return(new LspRequest(requestId, method, msgJson["params"]));
                }

                return(new LspNotification(method, msgJson["params"]));
            }

            string id = ((JValue)msgJson["id"]).Value.ToString();

            if (msgJson.TryGetValue("result", out JToken resultToken))
            {
                return(new LspSuccessfulResponse(id, resultToken));
            }

            JObject          errorBody = (JObject)msgJson["error"];
            JsonRpcErrorCode errorCode = (JsonRpcErrorCode)(int)((JValue)errorBody["code"]).Value;
            string           message   = (string)((JValue)errorBody["message"]).Value;

            return(new LspErrorResponse(id, errorCode, message, errorBody["data"]));
        }
コード例 #3
0
ファイル: JsonRpcResponse.cs プロジェクト: ilahsa/bai_pro
 public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, string responseBody, JsonRpcException exception, int originalErrorCode)
 {
     _rpcErrorCode      = rpcErrorCode;
     _respBody          = responseBody;
     _exception         = exception;
     _originalErrorCode = originalErrorCode;
 }
コード例 #4
0
ファイル: JsonRpcError.cs プロジェクト: zutobg/Meadow
 public JsonRpcErrorException(JsonRpcErrorCode errorCode, string message) : base(message)
 {
     Error = new JsonRpcError
     {
         Code    = (long)errorCode,
         Message = message
     };
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteMethodNotFoundException"/> class
 /// with supplied message and target method.
 /// </summary>
 /// <param name="message">Exception message describing why the method was not found.</param>
 /// <param name="targetMethod">Target method that was not found.</param>
 /// <param name="errorCode">The value of the error.code field in the response.</param>
 /// <param name="errorData">The value of the error.data field in the response.</param>
 /// <param name="deserializedErrorData">The value of the error.data field in the response, deserialized according to <see cref="JsonRpc.GetErrorDetailsDataType(JsonRpcError)"/>.</param>
 internal RemoteMethodNotFoundException(string?message, string targetMethod, JsonRpcErrorCode errorCode, object?errorData, object?deserializedErrorData)
     : base(message)
 {
     Requires.NotNullOrEmpty(targetMethod, nameof(targetMethod));
     base.ErrorCode             = errorCode;
     this.TargetMethod          = targetMethod;
     base.ErrorData             = errorData;
     base.DeserializedErrorData = deserializedErrorData;
 }
コード例 #6
0
 private void TrySetErrorResponse(RequestContext context, JsonRpcErrorCode errorCode,
                                  string message)
 {
     Logger.LogError("({code}) {message}", errorCode, message);
     if (context.Response == null)
     {
         return;
     }
     context.Response.Error = new ResponseError(errorCode, message);
 }
コード例 #7
0
 public LspErrorResponse(
     string id,
     JsonRpcErrorCode code,
     string message,
     JToken data)
     : base(id)
 {
     Code    = code;
     Message = message;
     Data    = data;
 }
コード例 #8
0
ファイル: JsonRpcError.cs プロジェクト: zutobg/Meadow
        public JsonRpcErrorException(JsonRpcErrorCode errorCode, string message, Exception ex) : base(message, ex)
        {
            Error = new JsonRpcError
            {
                Code    = (long)errorCode,
                Message = message
            };
            var dataDict = new Dictionary <string, object>();

            dataDict["exception"] = ex.ToString();
            // Populate the RPC data object with entries from the exception's Data dictionary.
            foreach (var item in ex.Data.Keys)
            {
                var dataVal = ex.Data[item];
                if (dataVal != null)
                {
                    dataDict[item.ToString()] = dataVal.ToString();
                }
            }

            Error.Data = dataDict;
        }
コード例 #9
0
 public static JsonRpcMessage CreateError(JToken id, JsonRpcErrorCode error, string message, JObject data)
 {
     return(CreateError(id, (int)error, message, data));
 }
コード例 #10
0
ファイル: Error.cs プロジェクト: 0xFireball/Extrasolar
 public Error(JsonRpcErrorCode code, string message, JToken data) : this((int)code, message, data)
 {
 }
コード例 #11
0
 public ErrorResponseMessage(JsonRpcErrorCode errorCode, string errorMessage, string version = "2.0", string id = "") : base(version, id)
 {
     Error = new ErrorClass {
         Code = (int)errorCode, Message = errorMessage
     };
 }
コード例 #12
0
 public void ReceivedError(long requestId, JsonRpcErrorCode errorCode)
 {
     this.WriteEvent(ReceivedErrorEvent, requestId, (long)errorCode);
 }
コード例 #13
0
 public void SendingError(long requestId, JsonRpcErrorCode errorCode)
 {
     this.WriteEvent(SendingErrorEvent, requestId, (long)errorCode);
 }
コード例 #14
0
ファイル: JsonRpcResponse.cs プロジェクト: ilahsa/bai_pro
 public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, string responseBody) : this(rpcErrorCode, responseBody, null, 0)
 {
 }
コード例 #15
0
        //public bool Wait()
        //{
        //    if (_waitHandle != null)
        //        return _waitHandle.WaitOne(_timeOut + 10000);

        //    return false;
        //}

        private static void ResponseCallback(IAsyncResult asyncResult)
        {
            //Console.WriteLine("接收应答222222222222222" + DateTime.Now.ToShortDateString());
            JsonRpcHttpClientTransaction trans = (JsonRpcHttpClientTransaction)asyncResult.AsyncState;
            JsonRpcResponse response           = null;
            WebResponse     webResponse        = null;

            try
            {
                webResponse        = trans._webRequest.EndGetResponse(asyncResult);
                trans._webResponse = webResponse;

                string warn      = webResponse.Headers.Get("UU-RESPONSE-RC");
                string lengthStr = webResponse.Headers.Get("UU-CONTENT-LENGTH");
                int    length    = 0;
                int.TryParse(lengthStr + "", out length);
                int orginalErrorCode = 0;
                int.TryParse(warn, out orginalErrorCode);
                string respBody = null;
                if (length > 0)
                {
                    Stream       stream       = webResponse.GetResponseStream();
                    StreamReader readerStream = new StreamReader(stream);
                    respBody = readerStream.ReadToEnd();

                    readerStream.Close();
                }

                if (!string.IsNullOrEmpty(warn) && warn != "0")
                {
                    JsonRpcErrorCode errCode = JsonRpcErrorCode.Unknown;
                    Enum.TryParse <JsonRpcErrorCode>(warn, true, out errCode);

                    response = new JsonRpcResponse(errCode, respBody, new JsonRpcException(trans._sericeUri, respBody, new Exception("rc != 0")), orginalErrorCode);
                }
                else
                {
                    response = new JsonRpcResponse(JsonRpcErrorCode.OK, respBody);
                }

                TracingManager.Info(
                    delegate()
                {
                    string responseCode = warn == null ? "0" : warn;

                    _tracing.Info(string.Format("jsonrpc response:response rc ={0}\r\nresponse body:{1}",
                                                responseCode, respBody));
                    //if (responseCode != "0")
                    //{
                    //    _tracing.ErrorFmt(response.Exception, "web data response error ,originalerrorcode is {0}", orginalErrorCode);
                    //}
                }
                    );
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    response = new JsonRpcResponse(JsonRpcErrorCode.TransactionTimeout, new JsonRpcException(null, null, ex), 500);
                }
                else
                {
                    response = new JsonRpcResponse(JsonRpcErrorCode.SendFailed, new JsonRpcException(null, null, ex), 500);
                }
            }
            catch (Exception ex)
            {
                SystemLog.Error(LogEventID.RpcFailed, ex, "SendRequest failed");
                response = new JsonRpcResponse(JsonRpcErrorCode.SendFailed, new JsonRpcException(null, null, ex), 500);
            }
            finally
            {
                if (webResponse != null)
                {
                    webResponse.Close();
                }

                trans.OnCallback(response);
            }
        }
コード例 #16
0
 public ResponseError(JsonRpcErrorCode code, string message)
     : this(code, message, null)
 {
 }
コード例 #17
0
ファイル: JsonRpcResponse.cs プロジェクト: ilahsa/bai_pro
 public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, JsonRpcException exception, int orginalErrorCode) : this(rpcErrorCode, null, exception, orginalErrorCode)
 {
 }
コード例 #18
0
ファイル: JsonRpcResponse.cs プロジェクト: ilahsa/bai_pro
 public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode) : this
     (rpcErrorCode, 0)
 {
 }
コード例 #19
0
 public ResponseError(JsonRpcErrorCode code, string message, object data)
     : this((int)code, message, data)
 {
 }
コード例 #20
0
 public JsonRpcException(string message, JsonRpcErrorCode jsonRpcErrorCode) : base(message)
 {
     JsonRpcErrorCode = jsonRpcErrorCode;
 }