private bool MessagePermitted(string message) { if (message.Length > MaximumMessageLengthAllowed && MaximumMessageLengthAllowed != -1) { OnClientThrottled?.Invoke(this, new OnClientThrottledArgs { Message = message, ThrottleViolation = ThrottleType.MessageTooLong }); return(false); } if (message.Length >= MinimumMessageLengthAllowed) { return(true); } OnClientThrottled?.Invoke(this, new OnClientThrottledArgs { Message = message, ThrottleViolation = ThrottleType.MessageTooShort }); return(false); }
/// <summary>Function that verifies a message is legal, returns true/false on message legality.</summary> public bool MessagePermitted(string message) { if (!_periodTimer.Enabled) { _periodTimer.Start(); } if (message.Length > MaximumMessageLengthAllowed && MaximumMessageLengthAllowed != -1) { OnClientThrottled?.Invoke(this, new Events.Services.MessageThrottler.OnClientThrottledArgs { Message = message, PeriodDuration = PeriodDuration, ThrottleViolation = Enums.ThrottleType.MessageTooLong }); return(false); } if (message.Length < MinimumMessageLengthAllowed) { OnClientThrottled?.Invoke(this, new Events.Services.MessageThrottler.OnClientThrottledArgs { Message = message, PeriodDuration = PeriodDuration, ThrottleViolation = Enums.ThrottleType.MessageTooShort }); return(false); } if (_currentMessageCount == MessagesAllowedInPeriod) { OnClientThrottled?.Invoke(this, new Events.Services.MessageThrottler.OnClientThrottledArgs { Message = message, PeriodDuration = PeriodDuration, ThrottleViolation = Enums.ThrottleType.TooManyMessages }); return(false); } _currentMessageCount++; return(true); }