public async Task <Maybe <string> > ExportStoredFiles(ICollection <DocumentReference> documents) { var documentReference = documents.FirstOrDefault(); if (!(documentReference?.Collection is FileCollectionReference)) { return(null); } Maybe <string> maybePath = null; if (documents.Count == 1) { var file = documentReference; maybePath = await _applicationInteraction.ShowSaveFileDialog(fileName : file.LiteDocument["filename"]); if (maybePath.HasValue) { (file.Collection as FileCollectionReference)?.SaveFile(file, maybePath.Value); } } else { maybePath = await _applicationInteraction.ShowFolderPickerDialog("Select folder to export files to..."); if (maybePath.HasValue) { foreach (var file in documents) { var prefix = file.LiteDocument["_id"].AsString.Replace('/', ' ').Split('.').FirstOrDefault(); var path = Path.Combine(maybePath.Value, $"{prefix}-{file.LiteDocument["filename"].AsString}"); ArchiveExtensions.EnsureFileDirectory(path); (file.Collection as FileCollectionReference)?.SaveFile(file, path); } } } return(maybePath); }
private async Task <Maybe <string> > ExportStoredFiles(ICollection <DocumentReference> documents) { var fileDocuments = documents.OfType <FileDocumentReference>().ToArray(); if (!fileDocuments.Any()) { return(null); } Maybe <string> maybePath; if (documents.Count == 1) { var file = fileDocuments[0]; maybePath = await _applicationInteraction.ShowSaveFileDialog(fileName : file.Filename); if (maybePath.HasValue) { file.SaveFile(maybePath.Value); } } else { maybePath = await _applicationInteraction.ShowFolderPickerDialog("Select folder to export files to..."); if (maybePath.HasValue) { foreach (var file in fileDocuments) { var prefix = file.GetIdAsFilename(); var path = Path.Combine(maybePath.Value, $"{prefix}-{file.Filename}"); ArchiveExtensions.EnsureFileDirectory(path); file.SaveFile(path); } } } return(maybePath); }