public static ProgressReporter FromAction(Action <object, ProgressReporterEventArgs> myAction) { ProgressReporter reporter = new ProgressReporter(); reporter.OnProgress += new EventHandler <ProgressReporterEventArgs>((sender, args) => myAction(sender, args)); return(reporter); }
public ProgressReporterEventArgs GetScaled(double min, double max, string newMessage) { return(new ProgressReporterEventArgs() { Percent = ProgressReporter.Scale(min, max, this.Percent), Message = newMessage }); }
// Public Methods public ProgressReporterEventArgs GetScaled(double min, double max) { return(new ProgressReporterEventArgs() { Percent = ProgressReporter.Scale(min, max, this.percent), Message = this.message }); }
// Public Methods public static ProgressReporter Coalesce(ref ProgressReporter reporter) { if (reporter == null) { reporter = new ProgressReporter(); } return(reporter); }
public static ProgressReporter FromAction(Action <double, string> action) { // public static implicit operator ProgressReporter(Action<double, string> action) ProgressReporter p = new ProgressReporter(); p.OnProgress += (sender, a) => { action(a.Percent, a.Message); }; return(p); }
public ProgressReporter GetTransformed(Func <ProgressReporterEventArgs, ProgressReporterEventArgs> transformFunction) { if (transformFunction == null) { return(this); } ProgressReporter reporter = new ProgressReporter(); reporter.OnProgress += (sender, args) => { if (OnProgress != null) { OnProgress(sender, transformFunction(args)); } }; return(reporter); }
public ProgressReporter[] GetBalanced(params int[] callCount) { double[] percents; percents = new double[callCount.Length]; int sum = 0; for (int i = 0; i < callCount.Length; i++) { sum += callCount[i]; percents[i] = sum; } percents = percents.Select(q => q * 100.0 / percents[callCount.Length - 1]).ToArray(); ProgressReporter[] reet = new ProgressReporter[callCount.Length]; double last = 0; for (int i = 0; i < callCount.Length; i++) { reet[i] = GetScaled(last, percents[i]); last = percents[i]; } return(reet); }