当前位置: 首页>>代码示例>>C#>>正文


C# CloudFile.DownloadToFileAsync方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.File.CloudFile.DownloadToFileAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudFile.DownloadToFileAsync方法的具体用法?C# CloudFile.DownloadToFileAsync怎么用?C# CloudFile.DownloadToFileAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.File.CloudFile的用法示例。


在下文中一共展示了CloudFile.DownloadToFileAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoUploadDownloadFileAsync

        private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
        {
            StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
            StorageFile inputFile = await tempFolder.CreateFileAsync("input.file", CreationCollisionOption.GenerateUniqueName);
            StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);

            try
            {
                byte[] buffer = GetRandomBuffer(fileSize);
                using (Stream localFile = await inputFile.OpenStreamForWriteAsync())
                {
                    await localFile.WriteAsync(buffer, 0, buffer.Length);
                }

                await file.UploadFromFileAsync(inputFile);

                OperationContext context = new OperationContext();
                await file.UploadFromFileAsync(inputFile, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                context = new OperationContext();
                await file.DownloadToFileAsync(outputFile, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                using (Stream inputFileStream = await inputFile.OpenStreamForReadAsync(),
                    outputFileStream = await outputFile.OpenStreamForReadAsync())
                {
                    TestHelper.AssertStreamsAreEqual(inputFileStream, outputFileStream);
                }
            }
            finally
            {
                inputFile.DeleteAsync().AsTask().Wait();
                outputFile.DeleteAsync().AsTask().Wait();
            }
        }
开发者ID:vinaysh-msft,项目名称:azure-storage-net,代码行数:36,代码来源:FileUploadDownloadTest.cs

示例2: DoUploadDownloadFileAsync

        private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
        {
            string inputFileName = Path.GetTempFileName();
            string outputFileName = Path.GetTempFileName();

            try
            {
                byte[] buffer = GetRandomBuffer(fileSize);
                using (FileStream fileStream = new FileStream(inputFileName, FileMode.Create, FileAccess.Write))
                {
                    await fileStream.WriteAsync(buffer, 0, buffer.Length);
                }

                await file.UploadFromFileAsync(inputFileName, FileMode.Open);

                OperationContext context = new OperationContext();
                await file.UploadFromFileAsync(inputFileName, FileMode.Open, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                await TestHelper.ExpectedExceptionAsync<IOException>(
                    async () => await file.DownloadToFileAsync(outputFileName, FileMode.CreateNew),
                    "CreateNew on an existing file should fail");

                context = new OperationContext();
                await file.DownloadToFileAsync(outputFileName, FileMode.Create, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                using (
                    FileStream inputFileStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
                               outputFileStream = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
                {
                    await TestHelper.AssertStreamsAreEqualAsync(inputFileStream, outputFileStream);
                }

                await file.DownloadToFileAsync(outputFileName, FileMode.Append);

                using (
                    FileStream inputFileStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
                               outputFileStream = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
                {
                    Assert.AreEqual(2 * fileSize, outputFileStream.Length);

                    for (int i = 0; i < fileSize; i++)
                    {
                        Assert.AreEqual(inputFileStream.ReadByte(), outputFileStream.ReadByte());
                    }

                    inputFileStream.Seek(0, SeekOrigin.Begin);
                    for (int i = 0; i < fileSize; i++)
                    {
                        Assert.AreEqual(inputFileStream.ReadByte(), outputFileStream.ReadByte());
                    }
                }
            }
            finally
            {
                File.Delete(inputFileName);
                File.Delete(outputFileName);
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:60,代码来源:FileUploadDownloadTest.cs

示例3: DoUploadDownloadFileAsync

        private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
        {
#if ASPNET_K
            string inputFileName = Path.GetTempFileName();
            string outputFileName = Path.GetTempFileName();
            if (System.IO.File.Exists(outputFileName))
            {
                System.IO.File.Delete(outputFileName);
            }
            try
            {
                byte[] buffer = GetRandomBuffer(fileSize);
                using (FileStream localFile = new FileStream(inputFileName, FileMode.Create, FileAccess.Write))
                {
                    await localFile.WriteAsync(buffer, 0, buffer.Length);
                }

                await file.UploadFromFileAsync(inputFileName);

                OperationContext context = new OperationContext();
                await file.UploadFromFileAsync(inputFileName, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                context = new OperationContext();
                await file.DownloadToFileAsync(outputFileName, FileMode.CreateNew, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                using (FileStream inputFile = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
                    outputFile = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
                {
                    TestHelper.AssertStreamsAreEqual(inputFile, outputFile);
                }
            }
            finally
            {
                System.IO.File.Delete(inputFileName);
                System.IO.File.Delete(outputFileName);
            }
#else
            StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
            StorageFile inputFile = await tempFolder.CreateFileAsync("input.file", CreationCollisionOption.GenerateUniqueName);
            StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);
            try
            {
                byte[] buffer = GetRandomBuffer(fileSize);
                using (Stream localFile = await inputFile.OpenStreamForWriteAsync())
                {
                    await localFile.WriteAsync(buffer, 0, buffer.Length);
                }

                await file.UploadFromFileAsync(inputFile);

                OperationContext context = new OperationContext();
                await file.UploadFromFileAsync(inputFile, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                context = new OperationContext();
                await file.DownloadToFileAsync(outputFile, null, null, context);
                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                using (Stream inputFileStream = await inputFile.OpenStreamForReadAsync(),
                    outputFileStream = await outputFile.OpenStreamForReadAsync())
                {
                    TestHelper.AssertStreamsAreEqual(inputFileStream, outputFileStream);
                }
            }
            finally
            {
                inputFile.DeleteAsync().AsTask().Wait();
                outputFile.DeleteAsync().AsTask().Wait();
            }
#endif
        }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:73,代码来源:FileUploadDownloadTest.cs


注:本文中的Microsoft.WindowsAzure.Storage.File.CloudFile.DownloadToFileAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。