Example #1
0
        /// <summary>
        /// Returns true if AverageMetrics instances are equal
        /// </summary>
        /// <param name="other">Instance of AverageMetrics to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(AverageMetrics other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Unauthenticated == other.Unauthenticated ||
                     Unauthenticated != null &&
                     Unauthenticated.Equals(other.Unauthenticated)
                     ) &&
                 (
                     HighPriority == other.HighPriority ||
                     HighPriority != null &&
                     HighPriority.Equals(other.HighPriority)
                 ) &&
                 (
                     MediumPriority == other.MediumPriority ||
                     MediumPriority != null &&
                     MediumPriority.Equals(other.MediumPriority)
                 ) &&
                 (
                     Unattended == other.Unattended ||
                     Unattended != null &&
                     Unattended.Equals(other.Unattended)
                 ));
        }
Example #2
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Unauthenticated != null)
         {
             hashCode = hashCode * 59 + Unauthenticated.GetHashCode();
         }
         if (HighPriority != null)
         {
             hashCode = hashCode * 59 + HighPriority.GetHashCode();
         }
         if (MediumPriority != null)
         {
             hashCode = hashCode * 59 + MediumPriority.GetHashCode();
         }
         if (Unattended != null)
         {
             hashCode = hashCode * 59 + Unattended.GetHashCode();
         }
         return(hashCode);
     }
 }
 public void CopyTo(T[] array, int index)
 {
     // unsafe:
     // nonatomic, one of these could fail but not the other
     // if HighPriority changes after CopyTo before we call Count we could have problems
     HighPriority.CopyTo(array, index);
     LowPriority.CopyTo(array, index + HighPriority.Count);
 }
            public void Handle(HighPriority <UpdateMessage> message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                Handle(message.Value);
            }
            public bool TryTake(out T item)
            {
                // worst-case, which I'm not worried about for this use case:
                // we add to highPrio after tryDequeue
                // for our purposes (rate limiting) it doesn't really matter

                if (HighPriority.TryDequeue(out item))
                {
                    return(true);
                }

                return(LowPriority.TryDequeue(out item));
            }
 private void OnHighPriority(object sender, CancelableEventArgs e)
 {
     HighPriority?.Invoke(sender, e);
 }
 public void AddHigh(T item) => HighPriority.Enqueue(item);
 // potentially unsafe
 public IEnumerator <T> GetEnumerator() => HighPriority.Concat(LowPriority).GetEnumerator();