Esempio n. 1
0
        public static ProgressReporter FromAction(Action <object, ProgressReporterEventArgs> myAction)
        {
            ProgressReporter reporter = new ProgressReporter();

            reporter.OnProgress += new EventHandler <ProgressReporterEventArgs>((sender, args) => myAction(sender, args));
            return(reporter);
        }
Esempio n. 2
0
 public ProgressReporterEventArgs GetScaled(double min, double max, string newMessage)
 {
     return(new ProgressReporterEventArgs()
     {
         Percent = ProgressReporter.Scale(min, max, this.Percent),
         Message = newMessage
     });
 }
Esempio n. 3
0
        // Public Methods 

        public ProgressReporterEventArgs GetScaled(double min, double max)
        {
            return(new ProgressReporterEventArgs()
            {
                Percent = ProgressReporter.Scale(min, max, this.percent),
                Message = this.message
            });
        }
Esempio n. 4
0
        // Public Methods 

        public static ProgressReporter Coalesce(ref ProgressReporter reporter)
        {
            if (reporter == null)
            {
                reporter = new ProgressReporter();
            }
            return(reporter);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }