Skip to content

Commit

Permalink
added exception handling functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Nov 1, 2010
1 parent 7498e52 commit 6b1a351
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 127 deletions.
15 changes: 15 additions & 0 deletions Test/Program.cs
Expand Up @@ -2,6 +2,7 @@

using XBMC.JsonRpc;
using System.Collections.Generic;
using System.Threading;

namespace Test
{
Expand Down Expand Up @@ -32,6 +33,20 @@ static void Main(string[] args)
Console.Out.WriteLine("succeeded (Version {0})", xbmc.JsonRpc.Version());
Console.Out.WriteLine("Press <Enter> to disconnect...");

xbmc.Playlist.Video.GetCurrentItem();

/*while (true)
{
IDictionary<string, string> info = xbmc.System.GetInfoLabels("System.CurrentWindow", "System.CurrentControl");
if (info.Count == 2)
{
Console.Out.WriteLine("Window = {0}", info["System.CurrentWindow"]);
Console.Out.WriteLine("Control = {0}", info["System.CurrentControl"]);
}
Thread.Sleep(1000);
}*/

while (!aborted)
{
int ch = Console.In.Peek();
Expand Down
35 changes: 21 additions & 14 deletions xbmc-jsonrpc-sharp/Media/XbmcAlbum.cs
Expand Up @@ -91,20 +91,27 @@ internal static XbmcAlbum FromJson(JObject obj)
return null;
}

return new XbmcAlbum(JsonRpcClient.GetField<int>(obj, "albumid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "album_title"),
JsonRpcClient.GetField<string>(obj, "album_artist"),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<int>(obj, "album_rating"),
JsonRpcClient.GetField<string>(obj, "album_genre", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_mood", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_theme", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_style", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_type", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_label", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_description", string.Empty));
try
{
return new XbmcAlbum(JsonRpcClient.GetField<int>(obj, "albumid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "album_title"),
JsonRpcClient.GetField<string>(obj, "album_artist"),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<int>(obj, "album_rating"),
JsonRpcClient.GetField<string>(obj, "album_genre", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_mood", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_theme", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_style", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_type", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_label", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_description", string.Empty));
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down
15 changes: 11 additions & 4 deletions xbmc-jsonrpc-sharp/Media/XbmcArtist.cs
Expand Up @@ -58,10 +58,17 @@ internal static XbmcArtist FromJson(JObject obj)
return null;
}

return new XbmcArtist(JsonRpcClient.GetField<int>(obj, "artistid"),
JsonRpcClient.GetField<string>(obj, "artist"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"));
try
{
return new XbmcArtist(JsonRpcClient.GetField<int>(obj, "artistid"),
JsonRpcClient.GetField<string>(obj, "artist"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"));
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down
4 changes: 0 additions & 4 deletions xbmc-jsonrpc-sharp/Media/XbmcAudio.cs
Expand Up @@ -36,9 +36,5 @@ public string Artist
}

#endregion

#region Internal static functions

#endregion
}
}
47 changes: 27 additions & 20 deletions xbmc-jsonrpc-sharp/Media/XbmcMovie.cs
Expand Up @@ -90,26 +90,33 @@ internal static new XbmcMovie FromJson(JObject obj)
return null;
}

return new XbmcMovie(JsonRpcClient.GetField<int>(obj, "movieid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<string>(obj, "genre", string.Empty),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<double>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "director", string.Empty),
JsonRpcClient.GetField<string>(obj, "trailer", string.Empty),
JsonRpcClient.GetField<string>(obj, "tagline", string.Empty),
JsonRpcClient.GetField<string>(obj, "plot", string.Empty),
JsonRpcClient.GetField<string>(obj, "plotoutline", string.Empty),
JsonRpcClient.GetField<string>(obj, "originaltitle", string.Empty),
JsonRpcClient.GetField<string>(obj, "lastplayed", string.Empty),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<int>(obj, "playcount"),
JsonRpcClient.GetField<string>(obj, "writer", string.Empty),
JsonRpcClient.GetField<string>(obj, "studio", string.Empty),
JsonRpcClient.GetField<string>(obj, "mpaa", string.Empty));
try
{
return new XbmcMovie(JsonRpcClient.GetField<int>(obj, "movieid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<string>(obj, "genre", string.Empty),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<double>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "director", string.Empty),
JsonRpcClient.GetField<string>(obj, "trailer", string.Empty),
JsonRpcClient.GetField<string>(obj, "tagline", string.Empty),
JsonRpcClient.GetField<string>(obj, "plot", string.Empty),
JsonRpcClient.GetField<string>(obj, "plotoutline", string.Empty),
JsonRpcClient.GetField<string>(obj, "originaltitle", string.Empty),
JsonRpcClient.GetField<string>(obj, "lastplayed", string.Empty),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<int>(obj, "playcount"),
JsonRpcClient.GetField<string>(obj, "writer", string.Empty),
JsonRpcClient.GetField<string>(obj, "studio", string.Empty),
JsonRpcClient.GetField<string>(obj, "mpaa", string.Empty));
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down
39 changes: 23 additions & 16 deletions xbmc-jsonrpc-sharp/Media/XbmcMusicVideo.cs
Expand Up @@ -111,22 +111,29 @@ internal static new XbmcMusicVideo FromJson(JObject obj)
throw new ArgumentNullException("obj");
}

return new XbmcMusicVideo(JsonRpcClient.GetField<int>(obj, "musicvideoid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<string>(obj, "genre", string.Empty),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<double>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "director", string.Empty),
JsonRpcClient.GetField<string>(obj, "plot", string.Empty),
JsonRpcClient.GetField<string>(obj, "lastplayed", string.Empty),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<int>(obj, "playcount"),
JsonRpcClient.GetField<string>(obj, "studio", string.Empty),
JsonRpcClient.GetField<string>(obj, "artist"),
JsonRpcClient.GetField<string>(obj, "album", string.Empty));
try
{
return new XbmcMusicVideo(JsonRpcClient.GetField<int>(obj, "musicvideoid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<string>(obj, "genre", string.Empty),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<double>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "director", string.Empty),
JsonRpcClient.GetField<string>(obj, "plot", string.Empty),
JsonRpcClient.GetField<string>(obj, "lastplayed", string.Empty),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<int>(obj, "playcount"),
JsonRpcClient.GetField<string>(obj, "studio", string.Empty),
JsonRpcClient.GetField<string>(obj, "artist"),
JsonRpcClient.GetField<string>(obj, "album", string.Empty));
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down
9 changes: 8 additions & 1 deletion xbmc-jsonrpc-sharp/Media/XbmcPlaylist.cs
Expand Up @@ -81,7 +81,14 @@ internal void Add(TMediaType item)

internal static XbmcPlaylist<TMediaType> FromJson(JObject obj)
{
return new XbmcPlaylist<TMediaType>((int)obj["current"], (int)obj["start"], (int)obj["total"]);
try
{
return new XbmcPlaylist<TMediaType>((int)obj["current"], (int)obj["start"], (int)obj["total"]);
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down
37 changes: 22 additions & 15 deletions xbmc-jsonrpc-sharp/Media/XbmcSong.cs
Expand Up @@ -106,21 +106,28 @@ internal static XbmcSong FromJson(JObject obj)
return null;
}

return new XbmcSong(JsonRpcClient.GetField<int>(obj, "songid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<string>(obj, "artist"),
JsonRpcClient.GetField<string>(obj, "genre", string.Empty),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<int>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "album", string.Empty),
JsonRpcClient.GetField<int>(obj, "tracknumber"),
JsonRpcClient.GetField<int>(obj, "discnumber"),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<string>(obj, "comment", string.Empty),
JsonRpcClient.GetField<string>(obj, "lyrics", string.Empty));
try
{
return new XbmcSong(JsonRpcClient.GetField<int>(obj, "songid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<string>(obj, "artist"),
JsonRpcClient.GetField<string>(obj, "genre", string.Empty),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<int>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "album", string.Empty),
JsonRpcClient.GetField<int>(obj, "tracknumber"),
JsonRpcClient.GetField<int>(obj, "discnumber"),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<string>(obj, "comment", string.Empty),
JsonRpcClient.GetField<string>(obj, "lyrics", string.Empty));
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down
47 changes: 27 additions & 20 deletions xbmc-jsonrpc-sharp/Media/XbmcTvEpisode.cs
Expand Up @@ -111,26 +111,33 @@ internal static new XbmcTvEpisode FromJson(JObject obj)
return null;
}

return new XbmcTvEpisode(JsonRpcClient.GetField<int>(obj, "episodeid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<double>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "director", string.Empty),
JsonRpcClient.GetField<string>(obj, "plot", string.Empty),
JsonRpcClient.GetField<string>(obj, "lastplayed", string.Empty),
JsonRpcClient.GetField<string>(obj, "showtitle"),
JsonRpcClient.GetField<string>(obj, "firstaired"),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<int>(obj, "season"),
JsonRpcClient.GetField<int>(obj, "episode"),
JsonRpcClient.GetField<int>(obj, "playcount"),
JsonRpcClient.GetField<string>(obj, "writer", string.Empty),
JsonRpcClient.GetField<string>(obj, "studio", string.Empty),
JsonRpcClient.GetField<string>(obj, "mpaa", string.Empty),
JsonRpcClient.GetField<string>(obj, "premiered", string.Empty));
try
{
return new XbmcTvEpisode(JsonRpcClient.GetField<int>(obj, "episodeid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "file"),
JsonRpcClient.GetField<string>(obj, "title"),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<double>(obj, "rating"),
JsonRpcClient.GetField<string>(obj, "director", string.Empty),
JsonRpcClient.GetField<string>(obj, "plot", string.Empty),
JsonRpcClient.GetField<string>(obj, "lastplayed", string.Empty),
JsonRpcClient.GetField<string>(obj, "showtitle"),
JsonRpcClient.GetField<string>(obj, "firstaired"),
JsonRpcClient.GetField<int>(obj, "duration"),
JsonRpcClient.GetField<int>(obj, "season"),
JsonRpcClient.GetField<int>(obj, "episode"),
JsonRpcClient.GetField<int>(obj, "playcount"),
JsonRpcClient.GetField<string>(obj, "writer", string.Empty),
JsonRpcClient.GetField<string>(obj, "studio", string.Empty),
JsonRpcClient.GetField<string>(obj, "mpaa", string.Empty),
JsonRpcClient.GetField<string>(obj, "premiered", string.Empty));
}
catch (Exception ex)
{
return null;
}
}

#endregion
Expand Down

0 comments on commit 6b1a351

Please sign in to comment.