Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions src/Groups/Groups/custom/Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using static Microsoft.Graph.PowerShell.Runtime.Extensions;
public partial class Groups
{
#region GroupsCreateGroupMember
/// <summary>Create new navigation property to members for groups</summary>
/// <param name="groupId">key: group-id of group</param>
/// <param name="body">New navigation property</param>
Expand Down Expand Up @@ -111,5 +112,115 @@ internal async System.Threading.Tasks.Task GroupsCreateGroupMember_Validate(stri
await eventListener.AssertObjectIsValid(nameof(body), body);
}
}
#endregion

#region GroupsCreateGroupOwner
/// <summary>Create new navigation property to owners for groups</summary>
/// <param name="groupId">key: group-id of group</param>
/// <param name="body">New navigation property</param>
/// <param name="onCreated">a delegate that is called when the remote service returns 204 (No Content).</param>
/// <param name="onDefault">a delegate that is called when the remote service returns default (any response code not handled
/// elsewhere).</param>
/// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
/// <param name="sender">an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request.</param>
/// <returns>
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
/// </returns>
public async System.Threading.Tasks.Task GroupsCreateGroupOwner(string apiVersion, string groupId, Models.IMicrosoftGraphDirectoryObject body, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphDirectoryObject>, System.Threading.Tasks.Task> onCreated, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphODataErrorsOdataError>, 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<string, string> { { "@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);
}
}

/// <summary>Actual wire call for <see cref="GroupsCreateGroupOwner" /> method.</summary>
/// <param name="request">the prepared HttpRequestMessage to send.</param>
/// <param name="onCreated">a delegate that is called when the remote service returns 204 (No content).</param>
/// <param name="onDefault">a delegate that is called when the remote service returns default (any response code not handled
/// elsewhere).</param>
/// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
/// <param name="sender">an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request.</param>
/// <returns>
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
/// </returns>
internal async System.Threading.Tasks.Task GroupsCreateGroupOwner_Call(System.Net.Http.HttpRequestMessage request, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphDirectoryObject>, System.Threading.Tasks.Task> onCreated, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphODataErrorsOdataError>, 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();
}
}
}

/// <summary>
/// Validation method for <see cref="GroupsCreateGroupOwner" /> method. Call this like the actual call, but you will
/// get validation events back.
/// </summary>
/// <param name="groupId">key: group-id of group</param>
/// <param name="body">New navigation property</param>
/// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
/// <returns>
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
/// </returns>
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
}
}
Loading