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); } }
public static int Main(string[] args) { try { var archivingSettings = ConsoleHelper.GetSettingsFromArguments(args); IArchiver archiver = new Archiver(); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; archiver.Abort(); while (archiver.CheckArchivingIsDone() == ResultState.Processing) { Thread.Sleep(100); } Environment.Exit(1); }; switch (archivingSettings.Mode) { case CompressionMode.Compress: archiver.Compress(archivingSettings.File, archivingSettings.Archive); break; case CompressionMode.Decompress: archiver.Decompress(archivingSettings.File, archivingSettings.Archive); break; } ResultState state; while ((state = archiver.CheckArchivingIsDone()) == ResultState.Processing) { Thread.Sleep(100); } Console.WriteLine("All done"); return state == ResultState.Done ? 0 : 1; } catch (Exception ex) { Console.WriteLine("Critical error: {0}. \r\nStack trace: {1}", ex.Message, ex.StackTrace); return 1; } }
static int Main(string[] args) { Console.CancelKeyPress += new ConsoleCancelEventHandler(_cancelHandler); Parse(args); if (args[0].ToLower() == "compress") { Arch = new Compressor(args[1], args[2]); } else { Arch = new Decompressor(args[1], args[2]); } try { Arch.Do(); return(1); } catch { return(0); } }
static void Main(String[] Arguments) { DateTime StartTime = DateTime.Now; Arguments = new String[3]; Arguments[0] = "compress"; Arguments[1] = @"D:\1.bin"; Arguments[2] = @"D:\2.bin.gz"; try { using (Archiver Archiver = new Archiver(new ArchiverParameters(Arguments))) { Console.CancelKeyPress += (o, e) => { e.Cancel = true; Archiver.Cancel(); }; Archiver.Process(); } } catch (Exception E) { Console.WriteLine($"Ошибка. {E.Message}"); Console.ReadKey(); Environment.Exit(1); } Console.WriteLine($"Время выполнения = {(DateTime.Now - StartTime).TotalSeconds} секунд."); Console.ReadKey(); Environment.Exit(0); }
public ControlThreads(string s_SourceFile, string s_ResultingFile) { this.s_SourceFile = s_SourceFile; this.s_ResultingFile = s_ResultingFile; w_ReadQueue = new WorkQueue(); w_WriteDictionary = new WorkDictionary(); //Получение числа процессоров Console.WriteLine("Получение характеристик компьютера..."); // Количество потоков: два потока на чтение и запись соответственно, и количество потоков на compress/decompress, // Равное числу ядер компьютера i_CountProcessors = Environment.ProcessorCount; m_ThreadsEnd = new ManualResetEvent[i_CountProcessors + 2]; // Класс работы с файлами w_WorkWithReadAndWrite = new WorkWithReadAndWrite(this.s_SourceFile, this.s_ResultingFile, i_BlockSize, w_ReadQueue, w_WriteDictionary, m_ThreadsEnd); Console.WriteLine("Характеристики компьютера получены."); // Класс сжатия/распаковки a_Archiver = new Archiver(this.w_ReadQueue, this.w_WriteDictionary, this.m_ThreadsEnd); }