Пример #1
0
 public RiotAccount Get(string realm, RiotAccountPreference preference)
 {
     switch (preference)
     {
         case RiotAccountPreference.Active:
             {
                 if (this.Active == null)
                 {
                     return null;
                 }
                 if (this.Active.RealmId != realm)
                 {
                     return null;
                 }
                 return this.Active;
             }
         case RiotAccountPreference.Inactive:
         case RiotAccountPreference.LeastContention:
             {
                 IEnumerable<RiotAccount> active = this.accounts.Where<RiotAccount>((RiotAccount x) =>
                 {
                     if (x.RealmId != realm)
                     {
                         return false;
                     }
                     return x.State == ConnectionState.Connected;
                 });
                 if (preference == RiotAccountPreference.Inactive)
                 {
                     active =
                         from x in active
                         where x != this.Active
                         select x;
                 }
                 RiotAccount[] array = active.ToArray<RiotAccount>();
                 if ((int)array.Length <= 0)
                 {
                     return null;
                 }
                 return ((IEnumerable<RiotAccount>)array).MinBy<RiotAccount, int>((RiotAccount x) => x.PendingInvocations);
             }
         case RiotAccountPreference.InactivePreferred:
             {
                 return this.Get(realm, RiotAccountPreference.Inactive) ?? this.Get(realm, RiotAccountPreference.Active);
             }
     }
     throw new ArgumentOutOfRangeException("preference");
 }
 public RiotAccount Get(string realm, RiotAccountPreference preference)
 {
   switch (preference)
   {
     case RiotAccountPreference.Active:
       if (this.Active == null)
         return (RiotAccount) null;
       if (!(this.Active.RealmId == realm))
         return (RiotAccount) null;
       else
         return this.Active;
     case RiotAccountPreference.Inactive:
     case RiotAccountPreference.LeastContention:
       IEnumerable<RiotAccount> source = Enumerable.Where<RiotAccount>((IEnumerable<RiotAccount>) this.accounts, (Func<RiotAccount, bool>) (x =>
       {
         if (x.RealmId == realm)
           return x.State == ConnectionState.Connected;
         else
           return false;
       }));
       if (preference == RiotAccountPreference.Inactive)
         source = Enumerable.Where<RiotAccount>(source, (Func<RiotAccount, bool>) (x => x != this.Active));
       RiotAccount[] riotAccountArray = Enumerable.ToArray<RiotAccount>(source);
       if (riotAccountArray.Length <= 0)
         return (RiotAccount) null;
       else
         return MoreEnumerable.MinBy<RiotAccount, int>((IEnumerable<RiotAccount>) riotAccountArray, (Func<RiotAccount, int>) (x => x.PendingInvocations));
     case RiotAccountPreference.InactivePreferred:
       return this.Get(realm, RiotAccountPreference.Inactive) ?? this.Get(realm, RiotAccountPreference.Active);
     default:
       throw new ArgumentOutOfRangeException("preference");
   }
 }