Example #1
0
        public async Task ExportAsync(
            string path,
            T file,
            XmlWriterSettings settings,
            IProgress <float> progress,
            CancellationToken cancel)
        {
            if (settings == null)
            {
                settings = GetDefaultWriterSettings();
            }

            settings.Async = true;

            long currentBytes = 0L;

            using (ProgressStream f = new ProgressStream(new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None), null, null))
                using (XmlWriter r = XmlWriter.Create(f, settings))
                {
                    if (progress != null)
                    {
                        float length = f.Length;
                        f.SetWriteProgress(new BasicProgress <int>(i =>
                        {
                            currentBytes += i;
                            progress.Report(currentBytes / length);
                        }));
                    }
                    await ExportAsync(file, r, cancel);
                }
        }