public void LoadModel(JSONDataMappingModel m) { uiIOGrid.Rows.Clear(); // Rootpath + json response type if (!string.IsNullOrEmpty(m.JsonRootPath)) { uiPathToArray.Text = m.JsonRootPath; } uiRootType.SelectedItem = Enum.GetName(typeof(RootType), m.RootType); // IoMap for json derived columns foreach (IOMapEntry e in m.IoMap) { int index = uiIOGrid.Rows.Add(); uiIOGrid.Rows[index].Cells[0].Value = e.InputFieldPath; uiIOGrid.Rows[index].Cells[1].Value = e.InputFieldLen; uiIOGrid.Rows[index].Cells[2].Value = e.OutputColName; uiIOGrid.Rows[index].Cells[3].Value = Enum.GetName(typeof(JsonTypes), e.OutputJsonColumnType); } // Set all items check status to false for (var j = 0; j < inputsCb.Items.Count; j++) { inputsCb.SetItemChecked(j, false); } if (m.InputColumnsToCopy != null) { // Input columns to be copied as output foreach (var i in m.InputColumnsToCopy) { // Note that the input might have changed here. // If we do not find the given lineage id among ours inputs, we simply skip them. for (var j = 0; j < inputsCb.Items.Count; j++) { string col = inputsCb.Items[j] as string; if (i == col) { // Ok this column is available. Check it. inputsCb.SetItemChecked(j, true); } } } } }
public JSONSourceComponentModel() { DataSource = new JSONDataSourceModel(); DataMapping = new JSONDataMappingModel(); AdvancedSettings = new JSONAdvancedSettingsModel(); }
public static JSONDataMappingModel LoadFromJson(string jsonConfig) { JSONDataMappingModel res = JsonConvert.DeserializeObject <JSONDataMappingModel>(jsonConfig); return(res); }
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); }