// ** Rule 1 **// public bool ReachedMaxReuestPerTimeSpan(DateTime now) { bool IsRestricted = false; if (this._firstCallTime == new DateTime(0001, 1, 1)) { this._firstCallTime = now; } if (this._clientRequestsCountInTimespan == this._allowedrequestCountsPerTimespan && now - this._firstCallTime < this._allowedTimeSpan) { IsRestricted = true; } else if (this._clientRequestsCountInTimespan == this._allowedrequestCountsPerTimespan && now - this._firstCallTime > this._allowedTimeSpan) { IsRestricted = true; } else if (now - this._firstCallTime > this._allowedTimeSpan) { CountCallsForClientsInTimspan[AuthToken] = 0; if (FirstCallTimeForClientsInTimeSpan.ContainsKey(AuthToken)) { FirstCallTimeForClientsInTimeSpan[AuthToken] = now; } else { FirstCallTimeForClientsInTimeSpan.Add(AuthToken, now); } } return(IsRestricted); }
public void AddRequest(DateTime now, int count) { if (CountCallsForClientsInTimspan.ContainsKey(AuthToken)) { CountCallsForClientsInTimspan[AuthToken] = count + 1; LastCallTimeForClients[AuthToken] = now; } else { CountCallsForClientsInTimspan.Add(AuthToken, 1); FirstCallTimeForClientsInTimeSpan.Add(AuthToken, now); LastCallTimeForClients.Add(AuthToken, now); } }