1+ namespace Microsoft . Graph . PowerShell
2+ {
3+ using Microsoft . Graph . PowerShell . Runtime . Json ;
4+ using System . Collections . Generic ;
5+ using static Microsoft . Graph . PowerShell . Runtime . Extensions ;
6+
7+ /// <summary>
8+ /// Custom Low-level API implementation for the Groups.DirectoryObject service.
9+ /// </summary>
10+ public partial class GroupsDirectoryObject
11+ {
12+ private static string baseUrl = "https://graph.microsoft.com/beta" ;
13+ /// <summary>Create new navigation property to members for groups</summary>
14+ /// <param name="groupId">key: group-id of group</param>
15+ /// <param name="body">New navigation property</param>
16+ /// <param name="onCreated">a delegate that is called when the remote service returns 204 (No Content).</param>
17+ /// <param name="onDefault">a delegate that is called when the remote service returns default (any response code not handled
18+ /// elsewhere).</param>
19+ /// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
20+ /// <param name="sender">an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request.</param>
21+ /// <returns>
22+ /// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
23+ /// </returns>
24+ public async System . Threading . Tasks . Task GroupsCreateGroupMember ( 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 . IOdataError > , System . Threading . Tasks . Task > onDefault , Runtime . IEventListener eventListener , Runtime . ISendAsync sender )
25+ {
26+ // Constant Parameters
27+ using ( NoSynchronizationContext )
28+ {
29+ // construct URL
30+ var _url = new System . Uri (
31+ System . Text . RegularExpressions . Regex . Replace ( $ "{ baseUrl } /groups/{ System . Uri . EscapeDataString ( groupId ) } /members/$ref",
32+ "\\ ?&*$|&*$|(\\ ?)&+|(&)&+" , "$1$2" ) ) ;
33+
34+ await eventListener . Signal ( Runtime . Events . URLCreated , _url ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
35+
36+ // generate request object
37+ var request = new System . Net . Http . HttpRequestMessage ( Runtime . Method . Post , _url ) ;
38+ await eventListener . Signal ( Runtime . Events . RequestCreated , _url ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
39+
40+ await eventListener . Signal ( Runtime . Events . HeaderParametersAdded , _url ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
41+ // set body content
42+ string requestContent = null != body ? new JsonObject ( new Dictionary < string , string > { { "@odata.id" , $ "{ baseUrl } /directoryObjects/{ body . Id } " } } ) : @"{}" ;
43+ request . Content = new System . Net . Http . StringContent ( requestContent , System . Text . Encoding . UTF8 ) ; ;
44+ request . Content . Headers . ContentType = System . Net . Http . Headers . MediaTypeHeaderValue . Parse ( "application/json" ) ;
45+ await eventListener . Signal ( Runtime . Events . BodyContentSet , _url ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
46+ // make the call
47+ await this . GroupsCreateGroupMember_Call ( request , onCreated , onDefault , eventListener , sender ) ;
48+ }
49+ }
50+
51+ /// <summary>Actual wire call for <see cref="GroupsCreateGroupMember" /> method.</summary>
52+ /// <param name="request">the prepared HttpRequestMessage to send.</param>
53+ /// <param name="onCreated">a delegate that is called when the remote service returns 204 (No content).</param>
54+ /// <param name="onDefault">a delegate that is called when the remote service returns default (any response code not handled
55+ /// elsewhere).</param>
56+ /// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
57+ /// <param name="sender">an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request.</param>
58+ /// <returns>
59+ /// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
60+ /// </returns>
61+ internal async System . Threading . Tasks . Task GroupsCreateGroupMember_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 . IOdataError > , System . Threading . Tasks . Task > onDefault , Runtime . IEventListener eventListener , Runtime . ISendAsync sender )
62+ {
63+ using ( NoSynchronizationContext )
64+ {
65+ System . Net . Http . HttpResponseMessage _response = null ;
66+ try
67+ {
68+ await eventListener . Signal ( Runtime . Events . BeforeCall , request ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
69+ _response = await sender . SendAsync ( request , eventListener ) ;
70+ await eventListener . Signal ( Runtime . Events . ResponseCreated , _response ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
71+ var _contentType = _response . Content . Headers . ContentType ? . MediaType ;
72+
73+ switch ( _response . StatusCode )
74+ {
75+ case System . Net . HttpStatusCode . NoContent :
76+ {
77+ await eventListener . Signal ( Runtime . Events . BeforeResponseDispatch , _response ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
78+ await onCreated ( _response , _response . Content . ReadAsStringAsync ( ) . ContinueWith ( body => Models . MicrosoftGraphDirectoryObject . FromJson ( Runtime . Json . JsonNode . Parse ( body . Result ) ) ) ) ;
79+ break ;
80+ }
81+ default :
82+ {
83+ await eventListener . Signal ( Runtime . Events . BeforeResponseDispatch , _response ) ; if ( eventListener . Token . IsCancellationRequested ) { return ; }
84+ await onDefault ( _response , _response . Content . ReadAsStringAsync ( ) . ContinueWith ( body => Models . OdataError . FromJson ( Runtime . Json . JsonNode . Parse ( body . Result ) ) ) ) ;
85+ break ;
86+ }
87+ }
88+ }
89+ finally
90+ {
91+ // finally statements
92+ await eventListener . Signal ( Runtime . Events . Finally , request , _response ) ;
93+ _response ? . Dispose ( ) ;
94+ request ? . Dispose ( ) ;
95+ }
96+ }
97+ }
98+
99+ /// <summary>
100+ /// Validation method for <see cref="GroupsCreateGroupMember" /> method. Call this like the actual call, but you will
101+ /// get validation events back.
102+ /// </summary>
103+ /// <param name="groupId">key: group-id of group</param>
104+ /// <param name="body">New navigation property</param>
105+ /// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
106+ /// <returns>
107+ /// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
108+ /// </returns>
109+ internal async System . Threading . Tasks . Task GroupsCreateGroupMember_Validate ( string groupId , Models . IMicrosoftGraphDirectoryObject body , Runtime . IEventListener eventListener )
110+ {
111+ using ( NoSynchronizationContext )
112+ {
113+ await eventListener . AssertNotNull ( nameof ( groupId ) , groupId ) ;
114+ await eventListener . AssertNotNull ( nameof ( body ) , body ) ;
115+ await eventListener . AssertObjectIsValid ( nameof ( body ) , body ) ;
116+ }
117+ }
118+ }
119+ }
0 commit comments