Exemplo n.º 1
0
 private void MtfoOnChunkFinished(object sender, FileOperationChunkFinishedEventArgs e)
 {
     Interlocked.Add(ref bytesCopied, e.ChunkSize);
     Interlocked.Increment(ref sizeIncrements);
 }
Exemplo n.º 2
0
        //private void FileOperationOnOperationCompleted(object sender, FileOperationCompletedEventArgs e)
        //{
        //    // Not used currently
        //}

        private void FileOperationOnChunkFinished(object sender, FileOperationChunkFinishedEventArgs e)
        {
            handlerControl.WaitOne();

            currentCursorTop = cursorTop;

            if (DateTime.Now - refreshed < ZCopyConfiguration.RefreshInterval && e.PercentComplete < 100.00)
            {
                return;
            }

            var(speedBase, uom) = Helpers.GetCopySpeedBase(ZCopyConfiguration.CopySpeedUom);
            var speed   = Helpers.GetCopySpeed(e.BytesCopied, speedBase, copyTimer.Elapsed - hashTimer.Elapsed);
            var elapsed = copyTimer.ElapsedMilliseconds < 1000 ? "<1s" : copyTimer.Elapsed.ToString("hh\\hmm\\mss\\s");

            ZCopyOutput.Print(OutputFormat,
                              TruncateFileName(Path.GetFileName(currentFile), 50),
                              new FileSize(e.SourceFile.Length),
                              new FileSize(e.BytesCopied),
                              PercentComplete(),
                              Helpers.CopySpeedToString(uom, speed).PadLeft(uom.Length < 3 ? 10 : 11),
                              Helpers.EtaToString(Helpers.GetTimeRemaining(e.SourceFile.Length, e.BytesCopied, speed, speedBase)),
                              elapsed,
                              VerificationStatus()?.PadRight(10));

            Console.SetCursorPosition(0, currentCursorTop);

            refreshed = DateTime.Now;

            handlerControl.ReleaseMutex();

            #region Local functions

            string TruncateFileName(string value, int maxLength)
            {
                if (value.Length <= maxLength)
                {
                    return(value);
                }

                return(value.Substring(0, maxLength / 2 - 3) + "..." + value.Substring(value.Length - maxLength / 2));
            }

            string PercentComplete()
            {
                return(e.PercentComplete.ToString("N0") + '%');
            }

            string VerificationStatus()
            {
                if (!showVerificationStatus)
                {
                    return(null);
                }

                if (!sourceVerificationComplete)
                {
                    return("Waiting");
                }

                if (targetVerificationComplete)
                {
                    return((verificationResult ? "OK".ColorText(EscapeCodes.ForegroundGreen) : "Failed".ColorText(EscapeCodes.ForegroundRed)) + EscapeCodes.EraseCharacters(8));
                }

                return("Verifying");
            }

            #endregion
        }