Esempio n. 1
0
        public override async Task <T> Handle <T>(PluginManager manager, JsonHCS jsonHCS, string route, List <Parameter> parameters, Type targetType, IInvocation invocation)
        {
            route = ApplyRouteParameters(route, parameters);
            route = ApplyQueryParameters(route, parameters);
            var headers = GetHeaders(parameters);

            var method = FindHttpMethod(invocation.Method, parameters);

            if (method == HttpMethod.Get && targetType == typeof(System.IO.Stream))
            {
                return((T)(object)await jsonHCS.GetStreamAsync(route).ConfigureAwait(false));
            }
            else if (method == HttpMethod.Get && targetType == typeof(System.IO.MemoryStream))
            {
                return((T)(object)await jsonHCS.GetMemoryStreamAsync(route).ConfigureAwait(false));
            }

            GetBodyOrFormContent(jsonHCS, parameters, out HttpContent content);

            var completion = HasAttribute(invocation.Method, typeof(HeaderHttpCompletionOptionAttribute)) ? HttpCompletionOption.ResponseHeadersRead : HttpCompletionOption.ResponseContentRead;

            var response = await jsonHCS.SendRequestAsync(method, route, content, headers, completion).ConfigureAwait(false);

            if (targetType == typeof(void) || targetType == typeof(HttpResponseMessage))
            {
                return((T)(object)response);
            }
            else if (HasAttribute(invocation.Method, typeof(RawStringAttribute)))
            {
                return((T)(object)await JsonHCS.ReadContentAsString(response).ConfigureAwait(false));
            }
            else if (targetType == typeof(JObject))
            {
                return((T)(object)jsonHCS.DeserializeJObject(await JsonHCS.ReadContentAsString(response).ConfigureAwait(false)));
            }
            else
            {
                return(jsonHCS.DeserializeJson <T>(await JsonHCS.ReadContentAsString(response).ConfigureAwait(false)));
            }
        }
Esempio n. 2
0
 public override Task <string> GetStringAsync()
 {
     return(JsonHCS.ReadContentAsString(Response));
 }