private static void WorkerMethod(LogStatItem item) { double gTime; double cTime; string indent = null; string gValue; if (string.IsNullOrEmpty(item.Group)) { gValue = string.Format("{0:00}", item.Id); if (EnableIndent) { indent = IndentTexts.GetOrAdd(item.Id, num => new string(' ', (num - 1) * 2)); } } else { gValue = item.Group; } switch (item.Type) { case 0: Core.Log.Write(item.Level, indent + "[" + gValue + "-START] " + item.Message); break; case 1: cTime = item.LastTapTicks * FrequencyTime; item.Counter?.Register(item.Message, cTime); if (Math.Abs(item.LastTapTicks - item.GlobalTicks) > 0.00001) { gTime = item.GlobalTicks * FrequencyTime; Core.Log.Write(item.Level, indent + string.Format(" [{0}-TAP, Time = {1:0.0000}ms, Cumulated = {2:0.0000}ms] {3}", gValue, cTime, gTime, item.Message)); } else { Core.Log.Write(item.Level, indent + string.Format(" [{0}-TAP, Time = {1:0.0000}ms] {2}", gValue, cTime, item.Message)); } break; case 2: cTime = item.LastTapTicks * FrequencyTime; gTime = item.GlobalTicks * FrequencyTime; item.Counter?.Register(item.Counter.Name == CounterPreffix + item.Message ? "Total" : item.Message, gTime); if (Math.Abs(cTime - gTime) > 0.00001) { Core.Log.Write(item.Level, indent + string.Format("[{0}-END, Time = {1:0.0000}ms, Total Time = {2:0.0000}ms] {3}", gValue, cTime, gTime, item.Message)); } else { Core.Log.Write(item.Level, indent + string.Format("[{0}-END, Total Time = {1:0.0000}ms] {2}", gValue, gTime, item.Message)); } break; } }
private static void WorkerMethod(LogStatItem item) { if ((Core.Log.MaxLogLevel & item.Level) == 0) { LogStatItemPool.Store(item); return; } double gTime; string indent = null; string gValue; if (string.IsNullOrEmpty(item.Group)) { gValue = $"{item.Id:00}"; if (EnableIndent) { indent = IndentTexts.GetOrAdd(item.Margin, num => new string(' ', (num - 1) * 3)); } } else { gValue = item.Group; } switch (item.Type) { case 0: Core.Log.Write(item.Level, null, indent + "[START] " + item.Message, gValue); break; case 1: var cTime = item.LastTapTicks * FrequencyTime; gTime = item.GlobalTicks * FrequencyTime; Core.Log.Write(item.Level, null, indent + $" [Time = {cTime:0.0000}ms, Cumulated = {gTime:0.0000}ms] {item.Message}", gValue); break; case 2: gTime = item.GlobalTicks * FrequencyTime; Core.Log.Write(item.Level, null, indent + $"[END: Total Time = {gTime:0.0000}ms] {item.Message}", gValue); break; } LogStatItemPool.Store(item); }
private static LogStatItem CreateLogStatInstance(string name, string value, string description, LogStatItem tmp) { var testCase = new LogStatItem { statName = name, statVal = value, uuid = tmp.uuid, timeStamp = tmp.timeStamp, machineGuid = tmp.machineGuid, product = tmp.product, installGuid = tmp.installGuid }; if (_metadata == null) { _metadata = GetMetadata(); } var index = _metadata.testschema.FindIndex(s => s.name == name); if (index == -1) { ALogger.LogWarn("Cannot find metadata for [{0}]", name); return null; } var schema = _metadata.testschema[index]; if (!schema.enabled) { return null; } if (schema.usedesc || string.IsNullOrWhiteSpace(value)) { if (!string.IsNullOrWhiteSpace(description) && description != "-") { testCase.statVal = description; } } if (schema.type == "boolean") { testCase.statVal = ParseBoolean(testCase.statVal); return testCase; } if (!string.IsNullOrEmpty(schema.unit)) { testCase.statVal = ParseUnit(testCase.statVal, schema.unit); return testCase; } if (testCase.statVal.Length <= 40) return testCase; var mapCode = _metadata.enumdict.Find(s => s.Test.Contains(name)); if (mapCode != null) { foreach (var map in mapCode.Map) { testCase.statVal = ReplaceCaseInsensitive(testCase.statVal, map.Value, "#" + map.ID, map.Display == null); if (testCase.statVal.Length <= 40) return testCase; } } if (testCase.statVal.Length <= 40) return testCase; //suppress warning message for some stats such as userID, email. var longStatIgnoreList = new List<string>() {"61","118"}; if (!longStatIgnoreList.Contains(testCase.statName)) { ALogger.LogWarn("[{0}] value length is over 40 characters, [{1}]", testCase.statName, testCase.statVal); } testCase.statVal = testCase.statVal.Substring(0, 37) + "..."; return testCase; }
public static void AddValidationStat(List<string> validationIDList, ref List<LogStatItem> logStatList, LogStatItem tmpLogStat, string valid, int total) { var i = 0; if (validationIDList.Count == 0 || total == 0) { logStatList.Add(CreateLogStatInstance(valid, "0", "", tmpLogStat)); } else { foreach (var varidateIds in validationIDList) { if (i == 0) { if (i == validationIDList.Count - 1) logStatList.Add(CreateLogStatInstance(valid, total + "[" + varidateIds + "]", "", tmpLogStat)); else logStatList.Add(CreateLogStatInstance(valid, total + "[" + varidateIds, "", tmpLogStat)); } else { if (i == validationIDList.Count - 1) logStatList.Add(CreateLogStatInstance(valid + "." + i, varidateIds + "]", "", tmpLogStat)); else logStatList.Add(CreateLogStatInstance(valid + "." + i, varidateIds, "", tmpLogStat)); } i++; } } }
public static List<LogStatItem> ConvertToLogStat(IReadOnlyCollection<TestResult> records) { if (records == null) { return null; } var uUid = ""; var logStatList = new List<LogStatItem>(); foreach (var item in records) { try { var testCaseFailIdList = new List<string>(); var testCaseAlertIdList = new List<string>(); var testCaseWarnIdList = new List<string>(); var testCaseFailIds = new StringBuilder(); var testCaseAlertIds = new StringBuilder(); var testCaseWarnIds = new StringBuilder(); var total = 0; var pass = 0; var info = 0; var warning = 0; var alert = 0; var fail = 0; var tmpLogStat = new LogStatItem { timeStamp = Convert.ToString(item.ServerDbsDateTime), uuid = item.UUID, machineGuid = GuidValidator(item.MachineID), installGuid = zeroGuid, product = ProductName }; if (IsEWM(item)) { ALogger.LogInfo("ConvertToLogStat: EWM Mapping {0}: {1}-{2}-{3}", item.UUID, item.ProdName, item.ProdVers, item.TestCases.Count); DataMapper.MapStatCodeEWM(item); logStatList.Add(CreateLogStatInstance("isewm", "1", "", tmpLogStat)); } else { logStatList.Add(CreateLogStatInstance("isewm", "0", "", tmpLogStat)); } foreach (var testCase in item.TestCases) { total++; var name = testCase.ID.Replace("#test.", ""); #region process validation switch (testCase.Valid) { case "pass": pass++; break; case "fail": fail++; if (testCaseFailIds.Length > 0 && testCaseFailIds[testCaseFailIds.Length - 1] != ',') testCaseFailIds.Append(","); if (name == "24") { name = "CMPNAME"; } testCaseFailIds.Append(name); if (testCaseFailIds.Length >= 30 || (total == item.TestCases.Count)) { testCaseFailIdList.Add(testCaseFailIds.ToString()); testCaseFailIds.Clear(); testCaseFailIds.Append(","); } break; case "alert": alert++; if (testCaseAlertIds.Length > 0 && testCaseAlertIds[testCaseAlertIds.Length - 1] != ',') testCaseAlertIds.Append(","); if (name == "24") { name = "CMPNAME"; } testCaseAlertIds.Append(name); if (testCaseAlertIds.Length >= 30 || (total == item.TestCases.Count)) { testCaseAlertIdList.Add(testCaseAlertIds.ToString()); testCaseAlertIds.Clear(); testCaseAlertIds.Append(","); } break; case "warning": warning++; if (testCaseWarnIds.Length > 0 && testCaseWarnIds[testCaseWarnIds.Length - 1] != ',') testCaseWarnIds.Append(","); if (name == "24") { name = "CMPNAME"; } testCaseWarnIds.Append(name); if (testCaseWarnIds.Length >= 30 || (total == item.TestCases.Count)) { testCaseWarnIdList.Add(testCaseWarnIds.ToString()); testCaseWarnIds.Clear(); testCaseWarnIds.Append(","); } break; case "info": info++; break; } #endregion process validation #region process test case if (name == "24") { name = "CMPNAME"; } var value = testCase.Value; var desc = testCase.Description; if (name == "127" && !string.IsNullOrEmpty(value)) { const string pattern = @"([\D^.,]*)([\d|.]*),"; var rgx = new Regex(pattern, RegexOptions.IgnoreCase); var matches = rgx.Matches(value); logStatList.AddRange(from Match match in matches where match.Success let testName = match.Groups[1].ToString() let testValue = match.Groups[2].ToString() select CreateLogStatInstance(ShortenTest127LongName(name + testName), testValue, desc, tmpLogStat) into logStat where logStat != null select logStat); } else if (name == "142") { const string pattern = @"\{(Primary Screen=(\w+),\{x=(-*\d+),y=(-*\d+),width=(-*\d+),height=(-*\d+)\})\}+"; var rgx = new Regex(pattern, RegexOptions.IgnoreCase); var matches = rgx.Matches(value); var i = 0; logStatList.AddRange(from Match match in matches where match.Success let newName = String.Format("{0}.{1}", name, ++i) let newValue = String.Format("{0}{1},{2},{3},{4}", match.Groups[2].Value.Equals("True", StringComparison.CurrentCultureIgnoreCase) ? "Primary " : "", match.Groups[3].Value, match.Groups[4].Value, match.Groups[5].Value, match.Groups[6].Value) select CreateLogStatInstance(newName, newValue, desc, tmpLogStat) into logStat where logStat != null select logStat); } else { if (name == "48") // TODO: consider to apply this logic if "@" can be removed from all test case { desc = desc.TrimToEnd("@"); } value = Regex.Replace(value, @"\s+", " "); desc = Regex.Replace(desc, @"\s+", " "); desc = desc.Trim(); var logStat = CreateLogStatInstance(name.Truncate(10), value, desc, tmpLogStat); if (logStat != null) logStatList.Add(logStat); } #endregion } #region add test cases // Fail if (testCaseFailIds.Length > 1) { testCaseFailIdList.Add(testCaseFailIds.ToString()); } if (testCaseAlertIds.Length > 1) { testCaseAlertIdList.Add(testCaseAlertIds.ToString()); } if (testCaseWarnIds.Length > 1) { testCaseWarnIdList.Add(testCaseWarnIds.ToString()); } var other = total - pass - info - warning - alert - fail; if(item.RunningMode!=null) logStatList.Add(CreateLogStatInstance("runmode", item.RunningMode, "", tmpLogStat)); logStatList.Add(CreateLogStatInstance("total", total.ToString(), "", tmpLogStat)); logStatList.Add(CreateLogStatInstance("pass", pass.ToString(), "", tmpLogStat)); logStatList.Add(CreateLogStatInstance("info", info.ToString(), "", tmpLogStat)); AddValidationStat(testCaseFailIdList, ref logStatList, tmpLogStat, "fail", fail); AddValidationStat(testCaseAlertIdList, ref logStatList, tmpLogStat, "alert", alert); AddValidationStat(testCaseWarnIdList, ref logStatList, tmpLogStat, "warn", warning); logStatList.Add(CreateLogStatInstance("other", other.ToString(), "", tmpLogStat)); if (item.ServerCompName != null) logStatList.Add(CreateLogStatInstance("servname", item.ServerCompName, "", tmpLogStat)); if (item.ServerDatacenter != null) logStatList.Add(CreateLogStatInstance("envname", item.ServerDatacenter, "", tmpLogStat)); logStatList.Add(CreateLogStatInstance("oldid", item.TestID.ToString(), "", tmpLogStat)); #endregion add test cases } catch (Exception ex) { ALogger.LogError("ConvertToLogStat: error processing item user {0}: {1}", uUid, ex.Message); } } ALogger.LogInfo("ConvertToLogStat: Done convert stat {0}", logStatList.Count); return logStatList; }