Ejemplo n.º 1
0
        //private void OperationOnRetryStarted(object sender, FileOperationRetryStartedEventArgs e)
        //{
        //    throw new NotImplementedException();
        //}

        #endregion

        #region Private methods

        private void ProgressThreadProc(object state)
        {
            var cancel         = (CancellationToken)state;
            var progressFormat = new StringBuilder()
                                 .SavePosition()
                                 .Append("{0:N0} files(s) found | ")
                                 .Append($"{{1,-4}} {(isCopy ? "copied" : "moved")} | ")
                                 .Append("{2,-6} (avg.)" + EscapeCodes.EraseCharacters(10))
                                 .RestorePosition()
                                 .ToString();

            // Wait for at least 1 file to be found
            while (fileCount < 1 && !cancel.IsCancellationRequested)
            {
                Thread.Sleep(500);
            }

            // Loop throughout the lifetime of the file operation, displaying average stats
            while (!cancel.IsCancellationRequested)
            {
                var(speedBase, uom) = Helpers.GetCopySpeedBase(ZCopyConfiguration.CopySpeedUom);
                var speed = Helpers.GetCopySpeed(bytesCopied, speedBase, stopwatch.Elapsed);
                lock (lockObj)
                    ZCopyOutput.Print(progressFormat, fileCount, new FileSize(bytesCopied), Helpers.CopySpeedToString(uom, speed));

                Thread.Sleep(ZCopyConfiguration.RefreshInterval);
            }
        }
Ejemplo n.º 2
0
        private void FileOperationOnRetryStarted(object sender, FileOperationRetryStartedEventArgs e)
        {
            // Using a ThreadPool thread so that the caller is not blocked
            ThreadPool.QueueUserWorkItem(RetryIntervalProgressProc);

            void RetryIntervalProgressProc(object state)
            {
                var timer  = Stopwatch.StartNew();
                var format = $"{EscapeCodes.SavePosition()}{{0}}{EscapeCodes.RestorePosition()}";

                ZCopyOutput.PrintError(e.Reason.Message + " " + e.Reason.InnerException?.Message, false);

                while (timer.ElapsedMilliseconds < e.RetryInterval.TotalMilliseconds)
                {
                    ZCopyOutput.Print(format, $"Retrying in {e.RetryInterval - timer.Elapsed:mm\\mss\\s}");
                }

                timer.Stop();
                ZCopyOutput.Print();
            }
        }
 public static StringBuilder SavePosition(this StringBuilder sb)
 {
     return(sb.Append(EscapeCodes.SavePosition()));
 }
Ejemplo n.º 4
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
        }