private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; _cancellation = true; if (_archiver != null) { _archiver.Stop(); } }
static int Main(string[] args) { if (!IsCorrectArgs(args)) { HelpMessageView(); return(1); } try { Console.CancelKeyPress += Console_CancelKeyPress; _cancellation = false; PreView(args); IFactoryProcessing processing; if (args[0].ToLower() == "compress") { processing = new GZipFileCompression(); } else { processing = new GZipFileDecompression(); } _archiver = new Archiver(processing); _archiver.Start(args[1], args[2]); if (_cancellation) { Console.WriteLine("Операция прервана пользователем"); return(1); } if (_archiver.IsError) { foreach (var error in _archiver.Errors) { throw error; } } SuccessView(args); return(0); } catch (Exception exp) { Console.WriteLine("Упс, что-то пошло не так!"); if (_archiver != null) { _archiver.Stop(); } ErrorView(exp); return(1); } }