Exemple #1
0
        internal override int Run()
        {
            try
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                //Initializing
                ParseMetadataFromSource();
                DestinationFileName = Helper.GetDecompressedFileNameWithExtension(DestinationFileName, Metadata.FileExtension);
                if (string.Equals(SourceFileName, DestinationFileName))
                {
                    throw new WrongCallException("Source and destination files can not be the same.");
                }
                var decompressThreadCount = Helper.GetDecompressThreadsCount(Metadata.ChunkList.Count);
                var queueLength           = Helper.GetMaxTaskQueueLength(decompressThreadCount);

                base.PositionToRead = new SharingPosition(0, Metadata.ChunkList.Count, 1);
                base.QueueToWrite   = new SharingTaskQueue <Task>(decompressThreadCount, queueLength);

                //Start work
                base.StartStatusThread("Decompressing", (double)100 / Metadata.ChunkList.Count);
                base.StartProcessThreads(decompressThreadCount, "ReaderDecompressor", StartReadAndDecompress);
                StartWrite();

                //Finish work
                ExecutionStatus.FinishStatus(true);
                base.JoinProcessThreads();
                base.JoinStatusThread();

                watch.Stop();

                Console.WriteLine($"Decompressed {SourceFileName} to {DestinationFileName} in {watch.Elapsed.ToString("g")}");
                return(0);
            }
            catch (WrongCallException ex)
            {
                base.AbortAllThreads();
                Console.WriteLine(ex.Message);
            }
            catch (WrongSourceFileException ex)
            {
                base.AbortAllThreads();
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                base.AbortAllThreads();
                Console.WriteLine("Error while decompressing: " + ex.Message);
            }
            finally
            {
                if (ExecutionStatus != null && ExecutionStatus.GetStatus() < 100)
                {
                    File.Delete(DestinationFileName);
                }
            }
            return(1);
        }
Exemple #2
0
        internal override int Run()
        {
            try
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                //Initializing
                if (string.Equals(SourceFileName, DestinationFileName))
                {
                    throw new WrongCallException("Source and destination files can not be the same.");
                }
                long sourceLength = new FileInfo(SourceFileName).Length;
                base.Metadata = new Metadata(SourceFileName, sourceLength);
                var compressThreadCount = Helper.GetCompressThreadsCount(sourceLength);
                var queueLength         = Helper.GetMaxTaskQueueLength(compressThreadCount);

                PositionToRead = new SharingPosition(0, sourceLength, Settings.ChunkSizeBytes);
                QueueToWrite   = new SharingTaskQueue <Task>(compressThreadCount, queueLength);

                //Start work
                base.StartStatusThread("Compressing", 100 / Math.Ceiling((double)sourceLength / Settings.ChunkSizeBytes));
                base.StartProcessThreads(compressThreadCount, "ReaderCompressor", StartReadAndCompress);
                StartWrite();

                //Finish work
                ExecutionStatus.FinishStatus(true);
                base.JoinProcessThreads();
                base.JoinStatusThread();

                watch.Stop();

                Console.WriteLine($"Compressed {SourceFileName} to {DestinationFileName} in {watch.Elapsed.ToString("g")}");
                return(0);
            }
            catch (WrongCallException ex)
            {
                base.AbortAllThreads();
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                base.AbortAllThreads();
                Console.WriteLine("Error while compressing: " + ex.Message);
            }
            finally
            {
                if (ExecutionStatus != null && ExecutionStatus.GetStatus() < 100)
                {
                    File.Delete(DestinationFileName);
                }
            }
            return(1);
        }