Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
 /// <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();
 }
Ejemplo n.º 3
0
 /// <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;
 }