Beispiel #1
0
        public void Reorder(IList source, int count)
        {
            ArrayListDataSet arrayListDataSet = null;

            if (source != null)
            {
                arrayListDataSet = new ArrayListDataSet();
                arrayListDataSet.CopyFrom(source);
                int newIndex;
                for (int itemIndex = 0; itemIndex < arrayListDataSet.Count; itemIndex = newIndex + 1)
                {
                    newIndex = itemIndex;
                    for (int index = itemIndex + 1; index < arrayListDataSet.Count; ++index)
                    {
                        if (this.Comparer.Compare(arrayListDataSet[itemIndex], arrayListDataSet[index]) == 0)
                        {
                            ++newIndex;
                            if (newIndex != index)
                            {
                                arrayListDataSet.Move(index, newIndex);
                            }
                        }
                    }
                }
            }
            if (this.Source is ArrayListDataSet)
            {
                ((ModelItem)this.Source).Dispose();
            }
            this.SetSource(arrayListDataSet, count);
        }
Beispiel #2
0
        /// <summary>
        /// Gets an amount of tracks from the current track list. The result is received through an asynchronous callback.
        /// </summary>
        /// <param name="startIndex">The start index of the current track list.</param>
        /// <param name="count">The track count (0 for all tracks).</param>
        /// <param name="callback">The callback when the track data arrives.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"/>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="System.IndexOutOfRangeException"/>
        /// <seealso cref="TrackListChanged"/>
        /// <seealso cref="MAX_TRACKS"/>
        public void GetTracks(int startIndex, int count, TrackListCallback callback)
        {
            if (startIndex < 0)
                throw new ArgumentOutOfRangeException("startIndex", startIndex, "The start index must be >= 0!");
            if (count < 0)
                throw new ArgumentOutOfRangeException("count", count, "Count must be >= 0!");
            if (callback == null)
                throw new ArgumentNullException("callback");

            if (!IsReady || !TransportControls.Instance.HasPlaylist)
                return;

            Application.DeferredInvoke(new DeferredInvokeHandler(delegate(object sender)
            {
                // Make a local copy of the playlist to avoid race conditions
                ArrayListDataSet playlist = new ArrayListDataSet();
                playlist.CopyFrom(TransportControls.Instance.CurrentPlaylist);

                if (playlist == null)
                    return;

                if (count == 0)
                    count = playlist.Count - startIndex;

                if (count > ZuneApi.MAX_TRACKS)
                    count = ZuneApi.MAX_TRACKS;

                if (startIndex + count > playlist.Count)
                    throw new IndexOutOfRangeException("Start index (" + startIndex + ") + count ("
                        + count + ") must be <= TrackCount (" + playlist.Count + ")!");

                Track[] tracks = new Track[count];
                for (int i = 0; i < count; i++)
                {
                    int playlistIndex = i + startIndex;
                    object playlistItem = playlist[playlistIndex];
                    if (playlistItem is PlaybackTrack)
                        tracks[i] = new Track((PlaybackTrack)playlistItem, playlistIndex);
                    else
                        tracks[i] = new Track();
                }

                callback(tracks);
            }), DeferredInvokePriority.Low); // low priority to save performance
        }