public override void CalculateValue(double value, DateTime timestamp)
        {
            GaugeDuration aggregateDuration = base.aggregateDuration;

            if (aggregateDuration.IsEmpty || ((IValueConsumer)this).GetProvider() == null)
            {
                base.CalculateValue(value, timestamp);
            }
            else
            {
                base.noMoreData = false;
                HistoryCollection data  = ((IValueConsumer)this).GetProvider().GetData(aggregateDuration, timestamp);
                HistoryEntry[]    array = data.Select(aggregateDuration, timestamp);
                double            num   = value;
                bool           flag     = false;
                HistoryEntry[] array2   = array;
                foreach (HistoryEntry historyEntry in array2)
                {
                    if (!double.IsNaN(historyEntry.Value))
                    {
                        num  = Math.Max(historyEntry.Value, num);
                        flag = true;
                    }
                }
                if (!flag)
                {
                    num             = ((data.Count <= 0) ? double.NaN : data.Top.Value);
                    base.noMoreData = true;
                }
                base.CalculateValue(num, timestamp);
            }
        }
 public void LoadEntries(HistoryCollection sourceHistory)
 {
     if (sourceHistory == null)
     {
         throw new ApplicationException(Utils.SRGetStr("ExceptionHistoryCannotNull"));
     }
     if (this.parent != null)
     {
         this.parent.IntState = ValueState.DataLoading;
         this.parent.Reset();
         foreach (HistoryEntry item in sourceHistory)
         {
             this.parent.SetValueInternal(item.Value, item.Timestamp);
         }
         this.parent.IntState = ValueState.Interactive;
         this.parent.Invalidate();
     }
     else
     {
         foreach (HistoryEntry item2 in sourceHistory)
         {
             base.InnerList.Add(item2.Clone());
         }
     }
 }
        public object Clone()
        {
            HistoryCollection historyCollection = new HistoryCollection(this.parent);

            foreach (HistoryEntry item in this)
            {
                historyCollection.InnerList.Add(item.Clone());
            }
            return(historyCollection);
        }
        public override void CalculateValue(double value, DateTime timestamp)
        {
            GaugeDuration aggregateDuration = base.aggregateDuration;

            if (aggregateDuration.IsEmpty)
            {
                base.CalculateValue(value, timestamp);
            }
            else
            {
                base.noMoreData = false;
                double num = value;
                if (((IValueConsumer)this).GetProvider() != null)
                {
                    HistoryCollection data  = ((IValueConsumer)this).GetProvider().GetData(aggregateDuration, timestamp);
                    HistoryEntry[]    array = data.Select(aggregateDuration, timestamp);
                    if (array.Length > 1)
                    {
                        num = 0.0;
                        long num2 = 0L;
                        long num3 = 0L;
                        for (int i = 0; i < array.Length - 1; i++)
                        {
                            num2 = array[i + 1].Timestamp.Ticks - array[i].Timestamp.Ticks;
                            if (num2 == 0)
                            {
                                num += (array[i + 1].Value - array[i].Value) / 2.0;
                            }
                            else
                            {
                                num  += array[i + 1].Value * (double)num2;
                                num3 += num2;
                            }
                        }
                        if (num3 > 0)
                        {
                            num /= (double)num3;
                        }
                    }
                    else if (array.Length > 0)
                    {
                        num = array[0].Value;
                    }
                    else
                    {
                        base.noMoreData = true;
                    }
                }
                base.CalculateValue(num, timestamp);
            }
        }
예제 #5
0
 private void RegenerateIntegralResult()
 {
     if (((IValueConsumer)this).GetProvider() is ValueBase)
     {
         TimeSpan          timeSpan  = this.interval.ToTimeSpan();
         ValueBase         valueBase = (ValueBase)((IValueConsumer)this).GetProvider();
         HistoryCollection history   = valueBase.History;
         this.integralResult = history.AccumulatedValue / (double)timeSpan.Ticks;
         int num = history.Locate(valueBase.Date);
         for (int i = 1; i < num; i++)
         {
             this.integralResult    += history[i].Value * (double)(history[i].Timestamp.Ticks - history[i - 1].Timestamp.Ticks) / (double)timeSpan.Ticks;
             this.oldValue.Timestamp = history[i].Timestamp;
             this.oldValue.Value     = history[i].Value;
         }
     }
 }
예제 #6
0
 public ValueBase()
 {
     this.history = new HistoryCollection(this);
 }
예제 #7
0
        public void DataBind(object dataSource, string valueFieldName, string dateFieldName, string dataMember)
        {
            if (this.IntState != ValueState.Interactive)
            {
                throw new ApplicationException(Utils.SRGetStr("ExceptionDatabindState"));
            }
            bool          flag                    = default(bool);
            IDbConnection dbConnection            = default(IDbConnection);
            object        dataSourceAsIEnumerable = this.GetDataSourceAsIEnumerable(dataSource, dataMember, out flag, out dbConnection);

            try
            {
                if (dataSource != null && !(valueFieldName == string.Empty))
                {
                    object            obj  = null;
                    object            obj2 = null;
                    double            num  = 0.0;
                    DateTime          now  = DateTime.Now;
                    HistoryCollection historyCollection = new HistoryCollection(this);
                    try
                    {
                        this.IntState = ValueState.DataLoading;
                        this.Reset();
                        foreach (object item in (IEnumerable)dataSourceAsIEnumerable)
                        {
                            obj = this.ConvertEnumerationItem(item, valueFieldName);
                            if (dateFieldName != string.Empty)
                            {
                                obj2 = this.ConvertEnumerationItem(item, dateFieldName);
                                if (obj != null && obj2 != null && obj2 != Convert.DBNull)
                                {
                                    num = ((obj != Convert.DBNull) ? Convert.ToDouble(obj, CultureInfo.InvariantCulture) : double.NaN);
                                    DateTime timestamp = Convert.ToDateTime(obj2, CultureInfo.InvariantCulture);
                                    historyCollection.Add(timestamp, num);
                                }
                            }
                            else if (obj != null)
                            {
                                num = ((obj != Convert.DBNull) ? Convert.ToDouble(obj, CultureInfo.InvariantCulture) : double.NaN);
                                historyCollection.Add(now, num);
                            }
                        }
                        foreach (HistoryEntry item2 in historyCollection)
                        {
                            this.SetValueInternal(item2.Value, item2.Timestamp);
                        }
                    }
                    finally
                    {
                        this.IntState = ValueState.Interactive;
                        historyCollection.Clear();
                    }
                    this.Invalidate();
                    goto end_IL_002d;
                }
                throw new ArgumentException(Utils.SRGetStr("ExceptionBadDatasource_fields"));
                end_IL_002d :;
            }
            finally
            {
                if (flag)
                {
                    ((IDataReader)dataSourceAsIEnumerable).Close();
                }
                if (dbConnection != null)
                {
                    dbConnection.Close();
                }
            }
            if (this.Common != null)
            {
                this.Common.GaugeCore.boundToDataSource = true;
            }
        }