Beispiel #1
0
        /// <summary>
        /// Returns a collection containing the tracks with the specified text.
        /// <para>
        /// If searchFields is ITPlaylistSearchFieldVisible , this is identical to the list of
        /// tracks displayed if the user enters the search text in the Search edit field in
        /// iTunes when this playlist is being displayed.
        /// </para>
        /// </summary>
        /// <param name="searchText">
        /// The text to search for. This string cannot be longer than 255 characters.
        /// </param>
        /// <param name="searchFields">
        /// Specifies which fields of each track should be searched for searchText.
        /// </param>
        /// <returns>
        /// Collection of Track objects. This will be empty if no tracks meet the search
        /// criteria.
        /// </returns>

        public TrackCollection Search(string searchText, ITPlaylistSearchField searchFields)
        {
            return(Invoke((Func <TrackCollection>) delegate
            {
                TrackCollection collection = new TrackCollection();
                IITTrackCollection results = playlist.Search(searchText, searchFields);
                if (results != null)
                {
                    foreach (IITTrack track in results)
                    {
                        if (track != null)
                        {
                            collection.Add(new Track(track));
                        }
                    }
                }
                return collection;
            }));
        }
        private void buttonSyncData_Click(object sender, EventArgs e)
        {
            if (dataGridView1.RowCount > 0 && dataGridView2.RowCount > 0)
            {
                int rowNumber = 0;

                if (dataGridView1.RowCount <= dataGridView2.RowCount)
                {
                    toolStripProgressBarCore.Maximum = dataGridView1.RowCount;
                }
                else
                {
                    toolStripProgressBarCore.Maximum = dataGridView2.RowCount;
                }
                toolStripProgressBarCore.Value   = rowNumber;
                toolStripProgressBarCore.Visible = true;

                while (rowNumber < dataGridView1.RowCount && rowNumber < dataGridView2.RowCount)
                {
                    if (dataGridView1.Rows[rowNumber].Cells["Name"].Value.ToString() == dataGridView2.Rows[rowNumber].Cells["Name"].Value.ToString() &&
                        dataGridView1.Rows[rowNumber].Cells["Album"].Value.ToString() == dataGridView2.Rows[rowNumber].Cells["Album"].Value.ToString() &&
                        dataGridView1.Rows[rowNumber].Cells["Artist"].Value.ToString() == dataGridView2.Rows[rowNumber].Cells["Artist"].Value.ToString() &&
                        dataGridView1.Rows[rowNumber].Cells["Disc"].Value.ToString() == dataGridView2.Rows[rowNumber].Cells["Disc"].Value.ToString() &&
                        dataGridView1.Rows[rowNumber].Cells["Track"].Value.ToString() == dataGridView2.Rows[rowNumber].Cells["Track"].Value.ToString()
                        )
                    {
                        //MessageBox.Show("The first rows are a match.");
                        IITSource   source1      = sources.get_ItemByName(sourceListing1.SelectedItem.ToString());
                        IITSource   source2      = sources.get_ItemByName(sourceListing2.SelectedItem.ToString());
                        IITPlaylist sourceMusic1 = source1.Playlists.get_ItemByName("Music");
                        IITPlaylist sourceMusic2 = source2.Playlists.get_ItemByName("Music");

                        try {
                            IITTrackCollection matchingTracks = sourceMusic2.Search(dataGridView2.Rows[rowNumber].Cells["Name"].Value.ToString(), ITPlaylistSearchField.ITPlaylistSearchFieldSongNames);
                            toolStripStatusLabelCore.Text = "Found " + matchingTracks.Count.ToString() + " matching tracks.";
                            foreach (IITTrack track in matchingTracks)
                            {
                                if (track.trackID.ToString() == dataGridView2.Rows[rowNumber].Cells["TrackId"].Value.ToString())
                                {
                                    textBoxUpdates.Text += "Updating trackid " + track.trackID.ToString() + " with rating "
                                                           + dataGridView1.Rows[rowNumber].Cells["Rating"].Value.ToString() + " from "
                                                           + track.Rating.ToString() + " and count to "
                                                           + dataGridView1.Rows[rowNumber].Cells["Count"].Value.ToString() + " from "
                                                           + track.PlayedCount.ToString() + "."
                                                           + Environment.NewLine;
                                    track.Rating      = int.Parse(dataGridView1.Rows[rowNumber].Cells["Rating"].Value.ToString());
                                    track.PlayedCount = int.Parse(dataGridView1.Rows[rowNumber].Cells["Count"].Value.ToString());
                                    track.PlayedDate  = (DateTime)dataGridView1.Rows[rowNumber].Cells["Date"].Value;
                                    //MessageBox.Show("Rating and count updated.");
                                    break;
                                }
                            }

                            //IITObject iObject = iTunes.GetITObjectByID(source2.sourceID, sourceMusic2.playlistID, int.Parse(dataGridView2.Rows[0].Cells["TrackId"].Value.ToString()), int.Parse(dataGridView2.Rows[0].Cells["DatabaseId"].Value.ToString()));
                        } catch (Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Items do not match. Stopping.");
                        break;
                    }
                    rowNumber++;
                    toolStripProgressBarCore.Value = rowNumber;
                }
                toolStripProgressBarCore.Visible = false;
            }
            else
            {
                MessageBox.Show("You must preview the sources to continue.");
            }
        }