- Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathUploadSessionRequestBuilder.cs
85 lines (78 loc) · 3.69 KB
/
UploadSessionRequestBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
namespaceMicrosoft.Graph
{
usingSystem.Net.Http;
usingSystem.Threading;
usingSystem.Threading.Tasks;
usingMicrosoft.Graph.Core.Models;
usingMicrosoft.Kiota.Abstractions;
internalclassUploadSessionRequestBuilder
{
privatereadonlyUploadResponseHandlerresponseHandler;
privatereadonlyIRequestAdapterrequestAdapter;
privatereadonlystringurlTemplate;
/// <summary>
/// Create a new UploadSessionRequest
/// </summary>
/// <param name="uploadSession">The IUploadSession to use in the request.</param>
/// <param name="requestAdapter">The <see cref="IRequestAdapter"/> for handling requests.</param>
publicUploadSessionRequestBuilder(IUploadSessionuploadSession,IRequestAdapterrequestAdapter)
{
this.responseHandler=newUploadResponseHandler();
this.requestAdapter=requestAdapter;
this.urlTemplate=uploadSession.UploadUrl;
}
/// <summary>
/// Deletes the specified Session
/// </summary>
/// <param name="cancellationToken"><see cref="CancellationToken"/> to use for cancelling requests</param>
/// <returns>The task to await.</returns>
publicasyncTaskDeleteAsync(CancellationTokencancellationToken=default)
{
varrequestInformation=this.ToDeleteRequestInformation();
awaitthis.requestAdapter.SendNoContentAsync(requestInformation,cancellationToken:cancellationToken);
}
/// <summary>
/// Creates <see cref="RequestInformation"/> instance for a DELETE request
/// </summary>
/// <returns>The <see cref="RequestInformation"/> instance.</returns>
publicRequestInformationToDeleteRequestInformation()
{
varrequestInfo=newRequestInformation
{
HttpMethod=Method.DELETE,
UrlTemplate=urlTemplate,
};
returnrequestInfo;
}
/// <summary>
/// Gets the specified UploadSession.
/// </summary>
/// <param name="cancellationToken"><see cref="CancellationToken"/> to use for cancelling requests</param>
/// <returns>The Item.</returns>
publicasyncTask<IUploadSession>GetAsync(CancellationTokencancellationToken=default)
{
varrequestInformation=this.ToGetRequestInformation();
varnativeResponseHandler=newNativeResponseHandler();
requestInformation.SetResponseHandler(nativeResponseHandler);
awaitthis.requestAdapter.SendNoContentAsync(requestInformation,cancellationToken:cancellationToken).ConfigureAwait(false);
varuploadResult=awaitthis.responseHandler.HandleResponseAsync<UploadSession>(nativeResponseHandler.ValueasHttpResponseMessage).ConfigureAwait(false);
returnuploadResult.UploadSession;
}
/// <summary>
/// Creates <see cref="RequestInformation"/> instance for a GET request
/// </summary>
/// <returns>The <see cref="RequestInformation"/> instance.</returns>
publicRequestInformationToGetRequestInformation()
{
varrequestInfo=newRequestInformation
{
HttpMethod=Method.GET,
UrlTemplate=urlTemplate,
};
returnrequestInfo;
}
}
}