예제 #1
0
        private void HandleRequest(string method, string requestId, JToken parameters)
        {
            RequestMethod requestMethod = null;

            requestMethods.TryGetValue(method, out requestMethod);
            if (requestMethod == null)
            {
                WriteServerLog(String.Format("No request handler was registered for method \"{0}\"", method));
            }
            else
            {
                RequestType requestType = requestMethod.Type;
                object      objParams   = null;
                if (parameters != null)
                {
                    objParams = parameters.ToObject(requestType.ParamsType);
                }
                try
                {
                    ResponseResultOrError resultOrError = requestMethod.HandleRequest(requestType, objParams);
                    Reply(requestId, resultOrError);
                }
                catch (Exception e)
                {
                    ResponseResultOrError error = new ResponseResultOrError()
                    {
                        code = ErrorCodes.InternalError, message = e.Message
                    };
                    Reply(requestId, error);
                }
            }
        }