public string Index() { var result = string.Empty; try { var tests = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(HealthTest).IsAssignableFrom(p)) .Where(x => !x.IsInterface) .Where(x => !x.IsAbstract); var model = new IndexPageModel(); string loc = Assembly.GetAssembly(typeof(HealthTest)).Location; FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(loc); model.PageTitle = versionInfo.ProductName + " " + versionInfo.FileVersion; model.Footer = versionInfo.ProductName + " © " + DateTime.Now.Year; foreach (var item in tests) { var watch = Stopwatch.StartNew(); var displayTestResult = new DisplayTestResult(); HealthTest instance = null; // creating an instance of the test try { instance = Activator.CreateInstance(item) as HealthTest; displayTestResult.TestName = instance.TestName; } catch (Exception ex) { displayTestResult.Successful = false; displayTestResult.ErrorMessage = ex.Message; } // running the test try { var testResult = instance.Run(); displayTestResult.Successful = testResult.Successful; displayTestResult.ErrorMessage = testResult.ErrorMessage; } catch (Exception ex) { displayTestResult.Successful = false; displayTestResult.ErrorMessage = ex.Message; } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; displayTestResult.ExecutionTime = elapsedMs + " ms"; model.TestResults.Add(displayTestResult); } var template = ReadEmbeddedResource("HealthCheck.Mvc.Views.Health.Index.html"); var templateKey = Guid.NewGuid().ToString(); result = Engine.Razor.RunCompile(template, templateKey, null, model); } catch (Exception ex2) { result = "An error occurred: " + ex2.Message; } return(result); }
private List <DisplayTestResult> ResultParser(List <AppResult> appResults, string functionName, double duration) { //ATENTION: //APS100, application will always give a fixed length of result, which is same as the site number //MT1600, application may adjust the legnth of result based on actionOnFail settings var grpAppResults = appResults.GroupBy(x => x.TestNumber); foreach (var item in grpAppResults) { if (item.ToList().Count > 1) { throw new Exception(string.Format("System error: test item {0} is duplicated in program, please contact the developer!", item.Key)); } } List <DisplayTestResult> list = new List <DisplayTestResult>(); foreach (var item in appResults) { if (item.TestResult.Count != siteNum) { throw new Exception(string.Format("System error: site number is not matching between program({0}) and program({1}), please contact the developer!", item.TestResult.Count, siteNum)); } TestLimit limit = limits.First(x => x.TestNumber == item.TestNumber.ToString()); if (limit != null) { if (isAllFailed() && workMode != FlowWorkMode.ContinueOnFail) { break; } DisplayTestResult tr = new DisplayTestResult(); tr.TestNumber = uint.Parse(limit.TestNumber); tr.TestName = limit.TestName; tr.Unit = limit.Units; tr.FTLower = double.Parse(limit.FTLower); tr.FTUpper = double.Parse(limit.FTUpper); tr.QALower = double.Parse(limit.QALower); tr.QAUpper = double.Parse(limit.QAUpper); tr.Offset = double.Parse(limit.Offset1); tr.Factor = UnitParser(limit.Units); for (int i = 0; i < item.TestResult.Count; i++) { if (actionOnFail[i] || workMode == FlowWorkMode.ContinueOnFail || (isAllFailed() && workMode == FlowWorkMode.StopOnAllFail)) { tr.Results.Add(item.TestResult[i]); double disVal = item.TestResult[i] * Math.Pow(10, tr.Factor) + tr.Offset; tr.DisplayResults.Add(string.Format("{0:N6}", disVal)); tr.PFFlags.Add((tr.FTLower <= disVal) && (disVal <= tr.FTUpper)); } else { tr.Results.Add(INVALID); tr.DisplayResults.Add(string.Empty); tr.PFFlags.Add(false); } } tr.FunctionName = functionName; tr.Duration = duration / appResults.Count; list.Add(tr); for (int i = 0; i < tr.PFFlags.Count; i++) { if (actionOnFail[i]) { actionOnFail[i] = tr.PFFlags[i]; } } } } return(list); }