Represents a metric value.
 /// <summary>
 /// Initializes a new instance of the PSMetricValue class.
 /// </summary>
 /// <param name="metricValue">The input MetricValue object</param>
 public PSMetricValue(MetricValue metricValue)
 {
     this.Average = metricValue.Average;
     this.Count = metricValue.Count;
     this.Last = metricValue.Last;
     this.Maximum = metricValue.Maximum;
     this.Minimum = metricValue.Minimum;
     this.Properties = new PSDictionaryElement(metricValue.Properties);
     this.Timestamp = metricValue.Timestamp;
     this.Total = metricValue.Total;
 }
        private static MetricValue GetConvertedMetric(MetricValueBlob m)
        {
            // If count is not supplied, we assume 1, so the total / average relation works.
            var metricValue = new MetricValue
            {
                Count = m.count == 0 ? 1 : m.count,
                Maximum = m.maximum,
                Minimum = m.minimum,
                Timestamp = m.time,
            };

            // In case the RP doesn't populate average, we calculate average from total / count.
            if (m.average == 0 && m.total != 0)
            {
                metricValue.Average = m.total / metricValue.Count;
            }
            else
            {
                metricValue.Average = m.average;
            }

            // In case the RP doesn't populate total, we calculate total from the average * count.
            if (m.total == 0 && m.average != 0)
            {
                metricValue.Total = m.average * metricValue.Count;
            }
            else
            {
                metricValue.Total = m.total;
            }

            return metricValue;
        }
        private static void Aggregate(MetricValue lastSeen, MetricValueBlob m)
        {
            // If count is not supplied, we assume 1, so the total / average relation works.
            lastSeen.Count += m.count == 0 ? 1 : m.count;

            // In case the RP doesn't populate total, we calculate total from the average * count.
            if (m.total == 0 && m.average != 0)
            {
                lastSeen.Total += m.average * lastSeen.Count;
            }
            else
            {
                lastSeen.Total += m.total;
            }

            if (m.maximum > lastSeen.Maximum)
            {
                lastSeen.Maximum = m.maximum;
            }

            if (m.minimum < lastSeen.Minimum)
            {
                lastSeen.Minimum = m.minimum;
            }
        }