예제 #1
0
        /// <summary>
        /// Deserializes an ZIP <see cref="HttpContent" /> as <seealso cref="ZipArchive" />.
        /// </summary>
        /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
        /// <param name="mode">(Optional) The specified <see cref="ZipArchiveMode" />.</param>
        /// <returns><see cref="ValueTask{T}" /> of type <see cref="ZipArchive" /></returns>
        public static ValueTask <ZipArchive> AsZipArchive(this ISolidHttpRequest request, ZipArchiveMode?mode = null)
        {
            if (!mode.HasValue)
            {
                return(request.As <ZipArchive>());
            }

            return(request.As <ZipArchive>((services, content) =>
            {
                var deserializer = services.GetService <ZipArchiveDeserializer>();
                return deserializer.DeserializeAsync(content, mode.Value);
            }));
        }
예제 #2
0
        /// <summary>
        /// Returns the content as a GzipStream, caller is responsable for disposing the stream
        /// </summary>
        /// <param name="request">The extended ISolidHttpRequest</param>
        /// <param name="mode">The zip archive mode</param>
        /// <returns>An awaitable task</returns>
        public static Task <ZipArchive> AsZipArchive(this ISolidHttpRequest request, ZipArchiveMode mode = ZipArchiveMode.Read)
        {
            var factory     = new ZipArchiveResponseDeserializerFactory(mode);
            var deserialize = factory.CreateDeserializer <ZipArchive>();

            return(request.As <ZipArchive>());
        }
예제 #3
0
        /// <summary>
        /// Deserializes the response content as the specified type using the specified settings
        /// </summary>
        /// <typeparam name="T">The type of response body</typeparam>
        /// <param name="request">The SolidHttpRequest</param>
        /// <param name="settings">The specified DataContractSerializerSettings</param>
        /// <returns>Task of type T</returns>
        public static async Task <T> As <T>(this ISolidHttpRequest request, DataContractSerializerSettings settings)
        {
            var factory     = new XmlResponseDeserializerFactory(settings);
            var deserialize = factory.CreateDeserializer <T>();

            return(await request.As <T>(deserialize));
        }
예제 #4
0
 /// <summary>
 /// Deserializes an XML <see cref="HttpContent" /> as <typeparamref name="T" /> using the
 /// specified serializer settings.
 /// </summary>
 /// <typeparam name="T">The type of response body.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <param name="settings">The specified <see cref="DataContractSerializerSettings" />.</param>
 /// <returns><see cref="ValueTask{T}" /> of type <typeparamref name="T" /></returns>
 public static ValueTask <T> As <T>(this ISolidHttpRequest request, DataContractSerializerSettings settings)
 {
     return(request.As <T>((services, content) =>
     {
         var deserializer = services.GetService <DataContractXmlDeserializer>();
         return deserializer.DeserializeAsync <T>(content, settings);
     }));
 }
        /// <summary>
        /// Deserializes <see cref="HttpContent" /> into <typeparamref name="T" />.
        /// </summary>
        /// <typeparam name="T">The type to deserialize as.</typeparam>
        /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
        /// <returns>A <see cref="ValueTask{T}" /> of type <typeparamref name="T" />.</returns>
        public static ValueTask <T> As <T>(this ISolidHttpRequest request)
        {
            var provider = request.Services.GetService <DeserializerProvider>();

            return(request
                   .As(content => content.ReadAsAsync <T>(provider))
                   );
        }
예제 #6
0
 /// <summary>
 /// Deserializes a JSON <see cref="HttpContent" /> as <typeparamref name="T" /> using the
 /// specified serializer settings.
 /// </summary>
 /// <typeparam name="T">The type of response body.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <param name="options">The specified <see cref="JsonSerializerOptions" />.</param>
 /// <returns><see cref="ValueTask{T}" /> of type <typeparamref name="T" /></returns>
 public static async ValueTask <T> As <T>(this ISolidHttpRequest request, JsonSerializerOptions options)
 {
     return(await request.As <T>(async content =>
     {
         using (var stream = await content.ReadAsStreamAsync())
         {
             return await JsonSerializer.DeserializeAsync <T>(stream, options);
         }
     }));
 }
        /// <summary>
        /// Deserializes a JSON <see cref="HttpContent" /> as <typeparamref name="T" /> using the
        /// specified serializer settings.
        /// </summary>
        /// <typeparam name="T">The type of response body.</typeparam>
        /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
        /// <param name="settings">The specified <see cref="JsonSerializerSettings" />.</param>
        /// <returns><see cref="ValueTask{T}" /> of type <typeparamref name="T" /></returns>
        public static async ValueTask <T> As <T>(this ISolidHttpRequest request, JsonSerializerSettings settings)
        {
            if (settings == null)
            {
                settings = request.Services.GetService <IOptions <SolidHttpNewtonsoftJsonOptions> >().Value.SerializerSettings;
            }

            return(await request.As <T>(async content =>
            {
                var json = await content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject <T>(json, settings);
            }));
        }
 /// <summary>
 /// Returns the <see cref="HttpContent" /> as a <seealso cref="string" />.
 /// </summary>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <returns>A <see cref="ValueTask{T}" /> of type <seeaslo cref="string" />.</returns>
 public static ValueTask <string> AsText(this ISolidHttpRequest request)
 => request.As(async content => await content.ReadAsStringAsync());
 /// <summary>
 /// Deserializes <see cref="HttpContent" /> into an <seealso cref="IEnumerable{T}" /> of type <typeparamref name="T" />.
 /// </summary>
 /// <typeparam name="T">The type to deserialize as.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <returns>A <see cref="ValueTask{T}" /> of type <seealso cref="IEnumerable{T}" /> of type <typeparamref name="T" />.</returns>
 public static async ValueTask <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request)
 => await request.As <IEnumerable <T> >();
 /// <summary>
 /// Deserializes <see cref="HttpContent" /> into <typeparamref name="T" /> using a specified deserialize delegate.
 /// </summary>
 /// <typeparam name="T">The type to deserialize as.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <param name="deserialize">A delegate that is used to deserialize <see cref="HttpContent" />.</param>
 /// <returns>A <see cref="ValueTask{T}" /> of type <typeparamref name="T" />.</returns>
 public static ValueTask <T> As <T>(this ISolidHttpRequest request, Func <HttpContent, ValueTask <T> > deserialize)
 => request.As((_, content) => deserialize(content));
예제 #11
0
 /// <summary>
 /// Returns the response content as text
 /// </summary>
 /// <param name="request">The ISolidHttpRequest</param>
 /// <returns>Task of type string</returns>
 public static async Task <string> AsText(this ISolidHttpRequest request)
 {
     return(await request.As(async content => await content.ReadAsStringAsync()));
 }
 /// <summary>
 /// Deserializes a JSON <see cref="HttpContent" /> as an <seealso cref="IEnumerable{T}" />
 /// of type <typeparamref name="T" /> using the specified serializer settings.
 /// </summary>
 /// <typeparam name="T">The type of response body.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <param name="anonymous">An object of type <typeparamref name="T" /> that provides a schema for deserialization.</param>
 /// <param name="settings">The specified <see cref="JsonSerializerSettings" />.</param>
 /// <returns><see cref="ValueTask{T}" /> of type <seealso cref="IEnumerable{T}" /> of type <typeparamref name="T" />.</returns>
 public static ValueTask <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request, T anonymous, JsonSerializerSettings settings = default)
 => request.As <IEnumerable <T> >(settings);
예제 #13
0
 /// <summary>
 /// Deserializes the response content as the specified anonymous type using the specified settings
 /// </summary>
 /// <typeparam name="T">The type of resonse body</typeparam>
 /// <param name="request">The SolidHttpRequest</param>
 /// <param name="anonymous">The anonymous type</param>
 /// <param name="settings">The specified JsonSerializerSettings</param>
 /// <returns>Task of type T</returns>
 public static Task <T> As <T>(this ISolidHttpRequest request, T anonymous, JsonSerializerSettings settings)
 {
     return(request.As <T>(settings));
 }
예제 #14
0
 /// <summary>
 /// Deserializes the response content as the specified anonymous type using the specified settings
 /// </summary>
 /// <typeparam name="T">The type of resonse body</typeparam>
 /// <param name="request">The SolidHttpRequest</param>
 /// <param name="anonymous">The anonymous type</param>
 /// <param name="settings">The specified DataContractSerializerSettings</param>
 /// <returns>Task of type IEnumerable&lt;T&gt;</returns>
 public static Task <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request, T anonymous, DataContractSerializerSettings settings)
 {
     return(request.As <IEnumerable <T> >(settings));
 }
예제 #15
0
 /// <summary>
 /// Deserializes an XML <see cref="HttpContent" /> as an <seealso cref="IEnumerable{T}" />
 /// of type <typeparamref name="T" /> using the specified serializer settings.
 /// </summary>
 /// <typeparam name="T">The type of response body.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <param name="settings">The specified <see cref="DataContractSerializerSettings" />.</param>
 /// <returns><see cref="ValueTask{T}" /> of type <seealso cref="IEnumerable{T}" /> of type <typeparamref name="T" />.</returns>
 public static ValueTask <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request, DataContractSerializerSettings settings)
 => request.As <IEnumerable <T> >(settings);
예제 #16
0
 /// <summary>
 /// Deserializes the response content as the specified anonymous type
 /// </summary>
 /// <typeparam name="T">The type to deserialize to</typeparam>
 /// <param name="request">The ISolidHttpRequest</param>
 /// <param name="anonymous">An anonumous type to infer T</param>
 /// <returns>Task of type T</returns>
 public static async Task <T> As <T>(this ISolidHttpRequest request, T anonymous)
 {
     return(await request.As <T>());
 }
예제 #17
0
 /// <summary>
 /// Deserializes a JSON <see cref="HttpContent" /> as an <seealso cref="IEnumerable{T}" />
 /// of type <typeparamref name="T" /> using the specified serializer settings.
 /// </summary>
 /// <typeparam name="T">The type of response body.</typeparam>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <param name="options">The specified <see cref="JsonSerializerOptions" />.</param>
 /// <returns><see cref="ValueTask{T}" /> of type <seealso cref="IEnumerable{T}" /> of type <typeparamref name="T" />.</returns>
 public static ValueTask <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request, JsonSerializerOptions options)
 => request.As <IEnumerable <T> >(options);
예제 #18
0
 /// <summary>
 /// Deserializes the response content as the specified type using the specified settings
 /// </summary>
 /// <typeparam name="T">The type of resonse body</typeparam>
 /// <param name="request">The SolidHttpRequest</param>
 /// <param name="settings">The specified JsonSerializerSettings</param>
 /// <returns>Task of type IEnumerable&lt;T&gt;</returns>
 public static Task <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request, JsonSerializerSettings settings)
 {
     return(request.As <IEnumerable <T> >(settings));
 }
 /// <summary>
 /// Returns the <see cref="HttpContent" /> as a <seealso cref="Stream" />.
 /// </summary>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <returns>A <see cref="ValueTask{T}" /> of type <seeaslo cref="Stream" />.</returns>
 public static ValueTask <Stream> AsStream(this ISolidHttpRequest request)
 => request.As(async content => await content.ReadAsStreamAsync());
 /// <summary>
 /// Returns the <see cref="HttpContent" /> as a <seealso cref="byte" /> array.
 /// </summary>
 /// <param name="request">The <see cref="ISolidHttpRequest" /> that is being extended.</param>
 /// <returns>A <see cref="ValueTask{T}" /> of type <seeaslo cref="byte" /> array.</returns>
 public static ValueTask <byte[]> AsBytes(this ISolidHttpRequest request)
 => request.As(async content => await content.ReadAsByteArrayAsync());
예제 #21
0
 /// <summary>
 /// Deserializes the response content as an array of type T
 /// </summary>
 /// <typeparam name="T">The type to deserialize to</typeparam>
 /// <param name="request">The ISolidHttpRequest</param>
 /// <returns>Task of type IEnumerable&lt;T&gt;</returns>
 public static async Task <IEnumerable <T> > AsMany <T>(this ISolidHttpRequest request)
 {
     return(await request.As <IEnumerable <T> >());
 }