/// <summary> /// Retrieve all Freedb servers from the main server site /// </summary> /// <param name="sites">SiteCollection that is populated with the site information</param> /// <returns>Response Code</returns> public string GetSites(out SiteCollection sites) { return GetSites(Site.PROTOCOLS.ALL, out sites); }
/// <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; } }
/// <overloads> /// Adds a range of elements to the end of the <see cref="SiteCollection"/>. /// </overloads> /// <summary> /// Adds the elements of another collection to the end of the <see cref="SiteCollection"/>. /// </summary> /// <param name="collection">The <see cref="SiteCollection"/> 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="SiteCollection"/> is read-only.</para> /// <para>-or-</para> /// <para>The <b>SiteCollection</b> has a fixed size.</para> /// <para>-or-</para> /// <para>The <b>SiteCollection</b> already contains one or more elements /// in the specified <paramref name="collection"/>, and the <b>SiteCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks> public virtual void AddRange(SiteCollection 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; }
/// <summary> /// Creates a shallow copy of the <see cref="SiteCollection"/>. /// </summary> /// <returns>A shallow copy of the <see cref="SiteCollection"/>.</returns> /// <remarks>Please refer to <see cref="ArrayList.Clone"/> for details.</remarks> public virtual object Clone() { SiteCollection collection = new SiteCollection(this._count); Array.Copy(this._array, 0, collection._array, 0, this._count); collection._count = this._count; collection._version = this._version; return collection; }
/// <summary> /// Returns a synchronized (thread-safe) wrapper /// for the specified <see cref="SiteCollection"/>. /// </summary> /// <param name="collection">The <see cref="SiteCollection"/> 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 SiteCollection Synchronized(SiteCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); return new SyncList(collection); }
/// <summary> /// Returns a wrapper for the specified <see cref="SiteCollection"/> /// ensuring that all elements are unique. /// </summary> /// <param name="collection">The <see cref="SiteCollection"/> 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="SiteCollection"/> 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>SiteCollection</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 SiteCollection Unique(SiteCollection 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); }
/// <summary> /// Initializes a new instance of the <see cref="SiteCollection"/> 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="SiteCollection"/> /// 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 SiteCollection(SiteCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); this._array = new Site[collection.Count]; AddRange(collection); }
/// <summary> /// Returns a read-only wrapper for the specified <see cref="SiteCollection"/>. /// </summary> /// <param name="collection">The <see cref="SiteCollection"/> 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 SiteCollection ReadOnly(SiteCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); return new ReadOnlyList(collection); }
internal UniqueList(SiteCollection collection) : base(Tag.Default) { this._collection = collection; }
public override void AddRange(SiteCollection collection) { foreach (Site value in collection) CheckUnique(value); this._collection.AddRange(collection); }
public override void AddRange(SiteCollection collection) { lock (this._root) this._collection.AddRange(collection); }
internal SyncList(SiteCollection collection) : base(Tag.Default) { this._root = collection.SyncRoot; this._collection = collection; }
public override void AddRange(SiteCollection collection) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
internal ReadOnlyList(SiteCollection collection) : base(Tag.Default) { this._collection = collection; }
internal Enumerator(SiteCollection collection) { this._collection = collection; this._version = collection._version; this._index = -1; }