Beispiel #1
0
        /// <summary>
        /// Deserializes a JSON object to a <see cref="HealthMonitor"/> instance of the proper type.
        /// </summary>
        /// <param name="jsonObject">The JSON object representing the health monitor.</param>
        /// <returns>A <see cref="HealthMonitor"/> object corresponding to the JSON object.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="jsonObject"/> is <see langword="null"/>.</exception>
        public static HealthMonitor FromJObject(JObject jsonObject)
        {
            if (jsonObject == null)
            {
                throw new ArgumentNullException("jsonObject");
            }

            JValue typeValue = jsonObject["type"] as JValue;

            if (typeValue == null)
            {
                return(null);
            }

            HealthMonitorType type = typeValue.ToObject <HealthMonitorType>();

            if (type == HealthMonitorType.Connect)
            {
                return(jsonObject.ToObject <ConnectionHealthMonitor>());
            }
            else if (type == HealthMonitorType.Http || type == HealthMonitorType.Https)
            {
                return(jsonObject.ToObject <WebServerHealthMonitor>());
            }
            else
            {
                return(jsonObject.ToObject <CustomHealthMonitor>());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HealthMonitor"/> class
        /// using the specified values.
        /// </summary>
        /// <param name="type">The type of health monitor.</param>
        /// <param name="attemptsBeforeDeactivation">The number of permissible monitor failures before removing a node from rotation.</param>
        /// <param name="timeout">The maximum number of seconds to wait for a connection to be established before timing out.</param>
        /// <param name="delay">The minimum time to wait before executing the health monitor.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="type"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="attemptsBeforeDeactivation"/> is less than or equal to 0.
        /// <para>-or-</para>
        /// <para>If <paramref name="timeout"/> is negative or <see cref="TimeSpan.Zero"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="delay"/> is negative or <see cref="TimeSpan.Zero"/>.</para>
        /// </exception>
        protected HealthMonitor(HealthMonitorType type, int attemptsBeforeDeactivation, TimeSpan timeout, TimeSpan delay)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (attemptsBeforeDeactivation <= 0)
            {
                throw new ArgumentOutOfRangeException("attemptsBeforeDeactivation");
            }
            if (timeout <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeout");
            }
            if (delay <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("delay");
            }

            _type = type;
            _attemptsBeforeDeactivation = attemptsBeforeDeactivation;
            _timeout = (int)timeout.TotalSeconds;
            _delay   = (int)delay.TotalSeconds;
        }
 /// <inheritdoc/>
 protected override HealthMonitorType FromName(string name)
 {
     return(HealthMonitorType.FromName(name));
 }