コード例 #1
0
ファイル: FreedbHelper.cs プロジェクト: rraguso/protone-suite
		/// <summary>
		/// Query the freedb server to see if there is information on this cd
		/// </summary>
		/// <param name="querystring"></param>
		/// <param name="queryResult"></param>
		/// <param name="queryResultsColl"></param>
		/// <returns></returns>
		public string Query(string querystring, out QueryResult queryResult, out List<QueryResult> queryResultsColl)
		{
            StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_QUERY);
            builder.Append(" ");
            builder.Append(querystring);

            queryResult = null;
            queryResultsColl = null;
           
			//make call
			try
			{
                string request = builder.ToString();
                List<string> reply = SendRequest(request);

                if (reply.Count <= 0)
                {
                    string msg = "No results returned from cddb query.";
                    Exception ex = new Exception(msg, null);
                    throw ex;
                }

                string code = GetReplyCode(reply, request);
                switch (code)
                {
                    case ResponseCodes.CODE_200:
                        queryResult = new QueryResult(reply[0]);
                        break;

                    case ResponseCodes.CODE_210:
                    case ResponseCodes.CODE_211:
                        {
                            queryResultsColl = new List<QueryResult>();
                            //remove first line, this one has code 210 or 211
                            reply.RemoveAt(0);
                            foreach (string line in reply)
                            {
                                if (line.StartsWith(Commands.CMD_TERMINATOR))
                                    break;

                                QueryResult result = new QueryResult(line, true);
                                queryResultsColl.Add(result);
                            }
                        }
                        break;
                }

                return code;
			}
			catch (Exception ex)
			{
				string msg = "Unable to perform cddb query.";
				Exception newex = new Exception(msg,ex);
				throw newex ;
			}
		}
コード例 #2
0
ファイル: FreedbHelper.cs プロジェクト: rraguso/protone-suite
		/// <summary>
		/// Read Entry from the database. 
		/// </summary>
		/// <param name="qr">A QueryResult object that is created by performing a query</param>
		/// <param name="cdEntry">out parameter - CDEntry object</param>
		/// <returns></returns>
		public string Read(QueryResult qr, out CDEntry cdEntry)
		{
            StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ);
            builder.Append(" ");
            builder.Append(qr.Category);
            builder.Append(" ");
            builder.Append(qr.Discid);

            cdEntry = null;

            try
            {
                string request = builder.ToString();
                List<string> reply = SendRequest(request);

                if (reply.Count <= 0)
                {
                    string msg = "No results returned from cddb query.";
                    Exception ex = new Exception(msg, null);
                    throw ex;
                }

                string code = GetReplyCode(reply, request);
                
                switch (code)
                {
                    case ResponseCodes.CODE_210:
                    case ResponseCodes.CODE_211:
                        {
                            //remove first line, this one has code 210 or 211
                            reply.RemoveAt(0);
                            cdEntry = new CDEntry(reply);
                        }
                        break;
                }

                return code;
            }
            catch (Exception ex)
            {
                string msg = "Unable to perform cddb query.";
                Exception newex = new Exception(msg, ex);
                throw newex;
            }
		}