Skip to content

Commit

Permalink
Merge pull request #345 from microsoft/fix/task-management
Browse files Browse the repository at this point in the history
fix/task management
  • Loading branch information
baywet authored Aug 28, 2024
2 parents a657ef5 + c7df801 commit 8203312
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 41 deletions.
4 changes: 4 additions & 0 deletions src/abstractions/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Std.UriTemplate" Version="1.0.5" />
</ItemGroup>

Expand Down
56 changes: 49 additions & 7 deletions src/abstractions/NativeResponseWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Kiota.Abstractions
Expand All @@ -22,14 +24,52 @@ public class NativeResponseWrapper
/// <param name="h">The request headers of the request</param>
/// <param name="o">Request options</param>
/// <returns></returns>
public static async Task<NativeResponseType?> CallAndGetNativeType<ModelType, NativeResponseType, QueryParametersType>(
[Obsolete("Use CallAndGetNativeTypeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
public static Task<NativeResponseType?> CallAndGetNativeType<ModelType, NativeResponseType, QueryParametersType>(
Func<Action<QueryParametersType>?, Action<IDictionary<string, string>>?, IEnumerable<IRequestOption>?, IResponseHandler, Task<ModelType>> originalCall,
Action<QueryParametersType>? q = default,
Action<IDictionary<string, string>>? h = default,
IEnumerable<IRequestOption>? o = default) where NativeResponseType : class
IEnumerable<IRequestOption>? o = default) where NativeResponseType : class => CallAndGetNativeTypeAsync<ModelType, NativeResponseType, QueryParametersType>((_q, _h, _o, _r, _c) => originalCall(_q, _h, _o, _r), q, h, o);

/// <summary>
/// Makes a request with the <typeparam name="RequestBodyType"/> and <typeparam name="QueryParametersType"/> instances to get a response with
/// a <typeparam name="NativeResponseType"/> instance and expect an instance of <typeparam name="ModelType"/>
/// </summary>
/// <param name="originalCall">The original request to make</param>
/// <param name="requestBody">The request body of the request</param>
/// <param name="q">The query parameters of the request</param>
/// <param name="h">The request headers of the request</param>
/// <param name="o">Request options</param>
[Obsolete("Use CallAndGetNativeTypeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Task<NativeResponseType?> CallAndGetNativeType<ModelType, NativeResponseType, QueryParametersType, RequestBodyType>(
Func<RequestBodyType, Action<QueryParametersType>?, Action<IDictionary<string, string>>?, IEnumerable<IRequestOption>?, IResponseHandler, Task<ModelType>> originalCall,
RequestBodyType requestBody,
Action<QueryParametersType>? q = default,
Action<IDictionary<string, string>>? h = default,
IEnumerable<IRequestOption>? o = default) where NativeResponseType : class => CallAndGetNativeTypeAsync<ModelType, NativeResponseType, QueryParametersType, RequestBodyType>((_b, _q, _h, _o, _r, _c) => originalCall(_b, _q, _h, _o, _r), requestBody, q, h, o);
#pragma warning restore VSTHRD200 // Use "Async" suffix for async methods
/// <summary>
/// Makes a request with the <typeparam name="QueryParametersType"/> instance to get a response with
/// a <typeparam name="NativeResponseType"/> instance and expect an instance of <typeparam name="ModelType"/>
/// </summary>
/// <param name="originalCall">The original request to make</param>
/// <param name="q">The query parameters of the request</param>
/// <param name="h">The request headers of the request</param>
/// <param name="o">Request options</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns></returns>
public static async Task<NativeResponseType?> CallAndGetNativeTypeAsync<ModelType, NativeResponseType, QueryParametersType>(
Func<Action<QueryParametersType>?, Action<IDictionary<string, string>>?, IEnumerable<IRequestOption>?, IResponseHandler, CancellationToken, Task<ModelType>> originalCall,
Action<QueryParametersType>? q = default,
Action<IDictionary<string, string>>? h = default,
IEnumerable<IRequestOption>? o = default,
CancellationToken cancellationToken = default) where NativeResponseType : class
{
var responseHandler = new NativeResponseHandler();
await originalCall.Invoke(q, h, o, responseHandler);
await originalCall.Invoke(q, h, o, responseHandler, cancellationToken);
return responseHandler.Value as NativeResponseType;
}

Expand All @@ -42,15 +82,17 @@ public class NativeResponseWrapper
/// <param name="q">The query parameters of the request</param>
/// <param name="h">The request headers of the request</param>
/// <param name="o">Request options</param>
public static async Task<NativeResponseType?> CallAndGetNativeType<ModelType, NativeResponseType, QueryParametersType, RequestBodyType>(
Func<RequestBodyType, Action<QueryParametersType>?, Action<IDictionary<string, string>>?, IEnumerable<IRequestOption>?, IResponseHandler, Task<ModelType>> originalCall,
/// <param name="cancellationToken">The cancellation token</param>
public static async Task<NativeResponseType?> CallAndGetNativeTypeAsync<ModelType, NativeResponseType, QueryParametersType, RequestBodyType>(
Func<RequestBodyType, Action<QueryParametersType>?, Action<IDictionary<string, string>>?, IEnumerable<IRequestOption>?, IResponseHandler, CancellationToken, Task<ModelType>> originalCall,
RequestBodyType requestBody,
Action<QueryParametersType>? q = default,
Action<IDictionary<string, string>>? h = default,
IEnumerable<IRequestOption>? o = default) where NativeResponseType : class
IEnumerable<IRequestOption>? o = default,
CancellationToken cancellationToken = default) where NativeResponseType : class
{
var responseHandler = new NativeResponseHandler();
await originalCall.Invoke(requestBody, q, h, o, responseHandler);
await originalCall.Invoke(requestBody, q, h, o, responseHandler, cancellationToken);
return responseHandler.Value as NativeResponseType;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.42.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\..\abstractions\Microsoft.Kiota.Abstractions.csproj" />
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions src/bundle/Microsoft.Kiota.Bundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
<ProjectReference Include="..\serialization\text\Microsoft.Kiota.Serialization.Text.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
Loading

0 comments on commit 8203312

Please sign in to comment.