Sparkles.Git.GitCommand.ParseProgress C# (CSharp) Méthode

ParseProgress() public static méthode

public static ParseProgress ( string line, double &percentage, double &speed, string &information ) : ErrorStatus
line string
percentage double
speed double
information string
Résultat ErrorStatus
        public static ErrorStatus ParseProgress(string line, out double percentage, out double speed, out string information)
        {
            percentage = 0;
            speed = 0;
            information = "";

            Match match;

            if (line.StartsWith ("Git LFS:")) {
                match = progress_regex_lfs_skipped.Match (line);

                int current_file = 0;
                int total_file_count = 0;
                int skipped_file_count = 0;

                if (match.Success) {
                    // "skipped" files are objects that have already been transferred
                    skipped_file_count = int.Parse (match.Groups [3].Value);

                } else {

                    match = progress_regex_lfs.Match (line);

                    if (!match.Success)
                        return ErrorStatus.None;
                }

                current_file = int.Parse (match.Groups [1].Value);

                if (current_file == 0)
                    return ErrorStatus.None;

                total_file_count = int.Parse (match.Groups [2].Value) - skipped_file_count;

                percentage = Math.Round ((double) current_file / total_file_count * 100, 0);
                information = string.Format ("{0} of {1} files", current_file, total_file_count);

                return ErrorStatus.None;
            }

            match = progress_regex.Match (line);

            if (!match.Success || string.IsNullOrWhiteSpace (line)) {
                if (!string.IsNullOrWhiteSpace (line))
                    Logger.LogInfo ("Git", line);

                return FindError (line);
            }

            int number = int.Parse (match.Groups [1].Value);

            // The transfer process consists of two stages: the "Compressing
            // objects" stage which we count as 20% of the total progress, and
            // the "Writing objects" stage which we count as the last 80%
            if (line.Contains ("Compressing objects")) {
                // "Compressing objects" stage
                percentage = (number / 100 * 20);

            } else if (line.Contains ("Writing objects")) {
                percentage = (number / 100 * 80 + 20);
                Match speed_match = speed_regex.Match (line);

                if (speed_match.Success) {
                    speed = double.Parse (speed_match.Groups [1].Value, new CultureInfo ("en-US")) * 1024;

                    if (speed_match.Groups [2].Value.Equals ("M"))
                        speed = speed * 1024;

                    information = speed.ToSize ();
                }
            }

            return ErrorStatus.None;
        }

Usage Example

        bool ReadStream(GitCommand command)
        {
            StreamReader output_stream = command.StandardError;

            if (StorageType == StorageType.LargeFiles)
            {
                output_stream = command.StandardOutput;
            }

            double percentage  = 0;
            double speed       = 0;
            string information = "";

            while (!output_stream.EndOfStream)
            {
                string      line  = output_stream.ReadLine();
                ErrorStatus error = GitCommand.ParseProgress(line, out percentage, out speed, out information);

                if (error != ErrorStatus.None)
                {
                    Error       = error;
                    information = line;

                    command.Kill();
                    command.Dispose();
                    Logger.LogInfo("Git", Name + " | Error status changed to " + Error);

                    return(false);
                }

                OnProgressChanged(percentage, speed, information);
            }

            return(true);
        }
All Usage Examples Of Sparkles.Git.GitCommand::ParseProgress