/// <summary>
 /// Call the Freedb server using the specified command and the current site
 /// If the current site is null use the default server
 /// </summary>
 /// <param name="command">The command to be exectued</param>
 /// <returns>StringCollection</returns>
 private StringCollection Call(string command)
 {
     if (m_CurrentSite != null)
     {
         return(Call(command, m_CurrentSite.GetUrl()));
     }
     else
     {
         return(Call(command, m_mainSite.GetUrl()));
     }
 }
        /// <summary>
        /// Get the Freedb sites
        /// </summary>
        /// <param name="protocol"></param>
        /// <param name="sites">SiteCollection that is populated with the site information</param>
        /// <returns>Response Code</returns>
        ///
        public string GetSites(string protocol, out SiteCollection sites)
        {
            if (protocol != Site.PROTOCOLS.CDDBP && protocol != Site.PROTOCOLS.HTTP)
            {
                protocol = Site.PROTOCOLS.ALL;
            }

            StringCollection coll;

            try
            {
                coll = Call(Commands.CMD_SITES, m_mainSite.GetUrl());
            }

            catch (Exception ex)
            {
                Debug.WriteLine("Error retrieving Sites." + ex.Message);
                Exception newEx = new Exception("FreedbHelper.GetSites: Error retrieving Sites.", ex);
                throw newEx;
            }

            sites = null;

            // check if results came back
            if (coll.Count < 0)
            {
                string    msg = "No results returned from sites request.";
                Exception ex  = new Exception(msg, null);
                throw ex;
            }

            string code = GetCode(coll[0]);

            if (code == ResponseCodes.CODE_INVALID)
            {
                string    msg = "Unable to process results Sites Request. Returned Data: " + coll[0];
                Exception ex  = new Exception(msg, null);
                throw ex;
            }

            switch (code)
            {
            case ResponseCodes.CODE_500:
                return(ResponseCodes.CODE_500);

            case ResponseCodes.CODE_401:
                return(ResponseCodes.CODE_401);

            case ResponseCodes.CODE_210:
            {
                coll.RemoveAt(0);
                sites = new SiteCollection();
                foreach (String line in coll)
                {
                    Debug.WriteLine("line: " + line);
                    Site site = new Site(line);
                    if (protocol == Site.PROTOCOLS.ALL)
                    {
                        sites.Add(new Site(line));
                    }
                    else if (site.Protocol == protocol)
                    {
                        sites.Add(new Site(line));
                    }
                }

                return(ResponseCodes.CODE_210);
            }

            default:
                return(ResponseCodes.CODE_500);
            }
        }