protected double?GetBalanceLimitRate(decimal balance, BalanceLimit limit) { ReaderWriterLockSlim _slimLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); _slimLock.EnterReadLock(); double?_rate = limit.DefaultRate; if (balance >= limit.Floor && balance <= limit.Ceiling) { _rate = limit.LimitRate; } else { _rate = limit.DefaultRate; } if (_slimLock.IsReadLockHeld) { _slimLock.ExitReadLock(); } return(_rate); }
// This is better to be exposed to the external runner. The user of the library should identify the rates rules. protected override void RegisterRateProviders() { IRateLimit limit = new BalanceLimit(0, 1000, 0.001, 0.002); this.RateLimits.Add(limit); }