Example #1
0
 private void Recurse(StatusResultsBuilder statusBuilder, int level, int sourceNumber)
 {
     if (level == 0)
     {
         statusBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
         if (sourceNumber < 3)
         {
             statusBuilder.AddOkay(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Okay", "This is the multiple source okay", 0.5f);
         }
         else if (sourceNumber < 6)
         {
             statusBuilder.AddAlert(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Alert", "This is the multiple source alert", 0.5f);
         }
         else
         {
             statusBuilder.AddFailure(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Fail", "This is the multiple source failure", 0.5f);
         }
     }
     else
     {
         if (level % 2 == 0)
         {
             statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
         }
         StatusResultsBuilder child = new StatusResultsBuilder("Level" + level.ToString());
         child.AddProperty("Level", level);
         child.AddProperty("SourceNumber", sourceNumber);
         Recurse(child, level - 1, sourceNumber);
         statusBuilder.AddChild(child.FinalResults);
     }
 }
Example #2
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
     statusBuilder.AddProperty("nc1", "a");
     statusBuilder.AddProperty("nc2", "b");
     statusBuilder.AddProperty("nc2", AmbientClock.UtcNow.AddMinutes(-3));
     return(Task.CompletedTask);
 }
Example #3
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
     statusBuilder.AddProperty("wc1", "a");
     statusBuilder.AddProperty("wc2", "b");
     statusBuilder.AddProperty("wc2", AmbientClock.UtcNow.AddMinutes(-10));
     statusBuilder.AddException(new ApplicationException("This is a test"));
     return(Task.CompletedTask);
 }
        public StatusAuditorAuditNeverRunTest(string targetSystem)
            : base(targetSystem, TimeSpan.MaxValue, null)
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
        }
        public StatusAuditorAuditExceptionTest(string targetSystem) // note that this parameter prevents this auditor from being used in the default status instance
            : base(targetSystem, TimeSpan.Zero, null)
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
        }
Example #6
0
        public TestMachineConstantStatus()
            : base(nameof(TestMachineConstantStatus))
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("MachineName", Environment.MachineName);
            sb.AddProperty("StartTime", AmbientClock.UtcNow);
            _results = sb.FinalResults;
            SetLatestResults(_results);
        }
        public StatusCheckerTest()
            : base("StatusCheckerTest")
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
            StatusResults results = sb.FinalResults;

            SetLatestResults(results);
            SetLatestResults(results);  // set the results twice so the first results (which are the same as the second) end up in the history
        }
        public StatusAuditorTest(string targetSystem, Status status = null)
            : base(targetSystem, TimeSpan.FromSeconds(10), status)
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(this)
            {
                NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant
            };

            sb.AddProperty("TestProperty1", Environment.MachineName);
            sb.AddProperty("TestProperty2", AmbientClock.UtcNow);
            StatusResults results = sb.FinalResults;

            SetLatestResults(results);
            SetLatestResults(results);  // set the results twice so the first results (which are the same as the second) end up in the history
        }
Example #9
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHomogenous;
     statusBuilder.AddProperty("ChildCount", _diskAuditors.Count());
     statusBuilder.AddFailure("TestFailCode", "TEST-FAIL!", "This is the detailed fail message", 0.0f);
     return(Task.CompletedTask);
 }
Example #10
0
        /// <summary>
        /// Gets the current status of the disk established in the constructor.
        /// </summary>
        /// <param name="cancel">A <see cref="CancellationToken"/> that may be used to cancel the operation before it completes.</param>
        /// <returns>A <see cref="StatusResultsBuilder"/> containing the status of the disk.</returns>
        public Task <StatusResultsBuilder> GetStatus(CancellationToken cancel = default(CancellationToken))
        {
            StatusResultsBuilder sb = new StatusResultsBuilder(_targetSystem);

            sb.NatureOfSystem = StatusNatureOfSystem.Leaf;
            if (_fakeFolderPath != null)
            {
                long   totalBytes       = Math.Abs(_fakeFolderPath.GetHashCode());
                long   freeBytes        = totalBytes * 8 / 10;
                long   availableBytes   = totalBytes * 8 / 10;
                double availablePercent = .8;
                sb.AddProperty("TotalBytes", totalBytes);
                sb.AddProperty("FreeBytes", freeBytes);
                sb.AddProperty("AvailableBytes", availableBytes);
                sb.AddProperty("AvailablePercent", availablePercent);
                return(Task.FromResult(sb));
            }
            return(null);
        }
Example #11
0
        public override async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
            foreach (SampleVolumeAuditor da in _diskAuditors)
            {
                try
                {
                    StatusResultsBuilder childResults = await da.GetStatus(cancel);

                    statusBuilder.AddChild(childResults);
                }
                catch (Exception ex)
                {
                    statusBuilder.AddException(ex);
                }
            }
            statusBuilder.AddProperty("wc1", "a");
            statusBuilder.AddProperty("wc2", "b");
            statusBuilder.AddProperty("wc2", AmbientClock.UtcNow.AddMinutes(-10));
            statusBuilder.AddAlert("TestAlertCode", "test-terseAlert", "This is the detailed alert message", 0.1f);
        }
Example #12
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     for (int source = 0; source < 10; ++source)
     {
         StatusResultsBuilder childBuilder = new StatusResultsBuilder("Subsystem");
         childBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
         childBuilder.SourceSystem   = "Source " + source.ToString();
         childBuilder.AddProperty("sourceNumber", source);
         AddSource(childBuilder, source);
         statusBuilder.AddChild(childBuilder.FinalResults);
     }
     return(Task.CompletedTask);
 }
Example #13
0
    /// <summary>
    /// Performs the disk audit, reporting results into <paramref name="statusBuilder"/>.
    /// </summary>
    /// <param name="statusBuilder">A <see cref="StatusResultsBuilder"/> to write the results into.</param>
    /// <param name="cancel">The optional <see cref="CancellationToken"/>.</param>
    public async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default)
    {
        statusBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
        statusBuilder.AddProperty("_Path", _driveInfo.Name);
        statusBuilder.AddProperty("_VolumeLabel", _driveInfo.VolumeLabel);
        statusBuilder.AddProperty("DriveFormat", _driveInfo.DriveFormat);
        statusBuilder.AddProperty("DriveType", _driveInfo.DriveType);
        statusBuilder.AddProperty("AvailableFreeBytes", _driveInfo.AvailableFreeSpace);
        statusBuilder.AddProperty("TotalFreeBytes", _driveInfo.TotalFreeSpace);
        statusBuilder.AddProperty("TotalBytes", _driveInfo.TotalSize);
        if (!string.IsNullOrEmpty(_testPath))
        {
            StatusResultsBuilder readBuilder = new StatusResultsBuilder("Read");
            statusBuilder.AddChild(readBuilder);
            try
            {
                // attempt to read a file (if one exists)
                foreach (string file in Directory.EnumerateFiles(Path.Combine(_driveInfo.RootDirectory.FullName, _testPath)))
                {
                    AmbientStopwatch s = AmbientStopwatch.StartNew();
                    try
                    {
                        using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            byte[] b = new byte[1];
                            await fs.ReadAsync(b, 0, 1, cancel);

                            await fs.FlushAsync();
                        }
                        readBuilder.AddProperty("ResponseMs", s.ElapsedMilliseconds);
                        readBuilder.AddOkay("Ok", "Success", "The read operation succeeded.");
                        break;
                    }
                    catch (IOException) // this will be thrown if the file cannot be accessed because it is open exclusively by another process (this happens a lot with temp files)
                    {
                        // just move on and try the next file
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                readBuilder.AddException(e);
            }
            if (!_readonly)
            {
                StatusResultsBuilder writeBuilder = new StatusResultsBuilder("Write");
                statusBuilder.AddChild(writeBuilder);
                try
                {
                    // attempt to write a temporary file
                    string           targetPath = Path.Combine(_driveInfo.RootDirectory.FullName, Guid.NewGuid().ToString("N"));
                    AmbientStopwatch s          = AmbientStopwatch.StartNew();
                    using (FileStream fs = new FileStream(targetPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read, 4096, FileOptions.DeleteOnClose))
                    {
                        byte[] b = new byte[1];
                        await fs.WriteAsync(b, 0, 1);

                        await fs.FlushAsync();

                        readBuilder.AddProperty("ResponseMs", s.ElapsedMilliseconds);
                        writeBuilder.AddOkay("Ok", "Success", "The write operation succeeded.");
                    }
                }
                catch (Exception e)
                {
                    writeBuilder.AddException(e);
                }
            }
        }
    }