/// <summary> /// Handles the 2 event of the MenuItem_Click control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void MenuItemSave_Click(object sender, RoutedEventArgs e) { if (this.CbxMethod.SelectedItem == null) { MessageBox.Show("Please select a RestMethod", "Missing Method", MessageBoxButton.OK, MessageBoxImage.Error); return; } SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = "Json file (*.json)|*.json", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; RestRequestConfiguration requestConfiguration = new RestRequestConfiguration() { Body = TbxBody.Text, EndpointUrl = TbxEndpointUrl.Text, Method = (Method)CbxMethod.SelectedItem, RestHeaders = this.restHeaders }; if (saveFileDialog.ShowDialog() == true) { File.WriteAllText(saveFileDialog.FileName, JsonConvert.SerializeObject(requestConfiguration)); } }
/// <summary> /// Handles the Click event of the Button Open control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void MenuItemOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog() { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Filter = "Json file (*.json)|*.json" }; if (openFileDialog.ShowDialog() == true) { string json = File.ReadAllText(openFileDialog.FileName, Encoding.UTF8); RestRequestConfiguration requestConfiguration = JsonConvert.DeserializeObject <RestRequestConfiguration>(json); this.TbxBody.Text = requestConfiguration.Body; this.TbxEndpointUrl.Text = requestConfiguration.EndpointUrl; this.CbxMethod.SelectedItem = requestConfiguration.Method; this.restHeaders = requestConfiguration.RestHeaders; this.TbxEndpointUrl.Focus(); this.DtgHeader.ItemsSource = this.restHeaders; this.DtgHeader.Items.Refresh(); } }