using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.Core { /// /// Represents a progress of some process. /// /// public class TangoProgress where T : IComparable, IFormattable { /// /// Gets or sets the progress message. /// public String Message { get; set; } /// /// Gets or sets a value indicating whether the progress is indeterminate. /// public bool IsIndeterminate { get; set; } /// /// Gets or sets the current progress value. /// public T Value { get; set; } /// /// Gets or sets the current maximum progress. /// public T Maximum { get; set; } /// /// Gets the progress percentage. /// public double Percentage { get { try { double max = Convert.ToDouble(Maximum); double value = Convert.ToDouble(Value); if (max > 0) { return Math.Round(value / max * 100d, 0); } else { return 0; } } catch { return 0; } } } /// /// Initializes a new instance of the class. /// public TangoProgress() { } /// /// Initializes a new instance of the class. /// public TangoProgress(String message, bool isIndeterminate = true, T value = default(T), T maximum = default(T)) : this() { Message = message; IsIndeterminate = isIndeterminate; Value = value; Maximum = maximum; } public override string ToString() { if (IsIndeterminate) { return $"{Message}..."; } else { return $"{Message} ({Value}/{Maximum})..."; } } } /// /// Represents a component process progress event arguments. /// /// /// public class TangoProgressChangedEventArgs : EventArgs where T : IComparable, IFormattable { /// /// Gets or sets the progress. /// public TangoProgress Progress { get; set; } /// /// Initializes a new instance of the class. /// public TangoProgressChangedEventArgs() { Progress = new TangoProgress(); } /// /// Initializes a new instance of the class. /// /// The progress. public TangoProgressChangedEventArgs(TangoProgress progress) : this() { Progress = progress; } } }