FlushAsync() public method

public FlushAsync ( CancellationToken cancellationToken ) : Task
cancellationToken CancellationToken
return Task
Exemplo n.º 1
0
        public void Precancellation()
        {
            var ms = new MemoryStream();

            using (Stream compressor = new GZipStream(ms, CompressionMode.Compress, leaveOpen: true))
            {
                Assert.True(compressor.WriteAsync(new byte[1], 0, 1, new CancellationToken(true)).IsCanceled);
                Assert.True(compressor.FlushAsync(new CancellationToken(true)).IsCanceled);
            }
            using (Stream decompressor = CreateStream(ms, CompressionMode.Decompress, leaveOpen: true))
            {
                Assert.True(decompressor.ReadAsync(new byte[1], 0, 1, new CancellationToken(true)).IsCanceled);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the plans to a file.
        /// </summary>
        /// <param name="plans">The plans.</param>
        public static async Task SavePlansAsync(IList<Plan> plans)
        {
            Character character = (Character)plans.First().Character;

            // Prompt the user to pick a file name
            using (SaveFileDialog sfdSave = new SaveFileDialog())
            {
                sfdSave.FileName = $"{character.Name} - Plans Backup";
                sfdSave.Title = @"Save to File";
                sfdSave.Filter = @"EVEMon Plans Backup Format (*.epb)|*.epb";
                sfdSave.FilterIndex = (int)PlanFormat.Emp;

                if (sfdSave.ShowDialog() == DialogResult.Cancel)
                    return;

                try
                {
                    string content = PlanIOHelper.ExportAsXML(plans);

                    // Moves to the final file
                    await FileHelper.OverwriteOrWarnTheUserAsync(
                        sfdSave.FileName,
                        async fs =>
                            {
                                // Emp is actually compressed xml
                                Stream stream = new GZipStream(fs, CompressionMode.Compress);
                                using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                                {
                                    await writer.WriteAsync(content);
                                    await writer.FlushAsync();
                                    await stream.FlushAsync();
                                    await fs.FlushAsync();
                                }
                                return true;
                            });
                }
                catch (IOException err)
                {
                    ExceptionHandler.LogException(err, false);
                    MessageBox.Show($"There was an error writing out the file:\n\n{err.Message}",
                                    @"Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 3
0
        public static async Task FlushAsyncFailsAfterDispose()
        {

            var ms = new MemoryStream();
            var ds = new GZipStream(ms, CompressionMode.Compress);
            ds.Dispose();
            await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
            {
                await ds.FlushAsync();
            });
        }
Exemplo n.º 4
0
        public static async Task Flush()
        {
            var ms = new MemoryStream();
            var ds = new GZipStream(ms, CompressionMode.Compress);
            ds.Flush();
            await ds.FlushAsync();

            // Just ensuring Flush doesn't throw
        }