コード例 #1
0
ファイル: Program.cs プロジェクト: tayaverba/FileCompressor
        /// <summary>
        /// Use this function to debug and test work.
        /// It compresses and decomresses file and then compares results by md5 hash
        /// </summary>
        /// <returns></returns>
        private static int Test(string inputFilePath, string compressedFilePath, string decompressedFilePath)
        {
            IFileArchiver archiver = new FileArchiver();

            try
            {
                var startTime = DateTime.Now;
                Console.WriteLine($"File {inputFilePath} is compressing, please wait...");
                archiver.Compress(inputFilePath, compressedFilePath);
                Console.WriteLine("Compressing time: " + DateTime.Now.Subtract(startTime).TotalMilliseconds);
                startTime = DateTime.Now;
                Console.WriteLine($"File {compressedFilePath} is decompressing, please wait...");
                archiver.Decompress(compressedFilePath, decompressedFilePath);
                Console.WriteLine("Decompressing time: " + DateTime.Now.Subtract(startTime).TotalMilliseconds);

                Console.WriteLine($"File {inputFilePath} was processed successfully. Result files located in {compressedFilePath} and {decompressedFilePath}");

                Console.WriteLine("Files equality check: " + CheckFilesEqual(inputFilePath, decompressedFilePath));
                File.Delete(compressedFilePath);
                File.Delete(decompressedFilePath);
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected error during processing file: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("Execution aborted");

                return(1);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: tayaverba/FileCompressor
        private static int Compress(string inputPath, string outputPath)
        {
            IFileArchiver archiver = new FileArchiver();

            try
            {
                Console.WriteLine("File {0} is compressing, please wait...", inputPath);
                if (!ValidateFiles(inputPath, outputPath))
                {
                    return(1);
                }
                archiver.Compress(inputPath, outputPath);
                Console.WriteLine("File {0} was compressed successfully. Result file located in {1}", inputPath, outputPath);
                Console.ReadLine();
                return(0);
            }
            catch (Exception ex)
            {
                CancelOperation(outputPath, ex.Message);
                return(1);
            }
        }