示例#1
0
文件: Form1.cs 项目: sdvpl/SongList
        public void ArtistSearch(String ArtistName)
        {
            ArtstAlbumSearchListView.Items.Clear();
            ArtstAlbumSearchListView.ListViewItemSorter = null;
            if (String.IsNullOrEmpty(ArtistSearchBox.Text))
            {
                Console.WriteLine(ArtistSearchBox.Text + "null");
            }
            else
            {
                var Artistrequest = (HttpWebRequest)WebRequest.Create("https://musicbrainz.org/ws/2/artist/?query=" + ArtistName);
                Artistrequest.Method      = "GET";
                Artistrequest.UserAgent   = "DesktopApp1/1.1.1 ( [email protected] )";
                Artistrequest.Credentials = new NetworkCredential("sdvpl2011", "musicbrainz");
                var    Artistresponse = (HttpWebResponse)Artistrequest.GetResponse();
                string ArtistID       = "";
                string name           = "";

                XmlReader reader = XmlReader.Create(Artistresponse.GetResponseStream());
                while (reader.Read())
                {
                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "artist"))
                    {
                        ArtistID = reader.GetAttribute("id");
                        Console.WriteLine(value: ArtistID);
                        reader.ReadToDescendant("name");
                        name = reader.ReadElementContentAsString();
                        Console.WriteLine("Check Name = " + name);
                        if (name == ArtistName)
                        {
                            break;
                        }
                        //reader.Skip();
                        //reader.ReadToFollowing("name");
                        //break;
                        //.ReadElementContentAsString();
                        //XmlReader inner = reader.ReadSubtree();

                        //inner.ReadToDescendant("name");
                        //Console.WriteLine("Check Name = " + reader.ReadElementContentAsString());
                    }

                    //reader.ReadToFollowing("artist");
                }
                Artistresponse.Close();


                if (String.IsNullOrEmpty(ArtistID))
                {
                    Console.WriteLine("ArtistID is empty");
                    ListViewItem NoArtist;
                    string[]     row1 = { "Could not find Artist/Band, Try Again" };
                    NoArtist = new ListViewItem(row1);
                    ArtstAlbumSearchListView.Items.Add(NoArtist);

                    //AlbumSearch(ArtistID);
                }
                else
                {
                    Console.WriteLine("ArtisID is not empty");
                    AlbumSearch(ArtistID, name);
                }
            }

            this.ArtstAlbumSearchListView.ListViewItemSorter = new ListViewItemComparer(2);
            ArtstAlbumSearchListView.Sort();
            //listView1.Columns[2].Width = 0;
        }
示例#2
0
文件: Form1.cs 项目: sdvpl/SongList
 private void AlbumSort(object sender, System.Windows.Forms.ColumnClickEventArgs e)
 {
     this.ArtstAlbumSearchListView.ListViewItemSorter = new ListViewItemComparer(e.Column);
     ArtstAlbumSearchListView.Sort();
     string column_name = e.Column.ToString();
 }