public static async Task<DocumentReference> New (string directory, string baseName, string ext, IFileSystem fs, DocumentConstructor dctor, string contents = null)
{
if (ext [0] != '.') {
ext = '.' + ext;
}
//
// Get a name
//
var n = baseName + ext;
var i = 1;
var p = Path.Combine (directory, n);
var files = await fs.ListFiles (directory);
while (files.Exists (x => x.Path == p)) {
i++;
n = baseName + " " + i + ext;
p = Path.Combine (directory, n);
}
return new DocumentReference (await fs.CreateFile (p, contents), dctor, isNew: true);
}