private void BuildRows(ResultTableBuilder tableBuilder, CheckResult result) { if (result.Content == null) { return; } for (int i = 0; i < result.Content.Count; i++) { var rowErrorList = (from e in result.ErrorList where e.Key.Row == i select e).ToList(); var rowWarningList = (from w in result.WarningList where w.Key.Row == i select w).ToList(); if (rowErrorList.Count == 0 && rowWarningList.Count == 0) { continue; } tableBuilder.BeginRow(); var row = result.Content[i]; for (int j = 0; j < row.Length; j++) { var cellError = (from e in rowErrorList where e.Key.Col == j select e.Value).FirstOrDefault(); var cellWarning = (from w in rowWarningList where w.Key.Col == j select w.Value).FirstOrDefault(); tableBuilder.AddCell(row[j], cellError == null ? null : cellError.ToArray(), cellWarning == null ? null : cellWarning.ToArray()); } var rowError = (from e in rowErrorList where e.Key.Col == -1 select e.Value).FirstOrDefault(); var rowWarning = (from w in rowWarningList where w.Key.Col == -1 select w.Value).FirstOrDefault(); tableBuilder.EndRow(rowError == null ? null : rowError.ToArray(), rowWarning == null ? null : rowWarning.ToArray()); } }
public string ToTable(bool skipEmpty = true, List <string> header = null) { // Todo: <jackrole> csv error/waring are not output to view result. add them in the future. ResultTableBuilder tableString = new ResultTableBuilder(); tableString.BeginTable(); foreach (var result in _result) { if (skipEmpty && !result.Any()) { continue; } Debug.Assert(result.Content != null && result.Content.Count > 0, ""); var colSpan = result.Content[0].Length; // add a division row with a name if possible. if (_result.IndexOf(result) != 0) { tableString.InsertDivisionRow(result.Name, colSpan); } else if (result.Name != null) { tableString.InsertDivisionRow(result.Name, colSpan); } if (header != null) { tableString.BeginRow(); header.ForEach(x => tableString.AddCell(x, null, null)); tableString.EndRow(null, null); } this.BuildRows(tableString, result); } tableString.EndTable(); return(tableString.ToString()); }