using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Beam.Exports { public class PlainTextExporter : IExporter, IAsyncExporter { public PlainTextExporter(IDocument document) { Document = document; } public IDocument Document { get; } protected virtual string Convert() { return Document.ToString(); } protected virtual Task ConvertAsync() { return Task.FromResult(Document.ToString()); } public virtual void Write(string path) { var text = Convert(); if (!Directory.Exists(Path.GetDirectoryName(path))) throw new ArgumentException(S.M.FileDirectoryDoesNotExist, nameof(path)); File.WriteAllText(path, text, Encoding.Unicode); } public virtual async Task WriteAsync(string path) { var text = await ConvertAsync(); if (!Directory.Exists(path)) throw new ArgumentException(S.M.FileDirectoryDoesNotExist, nameof(path)); await File.WriteAllTextAsync(path, text); } } }