//****************************************************************************************************** // MessageRate.cs - Gbtc // // Copyright © 2016, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/eclipse-1.0.php // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 10/24/2016 - Steven E. Chisholm // Generated original version of source code. // // //****************************************************************************************************** namespace GSF.Diagnostics { /// /// Defines a message rate for the message suppression algorithm /// public struct MessageRate { /// /// The rate in messages per second. (add 1 to this time, so the default is 1 message per second) /// private readonly double m_rate; private MessageRate(double rate) { m_rate = rate - 1; } /// /// Gets the default message rate. Which is 1 message per second. /// public static readonly MessageRate Default = new MessageRate(1); /// /// As messages per second. /// /// the number of messages to allow per second /// public static MessageRate PerSecond(double messagesPerSecond) { return new MessageRate(messagesPerSecond); } /// /// As messages per minute. /// /// the number of messages to allow per minute /// public static MessageRate PerMinute(double messagesPerMinute) { return new MessageRate(messagesPerMinute * (1.0 / 60.0)); } /// /// As messages per hour. /// /// the number of messages to allow per hour /// public static MessageRate PerHour(double messagesPerHour) { return new MessageRate(messagesPerHour * (1.0 / (60.0 * 60.0))); } /// /// As messages per day. /// /// the number of messages to allow per day /// public static MessageRate PerDay(double messagesPerDay) { return new MessageRate(messagesPerDay * (1.0 / (60.0 * 60.0 * 24.0))); } /// /// As a minimum timespan between each message. /// /// the number of seconds between messages /// public static MessageRate EveryFewSeconds(double seperation) { return PerSecond(1.0 / seperation); } /// /// As a minimum timespan between each message. /// /// the number of Minutes between messages /// public static MessageRate EveryFewMinutes(double seperation) { return PerMinute(1.0 / seperation); } /// /// As a minimum timespan between each message. /// /// the number of Hours between messages /// public static MessageRate EveryFewHours(double seperation) { return PerHour(1.0 / seperation); } /// /// As a minimum timespan between each message. /// /// the number of Days between messages /// public static MessageRate EveryFewDays(double seperation) { return PerDay(1.0 / seperation); } /// /// Implicitly convert the message rate to a rate per second. /// /// the item to convert. /// public static implicit operator double(MessageRate rate) { return rate.m_rate + 1; } } }