コード例 #1
0
        public Choke(DataRate targetRate, IStopwatch?stopwatch = null)
        {
            Helpers.Argument.ValidateRange(targetRate.BytesPerSecond, nameof(targetRate.BytesPerSecond), min: 1);

            RateLimit = targetRate;

            _stopwatch = stopwatch ?? new RealStopwatch();

            BucketSizeBytes    = (long)(targetRate.BytesPerSecond * BucketSize.TotalSeconds);
            _availableCapacity = BucketSizeBytes;
            _lastRefillTime    = _stopwatch.GetTimestamp();

            // How many ticks does it take to increase budget by one refill step?

            // Rounds down - safer is to send less often.
            var refillStepsPerSecond = targetRate.BytesPerSecond / RefillStepSizeBytes;

            if (refillStepsPerSecond == 0)
            {
                throw new ArgumentException("Target rate is too low for meaningful operation.", nameof(targetRate));
            }

            _ticksPerRefillStep = _stopwatch.Frequency / refillStepsPerSecond;

            // Rounds up - safer is to send less often (pay more ticks per refill step).
            if (_stopwatch.Frequency % refillStepsPerSecond != 0)
            {
                _ticksPerRefillStep++;
            }
        }
コード例 #2
0
            public void Run(TimeInterval <TSource> parent)
            {
                _watch = parent._scheduler.StartStopwatch();
                _last  = TimeSpan.Zero;

                SetUpstream(parent._source.Subscribe(this));
            }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponseScope"/> class.
 /// </summary>
 /// <param name="statusCode">The status response code.</param>
 /// <param name="stopwatch">The elapsed time stopwatch.</param>
 public ResponseScope(int?statusCode, IStopwatch?stopwatch)
     : base(3)
 {
     Add("EventName", "HttpResponse");
     Add("StatusCode", statusCode !);
     Add("Elapsed", Math.Round(stopwatch?.Elapsed.TotalMilliseconds ?? 0d));
 }
コード例 #4
0
ファイル: Delay.cs プロジェクト: Scopola/reactive
                public void Run(TParent parent)
                {
                    _watch = _scheduler.StartStopwatch();

                    RunCore(parent);

                    base.Run(parent._source);
                }
コード例 #5
0
        /// <inheritdoc cref="IContextLogger" />
        public void LogError(Exception exception, IStopwatch?stopwatch)
        {
            _statusCode = 500;
            var request  = RequestDetails.From(_context.Request);
            var response = ResponseDetails.From(_context.Response, stopwatch, _statusCode);

            _httpLogger.LogError(exception, request, response);
        }
コード例 #6
0
        /// <summary>
        /// Handles the event when the algorithm completes execution.
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">The<see cref="EventArgs"/> associated with the event.</param>
        private void Algorithm_AlgorithmCompleted(object?sender, EventArgs e)
        {
            this.Dispatcher.Invoke(() =>
            {
                this.RefreshChart(true);
            });

            this.stopwatch = null;
        }
コード例 #7
0
            public IDisposable Start()
            {
                RegisterHostLifecycleEventHandlers();

                _stopwatch = _stopwatchProvider.StartStopwatch();
                _nextDue   = _period;
                _runState  = Running;

                _task.Disposable = _scheduler.Schedule(this, _nextDue, static (@this, a) => @this.Tick(a));
                return(this);
            }
コード例 #8
0
        /// <summary>
        /// Initializes the stopwatch if it's not yet set.
        /// </summary>
        /// <returns>True if the stopwatch was initialized; otherwise, false.</returns>
        private bool TryInitializeStopwatch()
        {
            if (this.stopwatch == null)
            {
                this.stopwatch = this.stopwatchFactory.Create();
                this.stopwatch.Start();
                return(true);
            }

            return(false);
        }
コード例 #9
0
        private ResponseDetails(HttpResponseMessage?response, IStopwatch?stopwatch, int?statusCode)
            : this(stopwatch)
        {
            if (response is null)
            {
                return;
            }

            StatusCode  = (HttpStatusCode)(statusCode ?? (int)response.StatusCode);
            ContentType = response.Content?.Headers.ContentType?.ToString();
            Headers     = ToDictionary(response.Headers);
            Content     = Read(response.Content);
        }
コード例 #10
0
        private ResponseDetails(HttpResponse?response, IStopwatch?stopwatch, int?statusCode)
            : this(stopwatch)
        {
            if (response is null)
            {
                return;
            }

            StatusCode  = (HttpStatusCode)(statusCode ?? response.StatusCode);
            ContentType = response.ContentType;
            Headers     = response.Headers;
            Content     = response.Body;
        }
コード例 #11
0
 private TimeMeasurable(IServiceProvider services, IStopwatch stopwatch)
 {
     _services  = services;
     _stopwatch = stopwatch;
     _stopwatch.Start();
 }
コード例 #12
0
ファイル: TakeLast.cs プロジェクト: ibebbs/reactive
 public void Run(IObservable <TSource> source, IScheduler scheduler)
 {
     _watch = scheduler.StartStopwatch();
     Run(source);
 }
コード例 #13
0
 private ResponseDetails(IStopwatch?stopwatch)
 {
     Stopwatch = stopwatch;
     Time      = stopwatch?.Time() ?? string.Empty;
 }
コード例 #14
0
                public void Run(Time parent)
                {
                    _watch = parent._scheduler.StartStopwatch();

                    SetUpstream(parent._source.SubscribeSafe(this));
                }