diff --git a/src/Groups/Groups/custom/Groups.cs b/src/Groups/Groups/custom/Groups.cs index d14afd2168b..302976e44ef 100644 --- a/src/Groups/Groups/custom/Groups.cs +++ b/src/Groups/Groups/custom/Groups.cs @@ -5,6 +5,7 @@ using static Microsoft.Graph.PowerShell.Runtime.Extensions; public partial class Groups { + #region GroupsCreateGroupMember /// Create new navigation property to members for groups /// key: group-id of group /// New navigation property @@ -111,5 +112,115 @@ internal async System.Threading.Tasks.Task GroupsCreateGroupMember_Validate(stri await eventListener.AssertObjectIsValid(nameof(body), body); } } + #endregion + + #region GroupsCreateGroupOwner + /// Create new navigation property to owners for groups + /// key: group-id of group + /// New navigation property + /// a delegate that is called when the remote service returns 204 (No Content). + /// a delegate that is called when the remote service returns default (any response code not handled + /// elsewhere). + /// an instance that will receive events. + /// an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request. + /// + /// A that will be complete when handling of the response is completed. + /// + public async System.Threading.Tasks.Task GroupsCreateGroupOwner(string apiVersion, string groupId, Models.IMicrosoftGraphDirectoryObject body, System.Func, System.Threading.Tasks.Task> onCreated, System.Func, System.Threading.Tasks.Task> onDefault, Runtime.IEventListener eventListener, Runtime.ISendAsync sender) + { + // Constant Parameters + using (NoSynchronizationContext) + { + // construct URL + string baseUrl = $"https://graph.microsoft.com/{apiVersion}"; + var _url = new System.Uri( + System.Text.RegularExpressions.Regex.Replace($"{baseUrl}/groups/{System.Uri.EscapeDataString(groupId)}/owners/$ref", + "\\?&*$|&*$|(\\?)&+|(&)&+", "$1$2")); + + await eventListener.Signal(Runtime.Events.URLCreated, _url); if (eventListener.Token.IsCancellationRequested) { return; } + + // generate request object + var request = new System.Net.Http.HttpRequestMessage(Runtime.Method.Post, _url); + await eventListener.Signal(Runtime.Events.RequestCreated, _url); if (eventListener.Token.IsCancellationRequested) { return; } + + await eventListener.Signal(Runtime.Events.HeaderParametersAdded, _url); if (eventListener.Token.IsCancellationRequested) { return; } + // set body content + string requestContent = null != body ? new JsonObject(new Dictionary { { "@odata.id", $"{baseUrl}/directoryObjects/{body.Id}" } }) : @"{}"; + request.Content = new System.Net.Http.StringContent(requestContent, System.Text.Encoding.UTF8); ; + request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + await eventListener.Signal(Runtime.Events.BodyContentSet, _url); if (eventListener.Token.IsCancellationRequested) { return; } + // make the call + await this.GroupsCreateGroupOwner_Call(request, onCreated, onDefault, eventListener, sender); + } + } + + /// Actual wire call for method. + /// the prepared HttpRequestMessage to send. + /// a delegate that is called when the remote service returns 204 (No content). + /// a delegate that is called when the remote service returns default (any response code not handled + /// elsewhere). + /// an instance that will receive events. + /// an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request. + /// + /// A that will be complete when handling of the response is completed. + /// + internal async System.Threading.Tasks.Task GroupsCreateGroupOwner_Call(System.Net.Http.HttpRequestMessage request, System.Func, System.Threading.Tasks.Task> onCreated, System.Func, System.Threading.Tasks.Task> onDefault, Runtime.IEventListener eventListener, Runtime.ISendAsync sender) + { + using (NoSynchronizationContext) + { + System.Net.Http.HttpResponseMessage _response = null; + try + { + await eventListener.Signal(Runtime.Events.BeforeCall, request); if (eventListener.Token.IsCancellationRequested) { return; } + _response = await sender.SendAsync(request, eventListener); + await eventListener.Signal(Runtime.Events.ResponseCreated, _response); if (eventListener.Token.IsCancellationRequested) { return; } + var _contentType = _response.Content.Headers.ContentType?.MediaType; + + switch (_response.StatusCode) + { + case System.Net.HttpStatusCode.NoContent: + { + await eventListener.Signal(Runtime.Events.BeforeResponseDispatch, _response); if (eventListener.Token.IsCancellationRequested) { return; } + await onCreated(_response, _response.Content.ReadAsStringAsync().ContinueWith(body => Models.MicrosoftGraphDirectoryObject.FromJson(Runtime.Json.JsonNode.Parse(body.Result)))); + break; + } + default: + { + await eventListener.Signal(Runtime.Events.BeforeResponseDispatch, _response); if (eventListener.Token.IsCancellationRequested) { return; } + await onDefault(_response, _response.Content.ReadAsStringAsync().ContinueWith(body => Models.MicrosoftGraphODataErrorsOdataError.FromJson(Runtime.Json.JsonNode.Parse(body.Result)))); + break; + } + } + } + finally + { + // finally statements + await eventListener.Signal(Runtime.Events.Finally, request, _response); + _response?.Dispose(); + request?.Dispose(); + } + } + } + + /// + /// Validation method for method. Call this like the actual call, but you will + /// get validation events back. + /// + /// key: group-id of group + /// New navigation property + /// an instance that will receive events. + /// + /// A that will be complete when handling of the response is completed. + /// + internal async System.Threading.Tasks.Task GroupsCreateGroupOwner_Validate(string groupId, Models.IMicrosoftGraphDirectoryObject body, Runtime.IEventListener eventListener) + { + using (NoSynchronizationContext) + { + await eventListener.AssertNotNull(nameof(groupId), groupId); + await eventListener.AssertNotNull(nameof(body), body); + await eventListener.AssertObjectIsValid(nameof(body), body); + } + } + #endregion } } diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_Create.cs b/src/Groups/Groups/custom/NewMgGroupOwner_Create.cs new file mode 100644 index 00000000000..e29fddeb8e3 --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_Create.cs @@ -0,0 +1,353 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_Create", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0-beta")] + public partial class NewMgGroupOwner_Create : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "beta"; + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameter; + + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "HELP MESSAGE MISSING", ValueFromPipeline = true)] + [Runtime.Info( + Required = true, + ReadOnly = false, + Description = @"", + SerializedName = @"bodyParameter", + PossibleTypes = new[] { typeof(Models.IMicrosoftGraphDirectoryObject) })] + public Models.IMicrosoftGraphDirectoryObject BodyParameter { get => this._bodyParameter; set => this._bodyParameter = value; } + + /// Wait for .NET debugger to attach + [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; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// Backing field for property. + private string _groupId; + + /// key: group-id of group + [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; } + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [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; } + + /// Credentials for a proxy server to use for the remote call + [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; } + + /// Use the default credentials for the proxy + [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; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + 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; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func 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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_Create() + { + + } + + /// Performs execution of the command. + 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 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as 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.GroupsCreateGroupOwner(_apiVersion, GroupId, BodyParameter, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_Create1.cs b/src/Groups/Groups/custom/NewMgGroupOwner_Create1.cs new file mode 100644 index 00000000000..06092024f8a --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_Create1.cs @@ -0,0 +1,354 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_Create1", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0")] + public partial class NewMgGroupOwner_Create1 : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "v1.0"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameter; + + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "HELP MESSAGE MISSING", ValueFromPipeline = true)] + [Runtime.Info( + Required = true, + ReadOnly = false, + Description = @"", + SerializedName = @"bodyParameter", + PossibleTypes = new[] { typeof(Models.IMicrosoftGraphDirectoryObject) })] + public Models.IMicrosoftGraphDirectoryObject BodyParameter { get => this._bodyParameter; set => this._bodyParameter = value; } + + /// Wait for .NET debugger to attach + [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; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// Backing field for property. + private string _groupId; + + /// key: group-id of group + [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; } + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [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; } + + /// Credentials for a proxy server to use for the remote call + [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; } + + /// Use the default credentials for the proxy + [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; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + 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; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func 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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_Create1() + { + + } + + /// Performs execution of the command. + 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 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as 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.GroupsCreateGroupOwner(_apiVersion, GroupId, BodyParameter, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_CreateExpanded.cs b/src/Groups/Groups/custom/NewMgGroupOwner_CreateExpanded.cs new file mode 100644 index 00000000000..0bfcd240de3 --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_CreateExpanded.cs @@ -0,0 +1,358 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_CreateExpanded", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0-beta")] + public partial class NewMgGroupOwner_CreateExpanded : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "beta"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameterBody = new Models.MicrosoftGraphDirectoryObject(); + + private Models.IMicrosoftGraphDirectoryObject BodyParameterBody { get => this._bodyParameterBody; set => this._bodyParameterBody = value; } + + /// Wait for .NET debugger to attach + [System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Wait for .NET debugger to attach")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Management.Automation.SwitchParameter Break { get; set; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// Backing field for property. + private string _groupId; + + /// key: group-id of group + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Path)] + public string GroupId { get => this._groupId; set => this._groupId = value; } + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public Runtime.SendAsyncStep[] HttpPipelineAppend { get; set; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public Runtime.SendAsyncStep[] HttpPipelinePrepend { get; set; } + + /// HELP MESSAGE MISSING + [System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "HELP MESSAGE MISSING")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Body)] + [Runtime.Info( + Required = false, + ReadOnly = false, + Description = @"id of directoryObject", + SerializedName = @"id", + PossibleTypes = new[] { typeof(string) })] + public string DirectoryObjectId { get => BodyParameterBody.Id ?? null; set => BodyParameterBody.Id = value; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "The URI for the proxy server to use")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Uri Proxy { get; set; } + + /// Credentials for a proxy server to use for the remote call + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Management.Automation.PSCredential ProxyCredential { get; set; } + + /// Use the default credentials for the proxy + [System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Use the default credentials for the proxy")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Management.Automation.SwitchParameter ProxyUseDefaultCredentials { get; set; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + protected override void BeginProcessing() + { + Module.Instance.SetProxyConfiguration(Proxy, ProxyCredential, ProxyUseDefaultCredentials); + if (Break) + { + Microsoft.Graph.PowerShell.Runtime.AttachDebugger.Break(); + } + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletBeginProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func messageData) + { + using (NoSynchronizationContext) + { + if (token.IsCancellationRequested) + { + return; + } + + switch (id) + { + case Microsoft.Graph.PowerShell.Runtime.Events.Verbose: + { + WriteVerbose($"{(messageData().Message ?? global::System.String.Empty)}"); + return; + } + case Microsoft.Graph.PowerShell.Runtime.Events.Warning: + { + WriteWarning($"{(messageData().Message ?? global::System.String.Empty)}"); + return; + } + case Microsoft.Graph.PowerShell.Runtime.Events.Information: + { + var data = messageData(); + WriteInformation(data, new[] { data.Message }); + return; + } + case Microsoft.Graph.PowerShell.Runtime.Events.Debug: + { + WriteDebug($"{(messageData().Message ?? global::System.String.Empty)}"); + return; + } + case Microsoft.Graph.PowerShell.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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_CreateExpanded() + { + + } + + /// Performs execution of the command. + protected override void ProcessRecord() + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordStart).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + try + { + // work + if (ShouldProcess($"Call remote 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Microsoft.Graph.PowerShell.Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelineAppend) ?? HttpPipelineAppend); + } + // get the client instance + try + { + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletBeforeAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await this.Client.GroupsCreateGroupOwner(_apiVersion, GroupId, BodyParameterBody, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = global::System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = global::System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_CreateExpanded1.cs b/src/Groups/Groups/custom/NewMgGroupOwner_CreateExpanded1.cs new file mode 100644 index 00000000000..9b5c596e6ac --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_CreateExpanded1.cs @@ -0,0 +1,358 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_CreateExpanded1", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0")] + public partial class NewMgGroupOwner_CreateExpanded1 : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "v1.0"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameterBody = new Models.MicrosoftGraphDirectoryObject(); + + private Models.IMicrosoftGraphDirectoryObject BodyParameterBody { get => this._bodyParameterBody; set => this._bodyParameterBody = value; } + + /// Wait for .NET debugger to attach + [System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Wait for .NET debugger to attach")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Management.Automation.SwitchParameter Break { get; set; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// Backing field for property. + private string _groupId; + + /// key: group-id of group + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Path)] + public string GroupId { get => this._groupId; set => this._groupId = value; } + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public Runtime.SendAsyncStep[] HttpPipelineAppend { get; set; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public Runtime.SendAsyncStep[] HttpPipelinePrepend { get; set; } + + /// HELP MESSAGE MISSING + [System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "HELP MESSAGE MISSING")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Body)] + [Runtime.Info( + Required = false, + ReadOnly = false, + Description = @"id of directoryObject", + SerializedName = @"id", + PossibleTypes = new[] { typeof(string) })] + public string DirectoryObjectId { get => BodyParameterBody.Id ?? null; set => BodyParameterBody.Id = value; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "The URI for the proxy server to use")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Uri Proxy { get; set; } + + /// Credentials for a proxy server to use for the remote call + [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(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Management.Automation.PSCredential ProxyCredential { get; set; } + + /// Use the default credentials for the proxy + [System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "Use the default credentials for the proxy")] + [Category(global::Microsoft.Graph.PowerShell.ParameterCategory.Runtime)] + public System.Management.Automation.SwitchParameter ProxyUseDefaultCredentials { get; set; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + protected override void BeginProcessing() + { + Module.Instance.SetProxyConfiguration(Proxy, ProxyCredential, ProxyUseDefaultCredentials); + if (Break) + { + Microsoft.Graph.PowerShell.Runtime.AttachDebugger.Break(); + } + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletBeginProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func messageData) + { + using (NoSynchronizationContext) + { + if (token.IsCancellationRequested) + { + return; + } + + switch (id) + { + case Microsoft.Graph.PowerShell.Runtime.Events.Verbose: + { + WriteVerbose($"{(messageData().Message ?? global::System.String.Empty)}"); + return; + } + case Microsoft.Graph.PowerShell.Runtime.Events.Warning: + { + WriteWarning($"{(messageData().Message ?? global::System.String.Empty)}"); + return; + } + case Microsoft.Graph.PowerShell.Runtime.Events.Information: + { + var data = messageData(); + WriteInformation(data, new[] { data.Message }); + return; + } + case Microsoft.Graph.PowerShell.Runtime.Events.Debug: + { + WriteDebug($"{(messageData().Message ?? global::System.String.Empty)}"); + return; + } + case Microsoft.Graph.PowerShell.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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_CreateExpanded1() + { + + } + + /// Performs execution of the command. + protected override void ProcessRecord() + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordStart).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + try + { + // work + if (ShouldProcess($"Call remote 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Microsoft.Graph.PowerShell.Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelineAppend) ?? HttpPipelineAppend); + } + // get the client instance + try + { + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletBeforeAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await this.Client.GroupsCreateGroupOwner(_apiVersion, GroupId, BodyParameterBody, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Microsoft.Graph.PowerShell.Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = global::System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = global::System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { GroupId = GroupId, body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentity.cs b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentity.cs new file mode 100644 index 00000000000..1d9179018c1 --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentity.cs @@ -0,0 +1,353 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_CreateViaIdentity", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0-beta")] + public partial class NewMgGroupOwner_CreateViaIdentity : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "beta"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameter; + + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "HELP MESSAGE MISSING", ValueFromPipeline = true)] + [Runtime.Info( + Required = true, + ReadOnly = false, + Description = @"", + SerializedName = @"bodyParameter", + PossibleTypes = new[] { typeof(Models.IMicrosoftGraphDirectoryObject) })] + public Models.IMicrosoftGraphDirectoryObject BodyParameter { get => this._bodyParameter; set => this._bodyParameter = value; } + + /// Wait for .NET debugger to attach + [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; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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; } + + /// Backing field for property. + private Models.IGroupsIdentity _inputObject; + + /// Identity Parameter + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Identity Parameter", ValueFromPipeline = true)] + [Category(ParameterCategory.Path)] + public Models.IGroupsIdentity InputObject { get => this._inputObject; set => this._inputObject = value; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [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; } + + /// Credentials for a proxy server to use for the remote call + [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; } + + /// Use the default credentials for the proxy + [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; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + 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; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func 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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_CreateViaIdentity() + { + + } + + /// Performs execution of the command. + 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 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as 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; } + // try to call with PATH parameters from Input Object + if (null == InputObject.GroupId) + { + ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new System.Exception("InputObject has null value for InputObject.GroupId"), string.Empty, System.Management.Automation.ErrorCategory.InvalidArgument, InputObject)); + } + await this.Client.GroupsCreateGroupOwner(_apiVersion, InputObject.GroupId ?? null, BodyParameter, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentity1.cs b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentity1.cs new file mode 100644 index 00000000000..7debac471fa --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentity1.cs @@ -0,0 +1,353 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_CreateViaIdentity1", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0")] + public partial class NewMgGroupOwner_CreateViaIdentity1 : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "v1.0"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameter; + + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "HELP MESSAGE MISSING", ValueFromPipeline = true)] + [Runtime.Info( + Required = true, + ReadOnly = false, + Description = @"", + SerializedName = @"bodyParameter", + PossibleTypes = new[] { typeof(Models.IMicrosoftGraphDirectoryObject) })] + public Models.IMicrosoftGraphDirectoryObject BodyParameter { get => this._bodyParameter; set => this._bodyParameter = value; } + + /// Wait for .NET debugger to attach + [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; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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; } + + /// Backing field for property. + private Models.IGroupsIdentity _inputObject; + + /// Identity Parameter + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Identity Parameter", ValueFromPipeline = true)] + [Category(ParameterCategory.Path)] + public Models.IGroupsIdentity InputObject { get => this._inputObject; set => this._inputObject = value; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [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; } + + /// Credentials for a proxy server to use for the remote call + [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; } + + /// Use the default credentials for the proxy + [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; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + 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; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func 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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_CreateViaIdentity1() + { + + } + + /// Performs execution of the command. + 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 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as 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; } + // try to call with PATH parameters from Input Object + if (null == InputObject.GroupId) + { + ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new System.Exception("InputObject has null value for InputObject.GroupId"), string.Empty, System.Management.Automation.ErrorCategory.InvalidArgument, InputObject)); + } + await this.Client.GroupsCreateGroupOwner(_apiVersion, InputObject.GroupId ?? null, BodyParameter, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameter }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentityExpanded.cs b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentityExpanded.cs new file mode 100644 index 00000000000..d8a05a8c70f --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentityExpanded.cs @@ -0,0 +1,357 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_CreateViaIdentityExpanded", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0-beta")] + public partial class NewMgGroupOwner_CreateViaIdentityExpanded : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "beta"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameterBody = new Models.MicrosoftGraphDirectoryObject(); + + private Models.IMicrosoftGraphDirectoryObject BodyParameterBody { get => this._bodyParameterBody; set => this._bodyParameterBody = value; } + + /// Wait for .NET debugger to attach + [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; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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; } + + /// HELP MESSAGE MISSING + [System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "HELP MESSAGE MISSING")] + [Category(ParameterCategory.Body)] + [Runtime.Info( + Required = false, + ReadOnly = false, + Description = @"id of directoryObject", + SerializedName = @"id", + PossibleTypes = new[] { typeof(string) })] + public string DirectoryObjectId { get => BodyParameterBody.Id ?? null; set => BodyParameterBody.Id = value; } + + /// Backing field for property. + private Models.IGroupsIdentity _inputObject; + + /// Identity Parameter + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Identity Parameter", ValueFromPipeline = true)] + [Category(ParameterCategory.Path)] + public Models.IGroupsIdentity InputObject { get => this._inputObject; set => this._inputObject = value; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [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; } + + /// Credentials for a proxy server to use for the remote call + [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; } + + /// Use the default credentials for the proxy + [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; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + 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; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func 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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_CreateViaIdentityExpanded() + { + + } + + /// Performs execution of the command. + 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 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as 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; } + // try to call with PATH parameters from Input Object + if (null == InputObject.GroupId) + { + ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new System.Exception("InputObject has null value for InputObject.GroupId"), string.Empty, System.Management.Automation.ErrorCategory.InvalidArgument, InputObject)); + } + await this.Client.GroupsCreateGroupOwner(_apiVersion, InputObject.GroupId ?? null, BodyParameterBody, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentityExpanded1.cs b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentityExpanded1.cs new file mode 100644 index 00000000000..e83de0741f6 --- /dev/null +++ b/src/Groups/Groups/custom/NewMgGroupOwner_CreateViaIdentityExpanded1.cs @@ -0,0 +1,357 @@ +namespace Microsoft.Graph.PowerShell.Cmdlets +{ + using static Microsoft.Graph.PowerShell.Runtime.Extensions; + + /// Add an owner to an Office 365 group or security group through the owners navigation property. + /// + /// + [System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.New, @"MgGroupOwner_CreateViaIdentityExpanded1", SupportsShouldProcess = true)] + [System.Management.Automation.OutputType(typeof(Models.IMicrosoftGraphDirectoryObject))] + [global::Microsoft.Graph.PowerShell.Description(@"Add an owner to an Office 365 group or security group through the owners navigation property.")] + [global::Microsoft.Graph.PowerShell.Generated] + [global::Microsoft.Graph.PowerShell.Profile("v1.0")] + public partial class NewMgGroupOwner_CreateViaIdentityExpanded1 : System.Management.Automation.PSCmdlet, + Runtime.IEventListener + { + private const string _apiVersion = "v1.0"; + + /// A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet) + private System.Management.Automation.InvocationInfo __invocationInfo; + + /// + /// The for this operation. + /// + private System.Threading.CancellationTokenSource _cancellationTokenSource = new System.Threading.CancellationTokenSource(); + + /// Backing field for property. + private Models.IMicrosoftGraphDirectoryObject _bodyParameterBody = new Models.MicrosoftGraphDirectoryObject(); + + private Models.IMicrosoftGraphDirectoryObject BodyParameterBody { get => this._bodyParameterBody; set => this._bodyParameterBody = value; } + + /// Wait for .NET debugger to attach + [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; } + + /// The reference to the client API class. + public Groups Client => Module.Instance.ClientAPI; + + /// SendAsync Pipeline Steps to be appended to the front of the pipeline + [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; } + + /// SendAsync Pipeline Steps to be prepended to the front of the pipeline + [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; } + + /// HELP MESSAGE MISSING + [System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "HELP MESSAGE MISSING")] + [Category(ParameterCategory.Body)] + [Runtime.Info( + Required = false, + ReadOnly = false, + Description = @"id of directoryObject", + SerializedName = @"id", + PossibleTypes = new[] { typeof(string) })] + public string DirectoryObjectId { get => BodyParameterBody.Id ?? null; set => BodyParameterBody.Id = value; } + + /// Backing field for property. + private Models.IGroupsIdentity _inputObject; + + /// Identity Parameter + [System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Identity Parameter", ValueFromPipeline = true)] + [Category(ParameterCategory.Path)] + public Models.IGroupsIdentity InputObject { get => this._inputObject; set => this._inputObject = value; } + + /// Accessor for our copy of the InvocationInfo. + public System.Management.Automation.InvocationInfo InvocationInformation { get => __invocationInfo = __invocationInfo ?? this.MyInvocation; set { __invocationInfo = value; } } + + /// + /// cancellation delegate. Stops the cmdlet when called. + /// + System.Action Runtime.IEventListener.Cancel => _cancellationTokenSource.Cancel; + + /// cancellation token. + System.Threading.CancellationToken Runtime.IEventListener.Token => _cancellationTokenSource.Token; + + /// + /// The instance of the that the remote call will use. + /// + private Runtime.HttpPipeline Pipeline { get; set; } + + /// The URI for the proxy server to use + [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; } + + /// Credentials for a proxy server to use for the remote call + [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; } + + /// Use the default credentials for the proxy + [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; } + + /// + /// overrideOnCreated 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// /// 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 ) + + partial void overrideOnCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// overrideOnDefault 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 + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// /// 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 ) + + partial void overrideOnDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response, ref System.Threading.Tasks.Task returnNow); + + /// + /// (overrides the default BeginProcessing method in global::System.Management.Automation.PSCmdlet) + /// + 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; } + } + + /// Performs clean-up after the command execution + protected override void EndProcessing() + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletEndProcessing).Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + + /// Handles/Dispatches events during the call to the REST service. + /// The message id + /// The message cancellation token. When this call is canceled, this should be true + /// Detailed message data for the message event. + /// + /// A that will be complete when handling of the message is completed. + /// + async System.Threading.Tasks.Task Runtime.IEventListener.Signal(string id, System.Threading.CancellationToken token, System.Func 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)}"); + } + } + + /// + /// Initializes a new instance of the cmdlet class. + /// + public NewMgGroupOwner_CreateViaIdentityExpanded1() + { + + } + + /// Performs execution of the command. + 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 'CreateGroupOwner' operation")) + { + using (var asyncCommandRuntime = new Runtime.PowerShell.AsyncCommandRuntime(this, ((Runtime.IEventListener)this).Token)) + { + asyncCommandRuntime.Wait(ProcessRecordAsync(), ((Runtime.IEventListener)this).Token); + } + } + } + catch (System.AggregateException aggregateException) + { + // unroll the inner exceptions to get the root cause + foreach (var innerException in aggregateException.Flatten().InnerExceptions) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(innerException, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + } + catch (System.Exception exception) when ((exception as System.Management.Automation.PipelineStoppedException) == null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null) + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletException, $"{exception.GetType().Name} - {exception.Message} : {exception.StackTrace}").Wait(); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + // Write exception out to error channel. + WriteError(new System.Management.Automation.ErrorRecord(exception, string.Empty, System.Management.Automation.ErrorCategory.NotSpecified, null)); + } + finally + { + ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordEnd).Wait(); + } + } + + /// Performs execution of the command, working asynchronously if required. + /// + /// A that will be complete when handling of the method is completed. + /// + protected async System.Threading.Tasks.Task ProcessRecordAsync() + { + using (NoSynchronizationContext) + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncStart); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletGetPipeline); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + Pipeline = Module.Instance.CreatePipeline(InvocationInformation); + if (null != HttpPipelinePrepend) + { + Pipeline.Prepend((this.CommandRuntime as Runtime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(HttpPipelinePrepend) ?? HttpPipelinePrepend); + } + if (null != HttpPipelineAppend) + { + Pipeline.Append((this.CommandRuntime as 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; } + // try to call with PATH parameters from Input Object + if (null == InputObject.GroupId) + { + ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new System.Exception("InputObject has null value for InputObject.GroupId"), string.Empty, System.Management.Automation.ErrorCategory.InvalidArgument, InputObject)); + } + await this.Client.GroupsCreateGroupOwner(_apiVersion, InputObject.GroupId ?? null, BodyParameterBody, onCreated, onDefault, this, Pipeline); + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletAfterAPICall); if (((Runtime.IEventListener)this).Token.IsCancellationRequested) { return; } + } + catch (Runtime.UndeclaredResponseException urexception) + { + WriteError(new System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action } + }); + } + finally + { + await ((Runtime.IEventListener)this).Signal(Runtime.Events.CmdletProcessRecordAsyncEnd); + } + } + } + + /// Interrupts currently running code within the command. + protected override void StopProcessing() + { + ((Runtime.IEventListener)this).Cancel(); + base.StopProcessing(); + } + + /// a delegate that is called when the remote service returns 201 (Created). + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onCreated(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.FromResult(false); + overrideOnCreated(responseMessage, response, ref _returnNow); + // if overrideOnCreated has returned true, then return right away. + if ((null != _returnNow && await _returnNow)) + { + return; + } + // onCreated - response for 201 / application/json + // (await response) // should be Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDirectoryObject + WriteObject((await response)); + } + } + + /// + /// a delegate that is called when the remote service returns default (any response code not handled elsewhere). + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a from the remote + /// call + /// + /// A that will be complete when handling of the method is completed. + /// + private async System.Threading.Tasks.Task onDefault(System.Net.Http.HttpResponseMessage responseMessage, System.Threading.Tasks.Task response) + { + using (NoSynchronizationContext) + { + var _returnNow = System.Threading.Tasks.Task.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 Runtime.RestException(responseMessage, await response); + WriteError(new System.Management.Automation.ErrorRecord(ex, ex.Code, System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(ex.Message) { RecommendedAction = ex.Action } + }); + } + else + { + WriteError(new System.Management.Automation.ErrorRecord(new System.Exception($"[{code}] : {message}"), code?.ToString(), System.Management.Automation.ErrorCategory.InvalidOperation, new { body = BodyParameterBody }) + { + ErrorDetails = new System.Management.Automation.ErrorDetails(message) { RecommendedAction = global::System.String.Empty } + }); + } + } + } + } +} \ No newline at end of file