Esempio n. 1
0
        /// <summary>
        /// For pruning to work properly and efficiently, it is assumed that you are adding items in order of oldest to newest.<para />
        /// Use a minutesToRetain greater than 0 to trim older SnapShots.
        /// </summary>
        public void AddSnapShot(DateTime timeStamp, int value, int minutesToRetain = 0)
        {
            for (int i = 0; i < SnapShots.Count; i++)
            {
                if (SnapShots[i].TimeStamp == timeStamp)
                {
                    SnapShots[i] = new SnapShot <int>(timeStamp, SnapShots[i].Value + value);
                    return;
                }
            }

            SnapShots.Add(new SnapShot <int>(timeStamp, value));

            if (minutesToRetain > 0)
            {
                for (int i = 0; i < SnapShots.Count; i++)
                {
                    if (DateTime.UtcNow - SnapShots[i].TimeStamp <= TimeSpan.FromMinutes(minutesToRetain))
                    {
                        break;
                    }

                    SnapShots.RemoveAt(i);
                    i--;
                }
            }
        }
Esempio n. 2
0
 public void Add(SnapShotEntry entry)
 {
     SnapShots.Add(entry);
     this.Write(this.Filename);
 }