public bool Do(string[] args)
        {
            var startedTime   = DateTime.Now;
            var clientOptions = _clientOptionsService.Map(args);

            try
            {
                if (clientOptions.CompressionMode == CompressionMode.Compress)
                {
                    Compress(clientOptions);
                }
                else
                {
                    Decompress(clientOptions);
                }

                _outcomeService.CompletedSuccessfully(clientOptions, startedTime);
            }
            catch (Exception)
            {
                _outcomeService.Failed(clientOptions);
                throw;
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool Do(string[] args)
        {
            var startedTime = DateTime.Now;

            var clientOptions = _clientOptionsService.Map(args);

            var readContext = _sourceReader.Read(clientOptions.SourceFileName, clientOptions.CompressionMode);

            var parallelCompressionContext = _parallelCompressionService.Run(clientOptions.CompressionMode,
                                                                             Environment.ProcessorCount, readContext);

            var calculationWorkFinishedSrc = new CancellationTokenSource();

            var writeContext = _destinationWriter.Write(clientOptions.DestinationFileName, clientOptions.CompressionMode,
                                                        parallelCompressionContext, calculationWorkFinishedSrc.Token);

            _threadService.WaitThreadsCompletion(parallelCompressionContext.Threads);

            calculationWorkFinishedSrc.Cancel();

            writeContext.ProcessingThread.Join();

            var failed = readContext.ExceptionSource.IsCancellationRequested ||
                         parallelCompressionContext.ExceptionSource.IsCancellationRequested ||
                         writeContext.ExceptionSource.IsCancellationRequested;

            if (failed)
            {
                _outcomeService.Failed(clientOptions);
            }
            else
            {
                _outcomeService.CompletedSuccessfully(clientOptions, startedTime);
            }

            return(!failed);
        }