CreateStreamedFileAsync() public static method

public static CreateStreamedFileAsync ( [ displayNameWithExtension, [ dataRequested, [ thumbnail ) : IAsyncOperation
displayNameWithExtension [
dataRequested [
thumbnail [
return IAsyncOperation
コード例 #1
0
        /// <summary>
        /// Convert <see cref="IBuffer"/> to <see cref="StorageFile"/>.
        /// </summary>
        /// <param name="buffer">Data of file.</param>
        /// <param name="fileName">Display name with extention.</param>
        /// <param name="thumbnail">Thumbnail for created file.</param>
        /// <returns>Streamed file.</returns>
        public static IAsyncOperation <StorageFile> AsStroageFileAsync(this IBuffer buffer, string fileName, IRandomAccessStreamReference thumbnail)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (fileName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            return(StorageFile.CreateStreamedFileAsync(fileName, dataRequested, thumbnail));

            async void dataRequested(StreamedFileDataRequest stream)
            {
                try
                {
                    await stream.WriteAsync(buffer);

                    await stream.FlushAsync();

                    stream.Dispose();
                }
                catch
                {
                    stream.FailAndClose(StreamedFileFailureMode.Failed);
                    throw;
                }
            }
        }