Example #1
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += CancelKeyPress;
            var stopwatch = new Stopwatch();

            try
            {
                Console.WriteLine();

                CompressionMode compressMode;
                FileInfo        inFile, outFile;
                ParseCmdLineParams(args, out inFile, out outFile, out compressMode);

                WorkerPool workerPool = new WorkerPool();
                BaseReader reader     = null;

                stopwatch.Start();

                Console.WriteLine("Start");
                Console.WriteLine();

                if (compressMode == CompressionMode.Compress)
                {
                    _writer = new CompressedWriter();
                    _writer.StartWrite(outFile, workerPool.OutQueue);
                    workerPool.Start <CompressWorker>();
                    reader = new RawReader();
                    reader.StartRead(inFile, workerPool.InQueue);
                }
                else if (compressMode == CompressionMode.Decompress)
                {
                    _writer = new RawWriter();
                    _writer.StartWrite(outFile, workerPool.OutQueue);
                    workerPool.Start <DecompressWorker>();
                    reader = new CompressedReader();
                    reader.StartRead(inFile, workerPool.InQueue);
                }

                while (!_canceled && !Logger.ErrorFixed)
                {
                    _writer.BlockWrittenEvent.WaitOne(TimeSpan.FromSeconds(1));

                    if (reader.Done && reader.BlocksRead == _writer.BlocksWritten)
                    {
                        break;
                    }
                    else if (_writer.BlockWrittenEvent.WaitOne(0))
                    {
                        _writer.BlockWrittenEvent.Reset();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.TraceError(string.Format("Global error: {0}", ex.ToString()));
            }

            if (_canceled || Logger.ErrorFixed)
            {
                Logger.DisableOutput();
                if (_writer != null)
                {
                    _writer.Cancel();
                }
            }

            PrintFooter(stopwatch);

            Environment.Exit(0);
        }