public void Init()
        {
            _sut          = new ArchivationService();
            _testFilesDir = new DirectoryInfo("..\\..\\..\\files");

            if (!_testFilesDir.Exists)
            {
                _testFilesDir.Create();
            }

            _fileToCompress   = new FileInfo(_testFilesDir.FullName + "\\file_to_compress.pdf");
            _fileToDecompress = new FileInfo(_testFilesDir.FullName + "\\file_to_decompress.pdf.gz");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // TODO Replace with event
            Console.WriteLine("Program has been started.");

            try
            {
                RunningArguments.Set(args);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            // TODO Replace with event
            Console.WriteLine("Arguments have been set.");

            if (RunningArguments.Current.DoShowHelp)
            {
                var helpShower = new HelpShower();
                helpShower.ShowHelp();
            }
            else
            {
                var archivationSrv = new ArchivationService();

                var actionDict = new Dictionary <CompressionMode, Action <string, string> >()
                {
                    { CompressionMode.Decompress, (input, output) => archivationSrv.DecompressFile(input, output) },
                    { CompressionMode.Compress, (input, output) => archivationSrv.CompressFile(input, output) },
                };

                var archiverAction = actionDict[RunningArguments.Current.CompressionMode];

                var watch = new Stopwatch();
                watch.Start();

                try
                {
                    archiverAction.Invoke(RunningArguments.Current.InputPath, RunningArguments.Current.OutputPath);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);

                    var outputFile = new FileInfo(RunningArguments.Current.OutputPath);
                    if (outputFile.Exists)
                    {
                        outputFile.Delete();
                    }

                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine("The unhandled exception has been thrown. Please create bug ticket on " +
                                      "https://github.com/ShefardPT/TestTask_GZipArchiver/issues");

                    var outputFile = new FileInfo(RunningArguments.Current.OutputPath);
                    if (outputFile.Exists)
                    {
                        outputFile.Delete();
                    }

                    return;
                }

                watch.Stop();

                // TODO Replace with event
                Console.WriteLine("Done!");
                Console.WriteLine($"It had taken {watch.ElapsedMilliseconds / 1000}.{watch.ElapsedMilliseconds % 1000} seconds to do job.");
                Console.WriteLine("Press ENTER to finish.");
                Console.ReadLine();
            }
        }