Esempio n. 1
0
        /// <summary>
        /// Adds a child node with the specified name and returns the corresponding <see cref="StatusResultsBuilder"/>.
        /// </summary>
        /// <param name="childName">The name of the child node to add.</param>
        public StatusResultsBuilder AddChild(string childName)
        {
            StatusResultsBuilder childNode = new StatusResultsBuilder(childName);

            _children.Add(childNode);
            return(childNode);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs a leaf node <see cref="StatusResultsBuilder"/> directly from the information for a single alert.
        /// </summary>
        /// <param name="targetSystem">The name of the target system.</param>
        /// <param name="rating">The status rating.</param>
        /// <param name="auditAlertCode">The audit alert code.</param>
        /// <param name="terse">The terse message.</param>
        /// <param name="details">The detailed message.</param>
        /// <returns>A <see cref="StatusResultsBuilder"/> constructed from the specified parameters.</returns>
        public static StatusResultsBuilder CreateRawStatusResultsBuilder(string targetSystem, float rating, string auditAlertCode, string terse, string details)
        {
            StatusResultsBuilder temp = new StatusResultsBuilder(targetSystem);

            temp.NatureOfSystem = StatusNatureOfSystem.Leaf;
            temp._worstAlert    = new StatusAuditAlert(rating, auditAlertCode, terse, details);
            return(temp);
        }
Esempio n. 3
0
        private async Task <StatusResults> InternalAuditAsync(bool foreground = false, CancellationToken cancel = default(CancellationToken))
        {
            StatusResultsBuilder builder = new StatusResultsBuilder(this);

            try
            {
                try
                {
                    // in case the timer went off more than once due to test (or overall system) slowness, disable the timer until we're done here
                    _auditTimer.Stop();
                    // have we already shut down?  bail out now!
                    if (foreground)
                    {
                        Interlocked.Increment(ref _foregroundAuditCount);
                    }
                    else
                    {
                        Interlocked.Increment(ref _backgroundAuditCount);
                    }
                    // call the derived object to get the status
                    await Audit(builder, cancel).ConfigureAwait(false);

                    // schedule the next audit
                    builder.NextAuditTime = ScheduleNextAudit(builder.WorstAlert == null ? (float?)null : builder.WorstAlert.Rating, builder.Elapsed);
                }
#pragma warning disable CA1031  // we really DO want to catch ALL exceptions here--this is a status test, and the exception will be reported through the status system.  if we rethrew it, it would crash the program
                catch (Exception ex)
#pragma warning restore CA1031
                {
                    builder.AddException(ex);
                }
                finally
                {
                    _auditTimer.Start();
                }
            }
            catch (ObjectDisposedException)
            {
                // ignore this exception--given the design of System.Timers.Timer, it's impossible to prevent
                // it happens when an audit happens to get triggered just before shutdown/disposal
                return(_shutdownInProgress);
            }
            // get the results
            StatusResults newStatusResults = builder.FinalResults;
            // save the results AND return them
            SetLatestResults(newStatusResults);
            return(newStatusResults);
        }
Esempio n. 4
0
 /// <summary>
 /// Adds the specified <see cref="StatusResultsBuilder"/> as a child to the node we're building.
 /// </summary>
 /// <param name="child">The child <see cref="StatusResultsBuilder"/>.</param>
 public void AddChild(StatusResultsBuilder child)
 {
     _children.Add(child);
 }
Esempio n. 5
0
 /// <summary>
 /// Computes the current status, filling in <paramref name="statusBuilder"/> with information about the status.
 /// Note that this function is only public instead of protected so that it can be unit tested more easily.
 /// The status system calls this function internally.
 /// </summary>
 /// <param name="statusBuilder">A <see cref="StatusResultsBuilder"/> to put the audit results into.</param>
 /// <param name="cancel">A <see cref="CancellationToken"/> to cancel the operation before it finishes.</param>
 public abstract Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken));