/// <summary>
 /// Searches for the specified value and returns the zero-based index of the first occurrence
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public int IndexOf(IMetricValue item)
 {
     lock (m_Lock)
     {
         return(m_ValueList.IndexOfKey(item));
     }
 }
 /// <summary>
 /// Determines whether an element is in the collection.
 /// </summary>
 /// <remarks>This method determines equality using the default equality comparer for the type of values in the list.  It performs
 /// a linear search and therefore is an O(n) operation.</remarks>
 /// <param name="item">The object to locate in the collection.</param>
 /// <returns>true if the item is found in the collection; otherwise false.</returns>
 public bool Contains(IMetricValue item)
 {
     lock (m_Lock)
     {
         //here we are relying on the fact that the MetricValue object implements IComparable sufficiently to guarantee uniqueness
         return(m_ValueList.ContainsKey(item));
     }
 }
Beispiel #3
0
 public bool IsSame(IMetricValue obj)
 {
     if (obj is NativeObjectMetric)
     {
         var o = (NativeObjectMetric)obj;
         return(o.m_ObjectIndex == m_ObjectIndex);
     }
     return(false);
 }
Beispiel #4
0
 public bool IsSame(IMetricValue obj)
 {
     if (obj is ManagedObjectMetric)
     {
         var o = (ManagedObjectMetric)obj;
         return(o.m_Object == m_Object);
     }
     return(false);
 }
        /// <summary>
        /// Determines if the provided MetricValue object is identical to this object.
        /// </summary>
        /// <param name="other">The MetricValue object to compare this object to.</param>
        /// <returns>True if the Metric Value objects represent the same data.</returns>
        public bool Equals(IMetricValue other)
        {
            // Careful, it could be null; check it without recursion
            if (object.ReferenceEquals(other, null))
            {
                return(false); // Since we're a live object we can't be equal to a null instance.
            }

            //they are equal if they have the same sequence and value
            return((Value == other.Value) && (Sequence == other.Sequence));
        }
        /// <summary>
        /// Adds the supplied MetricValue item to this collection.
        /// </summary>
        /// <remarks>The MetricValue item must refer to this metric value set, and have a unique timestamp.</remarks>
        /// <param name="item">The new MetricValue item to add.</param>
        public void Add(IMetricValue item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item), "No metric value item was provided to add to the collection");
            }

            if (item.ValueCollection != this)
            {
                throw new ArgumentException("The provided metric value item was not created for this metric value set.", nameof(item));
            }

            lock (m_Lock)
            {
                //OK, now add it to our sorted list.
                m_ValueList.Add(item, item);

                MetricValue nativeValue = (MetricValue)item;

                //since we were successful, now compare it with our min & max values, etc. to make sure that they are up to date.
                if (m_MinValueMetricValue == null)
                {
                    //we are automatically the new minimum value
                    m_MinValueMetricValue = nativeValue;
                }
                else if (m_MinValueMetricValue.Value > nativeValue.Value)
                {
                    //we are less than the previous minimum value, making us the new minimum value
                    m_MinValueMetricValue = nativeValue;
                }

                if (m_MaxValueMetricValue == null)
                {
                    //we are automatically the new maximum value
                    m_MaxValueMetricValue = nativeValue;
                }
                else if (m_MaxValueMetricValue.Value < nativeValue.Value)
                {
                    //we are greater than the old maximum value, making us the new maximum value
                    m_MaxValueMetricValue = nativeValue;
                }

                //to avoid overflow we have to calculate our average incrementally, otherwise it could go bad....
                m_AverageValue = ((nativeValue.Value - m_AverageValue) / (m_ValueList.Count)) + m_AverageValue;

                m_StatsCurrent = false; //even if they were, they aren't now.
            }
        }
Beispiel #7
0
        public void AddMetric(IMetricValue metric)
        {
            var groupName = metric.GetGroupName();

            if (!_groups.ContainsKey(groupName))
            {
                Group newGroup = new Group();
                newGroup._name  = groupName;
                newGroup._items = new List <Item>();
                _groups.Add(groupName, newGroup);
            }
            Item item = new Item(metric, _groups[groupName]);

            _items.Add(item);
            _groups[groupName]._items.Add(item);
        }
Beispiel #8
0
 public Item(IMetricValue metric, Group group)
 {
     _metric = metric;
     _group  = group;
 }
 /// <summary>
 /// Removing objects is not supported.
 /// </summary>
 /// <remarks>This method is implemented only for ICollection interface support and will throw an exception if called.</remarks>
 /// <param name="item">The MetricValue item to remove.</param>
 public bool Remove(IMetricValue item)
 {
     throw new NotSupportedException();
 }
 /// <summary>
 /// Not Supported.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="item"></param>
 public void Insert(int index, IMetricValue item)
 {
     //we don't support setting an object by index; we are sorted.
     throw new NotSupportedException();
 }
 /// <summary>
 /// Compare this metric value to another for the purpose of sorting them in time.
 /// </summary>
 /// <remarks>MetricValue instances are sorted by their Sequence number property.</remarks>
 /// <param name="other">The MetricValue object to compare this object to.</param>
 /// <returns>An int which is less than zero, equal to zero, or greater than zero to reflect whether
 /// this MetricValue should sort as being less-than, equal to, or greater-than the other
 /// MetricValue, respectively.</returns>
 public int CompareTo(IMetricValue other)
 {
     //we are all about the sequence number baby!
     return(m_Sequence.CompareTo(other.Sequence));
 }
Beispiel #12
0
 public CloudWatchMetric(string name, IMetricValue metric, params IMetricDimension[] dimensions)
 {
     Dimensions = dimensions ?? throw new System.ArgumentNullException(nameof(dimensions));
     Name       = name ?? throw new System.ArgumentNullException(nameof(name));
     Metric     = metric ?? throw new System.ArgumentNullException(nameof(metric));
 }
Beispiel #13
0
 public string GetGroupName(IMetricValue thing)
 {
     return("MissingGroupName");
 }
Beispiel #14
0
        public bool HasMetric(IMetricValue metric)
        {
            var i = _items.FindIndex(x => x._metric == metric);

            return(i >= 0);
        }
Beispiel #15
0
        public void SelectThing(IMetricValue thing)
        {
            var item = _items.First(i => i._metric == thing);

            SelectItem(item);
        }