void TryChangeTab(object sender, SelectionChangedEventArgs e) { if (e.Source is TabControl ctrl) { var tabCtrl = ctrl; var tabItem = tabCtrl.SelectedItem as TabItem; if (DataContext is WorkflowInputDataViewModel vm) { vm.IsInError = false; if (tabItem != null && tabItem.Header.ToString() == "XML") { TryShowDataInOutputWindow(vm); _currentTab = InputTab.Xml; } else if (tabItem != null && tabItem.Header.ToString() == "JSON") { SetCurrentTabToJson(vm); } else { TryChangeTab(vm); } } } }
void TryChangeTab(WorkflowInputDataViewModel vm) { try { var xmlData = _editor.Text; if (_currentTab == InputTab.Json) { xmlData = GetXmlDataFromJson(); } vm.XmlData = xmlData; vm.SetWorkflowInputData(); _currentTab = InputTab.Grid; } catch (Exception ex) { vm.IsInError = true; } }
private void SetCurrentTabToJson(WorkflowInputDataViewModel vm) { string input = string.Empty; if (_currentTab == InputTab.Grid) { vm.SetXmlData(); if (vm.XmlData != null) { input = vm.XmlData; } } if (_currentTab == InputTab.Xml && !string.IsNullOrEmpty(_editor.Text)) { input = _editor.Text; } ShowDataInJsonOutputWindow(vm, input); _currentTab = InputTab.Json; }
private void SetCurrentTabToJson(WorkflowInputDataViewModel vm) { var xml = new XmlDocument(); if (_currentTab == InputTab.Grid) { vm.SetXmlData(); if (vm.XmlData != null) { xml.LoadXml(vm.XmlData); } } if (_currentTab == InputTab.Xml && !string.IsNullOrEmpty(_editor.Text)) { try { xml.LoadXml(_editor.Text); } catch (Exception ex) { vm.ShowInvalidDataPopupMessage(); } } if (!string.IsNullOrEmpty(vm.JsonData)) { _jsonEditor.Text = vm.JsonData; } else { if (xml.FirstChild != null) { var json = JsonConvert.SerializeXmlNode(xml.FirstChild, Newtonsoft.Json.Formatting.Indented, true); _jsonEditor.Text = json; } } JsonOutput.Content = _jsonEditor; _currentTab = InputTab.Json; }
private void TabControlSelectionChanged(object sender, SelectionChangedEventArgs e) { var ctrl = e.Source as TabControl; if (ctrl != null) { var tabCtrl = ctrl; var tabItem = tabCtrl.SelectedItem as TabItem; var vm = DataContext as WorkflowInputDataViewModel; if (vm != null) { vm.IsInError = false; if (tabItem != null && tabItem.Header.ToString() == "XML") { switch (_currentTab) { case InputTab.Grid: try { vm.SetXmlData(); ShowDataInOutputWindow(vm.XmlData); } catch { vm.ShowInvalidDataPopupMessage(); } break; case InputTab.Json: try { vm.XmlData = GetXmlDataFromJson(); vm.SetWorkflowInputData(); vm.SetXmlData(); ShowDataInOutputWindow(vm.XmlData); } catch { vm.ShowInvalidDataPopupMessage(); } break; } _currentTab = InputTab.Xml; } else if (tabItem != null && tabItem.Header.ToString() == "JSON") { var xml = new XmlDocument(); switch (_currentTab) { case InputTab.Grid: vm.SetXmlData(); if (vm.XmlData != null) { xml.LoadXml(vm.XmlData); } break; case InputTab.Xml: if (!string.IsNullOrEmpty(_editor.Text)) { try { xml.LoadXml(_editor.Text); } catch { vm.ShowInvalidDataPopupMessage(); } } break; } if (!string.IsNullOrEmpty(vm.JsonData)) { _jsonEditor.Text = vm.JsonData; } else { if (xml.FirstChild != null) { var json = JsonConvert.SerializeXmlNode(xml.FirstChild, Newtonsoft.Json.Formatting.Indented, true); _jsonEditor.Text = json; } } JsonOutput.Content = _jsonEditor; _currentTab = InputTab.Json; } else { try { var xmlData = _editor.Text; if (_currentTab == InputTab.Json) { xmlData = GetXmlDataFromJson(); } vm.XmlData = xmlData; vm.SetWorkflowInputData(); _currentTab = InputTab.Grid; } catch { vm.IsInError = true; } } } } }