public void WriteXml(XmlWriter writer) { if (writer == null || !this.IsValid) { return; } // <result version="" date=""> // <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/> // <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/> // </result> writer.WriteStartElement("result"); writer.WriteAttributeString("version", _version); writer.WriteAttributeString("date", XmlConvert.ToString(_date, XmlDateTimeSerializationMode.RoundtripKind)); for (int i = 0; i < _categories.Count; i++) { SvgTestCategory category = _categories[i]; if (category != null && category.IsValid) { category.WriteXml(writer); } } writer.WriteEndElement(); }
public bool IsEqualTo(SvgTestCategory other) { if (other == null) { return(false); } if (!string.Equals(_label, other._label)) { return(false); } if (_total != other._total) { return(false); } if (_unknowns != other._unknowns) { return(false); } if (_failures != other._failures) { return(false); } if (_successes != other._successes) { return(false); } if (_partials != other._partials) { return(false); } return(true); }
public void ReadXml(XmlReader reader) { if (reader == null || reader.NodeType != XmlNodeType.Element) { return; } if (!string.Equals(reader.Name, "result", StringComparison.OrdinalIgnoreCase)) { return; } if (_categories == null | _categories.Count != 0) { _categories = new List <SvgTestCategory>(); } // <result version="" date=""> // <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/> // <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/> // </result> string version = reader.GetAttribute("version"); string date = reader.GetAttribute("date"); if (!string.IsNullOrWhiteSpace(version) && !string.IsNullOrWhiteSpace(date)) { _version = version; _date = XmlConvert.ToDateTime(date, XmlDateTimeSerializationMode.RoundtripKind); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase)) { SvgTestCategory category = new SvgTestCategory(reader); if (category.IsValid) { _categories.Add(category); } } } else if (reader.NodeType == XmlNodeType.EndElement) { if (string.Equals(reader.Name, "result", StringComparison.OrdinalIgnoreCase)) { break; } } } } }
public static bool AreEqual(SvgTestCategory left, SvgTestCategory right) { if (left == null && right == null) { return(true); } if (left == null && right != null) { return(false); } if (left != null && right == null) { return(false); } return(left.IsEqualTo(right)); }
public bool IsEqualTo(SvgTestResult other) { if (other == null) { return(false); } if (!string.Equals(this._version, other._version)) { return(false); } if (this._categories == null && other._categories == null) { return(true); } if (this._categories == null && other._categories != null) { return(false); } if (this._categories != null && other._categories == null) { return(false); } if (this._categories.Count != other._categories.Count) { return(false); } int itemCount = _categories.Count; for (int i = 0; i < itemCount; i++) { if (!SvgTestCategory.AreEqual(this._categories[i], other._categories[i])) { return(false); } } return(true); }
private void SaveTreeViewCategory(XmlWriter writer, TreeViewItem categoryItem, SvgTestCategory testCategory) { int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0; writer.WriteStartElement("category"); writer.WriteAttributeString("label", testCategory.Label); ItemCollection treeItems = categoryItem.Items; for (int j = 0; j < treeItems.Count; j++) { TreeViewItem treeItem = treeItems[j] as TreeViewItem; if (treeItem != null) { SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo; if (testInfo != null) { testInfo.WriteXml(writer); total++; SvgTestState testState = testInfo.State; switch (testState) { case SvgTestState.Unknown: unknowns++; break; case SvgTestState.Failure: failures++; break; case SvgTestState.Success: successes++; break; case SvgTestState.Partial: partials++; break; } } } } writer.WriteEndElement(); testCategory.SetValues(total, unknowns, failures, successes, partials); }
private void SaveTreeView(XmlWriter writer) { if (writer == null) { return; } ItemCollection treeNodes = treeView.Items; if (treeNodes == null || treeNodes.Count == 0) { return; } SvgTestResult testResult = new SvgTestResult(); writer.WriteStartDocument(); writer.WriteStartElement("tests"); for (int i = 0; i < treeNodes.Count; i++) { TreeViewItem categoryItem = treeNodes[i] as TreeViewItem; if (categoryItem != null) { BulletDecorator header = categoryItem.Header as BulletDecorator; if (header == null) { continue; } TextBlock headerText = header.Child as TextBlock; if (headerText == null) { continue; } SvgTestCategory testCategory = new SvgTestCategory(headerText.Text); this.SaveTreeViewCategory(writer, categoryItem, testCategory); if (testCategory.IsValid) { testResult.Categories.Add(testCategory); } } } writer.WriteEndElement(); writer.WriteEndDocument(); if (_testResults == null) { _testResults = new List <SvgTestResult>(); } if (testResult.IsValid) { if (_testResults.Count == 0) { _testResults.Add(testResult); } } else { int foundAt = -1; for (int i = 0; i < _testResults.Count; i++) { SvgTestResult nextResult = _testResults[i]; if (nextResult != null && nextResult.IsValid) { if (string.Equals(nextResult.Version, testResult.Version)) { foundAt = i; break; } } } if (foundAt >= 0) { SvgTestResult nextResult = _testResults[foundAt]; if (!SvgTestResult.AreEqual(nextResult, testResult)) { _testResults[foundAt] = testResult; } } else { _testResults.Add(testResult); } } }
private void LoadTreeViewCategory(XmlReader reader, TreeViewItem categoryItem, SvgTestCategory testCategory) { int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0; int itemCount = 0; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (string.Equals(reader.Name, "test", StringComparison.OrdinalIgnoreCase)) { SvgTestInfo testInfo = new SvgTestInfo(reader); if (!testInfo.IsEmpty) { TextBlock headerText = new TextBlock(); headerText.Text = string.Format("({0:D3}) - {1}", itemCount, testInfo.Title); headerText.Margin = new Thickness(3, 0, 0, 0); Ellipse bullet = new Ellipse(); bullet.Height = 16; bullet.Width = 16; bullet.Fill = testInfo.StateBrush; bullet.Stroke = Brushes.DarkGray; bullet.StrokeThickness = 1; BulletDecorator decorator = new BulletDecorator(); decorator.Bullet = bullet; decorator.Margin = new Thickness(0, 0, 10, 0); decorator.Child = headerText; TreeViewItem treeItem = new TreeViewItem(); treeItem.Header = decorator; treeItem.Padding = new Thickness(3); treeItem.FontSize = 12; treeItem.FontWeight = FontWeights.Normal; treeItem.Tag = testInfo; categoryItem.Items.Add(treeItem); itemCount++; total++; SvgTestState testState = testInfo.State; switch (testState) { case SvgTestState.Unknown: unknowns++; break; case SvgTestState.Failure: failures++; break; case SvgTestState.Success: successes++; break; case SvgTestState.Partial: partials++; break; } } } } else if (reader.NodeType == XmlNodeType.EndElement) { if (string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase)) { break; } } } testCategory.SetValues(total, unknowns, failures, successes, partials); }
private void LoadTreeView(XmlReader reader) { SvgTestResult testResult = new SvgTestResult(); treeView.BeginInit(); treeView.Items.Clear(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase)) { // <category label="Animations"> string category = reader.GetAttribute("label"); if (!string.IsNullOrWhiteSpace(category)) { SvgTestCategory testCategory = new SvgTestCategory(category); TextBlock headerText = new TextBlock(); headerText.Text = category; headerText.Margin = new Thickness(3, 0, 0, 0); BulletDecorator decorator = new BulletDecorator(); if (_folderClose != null) { Image image = new Image(); image.Source = _folderClose; decorator.Bullet = image; } else { Ellipse bullet = new Ellipse(); bullet.Height = 16; bullet.Width = 16; bullet.Fill = Brushes.Goldenrod; bullet.Stroke = Brushes.DarkGray; bullet.StrokeThickness = 1; decorator.Bullet = bullet; } decorator.Margin = new Thickness(0, 0, 10, 0); decorator.Child = headerText; TreeViewItem categoryItem = new TreeViewItem(); categoryItem.Header = decorator; categoryItem.Margin = new Thickness(0, 3, 0, 3); categoryItem.FontSize = 14; categoryItem.FontWeight = FontWeights.Bold; treeView.Items.Add(categoryItem); LoadTreeViewCategory(reader, categoryItem, testCategory); if (testCategory.IsValid) { testResult.Categories.Add(testCategory); } } } } if (_testResults == null) { _testResults = new List <SvgTestResult>(); } bool saveResults = false; if (testResult.IsValid) { if (_testResults.Count == 0) { _testResults.Add(testResult); saveResults = true; } else { int foundAt = -1; for (int i = 0; i < _testResults.Count; i++) { SvgTestResult nextResult = _testResults[i]; if (nextResult != null && nextResult.IsValid) { if (string.Equals(nextResult.Version, testResult.Version)) { foundAt = i; break; } } } if (foundAt >= 0) { SvgTestResult nextResult = _testResults[foundAt]; if (!SvgTestResult.AreEqual(nextResult, testResult)) { _testResults[foundAt] = testResult; saveResults = true; } } else { _testResults.Add(testResult); saveResults = true; } } } if (saveResults) { if (!string.IsNullOrWhiteSpace(_testResultsPath)) { string backupFile = null; if (File.Exists(_testResultsPath)) { backupFile = IoPath.ChangeExtension(_testResultsPath, ".bak"); try { if (File.Exists(backupFile)) { File.Delete(backupFile); } File.Move(_testResultsPath, backupFile); } catch (Exception ex) { MessageBox.Show(ex.ToString(), AppErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error); return; } } try { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.Encoding = Encoding.UTF8; using (XmlWriter writer = XmlWriter.Create(_testResultsPath, settings)) { this.SaveTestResults(writer); } } catch (Exception ex) { if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile)) { File.Move(backupFile, _testResultsPath); } MessageBox.Show(ex.ToString(), AppErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error); } } } treeView.EndInit(); }
private Table CreateSummaryTable() { int resultCount = _testResults.Count; Table summaryTable = new Table(); summaryTable.CellSpacing = 0; summaryTable.BorderBrush = Brushes.Gray; summaryTable.BorderThickness = new Thickness(1); summaryTable.Margin = new Thickness(16, 0, 16, 16); TableColumn categoryCol = new TableColumn(); categoryCol.Width = new GridLength(2, GridUnitType.Star); summaryTable.Columns.Add(categoryCol); TableColumn totalCol = new TableColumn(); totalCol.Width = new GridLength(1, GridUnitType.Star); summaryTable.Columns.Add(totalCol); for (int i = 0; i < resultCount; i++) { TableColumn successCol = new TableColumn(); successCol.Width = new GridLength(1, GridUnitType.Star); summaryTable.Columns.Add(successCol); } TableRowGroup headerGroup = new TableRowGroup(); headerGroup.Background = Brushes.LightGray; TableRow headerRow = new TableRow(); headerRow.Cells.Add(CreateHeaderCell("Category", false, false)); headerRow.Cells.Add(CreateHeaderCell("Total", false, false)); for (int i = 0; i < resultCount; i++) { SvgTestResult testResult = _testResults[i]; headerRow.Cells.Add(CreateHeaderCellEx(testResult.Version, (i == (resultCount - 1)), false)); } headerGroup.Rows.Add(headerRow); summaryTable.RowGroups.Add(headerGroup); int[] successValues = new int[resultCount]; int totalValue = 0; // Start with color of newer vesions Brush[] changedBrushes = { Brushes.LightCyan, Brushes.LightGoldenrodYellow, Brushes.LightGreen, Brushes.LightSalmon, Brushes.LightSeaGreen, // Version 1.2 Brushes.LightSkyBlue, // Version 1.1 Brushes.LightPink, Brushes.LightSteelBlue, Brushes.LightSkyBlue, Brushes.LightSkyBlue }; for (int k = 0; k < _categoryLabels.Count; k++) { TableRowGroup resultGroup = new TableRowGroup(); TableRow resultRow = new TableRow(); bool lastBottom = (k == (_categoryLabels.Count - 1)); resultRow.Cells.Add(CreateCell(_categoryLabels[k], false, lastBottom)); for (int i = 0; i < resultCount; i++) { SvgTestResult testResult = _testResults[i]; IList <SvgTestCategory> testCategories = testResult.Categories; SvgTestCategory testCategory = testCategories[k]; if (!testCategory.IsValid) { continue; } int total = testCategory.Total; if (i == 0) { resultRow.Cells.Add(CreateCell(total, false, lastBottom)); } successValues[i] = testCategory.Successes; totalValue = total; bool lastRight = (i == (resultCount - 1)); double percentValue = Math.Round(testCategory.Successes * 100.0d / total, 2); resultRow.Cells.Add(CreateCell(percentValue.ToString("00.00"), lastRight, lastBottom, false, false)); } int cellCount = resultRow.Cells.Count; if (IsAllZero(successValues)) { for (int i = 1; i < cellCount; i++) { resultRow.Cells[i].Background = Brushes.PaleVioletRed; } } else if (IsAllDone(successValues, totalValue)) { for (int i = 1; i < cellCount; i++) { resultRow.Cells[i].Background = Brushes.Silver; } } else { if (IsNowDone(successValues, totalValue)) { for (int i = 1; i < cellCount; i++) { resultRow.Cells[i].Background = Brushes.Silver; } } if (resultCount > 1) { int i = 0; for (int j = (resultCount - 1); j >= 1; j--) { var selectedBrush = changedBrushes[i]; i++; if (IsBetterResult(successValues, j)) { resultRow.Cells[cellCount - i].Background = selectedBrush; } } } } resultGroup.Rows.Add(resultRow); summaryTable.RowGroups.Add(resultGroup); } return(summaryTable); }
private Table CreateResultTable(IList <SvgTestCategory> testCategories) { Table resultTable = new Table(); resultTable.CellSpacing = 0; resultTable.BorderBrush = Brushes.Gray; resultTable.BorderThickness = new Thickness(1); resultTable.Margin = new Thickness(16, 0, 16, 16); TableColumn categoryCol = new TableColumn(); TableColumn failureCol = new TableColumn(); TableColumn successCol = new TableColumn(); TableColumn partialCol = new TableColumn(); TableColumn unknownCol = new TableColumn(); TableColumn totalCol = new TableColumn(); categoryCol.Width = new GridLength(2, GridUnitType.Star); failureCol.Width = new GridLength(1, GridUnitType.Star); successCol.Width = new GridLength(1, GridUnitType.Star); partialCol.Width = new GridLength(1, GridUnitType.Star); unknownCol.Width = new GridLength(1, GridUnitType.Star); totalCol.Width = new GridLength(1, GridUnitType.Star); resultTable.Columns.Add(categoryCol); resultTable.Columns.Add(failureCol); resultTable.Columns.Add(successCol); resultTable.Columns.Add(partialCol); resultTable.Columns.Add(unknownCol); resultTable.Columns.Add(totalCol); TableRowGroup headerGroup = new TableRowGroup(); headerGroup.Background = Brushes.LightGray; TableRow headerRow = new TableRow(); headerRow.Cells.Add(CreateHeaderCell("Category", false, false)); headerRow.Cells.Add(CreateHeaderCell("Failure", false, false)); headerRow.Cells.Add(CreateHeaderCell("Success", false, false)); headerRow.Cells.Add(CreateHeaderCell("Partial", false, false)); headerRow.Cells.Add(CreateHeaderCell("Unknown", false, false)); headerRow.Cells.Add(CreateHeaderCell("Total", true, false)); headerGroup.Rows.Add(headerRow); resultTable.RowGroups.Add(headerGroup); for (int i = 0; i < testCategories.Count; i++) { SvgTestCategory testCategory = testCategories[i]; if (!testCategory.IsValid) { continue; } TableRowGroup resultGroup = new TableRowGroup(); TableRow resultRow = new TableRow(); bool lastBottom = (i == (testCategories.Count - 1)); resultRow.Cells.Add(CreateCell(testCategory.Label, false, lastBottom)); resultRow.Cells.Add(CreateCell(testCategory.Failures, false, lastBottom)); resultRow.Cells.Add(CreateCell(testCategory.Successes, false, lastBottom)); resultRow.Cells.Add(CreateCell(testCategory.Partials, false, lastBottom)); resultRow.Cells.Add(CreateCell(testCategory.Unknowns, false, lastBottom)); resultRow.Cells.Add(CreateCell(testCategory.Total, true, lastBottom)); resultGroup.Rows.Add(resultRow); resultTable.RowGroups.Add(resultGroup); } return(resultTable); }
private Table CreateSummaryTable() { int resultCount = _testResults.Count; Table summaryTable = new Table(); summaryTable.CellSpacing = 0; summaryTable.BorderBrush = Brushes.Gray; summaryTable.BorderThickness = new Thickness(1); summaryTable.Margin = new Thickness(16, 0, 16, 16); TableColumn categoryCol = new TableColumn(); categoryCol.Width = new GridLength(2, GridUnitType.Star); summaryTable.Columns.Add(categoryCol); TableColumn totalCol = new TableColumn(); totalCol.Width = new GridLength(1, GridUnitType.Star); summaryTable.Columns.Add(totalCol); for (int i = 0; i < resultCount; i++) { TableColumn successCol = new TableColumn(); successCol.Width = new GridLength(1, GridUnitType.Star); summaryTable.Columns.Add(successCol); } TableRowGroup headerGroup = new TableRowGroup(); headerGroup.Background = Brushes.LightGray; TableRow headerRow = new TableRow(); headerRow.Cells.Add(CreateHeaderCell("Category", false, false)); headerRow.Cells.Add(CreateHeaderCell("Total", false, false)); for (int i = 0; i < resultCount; i++) { SvgTestResult testResult = _testResults[i]; headerRow.Cells.Add(CreateHeaderCell(testResult.Version + " (%)", (i == (resultCount - 1)), false)); } headerGroup.Rows.Add(headerRow); summaryTable.RowGroups.Add(headerGroup); int[] successValues = new int[resultCount]; int totalValue = 0; for (int k = 0; k < _categoryLabels.Count; k++) { TableRowGroup resultGroup = new TableRowGroup(); TableRow resultRow = new TableRow(); bool lastBottom = (k == (_categoryLabels.Count - 1)); resultRow.Cells.Add(CreateCell(_categoryLabels[k], false, lastBottom)); for (int i = 0; i < resultCount; i++) { SvgTestResult testResult = _testResults[i]; IList <SvgTestCategory> testCategories = testResult.Categories; SvgTestCategory testCategory = testCategories[k]; if (!testCategory.IsValid) { continue; } int total = testCategory.Total; if (i == 0) { resultRow.Cells.Add(CreateCell(total, false, lastBottom)); } successValues[i] = testCategory.Successes; totalValue = total; bool lastRight = (i == (resultCount - 1)); double percentValue = Math.Round(testCategory.Successes * 100.0d / total, 2); resultRow.Cells.Add(CreateCell(percentValue.ToString("00.00"), lastRight, lastBottom, false, false)); } int cellCount = resultRow.Cells.Count; if (IsAllZero(successValues)) { for (int i = 1; i < cellCount; i++) { resultRow.Cells[i].Background = Brushes.PaleVioletRed; } } else if (IsAllDone(successValues, totalValue)) { for (int i = 1; i < cellCount; i++) { resultRow.Cells[i].Background = Brushes.Silver; } } else { // TODO: Improve this, currently only good for two results... if (resultCount > 1 && IsBetterResult(successValues, resultCount - 1)) { resultRow.Cells[cellCount - 1].Background = Brushes.LightSkyBlue; } } resultGroup.Rows.Add(resultRow); summaryTable.RowGroups.Add(resultGroup); } return(summaryTable); }