using System.ComponentModel; using MusicMetaTagger.Core.Model; using MusicMetaTagger.Core.Queries; namespace MusicMetaTagger.UI { public class TrackQueryStatus : TrackQuery, INotifyPropertyChanged { private int _percentProgress; private string _status; /// /// Occurs when a property value changes. /// public event PropertyChangedEventHandler PropertyChanged; /// /// Gets or sets the status. /// /// The status. public string Status { get { return _status; } set { if (_status == null && value == null) { return; } if ((_status == null) || !_status.Equals(value)) { _status = value + " <- " + _status; SignalPropertyChanged("Status"); } } } public void UpdateStatus(StatusEventArgs data) { Status = data.Status; } /// /// Gets or sets the progress. 0 to 100. /// /// The progress. public int PercentProgress { get { return _percentProgress; } set { CheckPropertyChangedValueType("PercentProgress", ref _percentProgress, ref value); } } /// /// Checks if the property (propertyName) has been updated or changed. /// /// Name of the property. /// The old value. /// The new value. /// True if the value was updated, false otherwise. protected bool CheckPropertyChangedValueType(string propertyName, ref T oldValue, ref T newValue) where T : struct { if (!oldValue.Equals(newValue)) { oldValue = newValue; SignalPropertyChanged(propertyName); return true; } return false; } /// /// Creates the event that a property has changed value /// /// protected void SignalPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } }