public void testTableRowParsing() { StagingTable table = new StagingTable(); table.setId("test_table"); table.setColumnDefinitions(new List <IColumnDefinition>() { new StagingColumnDefinition("key1", "Input 1", ColumnType.INPUT) }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { ",1,2,3" }); table.getRawRows().Add(new List <String>() { "1,2,3," }); StagingDataProvider.initTable(table); Assert.AreEqual(2, table.getTableRows().Count); //StagingTableRow List <ITableRow> tablerows = table.getTableRows(); StagingTableRow row = (tablerows[0] as StagingTableRow); Assert.AreEqual(4, row.getInputs()["key1"].Count); row = (tablerows[1] as StagingTableRow); Assert.AreEqual(4, row.getInputs()["key1"].Count); }
public void testNumericRangeTableMatch() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("psa"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("psa"); def1.setName("PSA Value"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("description"); def2.setName("PSA Description"); def2.setType(ColumnType.DESCRIPTION); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "0.1", "0.1 or less nanograms/milliliter (ng/ml)" }); table.getRawRows().Add(new List <String>() { "0.2-999.9", "0.2 – 999.9 ng/ml" }); provider.addTable(table); TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider); Assert.AreEqual(0, staging.findMatchingTableRow("psa", "psa", "0.1")); Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "0.2")); Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "500")); Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "500.99")); Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "500.0001")); Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "999.9")); Assert.AreEqual(-1, staging.findMatchingTableRow("psa", "psa", "1000")); Assert.AreEqual(-1, staging.findMatchingTableRow("psa", "psa", "-1")); Assert.AreEqual(-1, staging.findMatchingTableRow("psa", "psa", "0.01")); }
public void testRangeParsing() { StagingTable table = _STAGING.getTable("path_n_daj"); Assert.IsNotNull(table); Assert.AreEqual("p0I-", table.getRawRows()[2][0]); StagingTableRow tablerow = (table.getTableRows()[2] as StagingTableRow); Assert.AreEqual("p0I-", tablerow.getInputs()["path_n"][0].getLow()); tablerow = (table.getTableRows()[2] as StagingTableRow); Assert.AreEqual("p0I-", tablerow.getInputs()["path_n"][0].getHigh()); }
private void Setup() { int iNumColumnsUsed = 0; List <int> lstDescriptionColumns = new List <int>(); String sColumnName = ""; String sColumnLabel = ""; StagingTable thisTable = mStaging.getTable(msTableId); //String sVariableTitle = thisTable.getTitle(); //String sVariableSubtitle = thisTable.getSubtitle(); Text = msInputVar; // Convert the notes, which are in MarkDown, to HTML String sNotes = thisTable.getNotes(); if (sNotes == null) { sNotes = ""; } CommonMark.CommonMarkSettings settings = CommonMark.CommonMarkSettings.Default.Clone(); settings.RenderSoftLineBreaksAsLineBreaks = true; String result = CommonMark.CommonMarkConverter.Convert(sNotes, settings); result = result.Replace("<p>", "<p style=\"font-family=Microsoft Sans Serif;font-size:11px\">"); webBrPickerNotes.DocumentText = result; // Set the rows to auto size to view the contents of larger text cells dataGridViewPicker.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; // Obtain the number of columns and rows for the table List <IColumnDefinition> lstColDefs = thisTable.getColumnDefinitions(); StagingColumnDefinition thisColDef = null; int iNumColumns = 0; int iNumRows = 0; ColumnType cType = 0; if (thisTable.getRawRows() != null) { iNumRows = thisTable.getRawRows().Count; } if (lstColDefs != null) { iNumColumns = lstColDefs.Count; for (int iColIndex = 0; iColIndex < lstColDefs.Count; iColIndex++) { thisColDef = (StagingColumnDefinition)lstColDefs[iColIndex]; // Get the column type. If the type is "INPUT" OR "DESCRIPTION", then display the column. Otherwise skip it. cType = thisColDef.getType(); if ((cType == ColumnType.INPUT) || (cType == ColumnType.DESCRIPTION)) { // Add a new column to the table data view sColumnName = "ColumnName"; sColumnName += iColIndex; sColumnLabel = thisColDef.getName(); dataGridViewPicker.Columns.Add(sColumnName, sColumnLabel); iNumColumnsUsed++; // keep track of descrption columns if (cType == ColumnType.DESCRIPTION) { lstDescriptionColumns.Add(iColIndex); } // Need to keep track of the first INPUT column. That column contains the information we pass back if a user // selects the row or cell. if ((cType == ColumnType.INPUT) && (miInputCol == -1)) { miInputCol = iNumColumnsUsed - 1; } dataGridViewPicker.Columns[iNumColumnsUsed - 1].DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridViewPicker.Columns[iNumColumnsUsed - 1].SortMode = DataGridViewColumnSortMode.NotSortable; } } } // Set the widths of the columns in the datagridview. Set the input column to be small and the description columns to be large // We do this so that if we only have an input and description will fill the entire grid view (no veritical scrolling). // If we have 2 or more desription fields, then we need to fit them all in. // int iWidthDivisor = 0; int iViewableWidth = dataGridViewPicker.Width - 50; // remove size of input column if (iNumColumnsUsed > 1) { iWidthDivisor = (int)((double)iViewableWidth / (double)(iNumColumnsUsed - 1)); } else { iWidthDivisor = 300; } for (int i = 0; i < dataGridViewPicker.Columns.Count; i++) { if (i == miInputCol) { if (iNumColumnsUsed == 1) { dataGridViewPicker.Columns[i].Width = 300; } else { dataGridViewPicker.Columns[i].Width = 50; } } else { dataGridViewPicker.Columns[i].Width = iWidthDivisor; } } // Now loop through the table rows and add each cell to the table String sCellValue = ""; for (int iRowIndex = 0; iRowIndex < iNumRows; iRowIndex++) { dataGridViewPicker.RowCount++; dataGridViewPicker.Rows[iRowIndex].Height = 40; for (int iColIndex = 0; iColIndex < iNumColumns; iColIndex++) { thisColDef = (StagingColumnDefinition)lstColDefs[iColIndex]; cType = thisColDef.getType(); if ((cType == ColumnType.INPUT) || (cType == ColumnType.DESCRIPTION)) { sCellValue = thisTable.getRawRows()[iRowIndex][iColIndex]; dataGridViewPicker[iColIndex, iRowIndex].Value = sCellValue; } } } // See if there are two or more description fields. If so, see if we can find one // that has a label of "Description" miDescriptionColumn = -1; if (lstDescriptionColumns.Count > 1) { sColumnLabel = ""; for (int iColIndex = 0; iColIndex < lstDescriptionColumns.Count; iColIndex++) { sColumnLabel = ((StagingColumnDefinition)lstColDefs[lstDescriptionColumns[iColIndex]]).getName(); if (sColumnLabel == "Description") { miDescriptionColumn = lstDescriptionColumns[iColIndex]; } } if (miDescriptionColumn == -1) { miDescriptionColumn = lstDescriptionColumns[0]; } } else if (lstDescriptionColumns.Count == 0) { miDescriptionColumn = 0; // for tables that do not have a description. point to the code } else { miDescriptionColumn = lstDescriptionColumns[0]; } }
public void testInvalidContext() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("table_input1"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1" }); table.getRawRows().Add(new List <String>() { "2" }); provider.addTable(table); table = new StagingTable(); table.setId("table_selection"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*" }); provider.addTable(table); table = new StagingTable(); table.setId("table_mapping"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("final_output"); def2.setName("Output"); def2.setType(ColumnType.ENDPOINT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*", "VALUE:ABC" }); provider.addTable(table); StagingSchema schema = new StagingSchema(); schema.setId("schema_test"); schema.setSchemaSelectionTable("table_selection"); List <StagingSchemaInput> inputs = new List <StagingSchemaInput>(); inputs.Add(new StagingSchemaInput("input1", "Input 1", "table_input1")); schema.setInputs(inputs); List <StagingSchemaOutput> outputs = new List <StagingSchemaOutput>(); outputs.Add(new StagingSchemaOutput("final_output", "Final Output")); schema.setOutputs(outputs); StagingMapping mapping = new StagingMapping(); mapping.setId("m1"); List <IKeyValue> mapInitialContext = new List <IKeyValue>(); mapInitialContext.Add(new StagingKeyValue("input1", "XXX")); mapping.setInitialContext(mapInitialContext); StagingTablePath path = new StagingTablePath(); path.setId("table_mapping"); HashSet <String> pathInputs = new HashSet <String>(); pathInputs.Add("input1"); path.setInputs(pathInputs); HashSet <String> pathOutputs = new HashSet <String>(); pathOutputs.Add("final_output"); path.setOutputs(pathOutputs); List <ITablePath> mapTablePaths = new List <ITablePath>(); mapTablePaths.Add(path); mapping.setTablePaths(mapTablePaths); List <IMapping> schemaMappings = new List <IMapping>(); schemaMappings.Add(mapping); schema.setMappings(schemaMappings); try { provider.addSchema(schema); Assert.Fail("Add Schema should have thrown an exception."); } catch (System.InvalidOperationException e) { Assert.IsTrue(e.Message.Contains("not allowed since it is also defined as an input")); } }
public void testGetInputsWithContext() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("table_input1"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1" }); table.getRawRows().Add(new List <String>() { "2" }); provider.addTable(table); table = new StagingTable(); table.setId("table_input2"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 2"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "" }); table.getRawRows().Add(new List <String>() { "A" }); table.getRawRows().Add(new List <String>() { "B" }); provider.addTable(table); table = new StagingTable(); table.setId("table_selection"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*" }); provider.addTable(table); table = new StagingTable(); table.setId("table_mapping"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("input2"); def2.setName("Input 2"); def2.setType(ColumnType.INPUT); StagingColumnDefinition def3 = new StagingColumnDefinition(); def3.setKey("mapped_field"); def3.setName("Temp value"); def3.setType(ColumnType.INPUT); StagingColumnDefinition def4 = new StagingColumnDefinition(); def4.setKey("final_output"); def4.setName("Output"); def4.setType(ColumnType.ENDPOINT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2, def3, def4 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*", "*", "*", "VALUE:ABC" }); provider.addTable(table); StagingSchema schema = new StagingSchema(); schema.setId("schema_test"); schema.setSchemaSelectionTable("table_selection"); List <StagingSchemaInput> inputs = new List <StagingSchemaInput>(); inputs.Add(new StagingSchemaInput("input1", "Input 1", "table_input1")); inputs.Add(new StagingSchemaInput("input2", "Input 2", "table_input2")); schema.setInputs(inputs); List <StagingSchemaOutput> outputs = new List <StagingSchemaOutput>(); outputs.Add(new StagingSchemaOutput("final_output", "Final Output")); schema.setOutputs(outputs); StagingMapping mapping = new StagingMapping(); mapping.setId("m1"); List <IKeyValue> mapInitialContext = new List <IKeyValue>(); mapInitialContext.Add(new StagingKeyValue("tmp_field", null)); mapping.setInitialContext(mapInitialContext); StagingTablePath path = new StagingTablePath(); path.setId("table_mapping"); HashSet <IKeyMapping> pathInputMap = new HashSet <IKeyMapping>(); pathInputMap.Add(new StagingKeyMapping("tmp_field", "mapped_field")); path.setInputMapping(pathInputMap); HashSet <String> pathInputs = new HashSet <String>(); pathInputs.Add("input1"); pathInputs.Add("input2"); pathInputs.Add("tmp_field"); path.setInputs(pathInputs); HashSet <String> pathOutputs = new HashSet <String>(); pathOutputs.Add("final_output"); path.setOutputs(pathOutputs); List <ITablePath> mapTablePaths = new List <ITablePath>(); mapTablePaths.Add(path); mapping.setTablePaths(mapTablePaths); List <IMapping> schemaMappings = new List <IMapping>(); schemaMappings.Add(mapping); schema.setMappings(schemaMappings); provider.addSchema(schema); TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider); HashSet <String> testSet1 = staging.getInputs(staging.getSchema("schema_test")); HashSet <String> testSet2 = new HashSet <String>(); testSet2.Add("input1"); testSet2.Add("input2"); // should only return the "real" inputs and not the temp field set in initial context Assert.IsTrue(testSet1.SetEquals(testSet2)); }
public void testBlankInputs() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("table_input1"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("result1"); def2.setName("Result1"); def2.setType(ColumnType.DESCRIPTION); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1", "ONE" }); table.getRawRows().Add(new List <String>() { "2", "TWO" }); provider.addTable(table); table = new StagingTable(); table.setId("table_input2"); def1 = new StagingColumnDefinition(); def1.setKey("input2"); def1.setName("Input 2"); def1.setType(ColumnType.INPUT); def2 = new StagingColumnDefinition(); def2.setKey("result2"); def2.setName("Result2"); def2.setType(ColumnType.DESCRIPTION); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "", "Blank" }); table.getRawRows().Add(new List <String>() { "A", "Letter A" }); table.getRawRows().Add(new List <String>() { "B", "Letter B" }); provider.addTable(table); table = new StagingTable(); table.setId("table_selection"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*" }); provider.addTable(table); table = new StagingTable(); table.setId("primary_site"); def1 = new StagingColumnDefinition(); def1.setKey("site"); def1.setName("Site"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "C509" }); provider.addTable(table); table = new StagingTable(); table.setId("histology"); def1 = new StagingColumnDefinition(); def1.setKey("hist"); def1.setName("Histology"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "8000" }); provider.addTable(table); table = new StagingTable(); table.setId("table_year_dx"); def1 = new StagingColumnDefinition(); def1.setKey("year_dx"); def1.setName("Year DX"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1900-2100" }); provider.addTable(table); StagingSchema schema = new StagingSchema(); schema.setId("schema_test"); schema.setSchemaSelectionTable("table_selection"); List <StagingSchemaInput> inputs = new List <StagingSchemaInput>(); inputs.Add(new StagingSchemaInput("site", "Primary Site", "primary_site")); inputs.Add(new StagingSchemaInput("hist", "Hist", "histology")); inputs.Add(new StagingSchemaInput("year_dx", "Year DX", "table_year_dx")); inputs.Add(new StagingSchemaInput("input1", "Input 1", "table_input1")); inputs.Add(new StagingSchemaInput("input2", "Input 2", "table_input2")); schema.setInputs(inputs); provider.addSchema(schema); TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider); Assert.AreEqual("schema_test", staging.getSchema("schema_test").getId()); // check case where required input field not supplied (i.e. no default); since there are is no workflow defined, this should // not cause an error StagingData data = new StagingData("C509", "8000"); data.setInput("year_dx", "2018"); data.setInput("input1", "1"); staging.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); // pass in blank for "input2" data = new StagingData("C509", "8000"); data.setInput("year_dx", "2018"); data.setInput("input1", "1"); data.setInput("input2", ""); staging.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); // pass in null for "input2" data = new StagingData("C509", "8000"); data.setInput("year_dx", "2018"); data.setInput("input1", "1"); data.setInput("input2", null); staging.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); }
public void testExtraInput() { StagingTable table = new StagingTable(); table.setId("test_table"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("result1"); def2.setName("Result1"); def2.setType(ColumnType.ENDPOINT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1", "MATCH" }); table.getRawRows().Add(new List <String>() { "2", "VALUE:{{extra1}}" }); table.getRawRows().Add(new List <String>() { "{{extra2}}", "MATCH" }); table.getRawRows().Add(new List <String>() { "{{ctx_year_current}}", "MATCH" }); table.getRawRows().Add(new List <String>() { "5", "VALUE:{{ctx_year_current}}" }); table.getRawRows().Add(new List <String>() { "6", "MATCH:{{match_extra}}" }); table.getRawRows().Add(new List <String>() { "7", "ERROR:{{error_extra}}" }); StagingDataProvider.initTable(table); HashSet <String> hash1 = new HashSet <String>() { "extra1", "extra2" }; HashSet <String> hash2 = table.getExtraInput(); // since context variables are not user-supplied, they should not be included in the extra input Assert.IsTrue(hash1.SetEquals(hash2)); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "{{ctx_year_current}}", "MATCH" }); StagingDataProvider.initTable(table); Assert.IsNull(table.getExtraInput()); }
public dlgTable(Staging pStaging, String sSchemaName, String sTableId) { InitializeComponent(); mStaging = pStaging; msSchemaName = sSchemaName; msTableId = sTableId; lblSchemaName.Text = msSchemaName; lblTableId.Text = msTableId; lblTableName.Text = ""; lblTitle.Text = ""; lblSubtitle.Text = ""; lblDescription.Text = ""; //webBrTableNotes.DocumentText = ""; StagingTable thisTable = mStaging.getTable(msTableId); if (thisTable != null) { lblTableName.Text = thisTable.getName(); lblTitle.Text = thisTable.getTitle(); lblSubtitle.Text = thisTable.getSubtitle(); lblDescription.Text = thisTable.getDescription(); String sNotes = thisTable.getNotes(); if (sNotes == null) { sNotes = ""; } CommonMark.CommonMarkSettings settings = CommonMark.CommonMarkSettings.Default.Clone(); settings.RenderSoftLineBreaksAsLineBreaks = true; String result = CommonMark.CommonMarkConverter.Convert(sNotes, settings); result = result.Replace("<p>", "<p style=\"font-family=Microsoft Sans Serif;font-size:11px\">"); webBrTableNotes.DocumentText = result; // Set the rows to auto size to view the contents of larger text cells dataGridViewTable.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; // Obtain the number of columns and column labels for the table String ColumnName = ""; String ColumnLabel = ""; ColumnType cType = 0; int iInputCol = 0; List <IColumnDefinition> cols = thisTable.getColumnDefinitions(); StagingColumnDefinition thisColDef = null; int iNumColumns = 0; int iNumRows = 0; if (thisTable.getRawRows() != null) { iNumRows = thisTable.getRawRows().Count; } if (cols != null) { iNumColumns = cols.Count; //int iNumRows = TNMStage_get_table_num_rows(sAlgorithmName.c_str(), sAlgorithmVersion.c_str(), strptrTableId); for (int iColIndex = 0; iColIndex < cols.Count; iColIndex++) { thisColDef = (StagingColumnDefinition)cols[iColIndex]; // Add a new column to the table data view ColumnName = "ColumnName" + iColIndex + thisColDef.getName(); ColumnLabel = thisColDef.getName(); dataGridViewTable.Columns.Add(ColumnName, ColumnLabel); // Get the column type. If the type is "INPUT" OR "DESCRIPTION", then display the column. Otherwise skip it. cType = thisColDef.getType(); if ((cType == ColumnType.INPUT) && (iInputCol == -1)) { iInputCol = iColIndex; } } } // Set widths of columns and their text wrap mode int iViewableWidth = dataGridViewTable.Width; int iWidthDivisor = 0; if (iInputCol >= 0) { iViewableWidth = dataGridViewTable.Width - 120; // remove size of input column } if (iNumColumns > 1) { iWidthDivisor = (int)((double)iViewableWidth / (double)(iNumColumns - 1)); } else { iWidthDivisor = 300; } for (int i = 0; i < dataGridViewTable.Columns.Count; i++) { if (i == iInputCol) { if (dataGridViewTable.Columns.Count == 1) { dataGridViewTable.Columns[i].Width = iWidthDivisor; } else { dataGridViewTable.Columns[i].Width = 100; } } else { dataGridViewTable.Columns[i].Width = iWidthDivisor; } dataGridViewTable.Columns[i].DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridViewTable.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } // Now loop through the table rows and add each cell to the table List <String> thisRow = null; String CellValue = ""; for (int iRowIndex = 0; iRowIndex < iNumRows; iRowIndex++) { dataGridViewTable.RowCount++; dataGridViewTable.Rows[iRowIndex].Height = 40; thisRow = null; if (thisTable.getRawRows() != null) { thisRow = thisTable.getRawRows()[iRowIndex]; } for (int iColIndex = 0; iColIndex < iNumColumns; iColIndex++) { thisColDef = (StagingColumnDefinition)cols[iColIndex]; // Get the column type. If the type is "INPUT" OR "DESCRIPTION", then display the column. Otherwise skip it. cType = thisColDef.getType(); CellValue = ""; if (thisRow.Count > iColIndex) { CellValue = thisRow[iColIndex]; } if ((cType == ColumnType.INPUT) || (cType == ColumnType.DESCRIPTION)) { // Nothing to do here - just display the string obtained from the DLL dataGridViewTable[iColIndex, iRowIndex].Value = CellValue; if (cType == ColumnType.INPUT) { dataGridViewTable.Columns[iColIndex].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } else { dataGridViewTable.Columns[iColIndex].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft; } } else if (cType == ColumnType.ENDPOINT) // has to be TNM_COLUMN_ENDPOINT { // Endpoints need a small text adjustment in order to make the viewing a little nicer // You need to remove the "VALUE:" string at the beginning of the string if (CellValue.StartsWith("VALUE:")) { CellValue = CellValue.Replace("VALUE:", ""); } dataGridViewTable[iColIndex, iRowIndex].Value = CellValue; dataGridViewTable.Columns[iColIndex].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } } } } }
// Initialize a table. // @param table table entity // @return initialized table entity public static StagingTable initTable(StagingTable table) { HashSet <String> extraInputs = new HashSet <String>(); List <List <String> > pTableRawRows = table.getRawRows(); // empty out the parsed rows List <ITableRow> newTableRows = new List <ITableRow>(); if (pTableRawRows != null) { newTableRows.Capacity = pTableRawRows.Count; } table.setTableRows(newTableRows); if (pTableRawRows != null) { foreach (List <String> row in pTableRawRows) { StagingTableRow tableRowEntity = new StagingTableRow(); // make sure the number of cells in the row matches the number of columns defined if (table.getColumnDefinitions().Count != row.Count) { throw new System.InvalidOperationException("Table '" + table.getId() + "' has a row with " + row.Count + " values but should have " + table.getColumnDefinitions().Count + ": " + row); } // loop over the column definitions in order since the data needs to be retrieved by array position for (int i = 0; i < table.getColumnDefinitions().Count; i++) { StagingColumnDefinition col = (StagingColumnDefinition)(table.getColumnDefinitions()[i]); String cellValue = row[i]; switch (col.getType()) { case ColumnType.INPUT: // if there are no ranges in the list, that means the cell was "blank" and is not needed in the table row List <Range> ranges = splitValues(cellValue); if (!(ranges.Count == 0)) { tableRowEntity.addInput(col.getKey(), ranges); // if there are key references used (values that reference other inputs) like {{key}}, then add them to the extra inputs list foreach (StagingRange range in ranges) { if (DecisionEngineFuncs.isReferenceVariable(range.getLow())) { extraInputs.Add(DecisionEngineFuncs.trimBraces(range.getLow())); } if (DecisionEngineFuncs.isReferenceVariable(range.getHigh())) { extraInputs.Add(DecisionEngineFuncs.trimBraces(range.getHigh())); } } } break; case ColumnType.ENDPOINT: StagingEndpoint endpoint = parseEndpoint(cellValue); endpoint.setResultKey(col.getKey()); tableRowEntity.addEndpoint(endpoint); // if there are key references used (values that reference other inputs) like {{key}}, then add them to the extra inputs list if (EndpointType.VALUE == endpoint.getType() && DecisionEngineFuncs.isReferenceVariable(endpoint.getValue())) { extraInputs.Add(DecisionEngineFuncs.trimBraces(endpoint.getValue())); } break; case ColumnType.DESCRIPTION: // do nothing break; default: throw new System.InvalidOperationException("Table '" + table.getId() + " has an unknown column type: '" + col.getType() + "'"); } } tableRowEntity.ConvertColumnInput(); newTableRows.Add(tableRowEntity); } } // add extra inputs, if any; do not include context variables since they are not user input foreach (String s in Staging.CONTEXT_KEYS) { extraInputs.Remove(s); } table.setExtraInput(extraInputs.Count == 0 ? null : extraInputs); table.GenerateInputColumnDefinitions(); return(table); }