2 changed files
WPE.App.Extensions | ||
HttpClientExtensions.cs | ||
WPE.App.Extensions.csproj | ||
HttpClientExtensions.cs
/WPE.App.Extensions/HttpClientExtensions.cs-5+34/WPE.App.Extensions/HttpClientExtensions.cs
Add comment 15 /// <param name="client">HttpClient to call with</param>
Add comment 16 /// <param name="uri">Uri to send message to</param>
Add comment 17 /// <param name="cacheMode">Controls, whether cache should be used and it's priority</param>
Add comment 18 Plus /// <param name="cacheTime">Time to cache the response for in seconds, ignored when <paramref name="cacheMode"/> is <see cref="CacheMode.None"/></param>
Add comment 18 19 /// <returns>Full http response</returns>
Add comment 19 Minus public static async Task<HttpResponseMessage> GetWithCache(this HttpClient client, string uri, CacheMode cacheMode = CacheMode.PreferCache)
Add comment 20 Plus public static async Task<HttpResponseMessage> GetWithCaching(this HttpClient client, string uri, CacheMode cacheMode, int cacheTime)
Add comment 20 21 {
Add comment 21 22 var message = new HttpRequestMessage(HttpMethod.Get, uri);
Add comment 22 23 message.Options.TryAdd("CacheMode", cacheMode);
Add comment 24 Plus message.Options.TryAdd("CacheTime", cacheTime);
Add comment 23 25 return await client.SendAsync(message);
Add comment 24 26 }
Add comment 25 27
Add comment 30 32 /// <param name="uri">Uri to send message to</param>
Add comment 31 33 /// <param name="cacheMode">Controls, whether cache should be used and it's priority</param>
Add comment 32 34 /// <returns>Full http response</returns>
Add comment 35 Plus [Obsolete("Use GetWithCaching instead, will be removed with 0.4")]
Add comment 36 Plus public static Task<HttpResponseMessage> GetWithCache(this HttpClient client, string uri, CacheMode cacheMode = CacheMode.PreferCache) =>
Add comment 37 Plus client.GetWithCaching(uri, cacheMode, 60);
Add comment 38 Plus
Add comment 39 Plus /// <summary>
Add comment 40 Plus /// Fetch data utilizing the cache
Add comment 41 Plus /// </summary>
Add comment 42 Plus /// <param name="client">HttpClient to call with</param>
Add comment 43 Plus /// <param name="uri">Uri to send message to</param>
Add comment 44 Plus /// <param name="cacheMode">Controls, whether cache should be used and it's priority</param>
Add comment 45 Plus /// <returns>Full http response</returns>
Add comment 46 Plus [Obsolete("Use GetWithCaching instead, will be removed with 0.4")]
Add comment 33 47 public static Task<HttpResponseMessage> GetWithCache(this HttpClient client, Uri uri, CacheMode cacheMode = CacheMode.PreferCache) =>
Add comment 34 Minus client.GetWithCache(uri.ToString(), cacheMode);
Add comment 48 Plus client.GetWithCaching(uri.ToString(), cacheMode, 60);
Add comment 35 49
Add comment 36 50 /// <summary>
Add comment 37 51 /// Fetch data and deserialize the response
Add comment 41 55 /// <param name="uri">Uri to send message to</param>
Add comment 42 56 /// <param name="options">Json serialization options, defaults to <see cref="JsonExtensions.JsonSerializerOptions"/></param>
Add comment 43 57 /// <param name="cacheMode">Controls, whether cache should be used and it's priority</param>
Add comment 58 Plus /// <param name="cacheTime">Time to cache the response for in seconds, ignored when <paramref name="cacheMode"/> is <see cref="CacheMode.None"/></param>
Add comment 44 59 /// <returns>Deserialized data or <see langword="null"/> on failure</returns>
Add comment 45 Minus public static async Task<TOut?> GetJson<TOut>(this HttpClient client, string uri, JsonSerializerOptions? options = default, CacheMode cacheMode = CacheMode.PreferCache)
Add comment 60 Plus public static async Task<TOut?> GetJson<TOut>(this HttpClient client, string uri, CacheMode cacheMode, int cacheTime, JsonSerializerOptions? options = default)
Add comment 46 61 {
Add comment 47 62 options ??= JsonExtensions.JsonSerializerOptions;
Add comment 48 63 try
Add comment 49 64 {
Add comment 50 Minus return await (await client.GetWithCache(uri, cacheMode)).Deserialize<TOut>(options);
Add comment 65 Plus return await(await client.GetWithCaching(uri, cacheMode, cacheTime)).Deserialize<TOut>(options);
Add comment 51 66 }
Add comment 52 67 catch (JsonException)
Add comment 53 68 {
Add comment 64 79 /// <param name="options">Json serialization options, defaults to <see cref="JsonExtensions.JsonSerializerOptions"/></param>
Add comment 65 80 /// <param name="cacheMode">Controls, whether cache should be used and it's priority</param>
Add comment 66 81 /// <returns>Deserialized data or <see langword="null"/> on failure</returns>
Add comment 82 Plus [Obsolete("Use GetJson(uri, cacheMode, cacheTime, options) instead, will be removed with 0.4")]
Add comment 83 Plus public static Task<TOut?> GetJson<TOut>(this HttpClient client, string uri, JsonSerializerOptions? options = default, CacheMode cacheMode = CacheMode.PreferCache) =>
Add comment 84 Plus client.GetJson<TOut>(uri, cacheMode, 60, options);
Add comment 85 Plus
Add comment 86 Plus /// <summary>
Add comment 87 Plus /// Fetch data and deserialize the response
Add comment 88 Plus /// </summary>
Add comment 89 Plus /// <typeparam name="TOut">Class to deserialize response to</typeparam>
Add comment 90 Plus /// <param name="client">HttpClient to call with</param>
Add comment 91 Plus /// <param name="uri">Uri to send message to</param>
Add comment 92 Plus /// <param name="options">Json serialization options, defaults to <see cref="JsonExtensions.JsonSerializerOptions"/></param>
Add comment 93 Plus /// <param name="cacheMode">Controls, whether cache should be used and it's priority</param>
Add comment 94 Plus /// <returns>Deserialized data or <see langword="null"/> on failure</returns>
Add comment 95 Plus [Obsolete("Use GetJson(uri, cacheMode, cacheTime, options) instead, will be removed with 0.4")]
Add comment 67 96 public static Task<TOut?> GetJson<TOut>(this HttpClient client, Uri uri, JsonSerializerOptions? options = default, CacheMode cacheMode = CacheMode.PreferCache) =>
Add comment 68 Minus client.GetJson<TOut>(uri.ToString(), options, cacheMode);
Add comment 97 Plus client.GetJson<TOut>(uri.ToString(), cacheMode, 60, options);
Add comment 69 98 #endregion
Add comment 70 99
Add comment 71 100 #region POST
WPE.App.Extensions.csproj
/WPE.App.Extensions/WPE.App.Extensions.csproj-1+1/WPE.App.Extensions/WPE.App.Extensions.csproj
Add comment 15 <PackageIcon>icon.png</PackageIcon>
Add comment 16 <PackageReadmeFile>ReadMe.md</PackageReadmeFile>
Add comment 17 <PackageTags>WPE;Workplace Experience;infsoft</PackageTags>
Add comment 18 Minus <Version>0.3.4</Version>
Add comment 18 Plus <Version>0.3.5</Version>
Add comment 19 <GenerateDocumentationFile>true</GenerateDocumentationFile>
Add comment 20 </PropertyGroup>
Add comment 21