示例#1
0
 public NativeToplistBrowse(ISession session, ToplistType toplistType, int region, object userData = null)
     : base(session, IntPtr.Zero)
 {
     _toplistType = toplistType;
     _region      = region;
     _userData    = userData;
 }
示例#2
0
 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));
 }
示例#4
0
 public NativeToplistBrowse(ISession session, ToplistType toplistType, int region, object userData = null)
     : base(session, IntPtr.Zero)
 {
     _toplistType = toplistType;
     _region = region;
     _userData = userData;
 }
        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);
        }
 internal static extern IntPtr sp_toplistbrowse_create(
     IntPtr sessionPtr,
     ToplistType toplistType,
     int toplistRegion,
     string userName,
     ToplistBrowseCompleteCallback completeCallback,
     IntPtr userDataPtr);
示例#7
0
        public IToplistBrowse Browse(ToplistType type, string userName, object userData = null)
        {
            AssertHandle();

            var browse = new NativeToplistBrowse(this, type, userName, userData);

            browse.Initialize();
            return(browse);
        }
示例#8
0
        public IToplistBrowse Browse(ToplistType type, int encodedCountryCode, object userData = null)
        {
            AssertHandle();

            var browse = new NativeToplistBrowse(this, type, encodedCountryCode, userData);

            browse.Initialize();
            return(browse);
        }
示例#9
0
        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;
        }
示例#10
0
        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;
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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;
        }
示例#14
0
        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.")
            });
示例#15
0
        public IToplistBrowse Browse(ToplistType type, string userName, object userData = null)
        {
            AssertHandle();

            var browse = new NativeToplistBrowse(this, type, userName, userData);
            browse.Initialize();
            return browse;
        }
示例#16
0
 public IToplistBrowse Browse(ToplistType type, object userData = null)
 {
     return(Browse(type, (int)ToplistSpecialRegion.Everywhere, userData));
 }
示例#17
0
 public static IToplistBrowse Browse(this IUser user, ToplistType toplistType, object userData = null)
 {
     return(user.Session.Browse(toplistType, user.CanonicalName, userData));
 }
示例#18
0
        public IToplistBrowse Browse(ToplistType type, int encodedCountryCode, object userData = null)
        {
            AssertHandle();

            var browse = new NativeToplistBrowse(this, type, encodedCountryCode, userData);
            browse.Initialize();
            return browse;
        }
示例#19
0
 public static IToplistBrowse Browse(this IUser user, ToplistType toplistType, object userData = null)
 {
     return user.Session.Browse(toplistType, user.CanonicalName, userData);
 }
示例#20
0
 public NativeToplistBrowse(ISession session, ToplistType toplistType, object userData = null)
     : this(session, toplistType, (int)ToplistSpecialRegion.Everywhere, userData)
 {
 }
示例#21
0
 public NativeToplistBrowse(ISession session, ToplistType toplistType, string userName, object userData = null)
     : this(session, toplistType, (int)ToplistSpecialRegion.User, userData)
 {
     _userName = userName;
 }
示例#22
0
 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());
            }
        }
示例#24
0
 public NativeToplistBrowse(ISession session, ToplistType toplistType, object userData = null)
     : this(session, toplistType, (int)ToplistSpecialRegion.Everywhere, userData)
 {
 }
示例#25
0
 public IToplistBrowse BrowseCurrentUser(ToplistType type, object userData = null)
 {
     return(Browse(type, null, userData));
 }
示例#26
0
        /// <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);
        }
示例#27
0
 public NativeToplistBrowse(ISession session, ToplistType toplistType, string userName, object userData = null)
     : this(session, toplistType, (int)ToplistSpecialRegion.User, userData)
 {
     _userName = userName;
 }
示例#28
0
 public IToplistBrowse BrowseCurrentUser(ToplistType type, object userData = null)
 {
     return Browse(type, null, userData);
 }