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


C# IStorageFile.OpenStreamForWriteAsync方法代码示例

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


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

示例1: WriteBytesAsync

 internal async static Task WriteBytesAsync(IStorageFile storageFile, byte[] bytes)
 {
   using (Stream stream = await storageFile.OpenStreamForWriteAsync())
   {
     await stream.WriteAsync(bytes, 0, bytes.Length);
   }
 }
开发者ID:KateGridina,项目名称:Q42.WinRT,代码行数:7,代码来源:FileIO.cs

示例2: WriteTextAsync

 internal async static Task WriteTextAsync(IStorageFile storageFile, string text)
 {
   using (Stream stream = await storageFile.OpenStreamForWriteAsync())
   {
     byte[] content = Encoding.UTF8.GetBytes(text);
     await stream.WriteAsync(content, 0, content.Length);
   }
 }
开发者ID:KateGridina,项目名称:Q42.WinRT,代码行数:8,代码来源:FileIO.cs

示例3: SaveToFile

 public static async Task SaveToFile(this ZipArchiveEntry entry, IStorageFile file)
 {
     Stream newFileStream = await file.OpenStreamForWriteAsync();
     Stream fileData = entry.Open();
     var data = new byte[entry.Length];
     await fileData.ReadAsync(data, 0, data.Length);
     newFileStream.Write(data, 0, data.Length);
     await newFileStream.FlushAsync();
 }
开发者ID:quandtm,项目名称:exXAMLate,代码行数:9,代码来源:ZipArchiveEntryExtensions.cs

示例4: SaveToFileAsync

 /// <summary>
 /// Saves instance of RenderTargetBitmap to specified file.
 /// </summary>
 public static async Task SaveToFileAsync(this RenderTargetBitmap image, IStorageFile file)
 {
     using (var stream = await file.OpenStreamForWriteAsync())
     {
         var encoder = await BitmapEncoder.CreateAsync(
             BitmapEncoder.JpegEncoderId, stream.AsRandomAccessStream());
         var pixels = await image.GetPixelsAsync();
         encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
             (uint)image.PixelWidth, (uint)image.PixelHeight, DefaultDPI, DefaultDPI, pixels.ToArray());
         await encoder.FlushAsync();
     }
 }
开发者ID:Syn-McJ,项目名称:PlugToolkit,代码行数:15,代码来源:RenderTargetBitmapExtensions.cs

示例5: SaveToFileAsync

 /// <summary>
 /// Saves instance of WriteableBitmap to specified file.
 /// </summary>
 public static async Task SaveToFileAsync(this WriteableBitmap image, IStorageFile file)
 {
     using (var stream = await file.OpenStreamForWriteAsync())
     {
         var encoder = await BitmapEncoder.CreateAsync(
             BitmapEncoder.JpegEncoderId, stream.AsRandomAccessStream());
         var pixelStream = image.PixelBuffer.AsStream();
         var pixels = new byte[image.PixelBuffer.Length];
         await pixelStream.ReadAsync(pixels, 0, pixels.Length);
         encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
             (uint)image.PixelWidth, (uint)image.PixelHeight, DefaultDPI, DefaultDPI, pixels);
         await encoder.FlushAsync();
     }
 }
开发者ID:Syn-McJ,项目名称:PlugToolkit,代码行数:17,代码来源:WriteableBitmapExtensions.cs

示例6: WriteResponseStreamToFileAsync

        public async Task WriteResponseStreamToFileAsync(IStorageFile storageFile, bool append, CancellationToken cancellationToken)
        {
            Stream outputStream = await storageFile.OpenStreamForWriteAsync().ConfigureAwait(false); 
            if (append)
            {                
                outputStream.Seek(0, SeekOrigin.End);
            }

            try
            {
                long current = 0;
                var inputStream = this.ResponseStream;
                byte[] buffer = new byte[S3Constants.DefaultBufferSize];
                int bytesRead = 0;
                long totalIncrementTransferred = 0;
                while ((bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length)
                    .ConfigureAwait(continueOnCapturedContext: false)) > 0)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    await outputStream.WriteAsync(buffer, 0, bytesRead)
                        .ConfigureAwait(continueOnCapturedContext: false);
                    current += bytesRead;
                    totalIncrementTransferred += bytesRead;

                    if (totalIncrementTransferred >= AWSSDKUtils.DefaultProgressUpdateInterval ||
                        current == this.ContentLength)
                    {
                        this.OnRaiseProgressEvent(storageFile.Path, bytesRead, current, this.ContentLength);
                        totalIncrementTransferred = 0;
                    }
                }
				
				ValidateWrittenStreamSize(current);
            }
            finally
            {
                if (outputStream!=null)
                {
                    outputStream.Dispose();
                }                
            }
        }
开发者ID:rossmas,项目名称:aws-sdk-net,代码行数:43,代码来源:GetObjectResponse.storagefile.cs

示例7: AppendLinesAsync

        /// <summary>
        /// Appends lines of text to the specified file using the specified character encoding.
        /// </summary>
        /// <param name="file">The file that the lines are appended to.</param>
        /// <param name="lines">The list of text strings to append as lines.</param>
        /// <param name="encoding">The character encoding of the file.</param>
        /// <returns>No object or value is returned when this method completes.</returns>
        public static Task AppendLinesAsync(IStorageFile file, IEnumerable<string> lines, UnicodeEncoding encoding)
        {
#if __ANDROID__ || __IOS__ || __TVOS__ || WIN32 || TIZEN
            return PathIO.AppendLinesAsync(file.Path, lines, encoding);
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return Windows.Storage.FileIO.AppendLinesAsync((Windows.Storage.StorageFile)((StorageFile)file), lines, (Windows.Storage.Streams.UnicodeEncoding)((int)encoding)).AsTask();
#elif WINDOWS_PHONE
            return Task.Run(async () =>
            {
                Stream s = await file.OpenStreamForWriteAsync();
                s.Position = s.Length;

                using (StreamWriter sw = new StreamWriter(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
                {
                    foreach (string line in lines)
                    {
                        sw.WriteLine(line);
                    }
                }
            });
#else
            throw new PlatformNotSupportedException();
#endif
        }
开发者ID:inthehand,项目名称:Charming,代码行数:31,代码来源:FileIO.cs

示例8: WriteTextAsync

        /// <summary>
        /// Writes text to the specified file using the specified character encoding.
        /// </summary>
        /// <param name="file">The file that the text is written to.</param>
        /// <param name="contents">The text to write.</param>
        /// <param name="encoding">The character encoding of the file.</param>
        /// <returns>No object or value is returned when this method completes.</returns>
        public static Task WriteTextAsync(IStorageFile file, string contents, UnicodeEncoding encoding)
        {
#if __ANDROID__ || __IOS__ || __TVOS__ || WIN32 || TIZEN
            return PathIO.WriteTextAsync(file.Path, contents, encoding);
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return Windows.Storage.FileIO.WriteTextAsync((Windows.Storage.StorageFile)((StorageFile)file), contents, (Windows.Storage.Streams.UnicodeEncoding)((int)encoding)).AsTask();
#elif WINDOWS_PHONE
            return Task.Run(async () =>
            {
                Stream s = await file.OpenStreamForWriteAsync();
                using (StreamWriter sw = new StreamWriter(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
                    sw.Write(contents);
            });
#else
            throw new PlatformNotSupportedException();
#endif
        }
开发者ID:inthehand,项目名称:Charming,代码行数:24,代码来源:FileIO.cs

示例9: UpdateId3TagsAsync

        /// <summary>
        ///     Updates the id3 tags. WARNING, there needs to be more testing with lower end devices.
        /// </summary>
        /// <param name="song">The song.</param>
        /// <param name="file">The file.</param>
        private async Task UpdateId3TagsAsync(Song song, IStorageFile file)
        {
            using (var fileStream = await file.OpenStreamForWriteAsync().ConfigureAwait(false))
            {
                File tagFile;

                try
                {
                    tagFile = File.Create(new SimpleFileAbstraction(file.Name, fileStream, fileStream));
                }
                catch
                {
                    // either the download is corrupted or is not an mp3 file
                    return;
                }

                var newTags = tagFile.GetTag(TagTypes.Id3v2, true);

                newTags.Title = song.Name;

                if (song.Artist.ProviderId != "autc.unknown")
                {
                    newTags.Performers = song.ArtistName.Split(',').Select(p => p.Trim()).ToArray();
                }

                newTags.Album = song.Album.Name;
                newTags.AlbumArtists = new[] {song.Album.PrimaryArtist.Name};

                if (!string.IsNullOrEmpty(song.Album.Genre))
                {
                    newTags.Genres = song.Album.Genre.Split(',').Select(p => p.Trim()).ToArray();
                }

                newTags.Track = (uint) song.TrackNumber;

                newTags.Comment = "Downloaded with Audiotica - http://audiotica.fm";

                try
                {
                    if (song.Album.HasArtwork)
                    {
                        var albumFilePath = string.Format(AppConstant.ArtworkPath, song.Album.Id);
                        var artworkFile = await StorageHelper.GetFileAsync(albumFilePath).ConfigureAwait(false);

                        using (var artworkStream = await artworkFile.OpenAsync(FileAccess.Read))
                        {
                            using (var memStream = new MemoryStream())
                            {
                                await artworkStream.CopyToAsync(memStream);
                                newTags.Pictures = new IPicture[]
                                {
                                    new Picture(
                                        new ByteVector(
                                            memStream.ToArray(),
                                            (int) memStream.Length))
                                };
                            }
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    // Should never happen, since we are opening the files in read mode and nothing is locking it.
                }

                await Task.Run(() => tagFile.Save());
            }
        }
开发者ID:jayharry28,项目名称:Audiotica,代码行数:73,代码来源:SongDownloadService.cs

示例10: SaveTransmissionToFileAsync

 private static async Task SaveTransmissionToFileAsync(Transmission transmission, IStorageFile file)
 {
     try
     {
         using (Stream stream = await file.OpenStreamForWriteAsync().ConfigureAwait(false))
         {
             await StorageTransmission.SaveAsync(transmission, stream).ConfigureAwait(false);
         }
     }
     catch (UnauthorizedAccessException)
     {
         string message = string.Format("Failed to save transmission to file. UnauthorizedAccessException. File path: {0}, FileName: {1}", file.Path, file.Name);
         CoreEventSource.Log.LogVerbose(message);
         throw;
     }
 }
开发者ID:iusafaro,项目名称:ApplicationInsights-dotnet,代码行数:16,代码来源:Storage.cs


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