예제 #1
0
        public static JsonRecorder Record(JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            JsonRecorder recorder = new JsonRecorder();
            recorder.WriteFromReader(reader);
            return recorder;
        }
예제 #2
0
        public static JsonRecorder Record(JsonReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            JsonRecorder jsonRecorder = new JsonRecorder();

            jsonRecorder.WriteFromReader(reader);
            return(jsonRecorder);
        }
예제 #3
0
        public static JsonRecorder Record(JsonReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var recorder = new JsonRecorder();

            recorder.WriteFromReader(reader);
            return(recorder);
        }
예제 #4
0
        protected virtual object ParseRequest(TextReader input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            JsonReader reader = (JsonReader) _serviceProvider.GetService(typeof(JsonReader));

            if (reader == null)
                reader = new JsonTextReader(input);

            ImportContext importContext = new ImportContext();

            JsonObject request = new JsonObject();
            Method method = null;
            JsonReader paramsReader = null;
            object args = null;

            reader.ReadToken(JsonTokenClass.Object);

            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();

                switch (memberName)
                {
                    case "id" :
                    {
                        request["id"] = importContext.Import(reader);
                        break;
                    }

                    case "method" :
                    {
                        string methodName = reader.ReadString();
                        request["method"] = methodName;
                        method = _service.GetClass().GetMethodByName(methodName);

                        if (paramsReader != null)
                        {
                            //
                            // If the parameters were already read in and
                            // buffer, then deserialize them now that we know
                            // the method we're dealing with.
                            //

                            args = ReadParameters(method, paramsReader, importContext);
                            paramsReader = null;
                        }

                        break;
                    }

                    case "params" :
                    {
                        //
                        // Is the method already known? If so, then we can
                        // deserialize the parameters right away. Otherwise
                        // we record them until hopefully the method is
                        // encountered.
                        //

                        if (method != null)
                        {
                            args = ReadParameters(method, reader, importContext);
                        }
                        else
                        {
                            JsonRecorder recorder = new JsonRecorder();
                            recorder.WriteFromReader(reader);
                            paramsReader = recorder.CreatePlayer();
                        }

                        break;
                    }

                    default:
                    {
                        reader.Skip();
                        break;
                    }
                }
            }

            reader.Read();

            if (args != null)
                request["params"] = args;

            return request;
        }
        protected virtual IDictionary ParseRequest(JsonReader input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            JsonReader reader = input; // alias for clarity
            JsonImportHandler importer = JsonImporter;

            JsonObject request = new JsonObject();
            Method method = null;
            JsonReader paramsReader = null;
            object args = null;

            try
            {
                reader.ReadToken(JsonTokenClass.Object);

                while (reader.TokenClass != JsonTokenClass.EndObject)
                {
                    string memberName = reader.ReadMember();

                    switch (memberName)
                    {
                        case "id" :
                        {
                            request["id"] = importer(AnyType.Value, reader);
                            break;
                        }

                        case "method" :
                        {
                            string methodName = reader.ReadString();
                            request["method"] = methodName;
                            method = Service.GetClass().GetMethodByName(methodName);

                            if (paramsReader != null)
                            {
                                //
                                // If the parameters were already read in and
                                // buffer, then deserialize them now that we know
                                // the method we're dealing with.
                                //

                                args = ReadParameters(method, paramsReader, importer);
                                paramsReader = null;
                            }

                            break;
                        }

                        case "params" :
                        {
                            //
                            // Is the method already known? If so, then we can
                            // deserialize the parameters right away. Otherwise
                            // we record them until hopefully the method is
                            // encountered.
                            //

                            if (method != null)
                            {
                                args = ReadParameters(method, reader, importer);
                            }
                            else
                            {
                                JsonRecorder recorder = new JsonRecorder();
                                recorder.WriteFromReader(reader);
                                paramsReader = recorder.CreatePlayer();
                            }

                            break;
                        }

                        default:
                        {
                            reader.Skip();
                            break;
                        }
                    }
                }

                reader.Read();

                if (args != null)
                    request["params"] = args;

                return request;
            }
            catch (JsonException e)
            {
                throw new BadRequestException(e.Message, e, request);
            }
            catch (MethodNotFoundException e)
            {
                throw new BadRequestException(e.Message, e, request);
            }
        }