示例#1
0
        private async Task <bool> TryAddItemToArchiveAsync(ZipArchive archive, Microsoft.Graph.DriveItem item, string baseUrl, string accessToken)
        {
            bool failure = false;

            var zipEntry = archive.CreateEntry(item.Name);

            zipEntry.LastWriteTime = item.LastModifiedDateTime.Value;
            using (var entryStream = zipEntry.Open())
            {
                try
                {
                    var itemContentUrl = ActionHelpers.BuildApiUrl(baseUrl, item.ParentReference.DriveId, item.Id, "content");
                    var contentStream  = await HttpHelper.Default.GetStreamContentForUrlAsync(itemContentUrl, accessToken);

                    await contentStream.CopyToAsync(entryStream);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error copying data into file stream: " + ex.ToString());
                    failure = true;
                }
            }

            if (failure)
            {
                zipEntry.Delete();
            }

            return(!failure);
        }