public static async Task <List <DirectoryObject> > GetGroupOwners(GraphServiceClient client, string groupid, CancellationToken token) { IGroupOwnersCollectionWithReferencesPage result = await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await client.Groups[groupid].Owners.Request().GetAsync(token), token, 0); return(await GetOwners(result, token)); }
private static async Task <string> GetGroups(IGroupDeltaRequest request, ITargetBlock <Group> target, CancellationToken token) { var page = await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await request.GetAsync(token), token, 0); return(await GetGroups(page, target, token)); }
public static async Task <Group> CreateGroup(GraphServiceClient client, Group group, CancellationToken token) { return(await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await client.Groups.Request().AddAsync(group, token), token, 1)); }
public static async Task DeleteGroup(GraphServiceClient client, string id, CancellationToken token) { await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await client.Groups[id].Request().DeleteAsync(token), token, 1); }
private static async Task <List <GraphBatchResult> > GetBatchResults(Dictionary <string, HttpResponseMessage> responses, bool ignoreNotFound, bool ignoreRefAlreadyExists, bool canRetry) { List <GraphBatchResult> results = new List <GraphBatchResult>(); foreach (KeyValuePair <string, HttpResponseMessage> r in responses) { using (r.Value) { GraphBatchResult result = new GraphBatchResult(); result.ID = r.Key; result.IsSuccess = r.Value.IsSuccessStatusCode; results.Add(result); if (result.IsSuccess) { continue; } if (ignoreNotFound && r.Value.StatusCode == HttpStatusCode.NotFound) { result.IsSuccess = true; GraphHelper.logger.Warn($"The request ({r.Key}) to remove object failed because it did not exist"); continue; } result.ErrorResponse = await GraphHelper.GetErrorResponseFromHttpResponseMessage(r); if (ignoreRefAlreadyExists && r.Value.StatusCode == HttpStatusCode.BadRequest && result.ErrorResponse.Error.Message.IndexOf("object references already exist", StringComparison.OrdinalIgnoreCase) > 0) { result.IsSuccess = true; GraphHelper.logger.Warn($"The request ({r.Key}) to add object failed because it already exists"); continue; } if (canRetry && r.Value.StatusCode == (HttpStatusCode)429) { if (r.Value.Headers.TryGetValues("Retry-After", out IEnumerable <string> outvalues)) { string tryAfter = outvalues.FirstOrDefault() ?? "0"; result.RetryInterval = int.Parse(tryAfter); GraphHelper.logger.Warn($"Rate limit encountered, backoff interval of {result.RetryInterval} found"); } else { GraphHelper.logger.Warn("Rate limit encountered, but no backoff interval specified"); } result.IsRetryable = true; continue; } if (canRetry && r.Value.StatusCode == HttpStatusCode.NotFound && string.Equals(result.ErrorResponse.Error.Code, "Request_ResourceNotFound", StringComparison.OrdinalIgnoreCase)) { result.IsRetryable = true; continue; } result.IsFailed = true; result.Exception = new ServiceException(result.ErrorResponse.Error, r.Value.Headers, r.Value.StatusCode); } } return(results); }