public void AddMapping(IOMapEntry map) { if (_ioMap == null) { _ioMap = new Dictionary <string, IOMapEntry>(); } _ioMap.Add(map.InputFieldPath, map); }
private void ok_Click(object sender, EventArgs e) { try { // Salva tutti i dettagli nel model if (inutColumnCb.SelectedIndex == -1) { MessageBox.Show("No input column has been selected. If none is available, please attach an input with textual columns to this component."); return; } else { _model.InputColumnName = inutColumnCb.SelectedItem.ToString(); } _model.ClearMapping(); // - Salva le impostazioni di IO if (uiIOGrid.IsCurrentCellDirty || uiIOGrid.IsCurrentRowDirty) { uiIOGrid.CurrentRow.DataGridView.EndEdit(); uiIOGrid.EndEdit(); CurrencyManager cm = (CurrencyManager)uiIOGrid.BindingContext[uiIOGrid.DataSource, uiIOGrid.DataMember]; cm.EndCurrentEdit(); } int row = 1; foreach (DataGridViewRow r in uiIOGrid.Rows) { if (r.IsNewRow) { continue; } string inputName = null; try { inputName = (string)r.Cells[0].Value; } catch (Exception ex) { MessageBox.Show("JSON Field Name on row " + row); return; } int maxLen = -1; try { maxLen = int.Parse((string)r.Cells[1].Value.ToString()); } catch (Exception ex) { MessageBox.Show("Maximum length is invalid on row " + row); return; } string outName = null; try { outName = (string)r.Cells[2].Value; if (string.IsNullOrEmpty(outName)) { throw new ArgumentException(); } } catch (Exception ex) { MessageBox.Show("Output Column name is invalid on row " + row); return; } JsonTypes dataType = 0; try { dataType = (JsonTypes)Enum.Parse(typeof(JsonTypes), (string)r.Cells[3].Value); } catch (Exception ex) { MessageBox.Show("Column type is invalid on row " + row); return; } IOMapEntry map = new IOMapEntry(); map.InputFieldPath = inputName; map.OutputColName = outName; map.OutputJsonColumnType = dataType; map.InputFieldLen = maxLen; _model.AddMapping(map); row++; } // - Salava le impostazioni avanzate if (!string.IsNullOrEmpty(uiTempDir.Text)) { _model.CustomLocalTempDir = uiTempDir.Text; } else { _model.CustomLocalTempDir = null; } if (!string.IsNullOrEmpty(uiPathToArray.Text)) { _model.JsonObjectRelativePath = uiPathToArray.Text; } else { _model.JsonObjectRelativePath = null; } _model.ParseDates = cbParseJsonDate.Checked; DialogResult = DialogResult.OK; Close(); } catch (FormatException ex) { MessageBox.Show("Invalid number (max length) specified. Please fix it."); } catch (Exception ex) { MessageBox.Show("An error has occurred: " + ex.Message); } }
public JSONDataMappingModel SaveToModel() { JSONDataMappingModel result = new JSONDataMappingModel(); // Json root and type RootType root; Enum.TryParse <RootType>(uiRootType.SelectedValue.ToString(), out root); result.RootType = root; if (!string.IsNullOrEmpty(uiPathToArray.Text)) { result.JsonRootPath = uiPathToArray.Text; } else { result.JsonRootPath = null; } // IO columns mapping result.ClearMapping(); if (uiIOGrid.IsCurrentCellDirty || uiIOGrid.IsCurrentRowDirty) { uiIOGrid.CurrentRow.DataGridView.EndEdit(); uiIOGrid.EndEdit(); CurrencyManager cm = (CurrencyManager)uiIOGrid.BindingContext[uiIOGrid.DataSource, uiIOGrid.DataMember]; cm.EndCurrentEdit(); } // In case of error, rewrite the exception for user friendliness int row = 1; foreach (DataGridViewRow r in uiIOGrid.Rows) { if (r.IsNewRow) { continue; } string inputName = null; try { inputName = (string)r.Cells[0].Value; } catch (Exception ex) { throw new Exception("JSON Field Name on row " + row); } int maxLen = -1; try { maxLen = int.Parse((string)r.Cells[1].Value.ToString()); } catch (Exception ex) { throw new Exception("Maximum length is invalid on row " + row); } string outName = null; try { outName = (string)r.Cells[2].Value; if (string.IsNullOrEmpty(outName)) { throw new ArgumentException(); } } catch (Exception ex) { throw new Exception("Output Column name is invalid on row " + row); } JsonTypes dataType = 0; try { dataType = (JsonTypes)Enum.Parse(typeof(JsonTypes), (string)r.Cells[3].Value); } catch (Exception ex) { throw new Exception("Column type is invalid on row " + row); } IOMapEntry map = new IOMapEntry(); map.InputFieldPath = inputName; map.OutputColName = outName; map.OutputJsonColumnType = dataType; map.InputFieldLen = maxLen; result.AddMapping(map); row++; } // Save the InputColumns to be copied as output var columnsToCopy = new List <string>(); for (var i = 0; i < inputsCb.CheckedItems.Count; i++) { // Setup a placemark. The UI will feed this after outputcolumns are added. columnsToCopy.Add(inputsCb.CheckedItems[i] as string); } result.InputColumnsToCopy = columnsToCopy; return(result); }