-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathDriveItemRequestBuilderExtensions.cs
More file actions
305 lines (293 loc) · 16.2 KB
/
DriveItemRequestBuilderExtensions.cs
File metadata and controls
305 lines (293 loc) · 16.2 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Graph.Drives.Item.Items.Item.Analytics;
using Microsoft.Graph.Drives.Item.Items.Item.AssignSensitivityLabel;
using Microsoft.Graph.Drives.Item.Items.Item.Children;
using Microsoft.Graph.Drives.Item.Items.Item.Content;
using Microsoft.Graph.Drives.Item.Items.Item.Checkin;
using Microsoft.Graph.Drives.Item.Items.Item.Checkout;
using Microsoft.Graph.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Drives.Item.Items.Item.CreatedByUser;
using Microsoft.Graph.Drives.Item.Items.Item.CreateLink;
using Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession;
using Microsoft.Graph.Drives.Item.Items.Item.Delta;
using Microsoft.Graph.Drives.Item.Items.Item.DeltaWithToken;
using Microsoft.Graph.Drives.Item.Items.Item.Follow;
using Microsoft.Graph.Drives.Item.Items.Item.GetActivitiesByInterval;
using Microsoft.Graph.Drives.Item.Items.Item.GetActivitiesByIntervalWithStartDateTimeWithEndDateTimeWithInterval;
using Microsoft.Graph.Drives.Item.Items.Item.Invite;
using Microsoft.Graph.Drives.Item.Items.Item.LastModifiedByUser;
using Microsoft.Graph.Drives.Item.Items.Item.ListItem;
using Microsoft.Graph.Drives.Item.Items.Item.PermanentDelete;
using Microsoft.Graph.Drives.Item.Items.Item.Preview;
using Microsoft.Graph.Drives.Item.Items.Item.Restore;
using Microsoft.Graph.Drives.Item.Items.Item.RetentionLabel;
using Microsoft.Graph.Drives.Item.Items.Item.Permissions;
using Microsoft.Graph.Drives.Item.Items.Item.SearchWithQ;
using Microsoft.Graph.Drives.Item.Items.Item.Subscriptions;
using Microsoft.Graph.Drives.Item.Items.Item.Thumbnails;
using Microsoft.Graph.Drives.Item.Items.Item.Unfollow;
using Microsoft.Graph.Drives.Item.Items.Item.ValidatePermission;
using Microsoft.Graph.Drives.Item.Items.Item.Workbook;
using Microsoft.Graph.Drives.Item.Items.Item.Versions;
using Microsoft.Kiota.Abstractions;
namespace Microsoft.Graph;
public static class DriveItemRequestBuilderExtensions
{
/// <summary>
/// Gets drive item request builder for the specified drive item path.
/// <returns>The drive item request builder.</returns>
/// </summary>
public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Graph.Drives.Item.Root.RootRequestBuilder rootRequestBuilder, string path)
{
if (path is null)
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("path cannot be empty or whitespace.", nameof(path));
if (!path.StartsWith("/"))
{
path = string.Format("/{0}", path);
}
var requestInformation = rootRequestBuilder.ToGetRequestInformation();
// Encode the path in accordance with the one drive spec
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/addressing-driveitems
UriBuilder builder = new UriBuilder(requestInformation.URI.OriginalString);
builder.Path += $":{path}:";
var parameter = builder.Uri.OriginalString.Split(new []{':'},StringSplitOptions.RemoveEmptyEntries).Last();
return new CustomDriveItemItemRequestBuilder(rootRequestBuilder.GetPathParameters(),rootRequestBuilder.GetRequestAdapter(), rootRequestBuilder.GetUrlTemplate().Replace("root",$"root:{parameter}:"));
}
/// <summary>
/// Gets drive item request builder for the specified drive item path.
/// <returns>The drive item request builder.</returns>
/// </summary>
public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Graph.Drives.Item.Items.Item.DriveItemItemRequestBuilder rootRequestBuilder, string path)
{
if (path is null)
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("path cannot be empty or whitespace.", nameof(path));
if (!path.StartsWith("/"))
{
path = string.Format("/{0}", path);
}
var requestInformation = rootRequestBuilder.ToGetRequestInformation();
// Encode the path in accordance with the one drive spec
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/addressing-driveitems
UriBuilder builder = new UriBuilder(requestInformation.URI.OriginalString);
builder.Path += $":{path}:";
var parameter = builder.Uri.OriginalString.Split(new []{':'},StringSplitOptions.RemoveEmptyEntries).Last();
return new CustomDriveItemItemRequestBuilder(rootRequestBuilder.GetPathParameters(), rootRequestBuilder.GetRequestAdapter(),rootRequestBuilder.GetUrlTemplate().Replace("{driveItem%2Did}",$"{{driveItem%2Did}}:{parameter}:"));
}
private static IRequestAdapter GetRequestAdapter(this object obj) {
var field = obj.GetType()
.BaseType!
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault( field => field.FieldType == typeof(IRequestAdapter));
return (IRequestAdapter)field?.GetValue(obj);
}
private static Dictionary<string, object> GetPathParameters(this object obj) {
var field = obj.GetType()
.BaseType!
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault( field => field.FieldType == typeof(Dictionary<string, object>));
return (Dictionary<string, object>)field?.GetValue(obj);
}
private static string GetUrlTemplate(this object obj) {
var field = obj.GetType()
.BaseType!
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault( field => field.FieldType == typeof(string));
return (string)field?.GetValue(obj);
}
internal static T UpdateUrlTemplate<T>(this T obj, string baseTemplate) where T : BaseRequestBuilder{
var field = obj.GetType()
.BaseType!
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault( field => field.FieldType == typeof(string));
var currentTemplate = (string)field?.GetValue(obj);
var templateSuffix = currentTemplate.Substring(currentTemplate.LastIndexOf('/'));
var originalPrefix = baseTemplate.Substring(0,baseTemplate.LastIndexOf(':')+1);
var updatedTemplate = originalPrefix +templateSuffix;
field?.SetValue(obj,updatedTemplate);
return obj;
}
}
public class CustomDriveItemItemRequestBuilder : Microsoft.Graph.Drives.Item.Items.Item.DriveItemItemRequestBuilder
{
/// <summary>
/// Instantiates a new DriveItemItemRequestBuilder and sets the default values.
/// </summary>
/// <param name="pathParameters">The path parameters to use for the request builder.</param>
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
/// <param name="urlTemplate">The UrlTemplate to use to execute the requests.</param>
public CustomDriveItemItemRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter, string urlTemplate): base(pathParameters,requestAdapter)
{
_ = pathParameters ?? throw new ArgumentNullException(nameof(pathParameters));
_ = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter));
this.PathParameters = pathParameters;
this.RequestAdapter = requestAdapter;
this.UrlTemplate = urlTemplate;
}
/// <summary>Provides operations to manage the analytics property of the microsoft.graph.driveItem entity.</summary>
public new AnalyticsRequestBuilder Analytics
{
get => new AnalyticsRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the assignSensitivityLabel method.</summary>
public new AssignSensitivityLabelRequestBuilder AssignSensitivityLabel
{
get => new AssignSensitivityLabelRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the checkin method.</summary>
public new CheckinRequestBuilder Checkin
{
get => new CheckinRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the checkout method.</summary>
public new CheckoutRequestBuilder Checkout
{
get => new CheckoutRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the children property of the microsoft.graph.driveItem entity.</summary>
public new ChildrenRequestBuilder Children
{
get => new ChildrenRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the media for the drive entity.</summary>
public new ContentRequestBuilder Content
{
get => new ContentRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the copy method.</summary>
public new CopyRequestBuilder Copy
{
get => new CopyRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the createdByUser property of the microsoft.graph.baseItem entity.</summary>
public new CreatedByUserRequestBuilder CreatedByUser
{
get => new CreatedByUserRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the createLink method.</summary>
public new CreateLinkRequestBuilder CreateLink
{
get => new CreateLinkRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the createUploadSession method.</summary>
public new CreateUploadSessionRequestBuilder CreateUploadSession
{
get => new CreateUploadSessionRequestBuilder(PathParameters , RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the delta method.</summary>
public new DeltaRequestBuilder Delta
{
get => new DeltaRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the follow method.</summary>
public new FollowRequestBuilder Follow
{
get => new FollowRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the getActivitiesByInterval method.</summary>
public new GetActivitiesByIntervalRequestBuilder GetActivitiesByInterval
{
get =>
new GetActivitiesByIntervalRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the invite method.</summary>
public new InviteRequestBuilder Invite
{
get => new InviteRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the lastModifiedByUser property of the microsoft.graph.baseItem entity.</summary>
public new LastModifiedByUserRequestBuilder LastModifiedByUser
{
get => new LastModifiedByUserRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the listItem property of the microsoft.graph.driveItem entity.</summary>
public new ListItemRequestBuilder ListItem {
get => new ListItemRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the permanentDelete method.</summary>
public new PermanentDeleteRequestBuilder PermanentDelete
{
get => new PermanentDeleteRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the permissions property of the microsoft.graph.driveItem entity.</summary>
public new PermissionsRequestBuilder Permissions {
get => new PermissionsRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the preview method.</summary>
public new PreviewRequestBuilder Preview
{
get => new PreviewRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the restore method.</summary>
public new RestoreRequestBuilder Restore
{
get => new RestoreRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the retentionLabel property of the microsoft.graph.driveItem entity.</summary>
public new RetentionLabelRequestBuilder RetentionLabel
{
get => new RetentionLabelRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the subscriptions property of the microsoft.graph.driveItem entity.</summary>
public new SubscriptionsRequestBuilder Subscriptions
{
get => new SubscriptionsRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the thumbnails property of the microsoft.graph.driveItem entity.</summary>
public new ThumbnailsRequestBuilder Thumbnails
{
get => new ThumbnailsRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the unfollow method.</summary>
public new UnfollowRequestBuilder Unfollow
{
get => new UnfollowRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to call the validatePermission method.</summary>
public new ValidatePermissionRequestBuilder ValidatePermission
{
get => new ValidatePermissionRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the versions property of the microsoft.graph.driveItem entity.</summary>
public new VersionsRequestBuilder Versions
{
get => new VersionsRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>Provides operations to manage the workbook property of the microsoft.graph.driveItem entity.</summary>
public new WorkbookRequestBuilder Workbook
{
get => new WorkbookRequestBuilder(PathParameters, RequestAdapter).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>
/// Provides operations to call the delta method.
/// </summary>
/// <param name="token">Usage: token='{token}'</param>
public new DeltaWithTokenRequestBuilder DeltaWithToken(string token)
{
return new DeltaWithTokenRequestBuilder(PathParameters, RequestAdapter, token).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>
/// Provides operations to call the getActivitiesByInterval method.
/// </summary>
/// <param name="endDateTime">Usage: endDateTime='{endDateTime}'</param>
/// <param name="interval">Usage: interval='{interval}'</param>
/// <param name="startDateTime">Usage: startDateTime='{startDateTime}'</param>
public new GetActivitiesByIntervalWithStartDateTimeWithEndDateTimeWithIntervalRequestBuilder GetActivitiesByIntervalWithStartDateTimeWithEndDateTimeWithInterval(string endDateTime, string interval, string startDateTime)
{
return new GetActivitiesByIntervalWithStartDateTimeWithEndDateTimeWithIntervalRequestBuilder(PathParameters, RequestAdapter, endDateTime, interval, startDateTime).UpdateUrlTemplate(this.UrlTemplate);
}
/// <summary>
/// Provides operations to call the search method.
/// </summary>
/// <param name="q">Usage: q='{q}'</param>
public new SearchWithQRequestBuilder SearchWithQ(string q)
{
return new SearchWithQRequestBuilder(PathParameters, RequestAdapter, q).UpdateUrlTemplate(this.UrlTemplate);
}
}