public NativeToplistBrowse(ISession session, ToplistType toplistType, int region, object userData = null) : base(session, IntPtr.Zero) { _toplistType = toplistType; _region = region; _userData = userData; }
internal static extern IntPtr sp_toplistbrowse_create( IntPtr sessionPtr, ToplistType toplistType, int toplistRegion, string userName, ToplistBrowseCompleteCallback completeCallback, IntPtr userDataPtr);
public ToplistParametersInfo(string toplistName, ToplistType toplistType, ToplistFormat toplistFormat) { ToplistName = toplistName.ThrowIfNullOrWhiteSpace(nameof(toplistName)); ToplistType = toplistType.ThrowIfEnumValueIsUndefined(nameof(toplistType)); ToplistFormat = toplistFormat.ThrowIfEnumValueIsUndefined(nameof(toplistFormat)); }
private void CreateToplist_DialogClosing(object sender, DialogClosingEventArgs eventArgs) { if (Equals(eventArgs.Parameter, false)) { return; } if (!(eventArgs.Parameter is CreateToplistViewModel createToplistViewModel)) { return; } string toplistName = createToplistViewModel.ToplistName; if (string.IsNullOrWhiteSpace(toplistName)) { eventArgs.Cancel(); return; } ToplistType toplistType = createToplistViewModel.SelectedToplistType; ToplistFormat toplistFormat = createToplistViewModel.SelectedToplistFormat; var parameters = new ToplistParametersInfo(toplistName, toplistType, toplistFormat); _eventAggregator .GetEvent <ConstructToplistMessage>() .Publish(parameters); }
public IToplistBrowse Browse(ToplistType type, string userName, object userData = null) { AssertHandle(); var browse = new NativeToplistBrowse(this, type, userName, userData); browse.Initialize(); return(browse); }
public IToplistBrowse Browse(ToplistType type, int encodedCountryCode, object userData = null) { AssertHandle(); var browse = new NativeToplistBrowse(this, type, encodedCountryCode, userData); browse.Initialize(); return(browse); }
public static Task<IToplistBrowse> BrowseCurrentUserAsync( this ISession session, ToplistType type, object userData = null) { var tcs = new TaskCompletionSource<IToplistBrowse>(); var browse = session.BrowseCurrentUser(type, userData); browse.Completed += (sender, args) => tcs.SetResult(browse); return tcs.Task; }
public static Task<IToplistBrowse> BrowseAsync( this ISession session, ToplistType toplist, object state = null) { var tcs = new TaskCompletionSource<IToplistBrowse>(); var browse = session.Browse(toplist, state); browse.Completed += (sender, args) => tcs.SetResult(browse); return tcs.Task; }
public static Task <IToplistBrowse> BrowseAsync( this ISession session, ToplistType toplist, object state = null) { var tcs = new TaskCompletionSource <IToplistBrowse>(); var browse = session.Browse(toplist, state); if (browse.IsComplete) { tcs.SetResult(browse); } browse.Completed += (sender, args) => tcs.SetResult(browse); return(tcs.Task); }
public static Task <IToplistBrowse> BrowseCurrentUserAsync( this ISession session, ToplistType type, object userData = null) { var tcs = new TaskCompletionSource <IToplistBrowse>(); var browse = session.BrowseCurrentUser(type, userData); if (browse.IsComplete) { tcs.SetResult(browse); } browse.Completed += (sender, args) => tcs.SetResult(browse); return(tcs.Task); }
public static Task<IToplistBrowse> BrowseAsync( this ISession session, ToplistType type, string userName, object userData = null) { var tcs = new TaskCompletionSource<IToplistBrowse>(); var browse = session.Browse(type, userName, userData); if (browse.IsComplete) { tcs.SetResult(browse); } browse.Completed += (sender, args) => tcs.SetResult(browse); return tcs.Task; }
public static ToplistBase Create(string toplistName, ToplistType toplistType, ToplistFormat toplistFormat) { toplistName.ThrowIfNullOrWhiteSpace(nameof(toplistName)); // Enum parameters are checked in implementation classes. _logger.Info($"Creating toplist [Name: {toplistName}, Type: {toplistType.ToString()} " + $"Format: {toplistFormat.ToString()}]."); return(toplistType switch { ToplistType.Score => new ScoreToplist(toplistName, toplistFormat), ToplistType.Simple => new SimpleToplist(toplistName, toplistFormat), _ => throw new ArgumentOutOfRangeException(nameof(toplistType), toplistType, "Could not recognize toplist type.") });
public IToplistBrowse Browse(ToplistType type, string userName, object userData = null) { AssertHandle(); var browse = new NativeToplistBrowse(this, type, userName, userData); browse.Initialize(); return browse; }
public IToplistBrowse Browse(ToplistType type, object userData = null) { return(Browse(type, (int)ToplistSpecialRegion.Everywhere, userData)); }
public static IToplistBrowse Browse(this IUser user, ToplistType toplistType, object userData = null) { return(user.Session.Browse(toplistType, user.CanonicalName, userData)); }
public IToplistBrowse Browse(ToplistType type, int encodedCountryCode, object userData = null) { AssertHandle(); var browse = new NativeToplistBrowse(this, type, encodedCountryCode, userData); browse.Initialize(); return browse; }
public static IToplistBrowse Browse(this IUser user, ToplistType toplistType, object userData = null) { return user.Session.Browse(toplistType, user.CanonicalName, userData); }
public NativeToplistBrowse(ISession session, ToplistType toplistType, object userData = null) : this(session, toplistType, (int)ToplistSpecialRegion.Everywhere, userData) { }
public NativeToplistBrowse(ISession session, ToplistType toplistType, string userName, object userData = null) : this(session, toplistType, (int)ToplistSpecialRegion.User, userData) { _userName = userName; }
public IToplistBrowse Browse(ToplistType type, object userData = null) { return Browse(type, (int)ToplistSpecialRegion.Everywhere, userData); }
public IEnumerable <ISpotifyObject> GetTopList(ToplistType listType, int maxNumber) { int currentRegion = -1; lock (libspotify.Mutex) { currentRegion = libspotify.sp_session_user_country(this.sessionPtr); } IntPtr topListBrowserPtr = IntPtr.Zero; ManualResetEvent reset = new ManualResetEvent(false); Exception createException = null; ThreadPool.QueueUserWorkItem(delegate(object obj) { try { lock (libspotify.Mutex) { topListBrowserPtr = libspotify.sp_toplistbrowse_create(this.sessionPtr, listType, currentRegion, null, GetPopularCallback, IntPtr.Zero); } } catch (Exception ex) { createException = ex; } finally { reset.Set(); } }); reset.WaitOne(); if (createException != null) { throw createException; } if (topListBrowserPtr == IntPtr.Zero) { throw new Exception("Top list browser pointer is zero"); } lock (popularLock) { if (!libspotify.sp_toplistbrowse_is_loaded(topListBrowserPtr)) { Monitor.Wait(popularLock); } } if (libspotify.sp_toplistbrowse_is_loaded(topListBrowserPtr)) { lock (libspotify.Mutex) { List <ISpotifyObject> objects = new List <ISpotifyObject>(); switch (listType) { case ToplistType.Tracks: { int maxTracks = libspotify.sp_toplistbrowse_num_tracks(topListBrowserPtr); if (maxTracks > maxNumber) { maxTracks = maxNumber; } for (int i = 0; i < maxTracks; i++) { var trackPtr = libspotify.sp_toplistbrowse_track(topListBrowserPtr, i); var track = Track.Get(this, trackPtr); objects.Add(track); } } break; case ToplistType.Artists: { int maxArtists = libspotify.sp_toplistbrowse_num_artists(topListBrowserPtr); if (maxArtists > maxNumber) { maxArtists = maxNumber; } for (int i = 0; i < maxArtists; i++) { var artistPtr = libspotify.sp_toplistbrowse_artist(topListBrowserPtr, i); var artist = Artist.Get(this, artistPtr); objects.Add(artist); } } break; case ToplistType.Albums: { int maxAlbums = libspotify.sp_toplistbrowse_num_albums(topListBrowserPtr); if (maxAlbums > maxNumber) { maxAlbums = maxNumber; } for (int i = 0; i < maxAlbums; i++) { var albumPtr = libspotify.sp_toplistbrowse_album(topListBrowserPtr, i); var album = Album.Get(this, albumPtr); objects.Add(album); } } break; default: throw new Exception("Unrecognized list type"); } libspotify.sp_toplistbrowse_release(topListBrowserPtr); return(objects); } } else { var error = libspotify.sp_toplistbrowse_error(topListBrowserPtr); libspotify.sp_toplistbrowse_release(topListBrowserPtr); throw new Exception("Error retrieving top list: " + error.ToString()); } }
public IToplistBrowse BrowseCurrentUser(ToplistType type, object userData = null) { return(Browse(type, null, userData)); }
/// <summary> /// Fetch a toplist. /// </summary> /// <param name="type">A toplist type. e.g. "artist", "album" or "track".</param> /// <param name="region">A region code or null. e.g. "SE" or "DE".</param> /// <param name="username">A username or null.</param> /// <returns></returns> public Result Toplist(ToplistType type, string region, string username) { /* Create channel callback and parameter map. */ ChannelCallback listener = new ChannelCallback(); Dictionary<string, string> paramsarg = new Dictionary<string, string>(); string str = EnumUtils.GetName(typeof(ToplistType), type).ToLower(); /* Add parameters. */ paramsarg.Add("type", str); paramsarg.Add("region", region); paramsarg.Add("username", username); /* Send toplist request. */ try { this.protocol.SendToplistRequest(listener, paramsarg); } catch (ProtocolException) { return null; } /* Get data. */ byte[] data = listener.Get(this.timeout); /* Create result from XML. */ return XMLMediaParser.ParseResult(data); }
public IToplistBrowse BrowseCurrentUser(ToplistType type, object userData = null) { return Browse(type, null, userData); }