/// <summary> /// Gets the list of mirrors from TvDb, supporting the specified type. /// </summary> /// <param name="type">The type the mirror should support.</param> /// <returns>a collection of TvDbMirror objects.</returns> public virtual IEnumerable<TvDbMirror> GetMirrors(TvDbMirrorType type) { var mirrors = GetMirrors(); mirrors = mirrors.Where(x => x.Type.HasFlag(type)).ToList(); return mirrors; }
/// <summary> /// Gets a random mirror from the mirrors list, supporting the specified type. /// </summary> /// <param name="type">The type the mirror should support.</param> /// <returns>a TvDbMirror object.</returns> public virtual TvDbMirror GetRandomMirror(TvDbMirrorType type) { var mirrors = GetMirrors(type).ToList(); if (mirrors.Count > 1) { Random rnd = new Random(); int index = rnd.Next(0, mirrors.Count - 1); return mirrors[index]; } else return mirrors.FirstOrDefault(); }
/// <summary> /// Gets a mirror that supports the specified type. /// </summary> /// <param name="type">The type the mirror should support.</param> /// <returns>the value of the Mirror property, if not null and supporting the specified type, otherwise a random mirror from the mirrors list.</returns> public virtual TvDbMirror GetMirror(TvDbMirrorType type) { TvDbMirror mirror = this.Mirror; if (mirror == null || !mirror.Type.HasFlag(type)) mirror = GetRandomMirror(type); if (mirror == null) throw new InvalidOperationException("No mirrors could be found supporting the specific mirror type."); return mirror; }