private async Task CreateZipFile(Document document, string savePath, IProgressInteraction progress) { using (var zip = new ZipFile { CompressionLevel = (CompressionLevel)SettingsManager.Settings.FileCompressionLevel }) { var taskManager = CreateSavingTasksInitialization(document, progress, out var writingTask, out var resourceTasks, out var count, out var finalizingTask); progress.ShowInteraction(); await Task.Run(() => { InitializeZipStructure(document, zip, writingTask); if (count == 0) { FinalizeFileTask(savePath, finalizingTask, zip); taskManager.WorkDone(); return; } ProcessResources(document, resourceTasks, zip); FinalizeFileTask(savePath, finalizingTask, zip); taskManager.WorkDone(); }); } }
public async Task <Document> OpenCompressedFileFormat(Stream fileStream, IProgressInteraction interaction) { var taskManager = new TaskManager(interaction, new [] { new ProgressTask(10, "Reading document base data...") }); interaction.ShowInteraction(); return(await Task.Run(() => { using (var zipFile = ZipFile.Read(fileStream)) { var doc = GetDocumentJson(zipFile); var resourceTasks = doc.Resources.Select(r => new ProgressTask(40, $"Reading resource {r.Name} ({doc.Resources.IndexOf(r) + 1}/{doc.Resources.Count})")); var progressTasks = resourceTasks as ProgressTask[] ?? resourceTasks.ToArray(); foreach (var task in progressTasks) { taskManager.Tasks.Add(task); } taskManager.Tasks[0].Complete(); foreach (var resource in doc.Resources) { ProcessDataCopying(zipFile, resource, progressTasks[doc.Resources.IndexOf(resource)]); // Copy the deeta to the resources. } taskManager.WorkDone(); return doc; // Yeah we're done :) dope nah? } })); }
// TODO: Implement smart zip updating. public async Task <Document> TryOpenDocument(FileStream fileStream, IProgressInteraction interaction) { try { return(await OpenCompressedFileFormat(fileStream, interaction)); } catch (ZipException) // Try reading as json { return(OpenJson(fileStream)); } }
private static TaskManager <IProgressInteraction> CreateSavingTasksInitialization(Document document, IProgressInteraction progress, out ProgressTask writingTask, out List <ProgressTask> resourceTasks, out int count, out ProgressTask finalizingTask) { writingTask = new ProgressTask(10, "Writing document base data..."); var tasks = new List <ProgressTask> { writingTask }; resourceTasks = new List <ProgressTask>(); count = document.Resources.Count; for (var i = 0; i < count; i++) { var progressTask = new ProgressTask(10, $"Writing resource : {document.Resources[i].Name}..."); tasks.Add(progressTask); resourceTasks.Add(progressTask); } finalizingTask = new ProgressTask(5, "Saving to file..."); tasks.Add(finalizingTask); return(new TaskManager <IProgressInteraction>(progress, tasks)); }
public Task SaveCompressedDocument(Document document, string savePath, IProgressInteraction progress) { return(CreateZipFile(document, savePath, progress)); }
public FileOperation(IProgressInteraction interaction) { Interaction = interaction; }
public CopyOperation(IProgressInteraction interaction) : base(interaction) { dirs_created = new Dictionary <string, FilePermissions> (); }
public FileOperation(IProgressInteraction interaction) { Interaction = interaction; }
public CopyOperation(IProgressInteraction interaction) : base(interaction) { dirs_created = new Dictionary<string,FilePermissions> (); }