Example #1
0
        public string ProcessRequest(string jsonRequest)
        {
            Reply reply = null;

            try
            {
                try
                {
                    var requestParams = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(jsonRequest);
                    if (requestParams.ContainsKey("action"))
                    {
                        string actionName = requestParams["action"];
                        if (RegisteredActions.ContainsKey(actionName))
                        {
                            reply = RegisteredActions[actionName].Run(RegisteredControls, requestParams);
                        }
                        else
                        {
                            throw new ErrorReplyException(ErrorCodes.UNSUPPORTED_ACTION, String.Format("no such action: {0}", actionName));
                        }
                    }
                    else
                    {
                        throw new ErrorReplyException(ErrorCodes.MISSING_PARAM, "param is required: action");
                    }
                }
                catch (JsonReaderException e)
                {
                    throw new ErrorReplyException(ErrorCodes.PARSE_ERROR, e.ToString());
                }
            }
            catch (ErrorReplyException e)
            {
                reply = e.Reply;
            }
            catch (Exception e)
            {
                reply = new ErrorReply(ErrorCodes.RUNTIME_ERROR, e.ToString());
            }

            string jsonString = JsonConvert.SerializeObject(reply.Fields);

            return(jsonString);
        }
Example #2
0
 public ErrorReplyException(ErrorCodes statusCode, string message)
 {
     Reply = new ErrorReply(statusCode, message);
 }