コード例 #1
0
 protected SlidingWindow(TimeSpan slidingWindowLength, TimeSpan bucketLength, Func <DateTime> currentTimeProvider)
 {
     SlidingWindow.ValidateSlidingWindowAndBucketLength(slidingWindowLength, bucketLength);
     ExAssert.RetailAssert(currentTimeProvider != null, "Current time provider should not be null.");
     this.BucketLength        = bucketLength;
     this.currentTimeProvider = currentTimeProvider;
     this.creationTime        = this.currentTimeProvider();
     this.NumberOfBuckets     = (int)(slidingWindowLength.Ticks / this.BucketLength.Ticks);
     this.filled = new bool[this.NumberOfBuckets];
 }
コード例 #2
0
 internal SegmentedSlidingCounter(TimeSpan[] segments, TimeSpan bucketLength, Func <DateTime> currentTimeProvider)
 {
     if (segments == null)
     {
         throw new ArgumentNullException("segments");
     }
     if (segments.Length == 0)
     {
         throw new ArgumentException("segments cannot be empty");
     }
     this.bucketLength = bucketLength;
     if (currentTimeProvider == null)
     {
         this.currentTimeProvider = new Func <DateTime>(this.GetCurrentTime);
         this.creationTime        = this.RoundToBucketLength(DateTime.UtcNow);
         this.currentTime         = this.creationTime;
     }
     else
     {
         this.currentTimeProvider = currentTimeProvider;
         this.creationTime        = this.RoundToBucketLength(this.currentTimeProvider());
     }
     this.numSegments          = (long)segments.Length;
     this.numBucketsPerSegment = new long[this.numSegments];
     this.segmentValues        = new long[this.numSegments + 1L];
     this.numBuckets           = 0L;
     for (long num = 0L; num < this.numSegments; num += 1L)
     {
         long num2;
         checked
         {
             TimeSpan slidingWindowLength = segments[(int)((IntPtr)num)];
             SlidingWindow.ValidateSlidingWindowAndBucketLength(slidingWindowLength, bucketLength);
             num2 = slidingWindowLength.Ticks / this.bucketLength.Ticks;
             this.numBucketsPerSegment[(int)((IntPtr)num)] = num2;
         }
         this.numBuckets += num2;
     }
     this.bucketValues = new long[this.numBuckets];
 }