/// <summary> /// Returns the zero-based index of the first occurrence of the specified /// <see cref="QueryResult"/> in the <see cref="QueryResultCollection"/>. /// </summary> /// <param name="value">The <see cref="QueryResult"/> object /// to locate in the <see cref="QueryResultCollection"/>. /// This argument can be a null reference. /// </param> /// <returns> /// The zero-based index of the first occurrence of <paramref name="value"/> /// in the <see cref="QueryResultCollection"/>, if found; otherwise, -1. /// </returns> /// <remarks>Please refer to <see cref="ArrayList.IndexOf"/> for details.</remarks> public virtual int IndexOf(QueryResult value) { return Array.IndexOf(this._array, value, 0, this._count); }
/// <overloads> /// Copies the <see cref="QueryResultCollection"/> or a portion of it to a one-dimensional array. /// </overloads> /// <summary> /// Copies the entire <see cref="QueryResultCollection"/> to a one-dimensional <see cref="Array"/> /// of <see cref="QueryResult"/> elements, starting at the beginning of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the /// <see cref="QueryResult"/> elements copied from the <see cref="QueryResultCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentException"> /// The number of elements in the source <see cref="QueryResultCollection"/> is greater /// than the available space in the destination <paramref name="array"/>.</exception> /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks> public virtual void CopyTo(QueryResult[] array) { CheckTargetArray(array, 0); Array.Copy(this._array, array, this._count); }
/// <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) { try { QueryResult result = new QueryResult(line, true); queryResultsColl.Add(result); } catch { } } 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; } }
/// <summary> /// Adds a <see cref="QueryResult"/> to the end of the <see cref="QueryResultCollection"/>. /// </summary> /// <param name="value">The <see cref="QueryResult"/> object /// to be added to the end of the <see cref="QueryResultCollection"/>. /// This argument can be a null reference. /// </param> /// <returns>The <see cref="QueryResultCollection"/> index at which the /// <paramref name="value"/> has been added.</returns> /// <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 the specified /// <paramref name="value"/>, and the <b>QueryResultCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.Add"/> for details.</remarks> public virtual int Add(QueryResult value) { if (this._count == this._array.Length) EnsureCapacity(this._count + 1); ++this._version; this._array[this._count] = value; return this._count++; }
/// <summary> /// Searches the entire sorted <see cref="QueryResultCollection"/> for an /// <see cref="QueryResult"/> element using the default comparer /// and returns the zero-based index of the element. /// </summary> /// <param name="value">The <see cref="QueryResult"/> object /// to locate in the <see cref="QueryResultCollection"/>. /// This argument can be a null reference. /// </param> /// <returns>The zero-based index of <paramref name="value"/> in the sorted /// <see cref="QueryResultCollection"/>, if <paramref name="value"/> is found; /// otherwise, a negative number, which is the bitwise complement of the index /// of the next element that is larger than <paramref name="value"/> or, if there /// is no larger element, the bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="InvalidOperationException"> /// Neither <paramref name="value"/> nor the elements of the <see cref="QueryResultCollection"/> /// implement the <see cref="IComparable"/> interface.</exception> /// <remarks>Please refer to <see cref="ArrayList.BinarySearch"/> for details.</remarks> public virtual int BinarySearch(QueryResult value) { return Array.BinarySearch(this._array, 0, this._count, value); }
public override void Remove(QueryResult value) { this._collection.Remove(value); }
private void CheckUnique(int index, QueryResult value) { int existing = IndexOf(value); if (existing >= 0 && existing != index) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); }
public override int Add(QueryResult value) { lock (this._root) return this._collection.Add(value); }
public override void AddRange(QueryResult[] array) { lock (this._root) this._collection.AddRange(array); }
public override void AddRange(QueryResult[] array) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
public override void Remove(QueryResult value) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
/// <summary> /// Copies the elements of the <see cref="QueryResultCollection"/> to a new /// <see cref="Array"/> of <see cref="QueryResult"/> elements. /// </summary> /// <returns>A one-dimensional <see cref="Array"/> of <see cref="QueryResult"/> /// elements containing copies of the elements of the <see cref="QueryResultCollection"/>.</returns> /// <remarks>Please refer to <see cref="ArrayList.ToArray"/> for details.</remarks> public virtual QueryResult[] ToArray() { QueryResult[] array = new QueryResult[this._count]; Array.Copy(this._array, array, this._count); return array; }
/// <summary> /// Removes the first occurrence of the specified <see cref="QueryResult"/> /// from the <see cref="QueryResultCollection"/>. /// </summary> /// <param name="value">The <see cref="QueryResult"/> object /// to remove from the <see cref="QueryResultCollection"/>. /// This argument can be a null reference. /// </param> /// <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></exception> /// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks> public virtual void Remove(QueryResult value) { int index = IndexOf(value); if (index >= 0) RemoveAt(index); }
/// <summary> /// Inserts a <see cref="QueryResult"/> element into the /// <see cref="QueryResultCollection"/> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="value"/> /// should be inserted.</param> /// <param name="value">The <see cref="QueryResult"/> object /// to insert into the <see cref="QueryResultCollection"/>. /// This argument can be a null reference. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para> /// <para><paramref name="index"/> is greater than <see cref="Count"/>.</para> /// </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 the specified /// <paramref name="value"/>, and the <b>QueryResultCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.Insert"/> for details.</remarks> public virtual void Insert(int index, QueryResult value) { if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (index > this._count) throw new ArgumentOutOfRangeException("index", index, "Argument cannot exceed Count."); if (this._count == this._array.Length) EnsureCapacity(this._count + 1); ++this._version; if (index < this._count) Array.Copy(this._array, index, this._array, index + 1, this._count - index); this._array[index] = value; ++this._count; }
public override int IndexOf(QueryResult value) { return this._collection.IndexOf(value); }
public override void Insert(int index, QueryResult value) { lock (this._root) this._collection.Insert(index, value); }
public override void Insert(int index, QueryResult value) { CheckUnique(value); this._collection.Insert(index, value); }
public override void Remove(QueryResult value) { lock (this._root) this._collection.Remove(value); }
private void CheckUnique(QueryResult value) { if (IndexOf(value) >= 0) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); }
public override int Add(QueryResult value) { CheckUnique(value); return this._collection.Add(value); }
/// <summary> /// Initializes a new instance of the <see cref="QueryResultCollection"/> class /// that contains elements copied from the specified <see cref="QueryResult"/> /// array and that has the same initial capacity as the number of elements copied. /// </summary> /// <param name="array">An <see cref="Array"/> of <see cref="QueryResult"/> /// elements that are copied to the new collection.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks> public QueryResultCollection(QueryResult[] array) { if (array == null) throw new ArgumentNullException("array"); this._array = new QueryResult[array.Length]; AddRange(array); }
public override void AddRange(QueryResult[] array) { foreach (QueryResult value in array) CheckUnique(value); this._collection.AddRange(array); }
/// <summary> /// Adds the elements of a <see cref="QueryResult"/> array /// to the end of the <see cref="QueryResultCollection"/>. /// </summary> /// <param name="array">An <see cref="Array"/> of <see cref="QueryResult"/> elements /// that should be added to the end of the <see cref="QueryResultCollection"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> 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="array"/>, 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(QueryResult[] array) { if (array == null) throw new ArgumentNullException("array"); if (array.Length == 0) return; if (this._count + array.Length > this._array.Length) EnsureCapacity(this._count + array.Length); ++this._version; Array.Copy(array, 0, this._array, this._count, array.Length); this._count += array.Length; }
public override int BinarySearch(QueryResult value) { return this._collection.BinarySearch(value); }
/// <summary> /// Determines whether the <see cref="QueryResultCollection"/> /// contains the specified <see cref="QueryResult"/> element. /// </summary> /// <param name="value">The <see cref="QueryResult"/> object /// to locate in the <see cref="QueryResultCollection"/>. /// This argument can be a null reference. /// </param> /// <returns><c>true</c> if <paramref name="value"/> is found in the /// <see cref="QueryResultCollection"/>; otherwise, <c>false</c>.</returns> /// <remarks>Please refer to <see cref="ArrayList.Contains"/> for details.</remarks> public bool Contains(QueryResult value) { return (IndexOf(value) >= 0); }
public override void CopyTo(QueryResult[] array) { this._collection.CopyTo(array); }
/// <summary> /// Copies the entire <see cref="QueryResultCollection"/> to a one-dimensional <see cref="Array"/> /// of <see cref="QueryResult"/> elements, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the /// <see cref="QueryResult"/> elements copied from the <see cref="QueryResultCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> /// at which copying begins.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="arrayIndex"/> is less than zero.</exception> /// <exception cref="ArgumentException"><para> /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>. /// </para><para>-or-</para><para> /// The number of elements in the source <see cref="QueryResultCollection"/> is greater than the /// available space from <paramref name="arrayIndex"/> to the end of the destination /// <paramref name="array"/>.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks> public virtual void CopyTo(QueryResult[] array, int arrayIndex) { CheckTargetArray(array, arrayIndex); Array.Copy(this._array, 0, array, arrayIndex, this._count); }
public override void CopyTo(QueryResult[] array, int arrayIndex) { this._collection.CopyTo(array, arrayIndex); }
/// <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) { Debug.Assert(qr != null); cdEntry = null; StringCollection coll = null; StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ); builder.Append("+"); builder.Append(qr.Genre); builder.Append("+"); builder.Append(qr.Discid); //make call try { coll = Call(builder.ToString()); } catch (Exception ex) { string msg = "Error performing cddb read."; Exception newex = new Exception(msg,ex); throw newex ; } // check if results came back if (coll.Count < 0) { string msg = "No results returned from cddb read."; Exception ex = new Exception(msg,null); throw ex; } string code = GetCode(coll[0]); if (code == ResponseCodes.CODE_INVALID) { string msg = "Unable to process results for cddb read. 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: // entry not found case ResponseCodes.CODE_402: // server error case ResponseCodes.CODE_403: // Database entry is corrupt case ResponseCodes.CODE_409: // No handshake return code; case ResponseCodes.CODE_210: // good { coll.RemoveAt(0); // remove the 210 cdEntry = new CDEntry(coll); return ResponseCodes.CODE_210; } default: return ResponseCodes.CODE_500; } }
private void BTNOkay_Click(object sender, System.EventArgs e) { if (this.LBQueryResults.SelectedIndex != -1) this._SelectedQueryResult = _Results[LBQueryResults.SelectedIndex]; else this._SelectedQueryResult = _Results[0]; this.DialogResult = DialogResult.OK; }