Exemplo n.º 1
0
		protected override void Dispose (bool disposing)
		{
			if (disposing) {
				if (responseStream != null)
					responseStream.Dispose ();
				responseStream = null;
			}
		}
        private async Task <object> ReadContentAsAsync(WebServiceResponseHandlerInfo <TResponse> info, Type propertyType)
        {
            HttpResponseMessage webResponse = info.WebResponse;
            object content = null;

            if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                content = true;
            }
            else if (propertyType == typeof(string))
            {
                info.MarkContentAsRead();
                content = await webResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
            }
            else if (propertyType == typeof(byte[]))
            {
                info.MarkContentAsRead();
                content = await webResponse.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
            }
            else if (propertyType == typeof(Stream))
            {
                info.MarkContentAsRead();
                content = await WebResponseStream.CreateAsync(info.WebResponse).ConfigureAwait(false);
            }
            else if (webResponse.HasJson() || webResponse.Content.Headers.ContentType == null)
            {
                info.MarkContentAsRead();
                content = await webResponse.GetJsonAsAsync(propertyType, JsonSettings).ConfigureAwait(false);
            }

            if (content == null)
            {
                throw await CreateExceptionAsync(info, "Web response content cannot be read as {0}.".FormatInvariant(propertyType)).ConfigureAwait(false);
            }

            return(content);
        }
Exemplo n.º 3
0
		internal Content (WebResponseStream stream)
			: base (stream)
		{
			this.responseStream = stream;
		}