-
Notifications
You must be signed in to change notification settings - Fork 173
/
NewMgGroupMember_Create.cs
377 lines (341 loc) · 23.3 KB
/
NewMgGroupMember_Create.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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
namespace Microsoft.Graph.PowerShell.Cmdlets
{
using Newtonsoft.Json;
using static Microsoft.Graph.PowerShell.Runtime.Extensions;
/// <summary>Add a member to an Office 365 group or security group through the members navigation property.</summary>
/// <remarks>
/// </remarks>
[System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupMember_Create1", SupportsShouldProcess = true)]
[System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))]
[global::Microsoft.Graph.PowerShell.Description(@"Add a member to an Office 365 group or security group through the members navigation property.")]
[global::Microsoft.Graph.PowerShell.Generated]
public partial class NewMgGroupMember_Create : System.Management.Automation.PSCmdlet,
Runtime.IEventListener
{
/// <summary>A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet)</summary>
private System.Management.Automation.InvocationInfo __invocationInfo;
/// <summary>
/// The <see cref="System.Threading.CancellationTokenSource" /> for this operation.
/// </summary>
private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource();
/// <summary>Backing field for <see cref="BodyParameter" /> property.</summary>
private Microsoft.Graph.PowerShell.Models.IReferenceCreate _bodyParameter;
/// <summary>Entity reference body</summary>
[global::Microsoft.Graph.PowerShell.ExportAs(typeof(global::System.Collections.Hashtable))]
[global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Entity reference body", ValueFromPipeline = true)]
[Microsoft.Graph.PowerShell.Runtime.Info(
Required = true,
ReadOnly = false,
Description = @"Entity reference body",
SerializedName = @"body",
PossibleTypes = new[] { typeof(Microsoft.Graph.PowerShell.Models.IReferenceCreate) })]
public Microsoft.Graph.PowerShell.Models.IReferenceCreate BodyParameter { get => this._bodyParameter; set => this._bodyParameter = value; }
/// <summary>Wait for .NET debugger to attach</summary>
[System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Wait for .NET debugger to attach")]
[Category(ParameterCategory.Runtime)]
public System.Management.Automation.SwitchParameter Break { get; set; }
/// <summary>The reference to the client API class.</summary>
public Groups Client => Module.Instance.ClientAPI;
/// <summary>Backing field for <see cref="Headers" /> property.</summary>
private System.Collections.IDictionary _headers;
/// <summary>Optional headers that will be added to the request.</summary>
[System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "Optional headers that will be added to the request.", ValueFromPipeline = true)]
[Category(ParameterCategory.Runtime)]
public System.Collections.IDictionary Headers { get => this._headers; set => this._headers = value; }
// <summary>Backing field for <see cref="ResponseHeadersVariable" /> property.</summary>
private string _responseHeadersVariable;
/// <summary>Optional Response Headers Variable</summary>
[global::System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "Optional Response Headers Variable.")]
[global::System.Management.Automation.Alias("RHV")]
public string ResponseHeadersVariable { get => this._responseHeadersVariable; set => this._responseHeadersVariable = value; }
/// <summary>Backing field for <see cref="GroupId" /> property.</summary>
private string _groupId;
/// <summary>key: group-id of group</summary>
[System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "key: group-id of group")]
[Runtime.Info(
Required = true,
ReadOnly = false,
Description = @"key: group-id of group",
SerializedName = @"group-id",
PossibleTypes = new[] { typeof(string) })]
[Category(ParameterCategory.Path)]
public string GroupId { get => this._groupId; set => this._groupId = value; }
/// <summary>SendAsync Pipeline Steps to be appended to the front of the pipeline</summary>
[System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "SendAsync Pipeline Steps to be appended to the front of the pipeline")]
[System.Management.Automation.ValidateNotNull]
[Category(ParameterCategory.Runtime)]
public Runtime.SendAsyncStep[] HttpPipelineAppend { get; set; }
/// <summary>SendAsync Pipeline Steps to be prepended to the front of the pipeline</summary>
[System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "SendAsync Pipeline Steps to be prepended to the front of the pipeline")]
[System.Management.Automation.ValidateNotNull]
[Category(ParameterCategory.Runtime)]
public Runtime.SendAsyncStep[] HttpPipelinePrepend { get; set; }
/// <summary>Accessor for our copy of the InvocationInfo.</summary>
public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } }
/// <summary>
/// <see cref="IEventListener" /> cancellation delegate. Stops the cmdlet when called.
/// </summary>
System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel;
/// <summary><see cref="IEventListener" /> cancellation token.</summary>
System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token;
/// <summary>
/// The instance of the <see cref="Runtime.HttpPipeline" /> that the remote call will use.
/// </summary>
private Runtime.HttpPipeline Pipeline { get; set; }
/// <summary>The URI for the proxy server to use</summary>
[System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "The URI for the proxy server to use")]
[Category(ParameterCategory.Runtime)]
public System.Uri Proxy { get; set; }
/// <summary>Credentials for a proxy server to use for the remote call</summary>
[System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Credentials for a proxy server to use for the remote call")]
[System.Management.Automation.ValidateNotNull]
[Category(ParameterCategory.Runtime)]
public System.Management.Automation.PSCredential ProxyCredential { get; set; }
/// <summary>Use the default credentials for the proxy</summary>
[System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Use the default credentials for the proxy")]
[Category(ParameterCategory.Runtime)]
public System.Management.Automation.SwitchParameter ProxyUseDefaultCredentials { get; set; }
/// <summary>
/// <c>overrideOnCreated</c> will be called before the regular onCreated has been processed, allowing customization of what
/// happens on that response. Implement this method in a partial class to enable this behavior
/// </summary>
/// <param name="responseMessage">the raw response message as an global::System.Net.Http.HttpResponseMessage.</param>
/// <param name="response">the body result as a <see cref="Models.IMicrosoftGraphDirectoryObject"
/// /> from the remote call</param>
/// <param name="returnNow">/// Determines if the rest of the onCreated method should be processed, or if the method should
/// return immediately (set to true to skip further processing )</param>
partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphDirectoryObject> response, ref System.Threading.Tasks.Task<bool> returnNow);
/// <summary>
/// <c>overrideOnDefault</c> will be called before the regular onDefault has been processed, allowing customization of what
/// happens on that response. Implement this method in a partial class to enable this behavior
/// </summary>
/// <param name="responseMessage">the raw response message as an global::System.Net.Http.HttpResponseMessage.</param>
/// <param name="response">the body result as a <see cref="Models.IMicrosoftGraphODataErrorsOdataError" /> from the remote
/// call</param>
/// <param name="returnNow">/// Determines if the rest of the onDefault method should be processed, or if the method should
/// return immediately (set to true to skip further processing )</param>
partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphODataErrorsOdataError> response, ref System.Threading.Tasks.Task<bool> returnNow);
/// <summary>
/// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet)
/// </summary>
protected override void BeginProcessing()
{
Module.Instance.SetProxyConfiguration(Proxy, ProxyCredential, ProxyUseDefaultCredentials);
if (Break)
{
Runtime.AttachDebugger.Break();
}
((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletBeginProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
}
/// <summary>Performs clean-up after the command execution</summary>
protected override void EndProcessing()
{
((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
}
/// <summary>Handles/Dispatches events during the call to the REST service.</summary>
/// <param name="id">The message id</param>
/// <param name="token">The message cancellation token. When this call is canceled, this should be <c>true</c></param>
/// <param name="messageData">Detailed message data for the message event.</param>
/// <returns>
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the message is completed.
/// </returns>
async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func<Runtime.EventData> messageData)
{
using (NoSynchronizationContext)
{
if (token.IsCancellationRequested)
{
return;
}
switch (id)
{
case Runtime.Events.Verbose:
{
WriteVerbose($"{(messageData().Message ?? global::System.String.Empty)}");
return;
}
case Runtime.Events.Warning:
{
WriteWarning($"{(messageData().Message ?? global::System.String.Empty)}");
return;
}
case Runtime.Events.Information:
{
var data = messageData();
WriteInformation(data, new[] { data.Message });
return;
}
case Runtime.Events.Debug:
{
WriteDebug($"{(messageData().Message ?? global::System.String.Empty)}");
return;
}
case Runtime.Events.Error:
{
WriteError(new System.Management.Automation.ErrorRecord(new System.Exception(messageData().Message), string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null));
return;
}
}
WriteDebug($"{id}: {(messageData().Message ?? global::System.String.Empty)}");
}
}
/// <summary>
/// Initializes a new instance of the <see cref="NewMgGroupMember_Create" /> cmdlet class.
/// </summary>
public NewMgGroupMember_Create()
{
}
/// <summary>Performs execution of the command.</summary>
protected override void ProcessRecord()
{
((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordStart).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
try
{
// work
if (ShouldProcess($"Call remote 'CreateGroupMember' operation"))
{
using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token))
{
asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token);
}
}
}
catch (global::System.AggregateException aggregateException)
{
// unroll the inner exceptions to get the root cause
foreach (var innerException in aggregateException.Flatten().InnerExceptions)
{
((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
// Write exception out to error channel.
WriteError(new global::System.Management.Automation.ErrorRecord(innerException, string.Empty, global::System.Management.Automation.ErrorCategory.NotSpecified, null));
}
}
catch (global::System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null)
{
((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
// Write exception out to error channel.
WriteError(new global::System.Management.Automation.ErrorRecord(exception, string.Empty, global::System.Management.Automation.ErrorCategory.NotSpecified, null));
}
finally
{
((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordEnd).Wait();
}
}
/// <summary>Performs execution of the command, working asynchronously if required.</summary>
/// <returns>
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the method is completed.
/// </returns>
protected async System.Threading.Tasks.Task ProcessRecordAsync()
{
using (NoSynchronizationContext)
{
await ((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordAsyncStart); if (((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
await ((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletGetPipeline); if (((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
Pipeline = Microsoft.Graph.PowerShell.Module.Instance.CreatePipeline(InvocationInformation, this.ParameterSetName);
if (null != HttpPipelinePrepend)
{
Pipeline.Prepend((this.CommandRuntime as Microsoft.Graph.PowerShell.Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend);
}
if (null != HttpPipelineAppend)
{
Pipeline.Append((this.CommandRuntime as Microsoft.Graph.PowerShell.Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelineAppend) ?? HttpPipelineAppend);
}
// get the client instance
try
{
await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletBeforeAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
await this.Client.GroupCreateMemberGraphBPreRef(GroupId, Headers, BodyParameter, onNoContent, onDefault, this, Pipeline);
await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; }
}
catch (Microsoft.Graph.PowerShell.Runtime.UndeclaredResponseException urexception)
{
WriteError(new global::System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, Headers = Headers, body = BodyParameter })
{
ErrorDetails = new global::System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action }
});
}
catch (System.Exception ex) { ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{ex.GetType().Name} - {ex.Message} : {ex.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } WriteError(new global::System.Management.Automation.ErrorRecord(ex, string.Empty, global::System.Management.Automation.ErrorCategory.NotSpecified, null)); }
finally
{
await ((Microsoft.Graph.PowerShell.Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordAsyncEnd);
}
}
}
/// <summary>Interrupts currently running code within the command.</summary>
protected override void StopProcessing()
{
((Runtime.IEventListener)this).Cancel();
base.StopProcessing();
}
/// <summary>a delegate that is called when the remote service returns 204 (NoContent).</summary>
/// <param name="responseMessage">the raw response message as an global::System.Net.Http.HttpResponseMessage.</param>
/// <returns>
/// A <see cref="global::System.Threading.Tasks.Task" /> that will be complete when handling of the method is completed.
/// </returns>
private async global::System.Threading.Tasks.Task onNoContent(global::System.Net.Http.HttpResponseMessage responseMessage)
{
using (NoSynchronizationContext)
{
var _returnNow = global::System.Threading.Tasks.Task<bool>.FromResult(false);
// if overrideOnNoContent has returned true, then return right away.
if ((null != _returnNow && await _returnNow))
{
return;
}
// onNoContent - response for 204 /
if (true == MyInvocation?.BoundParameters?.ContainsKey("PassThru"))
{
WriteObject(true);
}
// get the headers from the response and assign it to the variable provided by the user via the RHV(ResponseHeadersVariable) parameter.
if (!string.IsNullOrEmpty(ResponseHeadersVariable))
{
var headers = Microsoft.Graph.PowerShell.ResponseHeaders.Helpers.ResponseHeaderHelper.GetHttpResponseHeaders(responseMessage);
var vi = this.SessionState.PSVariable;
vi.Set(new System.Management.Automation.PSVariable($"global:{ResponseHeadersVariable}", headers));
}
}
}
/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
/// <param name="responseMessage">the raw response message as an global::System.Net.Http.HttpResponseMessage.</param>
/// <param name="response">the body result as a <see cref="Microsoft.Graph.PowerShell.Models.IMicrosoftGraphODataErrorsOdataError">Microsoft.Graph.PowerShell.Models.IMicrosoftGraphODataErrorsOdataError</see>
/// from the remote call</param>
/// <returns>
/// A <see cref="global::System.Threading.Tasks.Task" /> that will be complete when handling of the method is completed.
/// </returns>
private async global::System.Threading.Tasks.Task onDefault(global::System.Net.Http.HttpResponseMessage responseMessage, global::System.Threading.Tasks.Task<Microsoft.Graph.PowerShell.Models.IMicrosoftGraphODataErrorsOdataError> response)
{
using (NoSynchronizationContext)
{
var _returnNow = global::System.Threading.Tasks.Task<bool>.FromResult(false);
overrideOnDefault(responseMessage, response, ref _returnNow);
// if overrideOnDefault has returned true, then return right away.
if ((null != _returnNow && await _returnNow))
{
return;
}
// Error Response : default
var code = (await response)?.Error?.Code;
var message = (await response)?.Error?.Message;
if ((null == code || null == message))
{
// Unrecognized Response. Create an error record based on what we have.
var ex = new Microsoft.Graph.PowerShell.Runtime.RestException<Microsoft.Graph.PowerShell.Models.IMicrosoftGraphODataErrorsOdataError>(responseMessage, await response);
WriteError(new global::System.Management.Automation.ErrorRecord(ex, ex.Code, global::System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter })
{
ErrorDetails = new global::System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action }
});
}
else
{
WriteError(new global::System.Management.Automation.ErrorRecord(new global::System.Exception($"[{code}] : {message}"), code?.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter })
{
ErrorDetails = new global::System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty }
});
}
}
}
}
}