Exemplo n.º 1
0
            // Initializing the parameters in the constructor
            public RateLimiter(string authToken, TimeSpan timeSpanPastSinceLastCall, TimeSpan allowedTimeSpan, int AllowedrequestCountsPerTimespan)
            {
                this._authToken = authToken;

                // parameters for X request per timespan
                this._allowedrequestCountsPerTimespan = AllowedrequestCountsPerTimespan;

                if (CountCallsForClientsInTimspan.ContainsKey(AuthToken))
                {
                    this._clientRequestsCountInTimespan = CountCallsForClientsInTimspan[AuthToken];
                }

                if (FirstCallTimeForClientsInTimeSpan.ContainsKey(AuthToken))
                {
                    this._firstCallTime = FirstCallTimeForClientsInTimeSpan[AuthToken];
                }

                this._allowedTimeSpan = allowedTimeSpan;


                // parameters for a certain timespan passed since the last call;
                this._timeSpanPastSinceLastCall = timeSpanPastSinceLastCall;

                if (LastCallTimeForClients.ContainsKey(AuthToken))
                {
                    this._lastCallTime = LastCallTimeForClients[AuthToken];
                }
            }
Exemplo n.º 2
0
 public void AddRequest(DateTime now)
 {
     if (LastCallTimeForClients.ContainsKey(AuthToken))
     {
         LastCallTimeForClients[AuthToken] = now;
     }
     else
     {
         LastCallTimeForClients.Add(AuthToken, now);
     }
 }