示例#1
0
        public Response <TE> Find(TQ query, Client client)
        {
            var queryData    = _queryCoder.Encode(query, client);
            var responseData = _dataSource.Execute(queryData, client);

            return(_responseDecoder.Decode(responseData, client));
        }
示例#2
0
        public override StringResponseBody Interpret(Stream stream)
        {
            bool             hasContentEncoding = !string.IsNullOrEmpty(contentEncoding);
            IResponseDecoder decoder            = !hasContentEncoding ? null : decoders.GetValueOrDefault(contentEncoding.ToLower());

            if (HttpConfig.DebugMode)
            {
                Console.WriteLine("Interpretation decoder " + decoder + " for content type: " + contentType + ", Body size: " + BodySize);
            }
            StringBuilder sb = new StringBuilder();

            using (StreamReader reader = new StreamReader(decoder is null ? stream : decoder.Decode(stream), Encoding.UTF8)) {
                while (true)   //!reader.EndOfStream
                {
                    try {
                        string line = reader.ReadLine();

                        if (line is null)
                        {
                            break;
                        }
                        AddProgress(line.Length);
                        sb.Append(line + Delimiters.Linebreak);

                        if (!hasContentEncoding && sb.Length >= BodySize)
                        {
                            break;
                        }
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                        continue;
                    }
                }
            }
            if (HttpConfig.DebugMode)
            {
                Console.WriteLine("Body interpretation successfull");
            }
            //return (StringResponseBody)Activator.CreateInstance(typeof(StringResponseBody), new object[] { sb.ToString() });
            byte[] bytes = Encoding.ASCII.GetBytes(sb.ToString());
            return(new StringResponseBody(Encoding.UTF8.GetString(bytes)));
        }