/// <summary> /// Initializes the NextPageRequest property. /// </summary> public void InitializeNextPageRequest(IBaseClient client, string nextPageLinkString) { if (!string.IsNullOrEmpty(nextPageLinkString)) { this.NextPageRequest = new UserDeltaRequest( nextPageLinkString, client, null); } }
private static async Task <string> GetUsersWithDelta(IUserDeltaRequest request, ITargetBlock <User> target, CancellationToken token) { var page = await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await request.GetAsync(token), token, 0); foreach (User user in page.CurrentPage) { target.Post(user); } return(await GraphHelperUsers.GetUsersWithDelta(page, target, token)); }
/// <summary> /// This is a "traditional" way of doing delta query. We download the currest state of the resource (Users collection) and then use delta links to pick up changes. /// The problem with this approach is that it cannot be optimized as we need to page the initial state sequentially. If there are a lot of users, this will take a while. /// </summary> /// <param name="client"></param> /// <returns></returns> public static IEnumerable <User> UserDeltaQueryTraditional(GraphServiceClient client) { //Initialize the delta query IUserDeltaRequest request = client.Users.Delta().Request().Top(999); // Step 1: populate the current state of users by following the nextLink in the collection IUserDeltaCollectionPage currentPage = ExecuteDeltaCycle(request); // Step 2: Get the deltaLink from the last response // Note: the Microsoft.Graph SDK doesn't fully implement delta, so we have to reach into the AdditionalData value bag IUserDeltaRequest deltaRequest = GetNextDeltaRequest(currentPage, client); // Step 3: After changes are made to users, execute the deltaRequest to pick them up return(WaitForDeltaChanges(deltaRequest)); }
private static IEnumerable <User> WaitForDeltaChanges(IUserDeltaRequest deltaRequest) { Console.WriteLine("Make some changes to users and hit any key to proceed after making the changes"); Console.ReadKey(); IUserDeltaCollectionPage deltaChanges; do { Console.WriteLine("Polling for changes"); Task.Delay(TimeSpan.FromSeconds(1)); deltaChanges = deltaRequest.GetAsync().Result; } while (deltaChanges.Count < 1); return(deltaChanges); }
private static IUserDeltaCollectionPage ExecuteDeltaCycle(IUserDeltaRequest request) { IUserDeltaCollectionPage currentUserState = new UserDeltaCollectionPage(); IUserDeltaCollectionPage currentPage; do { currentPage = request.GetAsync().Result; foreach (var user in currentPage) { currentUserState.Add(user); } request = currentPage.NextPageRequest; } while (request != null); currentUserState.AdditionalData = currentPage.AdditionalData; return(currentUserState); }