Skip to content

Commit b5b4065

Browse files
authored
Add Documentation in Autodesk.Forge.Core (#165)
1 parent 8151dae commit b5b4065

17 files changed

+259
-20
lines changed

Autodesk.Forge.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autodesk.Forge.Core.Test",
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autodesk.Forge.Core.E2eTestHelpers", "src\Autodesk.Forge.Core.E2eTestHelpers\Autodesk.Forge.Core.E2eTestHelpers.csproj", "{66694EE2-D632-476D-B533-589AC9B975F3}"
1111
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{BC49E389-CECC-489D-ACE8-BB97869391B9}"
13+
ProjectSection(SolutionItems) = preProject
14+
CHANGELOG.md = CHANGELOG.md
15+
Directory.Build.props = Directory.Build.props
16+
Directory.Build.targets = Directory.Build.targets
17+
README.md = README.md
18+
EndProjectSection
19+
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3E0D0E6A-0664-491F-93E8-0290B21C3D09}"
21+
ProjectSection(SolutionItems) = preProject
22+
src\Directory.Build.props = src\Directory.Build.props
23+
src\Directory.Build.targets = src\Directory.Build.targets
24+
EndProjectSection
25+
EndProject
26+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6E857E79-2F5E-4B70-996D-A42A445F67B4}"
27+
EndProject
1228
Global
1329
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1430
Debug|Any CPU = Debug|Any CPU
@@ -31,6 +47,11 @@ Global
3147
GlobalSection(SolutionProperties) = preSolution
3248
HideSolutionNode = FALSE
3349
EndGlobalSection
50+
GlobalSection(NestedProjects) = preSolution
51+
{E59655EF-C1BF-4318-B344-B2C6B67E1A74} = {3E0D0E6A-0664-491F-93E8-0290B21C3D09}
52+
{B52C434A-3AA1-4CA7-9F88-39AA2C208A67} = {6E857E79-2F5E-4B70-996D-A42A445F67B4}
53+
{66694EE2-D632-476D-B533-589AC9B975F3} = {3E0D0E6A-0664-491F-93E8-0290B21C3D09}
54+
EndGlobalSection
3455
GlobalSection(ExtensibilityGlobals) = postSolution
3556
SolutionGuid = {D05CFF55-5724-433F-9941-337DC508F5FE}
3657
EndGlobalSection

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 4.0.1
2+
3+
* Add Documentation in the `Autodesk.Forge.Core` project.
4+
15
### 4.0.0.0
26

37
* Migrate to .Net 8

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<PropertyGroup>
3+
<Version>4.0.1</Version>
34
<TargetFramework>net8.0</TargetFramework>
45
<ImplicitUsings>enable</ImplicitUsings>
56
</PropertyGroup>

src/Autodesk.Forge.Core.E2eTestHelpers/Autodesk.Forge.Core.E2eTestHelpers.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<Description>Shared code for Forge client sdks e2e tests</Description>
5-
<PackageVersion>4.0.0</PackageVersion>
65
<IsTestProject>false</IsTestProject>
76
<NoWarn>NU5100</NoWarn>
87
</PropertyGroup>

src/Autodesk.Forge.Core/ApiResponse.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace Autodesk.Forge.Core
2323
/// </summary>
2424
public class ApiResponse : IDisposable
2525
{
26+
/// <summary>
27+
/// Gets or sets the HTTP response message.
28+
/// </summary>
29+
/// <value>The HTTP response message.</value>
2630
public HttpResponseMessage HttpResponse { get; private set; }
2731

2832
/// <summary>
@@ -34,6 +38,9 @@ public ApiResponse(HttpResponseMessage response)
3438
this.HttpResponse = response;
3539
}
3640

41+
/// <summary>
42+
/// Disposes the API response.
43+
/// </summary>
3744
public void Dispose()
3845
{
3946
HttpResponse?.Dispose();
@@ -55,7 +62,7 @@ public class ApiResponse<T> : ApiResponse
5562
/// Initializes a new instance of the <see cref="ApiResponse&lt;T&gt;" /> class.
5663
/// </summary>
5764
/// <param name="response">Http response message.</param>
58-
/// <param name="data">content (parsed HTTP body)</param>
65+
/// <param name="content">content (parsed HTTP body)</param>
5966
public ApiResponse(HttpResponseMessage response, T content)
6067
: base(response)
6168
{

src/Autodesk.Forge.Core/Autodesk.Forge.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Shared code for APS client sdks</Description>
5-
<PackageVersion>4.0.0</PackageVersion>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
</PropertyGroup>
77

88
<ItemGroup>

src/Autodesk.Forge.Core/ForgeAgentConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@
1818

1919
namespace Autodesk.Forge.Core
2020
{
21+
/// <summary>
22+
/// Represents the configuration for the Forge Agent.
23+
/// </summary>
2124
public class ForgeAgentConfiguration
2225
{
26+
/// <summary>
27+
/// Gets or sets the client ID.
28+
/// </summary>
2329
public string ClientId { get; init; }
30+
31+
/// <summary>
32+
/// Gets or sets the client secret.
33+
/// </summary>
2434
public string ClientSecret { get; init; }
2535
}
2636
}

src/Autodesk.Forge.Core/ForgeAgentHandler.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,33 @@
1818

1919
namespace Autodesk.Forge.Core
2020
{
21+
/// <summary>
22+
/// Represents a handler for Forge agents.
23+
/// </summary>
2124
public class ForgeAgentHandler : DelegatingHandler
2225
{
26+
/// <summary>
27+
/// The default agent name.
28+
/// </summary>
2329
public const string defaultAgentName = "default";
24-
30+
2531
private string user;
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="ForgeAgentHandler"/> class.
35+
/// </summary>
36+
/// <param name="user">The user associated with the agent.</param>
2637
public ForgeAgentHandler(string user)
2738
{
2839
this.user = user;
2940
}
41+
42+
/// <summary>
43+
/// Sends an HTTP request asynchronously.
44+
/// </summary>
45+
/// <param name="request">The HTTP request message.</param>
46+
/// <param name="cancellationToken">The cancellation token.</param>
47+
/// <returns>The task representing the asynchronous operation.</returns>
3048
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
3149
{
3250
request.Options.TryAdd(ForgeConfiguration.AgentKey.Key, user);

src/Autodesk.Forge.Core/ForgeConfiguration.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,50 @@
1818

1919
namespace Autodesk.Forge.Core
2020
{
21+
/// <summary>
22+
/// Represents the configuration settings for the Forge SDK.
23+
/// </summary>
2124
public class ForgeConfiguration
2225
{
26+
/// <summary>
27+
/// Represents the key for the Forge agent in the HTTP request options.
28+
/// </summary>
2329
public static readonly HttpRequestOptionsKey<string> AgentKey = new HttpRequestOptionsKey<string>("Autodesk.Forge.Agent");
30+
/// <summary>
31+
/// Represents the key for the Forge scope in the HTTP request options.
32+
/// </summary>
2433
public static readonly HttpRequestOptionsKey<string> ScopeKey = new HttpRequestOptionsKey<string>("Autodesk.Forge.Scope");
34+
/// <summary>
35+
/// Represents the key for the Forge timeout in the HTTP request options.
36+
/// </summary>
2537
public static readonly HttpRequestOptionsKey<int> TimeoutKey = new HttpRequestOptionsKey<int>("Autodesk.Forge.Timeout");
2638

39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="ForgeConfiguration"/> class.
41+
/// </summary>
2742
public ForgeConfiguration()
2843
{
2944
this.AuthenticationAddress = new Uri("https://developer.api.autodesk.com/authentication/v2/token");
3045
}
46+
47+
/// <summary>
48+
/// Gets or sets the client ID.
49+
/// </summary>
3150
public string ClientId { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the client secret.
54+
/// </summary>
3255
public string ClientSecret { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets the dictionary of Forge agent configurations.
59+
/// </summary>
3360
public IDictionary<string, ForgeAgentConfiguration> Agents { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the authentication address.
64+
/// </summary>
3465
public Uri AuthenticationAddress { get; set; }
3566
}
3667
}

src/Autodesk.Forge.Core/ForgeHandler.cs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,61 @@
2323

2424
namespace Autodesk.Forge.Core
2525
{
26+
/// <summary>
27+
/// Represents a handler for Forge API requests.
28+
/// </summary>
2629
public class ForgeHandler : DelegatingHandler
2730
{
2831
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
2932
private readonly Random rand = new Random();
3033
private readonly IAsyncPolicy<HttpResponseMessage> resiliencyPolicies;
3134

35+
/// <summary>
36+
/// Gets or sets the Forge configuration options.
37+
/// </summary>
3238
protected readonly IOptions<ForgeConfiguration> configuration;
3339

40+
/// <summary>
41+
/// Gets or sets the token cache.
42+
/// </summary>
3443
protected ITokenCache TokenCache { get; private set; }
3544

3645
private bool IsDefaultClient(string user) => string.IsNullOrEmpty(user) || user == ForgeAgentHandler.defaultAgentName;
3746

47+
/// <summary>
48+
/// Initializes a new instance of the <see cref="ForgeHandler"/> class.
49+
/// </summary>
50+
/// <param name="configuration">The Forge configuration options.</param>
3851
public ForgeHandler(IOptions<ForgeConfiguration> configuration)
3952
{
4053
this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
4154
this.TokenCache = new TokenCache();
4255
this.resiliencyPolicies = GetResiliencyPolicies(GetDefaultTimeout());
4356
}
57+
/// <summary>
58+
/// Gets the default timeout value.
59+
/// </summary>
60+
/// <returns>The default timeout value.</returns>
4461
protected virtual TimeSpan GetDefaultTimeout()
4562
{
46-
// use timeout greater than the forge gateways (10s), we handle the GatewayTimeout response
47-
return TimeSpan.FromSeconds(15);
63+
// use timeout greater than the forge gateways (10s), we handle the GatewayTimeout response
64+
return TimeSpan.FromSeconds(15);
4865
}
49-
protected virtual (int baseDelayInMs, int multiplier ) GetRetryParameters()
66+
/// <summary>
67+
/// Gets the retry parameters for resiliency policies.
68+
/// </summary>
69+
/// <returns>A tuple containing the base delay in milliseconds and the multiplier.</returns>
70+
protected virtual (int baseDelayInMs, int multiplier) GetRetryParameters()
5071
{
5172
return (500, 1000);
5273
}
74+
/// <summary>
75+
/// Sends an HTTP request asynchronously.
76+
/// </summary>
77+
/// <param name="request">The HTTP request message.</param>
78+
/// <param name="cancellationToken">The cancellation token.</param>
79+
/// <returns>The task representing the asynchronous operation.</returns>
80+
/// <exception cref="ArgumentNullException">Thrown when the request URI is null.</exception>
5381
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
5482
{
5583
if (request.RequestUri == null)
@@ -80,18 +108,25 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
80108
}
81109
return await policies.ExecuteAsync(async (ct) => await base.SendAsync(request, ct), cancellationToken);
82110
}
83-
111+
/// <summary>
112+
/// Gets the token refresh policy.
113+
/// A policy that attempts to retry exactly once when a 401 error is received after obtaining a new token.
114+
/// </summary>
115+
/// <returns>The token refresh policy.</returns>
84116
protected virtual IAsyncPolicy<HttpResponseMessage> GetTokenRefreshPolicy()
85117
{
86-
// A policy that attempts to retry exactly once when 401 error is received after obtaining a new token
87118
return Policy
88119
.HandleResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.Unauthorized)
89120
.RetryAsync(
90121
retryCount: 1,
91122
onRetryAsync: async (outcome, retryNumber, context) => await RefreshTokenAsync(outcome.Result.RequestMessage, true, CancellationToken.None)
92123
);
93124
}
94-
125+
/// <summary>
126+
/// Gets the resiliency policies for handling HTTP requests.
127+
/// </summary>
128+
/// <param name="timeoutValue">The timeout value for the policies.</param>
129+
/// <returns>The resiliency policies.</returns>
95130
protected virtual IAsyncPolicy<HttpResponseMessage> GetResiliencyPolicies(TimeSpan timeoutValue)
96131
{
97132
// Retry when HttpRequestException is thrown (low level network error) or
@@ -149,6 +184,13 @@ protected virtual IAsyncPolicy<HttpResponseMessage> GetResiliencyPolicies(TimeSp
149184
return Policy.WrapAsync<HttpResponseMessage>(breaker, retry, timeout);
150185
}
151186

187+
/// <summary>
188+
/// Refreshes the token asynchronously.
189+
/// </summary>
190+
/// <param name="request">The HTTP request message.</param>
191+
/// <param name="ignoreCache">A flag indicating whether to ignore the cache and always refresh the token.</param>
192+
/// <param name="cancellationToken">The cancellation token.</param>
193+
/// <returns>The task representing the asynchronous operation.</returns>
152194
protected virtual async Task RefreshTokenAsync(HttpRequestMessage request, bool ignoreCache, CancellationToken cancellationToken)
153195
{
154196
if (request.Options.TryGetValue(ForgeConfiguration.ScopeKey, out var scope))
@@ -176,6 +218,14 @@ protected virtual async Task RefreshTokenAsync(HttpRequestMessage request, bool
176218
}
177219
}
178220
}
221+
222+
/// <summary>
223+
/// Gets a 2-legged token asynchronously.
224+
/// </summary>
225+
/// <param name="user">The user.</param>
226+
/// <param name="scope">The scope.</param>
227+
/// <param name="cancellationToken">The cancellation token.</param>
228+
/// <returns>A tuple containing the token and its expiry time.</returns>
179229
protected virtual async Task<(string, TimeSpan)> Get2LeggedTokenAsync(string user, string scope, CancellationToken cancellationToken)
180230
{
181231
using (var request = new HttpRequestMessage())

0 commit comments

Comments
 (0)