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


C# IFile.OpenAsync方法代码示例

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


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

示例1: ConvertAsync

 private static async Task ConvertAsync(TopicData topic, IDictionary<string, TopicData> name2topic, Paths paths, IFile destFile, CancellationToken cancellationToken)
 {
     using (var destStream = await destFile.OpenAsync(FileAccess.ReadAndWrite, cancellationToken))
     {
         await ConvertAsync(topic, destStream, name2topic, paths, cancellationToken);
     }
 }
开发者ID:AMDL,项目名称:amdl2maml,代码行数:7,代码来源:TopicConverter.cs

示例2: Init

        private async Task Init(IFile storageFile)
        {
            var fileAsStream = await storageFile.OpenAsync(FileAccess.Read);
            byte[] pbKey = await LoadXmlKeyFile(fileAsStream);
            if (pbKey == null) pbKey = LoadKeyFile(fileAsStream.ToArray());

            if (pbKey == null) throw new InvalidOperationException();

            _keyData = pbKey;
        }
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:10,代码来源:KcpKeyfile.cs

示例3: DownloadFileAsync

        // http://stackoverflow.com/questions/21169573/how-to-implement-progress-reporting-for-portable-httpclient
        // var progress = new Microsoft.Progress<double>();
        // progress.ProgressChanged += (sender, value) => System.Console.Write("\r%{0:N0}", value);
        // var cancellationToken = new CancellationTokenSource();
        // await DownloadFileAsync("http://www.dotpdn.com/files/Paint.NET.3.5.11.Install.zip", progress, cancellationToken.Token);
        public async Task DownloadFileAsync(string url, ProgressBar_Model progressBar, IFile file,CancellationToken token)
        {
            HttpClient client = new HttpClient();
            var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(string.Format("The request returned with HTTP status code {0}", response.StatusCode));
            }

            long total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
            bool canReportProgress = progressBar != null && total != -1;
            if (total == -1 && progressBar != null) progressBar.IsIndeterminate = true;

            using (Stream 
                stream = await response.Content.ReadAsStreamAsync(),
                writestream = await file.OpenAsync(FileAccess.ReadAndWrite))
            {
                int totalRead = 0;
                byte[] buffer = new byte[4096];
                bool isMoreToRead = true;

                do
                {
                    token.ThrowIfCancellationRequested();

                    var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);

                    if (read == 0)
                    {
                        isMoreToRead = false;
                    }
                    else
                    {
                        //var data = new byte[read];
                        //buffer.ToList().CopyTo(0, data, 0, read);

                        // TODO: put here the code to write the file to disk
                        await writestream.WriteAsync(buffer, totalRead, read);

                        totalRead += read;

                        if (canReportProgress)
                        {
                            progressBar.Value = Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
                        }

                    }
                } while (isMoreToRead);
            }
        }
开发者ID:vlkam,项目名称:OpenLearningPlayer,代码行数:56,代码来源:WebHelpers.cs

示例4: Write

        public async Task Write(PwDatabase databaseData, IFile databaseFile)
        {
             kdb4File = new Kdb4File(databaseData);

            ResetHeaderBytes();

            MemoryStream memStream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(memStream);
         
            _headerWriter.WriteHeaders(writer, kdb4File);

           var header = memStream.ToArray();
           var hashOfHeader = _hasher.Hash(header);


            var outStream = new MemoryStream();
            await outStream.WriteAsync(kdb4File.pbStreamStartBytes, 0, (int)kdb4File.pbStreamStartBytes.Length);
            var configuredStream = ConfigureStream(outStream);

            var persister = new Kdb4Persister(new CryptoRandomStream(CrsAlgorithm.Salsa20, kdb4File.pbProtectedStreamKey, _hasher));
            var data = persister.Persist(databaseData.Tree, hashOfHeader);
            try
            {
                await Task.Run(() =>
                    configuredStream.Write(data, 0, data.Length));
            }
            catch(Exception e)
            {
                
            }
         

            configuredStream.Dispose();
            var compressed = outStream.ToArray();

            var keyGenerator = new KeyGenerator(
                _hasher, 
                 _keyTransformer,
                databaseData.MasterKey, 
                databaseData.MasterKey.PercentComplete);
            var aesKey = await keyGenerator.GenerateHashedKeyAsync(kdb4File.pbMasterSeed, kdb4File.pbTransformSeed, (int)databaseData.KeyEncryptionRounds);
            var encrypted = await _databaseEncryptor.Encrypt(compressed, aesKey, kdb4File.pbEncryptionIV);
            
            writer.Write(encrypted);

            var streamToWriteToFile = writer.BaseStream;
            streamToWriteToFile.Position = 0;

            var bytesToWrite = streamToWriteToFile.ToArray();


            var databaseStream = await databaseFile.OpenAsync(FileAccess.ReadAndWrite);
            databaseStream.SetLength(0);
            await databaseStream.FlushAsync();
            await databaseStream.WriteAsync(bytesToWrite, 0, bytesToWrite.Length);
            await databaseStream.FlushAsync();
            databaseStream.Dispose();

            var cryptoStream = new CryptoRandomStream(CrsAlgorithm.Salsa20, kdb4File.pbProtectedStreamKey,_hasher);
            var parser = new Kdb4Parser(cryptoStream);
            databaseData.Tree = parser.ParseAndDecode(databaseData.Tree.Document);
        }
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:62,代码来源:Kdb4Writer.cs


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