コード例 #1
0
ファイル: Program.cs プロジェクト: EvanParallax/GZipTest
 private static int Compress(string compressFile, string compressedFile)
 {
     try
     {
         using (IZipProcessor c = new Compressor(compressFile, compressedFile))
             if (c.Process())
             {
                 return(0);
             }
             else
             {
                 return(1);
             }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(1);
     }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                printUsage();
                return;
            }

            CompressionMode mode = CompressionMode.Compress;

            if (string.Compare(args[0], decompress, true) == 0)
            {
                mode = CompressionMode.Decompress;
            }
            else if (string.Compare(args[0], compress, true) != 0)
            {
                printUsage();
                return;
            }


            IGZipProcessor proc = null;

            if (mode == CompressionMode.Compress)
            {
                proc = new Compressor();
            }
            else
            {
                proc = new Decompressor();
            }

            try
            {
                proc.Process(args[1], args[2], mode);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            try
            {
                int result = 1;

                if (IsArgumentsValid(args))
                {
                    if (File.Exists(args[2]))
                    {
                        File.Delete(args[2]);
                    }

                    switch (args[0])
                    {
                    case "compress":
                        var compressor = new Compressor();
                        result = compressor.Compute(args[1], args[2]);
                        break;

                    case "decompress":
                        var decompressor = new Decompressor();
                        result = decompressor.Compute(args[1], args[2]);
                        break;

                    default:
                        throw new Exception("Нераспознан режим работы. Выберете compress или decompress");
                    }
                }

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                WriteError(ex.Message);
                Console.WriteLine(1);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: lyalyagin/GzipApp
        static int Main(string[] args)
        {
            int result = -1;

            ConsoleArgumentValidator.Validate(args);

            GZipArchiver archiver;

            try
            {
                switch (args[0].ToLower())
                {
                case "compress":
                    archiver = new Compressor(args[1], args[2]);
                    break;

                case "decompress":
                    archiver = new Decompressor(args[1], args[2]);
                    break;

                default: throw new ArgumentException("Action has not been provided");
                }

                archiver.Process();

                result = 0;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error has been occurred: {ex.Message}");

                result = 1;
            }

            return(result);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            ParseArgs options;

            try
            {
                options = new ParseArgs(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            ICommand Command = null;

            ProgressReport progress;

            if (options.Command == Operation.Compress)
            {
                Command  = new Compressor();
                progress = new ProgressReport("Compress");
            }
            else
            {
                Command  = new Decompressor();
                progress = new ProgressReport("Decompress");
            }

            _readerTaskPool = new TaskPool(_cores);
            _writerTaskPool = new TaskPool(_cores);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Command.ShowProgress += progress.ShowProgress;
            Command.Terminate    += _readerTaskPool.Terminate;
            Command.Terminate    += _writerTaskPool.Terminate;

            _reader = new Thread(delegate() { Command.Reader(options.Source, ref _readerTaskPool); });

            for (int i = 0; i < _cores; i++)
            {
                _handlers[i] = new Thread(delegate() { Command.Handler(ref _readerTaskPool, ref _writerTaskPool); });
            }

            _writer = new Thread(delegate() { Command.Writer(options.Destination, ref _writerTaskPool); });

            _reader.Start();
            foreach (Thread handler in _handlers)
            {
                handler.Start();
            }
            _writer.Start();

            _writer.Join();
            foreach (Thread handler in _handlers)
            {
                handler.Join();
            }
            _reader.Join();

            sw.Stop();
            progress.Done(sw.Elapsed);

            Command.Terminate    -= _writerTaskPool.Terminate;
            Command.Terminate    -= _readerTaskPool.Terminate;
            Command.ShowProgress -= progress.ShowProgress;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Predictor/gzip-stream-test
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Invalid argument count.");
                Console.WriteLine(Usage);
                return(1);
            }
            var inputFilePath = args[1];

            if (!File.Exists(inputFilePath))
            {
                Console.WriteLine("Input file does not exist.");
                return(1);
            }

            var outFilePath = args[2];

            try
            {
                Path.GetFileName(outFilePath);
            }
            catch
            {
                Console.WriteLine("Invalid output file name.");
                return(1);
            }

            if (File.Exists(outFilePath))
            {
                Console.WriteLine("Output file already exists. Specify a new file name.");
                return(1);
            }

            switch (args[0])
            {
            case "compress":
                var compressor = new Compressor(inputFilePath, FilePartitioner.GetRecommendedChunkSize(inputFilePath), outFilePath);
                try
                {
                    compressor.Compress();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    Console.WriteLine($"Unexpected error occured: {e.Message}.");
                    return(1);
                }
                break;

            case "decompress":
                var decompressor = new Decompressor(inputFilePath, outFilePath);
                try
                {
                    decompressor.Decompress();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    Console.WriteLine($"Unexpected error occured: {e.Message}.");
                    return(1);
                }

                break;

            default:
                Console.WriteLine("Cannot parse arguments.");
                Console.WriteLine(Usage);
                return(1);
            }

            return(0);
        }