-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handling of the stats command, both ran one time or to refresh…
… an existing stats object
- Loading branch information
1 parent
04776fe
commit 12762e4
Showing
4 changed files
with
142 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpeedifyCliWrapper.ReturnTypes | ||
{ | ||
public class SpeedifyStats : ICustomJson | ||
public class SpeedifyStats : ICustomJson, INotifyPropertyChanged | ||
{ | ||
public SpeedifyState State { get; private set; } | ||
public SpeedifyState State | ||
{ | ||
get { return this._state; } | ||
private set | ||
{ | ||
if (Equals(value, this._state)) return; | ||
this._state = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public List<SpeedifyAdapter> Adapters { get; private set; } = new List<SpeedifyAdapter>(); | ||
public List<SpeedifyAdapter> Adapters | ||
{ | ||
get { return this._adapters; } | ||
private set | ||
{ | ||
if (Equals(value, this._adapters)) return; | ||
this._adapters = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public SpeedifyConnectionStats ConnectionStats { get; private set; } | ||
public SpeedifyConnectionStats ConnectionStats | ||
{ | ||
get { return this._connectionStats; } | ||
private set | ||
{ | ||
if (Equals(value, this._connectionStats)) return; | ||
this._connectionStats = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public SpeedifySessionStats SessionStats { get; private set; } | ||
public SpeedifySessionStats SessionStats | ||
{ | ||
get { return this._sessionStats; } | ||
private set | ||
{ | ||
if (Equals(value, this._sessionStats)) return; | ||
this._sessionStats = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
private readonly IReadOnlyDictionary<string, MethodInfo> _accessorDictionary; | ||
private SpeedifyState _state; | ||
private List<SpeedifyAdapter> _adapters = new List<SpeedifyAdapter>(); | ||
private SpeedifyConnectionStats _connectionStats; | ||
private SpeedifySessionStats _sessionStats; | ||
|
||
public SpeedifyStats() | ||
{ | ||
this._accessorDictionary = this.GetType().GetProperties().ToDictionary(kp => kp.Name.ToLower(), vp => vp.SetMethod); | ||
} | ||
|
||
|
||
public MethodInfo this[string part] | ||
public MethodInfo this[string part] => this._accessorDictionary[part.Replace("_", "")]; | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
[NotifyPropertyChangedInvocator] | ||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
get | ||
{ | ||
return this._accessorDictionary[part.Replace("_", "")]; | ||
} | ||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters