예제 #1
0
    public CDInfo[] GetDiscInfoByID(string ID)
    {
      CDInfo[] retval = null;
      string command = "cddb+query+" + ID.Replace(" ", "+");
      using (StreamReader urlRdr = GetStreamFromSite(command))
      {
        m_message = urlRdr.ReadLine();

        int code = GetCode(m_message);
        m_message = m_message.Substring(4); // remove the code...

        char[] sep = {' '};
        string title = "";
        int index = 0;
        string[] match;
        string[] matches;

        switch (code)
        {
          case 200: // Exact Match...
            match = m_message.Split(sep);
            retval = new CDInfo[1];

            retval[0] = new CDInfo();
            retval[0].Category = match[0];
            retval[0].DiscId = match[1];
            for (int i = 2; i < match.Length; i++)
            {
              title += match[i] + " ";
            }
            retval[0].Title = title.Trim();
            break;
          case 202: // no match found
            break;
          case 211: // Found Inexact Matches. List Follows.
          case 210: // Found Exact Matches. List Follows.
            matches = ParseMultiLine(urlRdr);
            retval = new CDInfo[matches.Length];
            foreach (string line in matches)
            {
              match = line.Split(sep);

              retval[index] = new CDInfo();
              retval[index].Category = match[0];
              retval[index].DiscId = match[1];
              for (int i = 2; i < match.Length; i++)
              {
                title += match[i] + " ";
              }
              retval[index].Title = title.Trim();
              index++;
            }
            break;
          case 403: // Database Entry is Corrupt.
            retval = null;
            break;
          case 409: // No handshake... Should not happen!
            retval = null;
            break;
          default:
            retval = null;
            break;
        }
      }
      return retval;
    }
        public CDInfo[] GetDiscInfoByID(string ID)
        {
            CDInfo[] retval  = null;
            string   command = "cddb+query+" + ID.Replace(" ", "+");

            using (StreamReader urlRdr = GetStreamFromSite(command))
            {
                m_message = urlRdr.ReadLine();

                int code = GetCode(m_message);
                m_message = m_message.Substring(4); // remove the code...

                char[]   sep   = { ' ' };
                string   title = "";
                int      index = 0;
                string[] match;
                string[] matches;

                switch (code)
                {
                case 200: // Exact Match...
                    match  = m_message.Split(sep);
                    retval = new CDInfo[1];

                    retval[0]          = new CDInfo();
                    retval[0].Category = match[0];
                    retval[0].DiscId   = match[1];
                    for (int i = 2; i < match.Length; i++)
                    {
                        title += match[i] + " ";
                    }
                    retval[0].Title = title.Trim();
                    break;

                case 202: // no match found
                    break;

                case 211: // Found Inexact Matches. List Follows.
                case 210: // Found Exact Matches. List Follows.
                    matches = ParseMultiLine(urlRdr);
                    retval  = new CDInfo[matches.Length];
                    foreach (string line in matches)
                    {
                        match = line.Split(sep);

                        retval[index]          = new CDInfo();
                        retval[index].Category = match[0];
                        retval[index].DiscId   = match[1];
                        for (int i = 2; i < match.Length; i++)
                        {
                            title += match[i] + " ";
                        }
                        retval[index].Title = title.Trim();
                        index++;
                    }
                    break;

                case 403: // Database Entry is Corrupt.
                    retval = null;
                    break;

                case 409: // No handshake... Should not happen!
                    retval = null;
                    break;

                default:
                    retval = null;
                    break;
                }
            }
            return(retval);
        }