Beispiel #1
0
        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();
                });
            }
        }
Beispiel #2
0
        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?
                }
            }));
        }