Add project files.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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<string> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user