예제 #1
0
        public async Async.Task DeltaLinkDriveItem()
        {
            try
            {
                // Get our first delta page.
                var driveItemDeltaCollectionPage = await graphClient.Me.Drive.Root.Delta().Request().GetAsync();

                // Go through all of the delta pages so that we can get the delta link on the last page.
                while (driveItemDeltaCollectionPage.NextPageRequest != null)
                {
                    driveItemDeltaCollectionPage = await driveItemDeltaCollectionPage.NextPageRequest.GetAsync();
                }

                // At this point we're up to date. messagesDeltaCollectionPage now has a deltalink.
                object deltaLink;

                // Now let's use the deltalink to make sure there aren't any changes. There shouldn't be.
                if (driveItemDeltaCollectionPage.AdditionalData.TryGetValue("@odata.deltaLink", out deltaLink))
                {
                    driveItemDeltaCollectionPage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
                    driveItemDeltaCollectionPage = await driveItemDeltaCollectionPage.NextPageRequest.GetAsync();
                }
                Assert.NotNull(deltaLink);
                Assert.Equal(0, driveItemDeltaCollectionPage.Count);

                // Create file to change.
                var excelTest = new ExcelTests();
                var fileId    = await excelTest.OneDriveCreateTestFile("_testDeltaLinkFile.xlsx");


                // Now let's use the deltalink to make sure there aren't any changes.
                if (driveItemDeltaCollectionPage.AdditionalData.TryGetValue("@odata.deltaLink", out deltaLink))
                {
                    driveItemDeltaCollectionPage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
                    driveItemDeltaCollectionPage = await driveItemDeltaCollectionPage.NextPageRequest.GetAsync();
                }

                // We expect two changes, one new item, and the root folder will have a change.
                Assert.Equal(2, driveItemDeltaCollectionPage.Count);


                // Delete the file
                await excelTest.OneDriveDeleteTestFile(fileId, 5000);
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Assert.True(false, $"Error code: {e.Error.Code}");
            }

            catch (Exception e)
            {
                Assert.True(false, $"Error code: {e.Message}");
            }
        }
        public async Task DeltaLinkDriveItem()
        {
            // Get our first delta page.
            var driveItemDeltaCollectionPage = await graphClient.Me.Drive.Root.Delta().Request().GetAsync();

            // Go through all of the delta pages so that we can get the delta link on the last page.
            while (driveItemDeltaCollectionPage.NextPageRequest != null)
            {
                driveItemDeltaCollectionPage = await driveItemDeltaCollectionPage.NextPageRequest.GetAsync();
            }

            // At this point we're up to date. messagesDeltaCollectionPage now has a deltalink.
            object deltaLink;

            // Now let's use the deltalink to make sure there aren't any changes. There shouldn't be.
            if (driveItemDeltaCollectionPage.AdditionalData.TryGetValue(Constants.OdataInstanceAnnotations.DeltaLink, out deltaLink))
            {
                driveItemDeltaCollectionPage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
                driveItemDeltaCollectionPage = await driveItemDeltaCollectionPage.NextPageRequest.GetAsync();
            }
            Assert.NotNull(deltaLink);
            Assert.Equal(driveItemDeltaCollectionPage.Count, 0);

            // Create file to change.
            var excelTest = new ExcelTests();
            var fileId    = await excelTest.OneDriveCreateTestFile("_testDeltaLinkFile.xlsx");


            // Now let's use the deltalink to make sure there aren't any changes.
            if (driveItemDeltaCollectionPage.AdditionalData.TryGetValue(Constants.OdataInstanceAnnotations.DeltaLink, out deltaLink))
            {
                driveItemDeltaCollectionPage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
                driveItemDeltaCollectionPage = await driveItemDeltaCollectionPage.NextPageRequest.GetAsync();
            }

            // We expect two changes, one new item, and the root folder will have a change.
            Assert.Equal(driveItemDeltaCollectionPage.Count, 2);


            // Delete the file
            await excelTest.OneDriveDeleteTestFile(fileId, 5000);
        }