コード例 #1
0
		/// <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 QueryResultCollection queryResultsColl)
		{
			queryResult = null;
			queryResultsColl = null;
			StringCollection coll = null;

			StringBuilder builder = new StringBuilder(FreeDBHelper.Commands.CMD_QUERY);
			builder.Append("+");
			builder.Append(querystring);

			//make call
			try
			{
				coll = Call(builder.ToString());
			}

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

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

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


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

				// Multiple results were returned
				// Put them into a queryResultCollection object
				case ResponseCodes.CODE_211:
				case ResponseCodes.CODE_210:
					{
						queryResultsColl = new QueryResultCollection();
						//remove the 210 or 211
						coll.RemoveAt(0);
						foreach (string line in coll)
						{
							QueryResult result = new QueryResult(line, true);
							queryResultsColl.Add(result);
						}

						return ResponseCodes.CODE_211;
					}


				// exact match 
				case ResponseCodes.CODE_200:
					{
						queryResult = new QueryResult(coll[0]);
						return ResponseCodes.CODE_200;
					}


				//not found
				case ResponseCodes.CODE_202:
					return ResponseCodes.CODE_202;

				//Database entry is corrupt
				case ResponseCodes.CODE_403:
					return ResponseCodes.CODE_403;

				//no handshake
				case ResponseCodes.CODE_409:
					return ResponseCodes.CODE_409;

				default:
					return ResponseCodes.CODE_500;

			} // end of switch


		}
コード例 #2
0
		/// <overloads>
		/// Adds a range of elements to the end of the <see cref="QueryResultCollection"/>.
		/// </overloads>
		/// <summary>
		/// Adds the elements of another collection to the end of the <see cref="QueryResultCollection"/>.
		/// </summary>
		/// <param name="collection">The <see cref="QueryResultCollection"/> whose elements
		/// should be added to the end of the current collection.</param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="QueryResultCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>QueryResultCollection</b> has a fixed size.</para>
		/// <para>-or-</para>
		/// <para>The <b>QueryResultCollection</b> already contains one or more elements
		/// in the specified <paramref name="collection"/>, and the <b>QueryResultCollection</b>
		/// ensures that all elements are unique.</para></exception>
		/// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks>

		public virtual void AddRange(QueryResultCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			if (collection.Count == 0) return;
			if (this._count + collection.Count > this._array.Length)
				EnsureCapacity(this._count + collection.Count);

			++this._version;
			Array.Copy(collection.InnerArray, 0,
				this._array, this._count, collection.Count);
			this._count += collection.Count;
		}
コード例 #3
0
		/// <summary>
		/// Creates a shallow copy of the <see cref="QueryResultCollection"/>.
		/// </summary>
		/// <returns>A shallow copy of the <see cref="QueryResultCollection"/>.</returns>
		/// <remarks>Please refer to <see cref="ArrayList.Clone"/> for details.</remarks>

		public virtual object Clone()
		{
			QueryResultCollection collection = new QueryResultCollection(this._count);

			Array.Copy(this._array, 0, collection._array, 0, this._count);
			collection._count = this._count;
			collection._version = this._version;

			return collection;
		}
コード例 #4
0
			public override void AddRange(QueryResultCollection collection)
			{
				foreach (QueryResult value in collection)
					CheckUnique(value);

				this._collection.AddRange(collection);
			}
コード例 #5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="QueryResultCollection"/> class
		/// that contains elements copied from the specified collection and
		/// that has the same initial capacity as the number of elements copied.
		/// </summary>
		/// <param name="collection">The <see cref="QueryResultCollection"/>
		/// whose elements are copied to the new collection.</param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>
		/// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks>

		public QueryResultCollection(QueryResultCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			this._array = new QueryResult[collection.Count];
			AddRange(collection);
		}
コード例 #6
0
			public override void AddRange(QueryResultCollection collection)
			{
				lock (this._root) this._collection.AddRange(collection);
			}
コード例 #7
0
			internal UniqueList(QueryResultCollection collection)
				:
				base(Tag.Default)
			{
				this._collection = collection;
			}
コード例 #8
0
			public override void AddRange(QueryResultCollection collection)
			{
				throw new NotSupportedException(
					"Read-only collections cannot be modified.");
			}
コード例 #9
0
			internal SyncList(QueryResultCollection collection)
				:
				base(Tag.Default)
			{

				this._root = collection.SyncRoot;
				this._collection = collection;
			}
コード例 #10
0
			internal ReadOnlyList(QueryResultCollection collection)
				:
				base(Tag.Default)
			{
				this._collection = collection;
			}
コード例 #11
0
			internal Enumerator(QueryResultCollection collection)
			{
				this._collection = collection;
				this._version = collection._version;
				this._index = -1;
			}
コード例 #12
0
		/// <summary>
		/// Returns a wrapper for the specified <see cref="QueryResultCollection"/>
		/// ensuring that all elements are unique.
		/// </summary>
		/// <param name="collection">The <see cref="QueryResultCollection"/> to wrap.</param>    
		/// <returns>
		/// A wrapper around <paramref name="collection"/> ensuring that all elements are unique.
		/// </returns>
		/// <exception cref="ArgumentException">
		/// <paramref name="collection"/> contains duplicate elements.</exception>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>
		/// <remarks><para>
		/// The <b>Unique</b> wrapper provides a set-like collection by ensuring
		/// that all elements in the <see cref="QueryResultCollection"/> are unique.
		/// </para><para>
		/// <b>Unique</b> raises an <see cref="ArgumentException"/> if the specified 
		/// <paramref name="collection"/> contains any duplicate elements. The returned
		/// wrapper raises a <see cref="NotSupportedException"/> whenever the user attempts 
		/// to add an element that is already contained in the <b>QueryResultCollection</b>.
		/// </para><para>
		/// <strong>Note:</strong> The <b>Unique</b> wrapper reflects any changes made
		/// to the underlying <paramref name="collection"/>, including the possible
		/// creation of duplicate elements. The uniqueness of all elements is therefore
		/// no longer assured if the underlying collection is manipulated directly.
		/// </para></remarks>

		public static QueryResultCollection Unique(QueryResultCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			for (int i = collection.Count - 1; i > 0; i--)
				if (collection.IndexOf(collection[i]) < i)
					throw new ArgumentException("collection",
						"Argument cannot contain duplicate elements.");

			return new UniqueList(collection);
		}
コード例 #13
0
		/// <summary>
		/// Returns a synchronized (thread-safe) wrapper
		/// for the specified <see cref="QueryResultCollection"/>.
		/// </summary>
		/// <param name="collection">The <see cref="QueryResultCollection"/> to synchronize.</param>
		/// <returns>
		/// A synchronized (thread-safe) wrapper around <paramref name="collection"/>.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>
		/// <remarks>Please refer to <see cref="ArrayList.Synchronized"/> for details.</remarks>

		public static QueryResultCollection Synchronized(QueryResultCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			return new SyncList(collection);
		}
コード例 #14
0
		/// <summary>
		/// Returns a read-only wrapper for the specified <see cref="QueryResultCollection"/>.
		/// </summary>
		/// <param name="collection">The <see cref="QueryResultCollection"/> to wrap.</param>
		/// <returns>A read-only wrapper around <paramref name="collection"/>.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>
		/// <remarks>Please refer to <see cref="ArrayList.ReadOnly"/> for details.</remarks>

		public static QueryResultCollection ReadOnly(QueryResultCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			return new ReadOnlyList(collection);
		}