From 017161cb546f93005b21f36c8422617736229639 Mon Sep 17 00:00:00 2001 From: Jimmy Appelt Date: Thu, 7 Jan 2016 09:23:58 +0100 Subject: [PATCH 1/2] delegates/events to newer usage --- SpotifyAPI/Local/SpotifyLocalAPI.cs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs index 0c72ab6e..0a50ca35 100644 --- a/SpotifyAPI/Local/SpotifyLocalAPI.cs +++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs @@ -52,21 +52,13 @@ namespace SpotifyAPI.Local private readonly Timer _eventTimer; private StatusResponse _eventStatusResponse; - public delegate void TrackChangeEventHandler(TrackChangeEventArgs e); + public event EventHandler OnTrackChange; - public delegate void PlayStateEventHandler(PlayStateEventArgs e); + public event EventHandler OnPlayStateChange; - public delegate void VolumeChangeEventHandler(VolumeChangeEventArgs e); + public event EventHandler OnVolumeChange; - public delegate void TrackTimeChangeEventHandler(TrackTimeChangeEventArgs e); - - public event TrackChangeEventHandler OnTrackChange; - - public event PlayStateEventHandler OnPlayStateChange; - - public event VolumeChangeEventHandler OnVolumeChange; - - public event TrackTimeChangeEventHandler OnTrackTimeChange; + public event EventHandler OnTrackTimeChange; public SpotifyLocalAPI() { @@ -104,7 +96,7 @@ namespace SpotifyAPI.Local { if (newStatusResponse.Track.TrackResource?.Name != _eventStatusResponse.Track.TrackResource?.Name) { - OnTrackChange?.Invoke(new TrackChangeEventArgs() + OnTrackChange?.Invoke(this, new TrackChangeEventArgs() { OldTrack = _eventStatusResponse.Track, NewTrack = newStatusResponse.Track @@ -113,14 +105,14 @@ namespace SpotifyAPI.Local } if (newStatusResponse.Playing != _eventStatusResponse.Playing) { - OnPlayStateChange?.Invoke(new PlayStateEventArgs() + OnPlayStateChange?.Invoke(this, new PlayStateEventArgs() { Playing = newStatusResponse.Playing }); } if (newStatusResponse.Volume != _eventStatusResponse.Volume) { - OnVolumeChange?.Invoke(new VolumeChangeEventArgs() + OnVolumeChange?.Invoke(this, new VolumeChangeEventArgs() { OldVolume = _eventStatusResponse.Volume, NewVolume = newStatusResponse.Volume @@ -128,7 +120,7 @@ namespace SpotifyAPI.Local } if (newStatusResponse.PlayingPosition != _eventStatusResponse.PlayingPosition) { - OnTrackTimeChange?.Invoke(new TrackTimeChangeEventArgs() + OnTrackTimeChange?.Invoke(this, new TrackTimeChangeEventArgs() { TrackTime = newStatusResponse.PlayingPosition }); From f2048748c3297f051d363ad3ccc4c3f4e064f488 Mon Sep 17 00:00:00 2001 From: Jimmy Appelt Date: Thu, 7 Jan 2016 09:33:40 +0100 Subject: [PATCH 2/2] delegates/events to newer usage --- SpotifyAPI.Example/LocalControl.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SpotifyAPI.Example/LocalControl.cs b/SpotifyAPI.Example/LocalControl.cs index 723e3ff6..f0b4e7b2 100644 --- a/SpotifyAPI.Example/LocalControl.cs +++ b/SpotifyAPI.Example/LocalControl.cs @@ -102,23 +102,23 @@ namespace SpotifyAPI.Example isPlayingLabel.Text = playing.ToString(); } - private void _spotify_OnVolumeChange(VolumeChangeEventArgs e) + private void _spotify_OnVolumeChange(object sender, VolumeChangeEventArgs e) { volumeLabel.Text = (e.NewVolume * 100).ToString(CultureInfo.InvariantCulture); } - private void _spotify_OnTrackTimeChange(TrackTimeChangeEventArgs e) + private void _spotify_OnTrackTimeChange(object sender, TrackTimeChangeEventArgs e) { timeLabel.Text = $"{FormatTime(e.TrackTime)}/{FormatTime(_currentTrack.Length)}"; timeProgressBar.Value = (int)e.TrackTime; } - private void _spotify_OnTrackChange(TrackChangeEventArgs e) + private void _spotify_OnTrackChange(object sender, TrackChangeEventArgs e) { UpdateTrack(e.NewTrack); } - private void _spotify_OnPlayStateChange(PlayStateEventArgs e) + private void _spotify_OnPlayStateChange(object sender, PlayStateEventArgs e) { UpdatePlayingStatus(e.Playing); }