public void testInputTables() { HashSet <String> errors = new HashSet <String>(); foreach (String schemaId in _STAGING.getSchemaIds()) { StagingSchema schema = _STAGING.getSchema(schemaId); // build a list of input tables that should be excluded foreach (StagingSchemaInput input in schema.getInputs()) { if (input.getTable() != null) { HashSet <String> inputKeys = new HashSet <String>(); StagingTable table = _STAGING.getTable(input.getTable()); foreach (StagingColumnDefinition def in table.getColumnDefinitions()) { if (ColumnType.INPUT == def.getType()) { inputKeys.Add(def.getKey()); } } // make sure the input key matches the an input column if (!inputKeys.Contains(input.getKey())) { errors.Add("Input key " + schemaId + ":" + input.getKey() + " does not match validation table " + table.getId() + ": " + inputKeys.ToString()); } } } } assertNoErrors(errors, "input values and their assocated validation tables"); }
// Given a table, return a Set of all the distinct input values. This is for tables that have a single INPUT column. // @param tableId table identifier // @return A set of unique inputs private HashSet <String> getAllInputValues(String tableId) { HashSet <String> values = new HashSet <String>(); // if the table is not found, return right away with an empty list //StagingTable table = (getTable(tableId) as StagingTable); StagingTable table = (StagingTable)(getTable(tableId)); if (table == null) { return(values); } // find the input key HashSet <String> inputKeys = new HashSet <String>(); foreach (StagingColumnDefinition col in table.getColumnDefinitions()) { if (col.getType() == ColumnType.INPUT) { inputKeys.Add(col.getKey()); } } if (inputKeys.Count != 1) { throw new System.InvalidOperationException("Table '" + table.getId() + "' must have one and only one INPUT column."); } HashSet <String> .Enumerator enumInput = inputKeys.GetEnumerator(); enumInput.MoveNext(); String inputKey = enumInput.Current; foreach (StagingTableRow row in table.getTableRows()) { foreach (StagingRange range in row.getColumnInput(inputKey)) { if (range.getLow() != null) { if (range.getLow() == range.getHigh()) { values.Add(range.getLow()); } else { int low = Convert.ToInt32(range.getLow()); int high = Convert.ToInt32(range.getHigh()); // add all values in range for (int i = low; i <= high; i++) { values.Add(padStart(i.ToString(), range.getLow().Length, '0')); } } } } } return(values); }
// Looks at all tables involved in all the mappings in the definition and returns a list of input keys that could be used. It will also deal with mapped // inputs. The inputs from each mapping will only be included if it passes the inclusion/exclusion criteria based on the context. Note that if an input // to a table was not a supplied input (i.e. it was created as an output of a previous table) it will not be included in the list of inputs. The inputs will // also include any used in schema selection. All inputs returned from this method should be in the schema input list otherwise there is a problem with the // schema. // @param schema a StagingSchema // @param context a context of values used to to check mapping inclusion/exclusion // @return a Set of unique input keys public HashSet <String> getInputs(StagingSchema schema, Dictionary <String, String> context) { HashSet <String> inputs = new HashSet <String>(); // add schema selection fields if (schema.getSchemaSelectionTable() != null) { StagingTable table = getTable(schema.getSchemaSelectionTable()); if (table != null) { foreach (StagingColumnDefinition def in table.getColumnDefinitions()) { if (ColumnType.INPUT == def.getType()) { inputs.Add(def.getKey()); } } } } // process all mappings if (schema.getMappings() != null) { HashSet <String> excludedInputs = new HashSet <String>(); HashSet <String> thisInput = null; foreach (StagingMapping mapping in schema.getMappings()) { thisInput = getInputs(mapping, context, excludedInputs); inputs.UnionWith(thisInput); } } // always remove all context variables since they are never needed to be supplied inputs.ExceptWith(CONTEXT_KEYS); return(inputs); }
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 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); }