public virtual AsyncPageable <DirectoryObject> GetObjectsByObjectIdsAsync(GetObjectsParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } async Task <Page <DirectoryObject> > FirstPageFunc(int?pageSizeHint) { using var scope = _clientDiagnostics.CreateScope("ObjectsClient.GetObjectsByObjectIds"); scope.Start(); try { var response = await RestClient.GetObjectsByObjectIdsAsync(parameters, cancellationToken).ConfigureAwait(false); return(Page.FromValues(response.Value.Value, response.Value.OdataNextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } async Task <Page <DirectoryObject> > NextPageFunc(string nextLink, int?pageSizeHint) { using var scope = _clientDiagnostics.CreateScope("ObjectsClient.GetObjectsByObjectIds"); scope.Start(); try { var response = await RestClient.GetObjectsByObjectIdsNextAsync(nextLink, cancellationToken).ConfigureAwait(false); return(Page.FromValues(response.Value.Value, response.Value.OdataNextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc)); }
internal HttpMessage CreateGetObjectsByObjectIdsRequest(GetObjectsParameters parameters) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/", false); uri.AppendPath(tenantID, true); uri.AppendPath("/getObjectsByObjectIds", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(parameters); request.Content = content; return(message); }
/// <summary> /// Gets AD group membership for the specified AD object IDs. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='parameters'> /// Objects filtering parameters. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <IPage <AADObjectInner> > GetObjectsByObjectIdsAsync(this IObjectsOperations operations, GetObjectsParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.GetObjectsByObjectIdsWithHttpMessagesAsync(parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Gets the directory objects specified in a list of object IDs. You can also /// specify which resource collections (users, groups, etc.) should be searched /// by specifying the optional types parameter. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='parameters'> /// Objects filtering parameters. /// </param> public static IPage <DirectoryObject> GetObjectsByObjectIds(this IObjectsOperations operations, GetObjectsParameters parameters) { return(operations.GetObjectsByObjectIdsAsync(parameters).GetAwaiter().GetResult()); }
/// <summary> /// Gets the directory objects specified in a list of object IDs. You can also /// specify which resource collections (users, groups, etc.) should be searched /// by specifying the optional types parameter. /// </summary> /// <param name='parameters'> /// Objects filtering parameters. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <IPage <DirectoryObject> > > GetObjectsByObjectIdsWithHttpMessagesAsync(GetObjectsParameters parameters, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (parameters == null) { throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (Client.TenantID == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("parameters", parameters); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "GetObjectsByObjectIds", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/getObjectsByObjectIds").ToString(); _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (parameters != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex = new CloudException(_errorBody.Message); ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_httpResponse.Headers.Contains("x-ms-request-id")) { ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <IPage <DirectoryObject> >(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <Page <DirectoryObject> >(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public async Task <Response <DirectoryObjectListResult> > GetObjectsByObjectIdsAsync(GetObjectsParameters parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var message = CreateGetObjectsByObjectIdsRequest(parameters); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { DirectoryObjectListResult value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); if (document.RootElement.ValueKind == JsonValueKind.Null) { value = null; } else { value = DirectoryObjectListResult.DeserializeDirectoryObjectListResult(document.RootElement); } return(Response.FromValue(value, message.Response)); }
/// <summary> /// Gets AD group membership by provided AD object Ids /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='parameters'> /// Objects filtering parameters. /// </param> public static IPage <AADObject> GetObjectsByObjectIds(this IObjectsOperations operations, GetObjectsParameters parameters) { return(Task.Factory.StartNew(s => ((IObjectsOperations)s).GetObjectsByObjectIdsAsync(parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Gets AD group membership by provided AD object Ids /// </summary> /// <param name='parameters'> /// Required. Objects filtering parameters. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Server response for Active Directory objects inquiry API calls /// </returns> public async Task <GetObjectsResult> GetObjectsByObjectIdsAsync(GetObjectsParameters parameters, CancellationToken cancellationToken) { // Validate if (parameters == null) { throw new ArgumentNullException("parameters"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("parameters", parameters); TracingAdapter.Enter(invocationId, this, "GetObjectsByObjectIdsAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; url = url + Uri.EscapeDataString(this.Client.TenantID); url = url + "/getObjectsByObjectIds"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=1.6-internal"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Post; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; JToken requestDoc = null; JObject getObjectsParametersValue = new JObject(); requestDoc = getObjectsParametersValue; if (parameters.Ids != null) { if (parameters.Ids is ILazyCollection == false || ((ILazyCollection)parameters.Ids).IsInitialized) { JArray objectIdsArray = new JArray(); foreach (string objectIdsItem in parameters.Ids) { objectIdsArray.Add(objectIdsItem); } getObjectsParametersValue["objectIds"] = objectIdsArray; } } if (parameters.Types != null) { if (parameters.Types is ILazyCollection == false || ((ILazyCollection)parameters.Types).IsInitialized) { JArray typesArray = new JArray(); foreach (string typesItem in parameters.Types) { typesArray.Add(typesItem); } getObjectsParametersValue["types"] = typesArray; } } getObjectsParametersValue["includeDirectoryObjectReferences"] = parameters.IncludeDirectoryObjectReferences; requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result GetObjectsResult result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new GetObjectsResult(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { AADObject aADObjectInstance = new AADObject(); result.AADObject.Add(aADObjectInstance); JToken objectIdValue = valueValue["objectId"]; if (objectIdValue != null && objectIdValue.Type != JTokenType.Null) { string objectIdInstance = ((string)objectIdValue); aADObjectInstance.ObjectId = objectIdInstance; } JToken objectTypeValue = valueValue["objectType"]; if (objectTypeValue != null && objectTypeValue.Type != JTokenType.Null) { string objectTypeInstance = ((string)objectTypeValue); aADObjectInstance.ObjectType = objectTypeInstance; } JToken displayNameValue = valueValue["displayName"]; if (displayNameValue != null && displayNameValue.Type != JTokenType.Null) { string displayNameInstance = ((string)displayNameValue); aADObjectInstance.DisplayName = displayNameInstance; } JToken userPrincipalNameValue = valueValue["userPrincipalName"]; if (userPrincipalNameValue != null && userPrincipalNameValue.Type != JTokenType.Null) { string userPrincipalNameInstance = ((string)userPrincipalNameValue); aADObjectInstance.UserPrincipalName = userPrincipalNameInstance; } JToken mailValue = valueValue["mail"]; if (mailValue != null && mailValue.Type != JTokenType.Null) { string mailInstance = ((string)mailValue); aADObjectInstance.Mail = mailInstance; } JToken mailEnabledValue = valueValue["mailEnabled"]; if (mailEnabledValue != null && mailEnabledValue.Type != JTokenType.Null) { bool mailEnabledInstance = ((bool)mailEnabledValue); aADObjectInstance.MailEnabled = mailEnabledInstance; } JToken securityEnabledValue = valueValue["securityEnabled"]; if (securityEnabledValue != null && securityEnabledValue.Type != JTokenType.Null) { bool securityEnabledInstance = ((bool)securityEnabledValue); aADObjectInstance.SecurityEnabled = securityEnabledInstance; } JToken signInNameValue = valueValue["signInName"]; if (signInNameValue != null && signInNameValue.Type != JTokenType.Null) { string signInNameInstance = ((string)signInNameValue); aADObjectInstance.SignInName = signInNameInstance; } JToken servicePrincipalNamesArray = valueValue["servicePrincipalNames"]; if (servicePrincipalNamesArray != null && servicePrincipalNamesArray.Type != JTokenType.Null) { foreach (JToken servicePrincipalNamesValue in ((JArray)servicePrincipalNamesArray)) { aADObjectInstance.ServicePrincipalNames.Add(((string)servicePrincipalNamesValue)); } } JToken userTypeValue = valueValue["userType"]; if (userTypeValue != null && userTypeValue.Type != JTokenType.Null) { string userTypeInstance = ((string)userTypeValue); aADObjectInstance.UserType = userTypeInstance; } } } JToken odatanextLinkValue = responseDoc["odata.nextLink"]; if (odatanextLinkValue != null && odatanextLinkValue.Type != JTokenType.Null) { string odatanextLinkInstance = ((string)odatanextLinkValue); result.NextLink = odatanextLinkInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("request-id")) { result.RequestId = httpResponse.Headers.GetValues("request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// Gets AD group membership by provided AD object Ids /// </summary> /// <param name='operations'> /// Reference to the Microsoft.Azure.Graph.RBAC.IObjectOperations. /// </param> /// <param name='parameters'> /// Required. Objects filtering parameters. /// </param> /// <returns> /// Server response for Active Directory objects inquiry API calls /// </returns> public static Task <GetObjectsResult> GetObjectsByObjectIdsAsync(this IObjectOperations operations, GetObjectsParameters parameters) { return(operations.GetObjectsByObjectIdsAsync(parameters, CancellationToken.None)); }