/// <summary> /// Perform custom class-level validation. /// </summary> public static ValidationResult ValidateAllProperties(StatusCounter counter, ValidationContext context) { string errorMessage = string.Empty; List<string> propertiesWithErrors = new List<string>(); // minimum & maximum if (counter.Maximum < counter.Minimum) { errorMessage += "Maximum must be greater than or equal to Minimum.\n"; propertiesWithErrors.Add("Maximum"); } // value if (counter.Value > counter.Maximum || counter.Value < counter.Minimum) { errorMessage += "Value must be between Minimum and Maximum.\n"; propertiesWithErrors.Add("Value"); } // warning threshold if (counter.WarningThreshold > counter.Maximum || counter.WarningThreshold < counter.Minimum) { errorMessage += "WarningThreshold must be between Minimum and Maximum.\n"; propertiesWithErrors.Add("WarningThreshold"); } if (counter.WarningThreshold > counter.CriticalThreshold) { errorMessage += "WarningThreshold must be less than or equal to CriticalThreshold.\n"; propertiesWithErrors.Add("WarningThreshold"); } // critical threshold if (counter.CriticalThreshold > counter.Maximum || counter.CriticalThreshold < counter.Minimum) { errorMessage += "CriticalThreshold must be between Minimum and Maximum.\n"; propertiesWithErrors.Add("CriticalThreshold"); } if (counter.CriticalThreshold < counter.WarningThreshold) { errorMessage += "CriticalThreshold must be greater than or equal to WarningThreshold.\n"; propertiesWithErrors.Add("CriticalThreshold"); } // return value if (propertiesWithErrors.Count > 0 ) { return new ValidationResult(errorMessage, propertiesWithErrors); } else { return ValidationResult.Success; } }
public SystemStatus() { // first machine in the dev environment Dev1 = new StatusCounter { CounterName = "DEV1", Maximum = 10, Minimum = 1, Value = 1, WarningThreshold = 7, CriticalThreshold = 9 }; // second machine in the dev environment Dev2 = new StatusCounter { CounterName = "DEV2", Maximum = 20, Minimum = 1, Value = 1, WarningThreshold = 15, CriticalThreshold = 17 }; // first machine in the uat environment UAT1 = new StatusCounter { CounterName = "UAT1", Maximum = 10, Minimum = 1, Value = 1, WarningThreshold = 7, CriticalThreshold = 9 }; // second machine in the uat environment UAT2 = new StatusCounter { CounterName = "UAT2", Maximum = 20, Minimum = 1, Value = 1, WarningThreshold = 15, CriticalThreshold = 17 }; // first machine in the prd environment Prd1 = new StatusCounter { CounterName = "PRD1", Maximum = 10, Minimum = 1, Value = 1, WarningThreshold = 7, CriticalThreshold = 9 }; // second machine in the prd environment Prd2 = new StatusCounter { CounterName = "PRD2", Maximum = 20, Minimum = 1, Value = 1, WarningThreshold = 15, CriticalThreshold = 17 }; }