diff --git a/SpotifyAPI.Example/App.config b/SpotifyAPI.Example/App.config
index 8e156463..1f6eeef1 100644
--- a/SpotifyAPI.Example/App.config
+++ b/SpotifyAPI.Example/App.config
@@ -1,6 +1,6 @@
-
-
-
+
+
+
\ No newline at end of file
diff --git a/SpotifyAPI.Example/ExampleForm.cs b/SpotifyAPI.Example/ExampleForm.cs
index b53b2040..d311c0ef 100644
--- a/SpotifyAPI.Example/ExampleForm.cs
+++ b/SpotifyAPI.Example/ExampleForm.cs
@@ -9,4 +9,4 @@ namespace SpotifyAPI.Example
InitializeComponent();
}
}
-}
+}
\ No newline at end of file
diff --git a/SpotifyAPI.Example/LocalControl.cs b/SpotifyAPI.Example/LocalControl.cs
index bb66fd8e..f43c34e4 100644
--- a/SpotifyAPI.Example/LocalControl.cs
+++ b/SpotifyAPI.Example/LocalControl.cs
@@ -1,10 +1,10 @@
-using System;
+using SpotifyAPI.Local;
+using SpotifyAPI.Local.Enums;
+using SpotifyAPI.Local.Models;
+using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;
-using SpotifyAPI.Local;
-using SpotifyAPI.Local.Enums;
-using SpotifyAPI.Local.Models;
namespace SpotifyAPI.Example
{
@@ -102,23 +102,23 @@ namespace SpotifyAPI.Example
isPlayingLabel.Text = playing.ToString();
}
- void _spotify_OnVolumeChange(VolumeChangeEventArgs e)
+ private void _spotify_OnVolumeChange(VolumeChangeEventArgs e)
{
- volumeLabel.Text = (e.NewVolume*100).ToString(CultureInfo.InvariantCulture);
+ volumeLabel.Text = (e.NewVolume * 100).ToString(CultureInfo.InvariantCulture);
}
- void _spotify_OnTrackTimeChange(TrackTimeChangeEventArgs e)
+ private void _spotify_OnTrackTimeChange(TrackTimeChangeEventArgs e)
{
timeLabel.Text = FormatTime(e.TrackTime) + "/" + FormatTime(_currentTrack.Length);
- timeProgressBar.Value = (int) e.TrackTime;
+ timeProgressBar.Value = (int)e.TrackTime;
}
- void _spotify_OnTrackChange(TrackChangeEventArgs e)
+ private void _spotify_OnTrackChange(TrackChangeEventArgs e)
{
UpdateTrack(e.NewTrack);
}
- void _spotify_OnPlayStateChange(PlayStateEventArgs e)
+ private void _spotify_OnPlayStateChange(PlayStateEventArgs e)
{
UpdatePlayingStatus(e.Playing);
}
@@ -162,4 +162,4 @@ namespace SpotifyAPI.Example
return mins + ":" + secs;
}
}
-}
+}
\ No newline at end of file
diff --git a/SpotifyAPI.Example/Program.cs b/SpotifyAPI.Example/Program.cs
index f07fa459..bdfac8ea 100644
--- a/SpotifyAPI.Example/Program.cs
+++ b/SpotifyAPI.Example/Program.cs
@@ -1,22 +1,19 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpotifyAPI.Example
{
- static class Program
+ internal static class Program
{
///
/// Der Haupteinstiegspunkt für die Anwendung.
///
[STAThread]
- static void Main()
+ private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ExampleForm());
}
}
-}
+}
\ No newline at end of file
diff --git a/SpotifyAPI.Example/Properties/AssemblyInfo.cs b/SpotifyAPI.Example/Properties/AssemblyInfo.cs
index 4215e0a6..2dad8ee7 100644
--- a/SpotifyAPI.Example/Properties/AssemblyInfo.cs
+++ b/SpotifyAPI.Example/Properties/AssemblyInfo.cs
@@ -1,8 +1,7 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-// Allgemeine Informationen über eine Assembly werden über die folgenden
+// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("SpotifyAPI.Example")]
@@ -14,8 +13,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
-// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
+// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
+// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
@@ -25,12 +24,12 @@ using System.Runtime.InteropServices;
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
-// Nebenversion
+// Nebenversion
// Buildnummer
// Revision
//
-// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
+// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/SpotifyAPI.Example/WebControl.cs b/SpotifyAPI.Example/WebControl.cs
index 9e8247a9..0a06679f 100644
--- a/SpotifyAPI.Example/WebControl.cs
+++ b/SpotifyAPI.Example/WebControl.cs
@@ -1,14 +1,13 @@
-using System;
+using SpotifyAPI.Web;
+using SpotifyAPI.Web.Auth;
+using SpotifyAPI.Web.Enums;
+using SpotifyAPI.Web.Models;
+using System;
using System.Collections.Generic;
-using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
-using SpotifyAPI.Web;
-using SpotifyAPI.Web.Auth;
-using SpotifyAPI.Web.Enums;
-using SpotifyAPI.Web.Models;
using Image = System.Drawing.Image;
namespace SpotifyAPI.Example
@@ -21,7 +20,7 @@ namespace SpotifyAPI.Example
private PrivateProfile _profile;
private List _savedTracks;
private List _playlists;
-
+
public WebControl()
{
InitializeComponent();
@@ -37,7 +36,7 @@ namespace SpotifyAPI.Example
_auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;
}
- void _auth_OnResponseReceivedEvent(Token token, string state)
+ private void _auth_OnResponseReceivedEvent(Token token, string state)
{
_auth.StopHttpServer();
@@ -77,7 +76,7 @@ namespace SpotifyAPI.Example
_savedTracks.ForEach(track => savedTracksListView.Items.Add(new ListViewItem()
{
Text = track.Name,
- SubItems = {string.Join(",", track.Artists.Select(source => source.Name)), track.Album.Name}
+ SubItems = { string.Join(",", track.Artists.Select(source => source.Name)), track.Album.Name }
}));
_playlists = GetPlaylists();
@@ -134,4 +133,4 @@ namespace SpotifyAPI.Example
_auth.DoAuth();
}
}
-}
+}
\ No newline at end of file
diff --git a/SpotifyAPI.Tests/Properties/AssemblyInfo.cs b/SpotifyAPI.Tests/Properties/AssemblyInfo.cs
index 07294755..a395e345 100644
--- a/SpotifyAPI.Tests/Properties/AssemblyInfo.cs
+++ b/SpotifyAPI.Tests/Properties/AssemblyInfo.cs
@@ -1,8 +1,7 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-// Allgemeine Informationen über eine Assembly werden über die folgenden
+// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("SpotifyAPI.Tests")]
@@ -14,8 +13,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
-// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
+// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
+// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
@@ -25,12 +24,12 @@ using System.Runtime.InteropServices;
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
-// Nebenversion
+// Nebenversion
// Buildnummer
// Revision
//
-// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
+// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/SpotifyAPI.Tests/TestClass.cs b/SpotifyAPI.Tests/TestClass.cs
index 2c63271f..3fc90f3d 100644
--- a/SpotifyAPI.Tests/TestClass.cs
+++ b/SpotifyAPI.Tests/TestClass.cs
@@ -1,11 +1,11 @@
-using System;
-using System.IO;
-using System.Linq;
-using Moq;
+using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Models;
+using System;
+using System.IO;
+using System.Linq;
namespace SpotifyAPI.Tests
{
@@ -67,4 +67,4 @@ namespace SpotifyAPI.Tests
//Will add more tests once I decided if this is worth the effort (propably not?)
}
-}
+}
\ No newline at end of file
diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs
index ac2f32ef..7d5ae8a6 100644
--- a/SpotifyAPI/Local/SpotifyLocalAPI.cs
+++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs
@@ -162,10 +162,12 @@ namespace SpotifyAPI.Local
public void Mute()
{
//Windows < Windows Vista Check
- Contract.Requires(Environment.OSVersion.Version.Major >= 6);
+ if (Environment.OSVersion.Version.Major < 6)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
- Contract.Requires(Environment.OSVersion.Version.Minor != 0);
+ if(Environment.OSVersion.Version.Minor == 0)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
VolumeMixerControl.MuteSpotify(true);
}
@@ -175,10 +177,12 @@ namespace SpotifyAPI.Local
public void UnMute()
{
//Windows < Windows Vista Check
- Contract.Requires(Environment.OSVersion.Version.Major >= 6);
+ if (Environment.OSVersion.Version.Major < 6)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
- Contract.Requires(Environment.OSVersion.Version.Minor != 0);
+ if (Environment.OSVersion.Version.Minor == 0)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
VolumeMixerControl.MuteSpotify(false);
}
@@ -186,13 +190,15 @@ namespace SpotifyAPI.Local
/// Checks whether Spotify is muted in the Volume Mixer control (required Windows 7 or newer)
///
/// Null if an error occured, otherwise the muted state
- public bool? IsSpotifyMuted()
+ public bool IsSpotifyMuted()
{
//Windows < Windows Vista Check
- Contract.Requires(Environment.OSVersion.Version.Major >= 6);
+ if (Environment.OSVersion.Version.Major < 6)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
- Contract.Requires(Environment.OSVersion.Version.Minor != 0);
+ if (Environment.OSVersion.Version.Minor == 0)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
return VolumeMixerControl.IsSpotifyMuted();
}
@@ -202,12 +208,15 @@ namespace SpotifyAPI.Local
/// A value between 0 and 100
public void SetSpotifyVolume(float volume = 100)
{
- Contract.Requires(0 <= volume && volume <= 100);
//Windows < Windows Vista Check
- Contract.Requires(Environment.OSVersion.Version.Major >= 6);
+ if (Environment.OSVersion.Version.Major < 6)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
- Contract.Requires(Environment.OSVersion.Version.Minor != 0);
+ if (Environment.OSVersion.Version.Minor == 0)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
+ if (volume < 0 || volume > 100)
+ throw new ArgumentOutOfRangeException("Volume parameter has to be a value between 0 and 100");
VolumeMixerControl.SetSpotifyVolume(volume);
}
@@ -215,13 +224,15 @@ namespace SpotifyAPI.Local
/// Return the Volume Mixer volume of Spotify (requires Windows 7 or newer)
///
/// Null if an error occured, otherwise a float between 0 and 100
- public float? GetSpotifyVolume()
+ public float GetSpotifyVolume()
{
//Windows < Windows Vista Check
- Contract.Requires(Environment.OSVersion.Version.Major >= 6);
+ if (Environment.OSVersion.Version.Major < 6)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
- Contract.Requires(Environment.OSVersion.Version.Minor != 0);
+ if (Environment.OSVersion.Version.Minor == 0)
+ throw new NotSupportedException("This feature is only available on Windows 7 or newer");
return VolumeMixerControl.GetSpotifyVolume();
}
diff --git a/SpotifyAPI/Local/VolumeMixerControl.cs b/SpotifyAPI/Local/VolumeMixerControl.cs
index f0613298..4a6c9f12 100644
--- a/SpotifyAPI/Local/VolumeMixerControl.cs
+++ b/SpotifyAPI/Local/VolumeMixerControl.cs
@@ -8,17 +8,20 @@ namespace SpotifyAPI.Local
{
private const String SPOTIFY_PROCESS_NAME = "spotify";
- internal static float? GetSpotifyVolume()
+ internal static float GetSpotifyVolume()
{
Process[] p = Process.GetProcessesByName(SPOTIFY_PROCESS_NAME);
if (p.Length == 0)
- return null;
+ throw new Exception("Spotify process is not running or was not found!");
int pid = p[0].Id;
ISimpleAudioVolume volume = GetVolumeObject(pid);
if (volume == null)
- return null;
+ {
+ Marshal.ReleaseComObject(volume);
+ throw new COMException("Volume object creation failed");
+ }
float level;
volume.GetMasterVolume(out level);
@@ -26,17 +29,20 @@ namespace SpotifyAPI.Local
return level * 100;
}
- internal static bool? IsSpotifyMuted()
+ internal static bool IsSpotifyMuted()
{
Process[] p = Process.GetProcessesByName(SPOTIFY_PROCESS_NAME);
if (p.Length == 0)
- return null;
+ throw new Exception("Spotify process is not running or was not found!");
int pid = p[0].Id;
ISimpleAudioVolume volume = GetVolumeObject(pid);
if (volume == null)
- return null;
+ {
+ Marshal.ReleaseComObject(volume);
+ throw new COMException("Volume object creation failed");
+ }
bool mute;
volume.GetMute(out mute);
@@ -48,13 +54,16 @@ namespace SpotifyAPI.Local
{
Process[] p = Process.GetProcessesByName(SPOTIFY_PROCESS_NAME);
if (p.Length == 0)
- return;
+ throw new Exception("Spotify process is not running or was not found!");
int pid = p[0].Id;
ISimpleAudioVolume volume = GetVolumeObject(pid);
if (volume == null)
- return;
+ {
+ Marshal.ReleaseComObject(volume);
+ throw new COMException("Volume object creation failed");
+ }
Guid guid = Guid.Empty;
volume.SetMasterVolume(level / 100, ref guid);
@@ -65,13 +74,16 @@ namespace SpotifyAPI.Local
{
Process[] p = Process.GetProcessesByName(SPOTIFY_PROCESS_NAME);
if (p.Length == 0)
- return;
+ throw new Exception("Spotify process is not running or was not found!");
int pid = p[0].Id;
ISimpleAudioVolume volume = GetVolumeObject(pid);
if (volume == null)
- return;
+ {
+ Marshal.ReleaseComObject(volume);
+ throw new COMException("Volume object creation failed");
+ }
Guid guid = Guid.Empty;
volume.SetMute(mute, ref guid);
@@ -125,6 +137,7 @@ namespace SpotifyAPI.Local
[Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
private class MMDeviceEnumerator
{
+
}
private enum EDataFlow