public async Task <bool> TryToPack(AcCommonObjectPackerParams packerParams, AcCommonObjectPacker customPacker = null) { try { using (var waiting = packerParams.Progress == null ? WaitingDialog.Create("Packing…") : null) { var progress = waiting ?? packerParams.Progress; var cancellation = waiting?.CancellationToken ?? packerParams.Cancellation; await Task.Run(() => { var destination = packerParams.Destination ?? Path.Combine(Location, $"{Id}-{(this as IAcObjectVersionInformation)?.Version ?? "0"}-{DateTime.Now.ToUnixTimestamp()}.zip"); using (var output = File.Create(destination)) { Pack(output, packerParams, new Progress <string>(x => progress?.Report(AsyncProgressEntry.FromStringIndetermitate($"Packing: {x}…"))), cancellation, customPacker); } if (cancellation.IsCancellationRequested) { return; } if (packerParams.ShowInExplorer) { WindowsHelper.ViewFile(destination); } }); } return(true); } catch (Exception e) { NonfatalError.Notify("Can’t pack", e); return(false); } }
private void Pack(Stream outputZipStream, AcCommonObjectPackerParams packParams, IProgress <string> progress, CancellationToken cancellation, AcCommonObjectPacker customPacker = null) { var packer = customPacker ?? CreatePacker(); packer.SetProgress(progress, cancellation); packer.SetParams(packParams); packer.Pack(outputZipStream, this); }
public static void Pack <T>(IEnumerable <T> objs, Stream outputZipStream, [CanBeNull] AcCommonObjectPackerParams packParams, [CanBeNull] IProgress <string> progress, CancellationToken cancellation, AcCommonObjectPacker customPacker = null) where T : AcCommonObject { var list = objs.ToList(); if (list.Count == 0) { return; } var packer = customPacker ?? list.First().CreatePacker(); packer.SetProgress(progress, cancellation); packer.SetParams(packParams); packer.Pack(outputZipStream, list); }