예제 #1
0
        static int Main(string[] args)
        {
            var logger  = new CompositeLogger();
            var fileLog = new FileLogger("GZipTest.log");

            logger.AddChild(fileLog);
            logger.AddChild(new ConsoleLogger());

            try
            {
                var argsParser = new ArgsParser(logger);
                var param      = argsParser.ParsParams(args);
                if (param == null)
                {
                    return(1);
                }

                _sourceFileNameProvider = new FileNameProviderStub(param.SourceFileName);
                _targetFileNameProvider = new FileNameProviderStub(param.TargetFileName);

                var systemInfoProvider = new SystemInfoProvider();
                var appl = new Appl(logger, systemInfoProvider);
                switch (param.ApplMode)
                {
                case ApplMode.Compress:
                    var compressStrategy = new SmartCompressStrategy(systemInfoProvider);
                    appl.ExecuteCompress(compressStrategy, _sourceFileNameProvider, _targetFileNameProvider);
                    break;

                case  ApplMode.Decompress:
                    var decompressStrategy = new SmartDecompressStrategy(systemInfoProvider);
                    appl.ExecuteDecompress(decompressStrategy, _sourceFileNameProvider, _targetFileNameProvider);
                    break;
                }
                return(0);
            }
            catch (Exception ex)
            {
                logger.Add("Произошла ошибка. Выполнение программы будет завершено\r\n" +
                           ex.Message + "\r\n" + ex.StackTrace);

                AddInnerExceptionToLog(ex, logger);

                return(1);
            }
            finally
            {
                logger.Close();
            }
        }
예제 #2
0
        private static int Main(string[] args)
        {
            try
            {
                var argsParser = new ArgsParser(args);
                argsParser.TryParse(out var srcFile, out var dstFile, out var mode);

                using (var processing = new Compressing(srcFile, dstFile, mode))
                {
                    processing.Start();
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"Error: {ex.Message}");
                Console.WriteLine("Use syntax: GZipTest.exe (compress|decompress) source_file_name result_file_name");
                return(1);
            }
        }