Exemplo n.º 1
0
        static int Main(string[] args)
        {
            Init();
            try
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("Input error");
                    return 1;
                }
                var multipartFlag = 0;
                if (args.Length==4)
                {
                    multipartFlag = int.Parse(args[3]);
                }
                switch (args[0].ToLower())
                {
                    case "compress":
                        _fileProcessor = GetCompressor(multipartFlag);
                        break;
                    case "decompress":
                        _fileProcessor = GetDecompressor(multipartFlag);
                        break;
                    default:
                        Console.WriteLine("Input error");
                        return 1;

                }
                var input = new FileInfo(args[1]);
                if (!input.Exists)
                {
                    Console.WriteLine("Input file does not exists");
                }
                var output = new FileInfo(args[2]);
                if (output.Exists)
                {
                    File.WriteAllText(output.FullName, string.Empty);
                }

                _timer.Start();
                _fileProcessor.Start(input,output);
                _fileProcessor.Join();
                _timer.Stop();

                if (_fileProcessor.State == EFileProcessorState.Failed)
                {
                    Console.WriteLine("File processing failed due to following error(s):");
                    if (_fileProcessor.Exceptions.Count != 0)
                        foreach (var exception in _fileProcessor.Exceptions)
                        {
                            Console.WriteLine(exception.Message);
                        }
                    return 1;
                }

                PrintInfo(input,output,_timer.Elapsed);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occured in main thread: \n {0}",e.Message);
                return 1;
            }
            return 0;
        }