Skip to content

Commit

Permalink
add custom headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilshod Komilov committed Feb 26, 2021
1 parent 06d94c0 commit d340c07
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ConnectionDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<StackPanel>
<CheckBox Margin="6,4,0,0" IsChecked="{Binding LogMethod}" TabIndex="11">Method</CheckBox>
<CheckBox Margin="6,4,0,0" IsChecked="{Binding LogHeaders}" TabIndex="12">Headers</CheckBox>
<Label TabIndex="10">
<Hyperlink Click="Hyperlink_Click">Custom Headers...</Hyperlink>
</Label>
</StackPanel>
</GroupBox>
</StackPanel>
Expand Down
22 changes: 22 additions & 0 deletions ConnectionDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace OData4.LINQPadDriver
Expand All @@ -24,5 +27,24 @@ private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e)
{
_connectionProperties.Password = PasswordBox.Password;
}

private void Hyperlink_Click(object sender, RoutedEventArgs e)
{
try
{
CustomHeadersDialog customHeadersDialog = new CustomHeadersDialog();
customHeadersDialog.ShowDialog();
var customeHeaders = new List<KeyValuePair<string, string>>();
foreach (var item in customHeadersDialog.CustomHeaders.Where(s => !string.IsNullOrEmpty(s.Name)))
{
customeHeaders.Add(new KeyValuePair<string, string>(item.Name, item.Value));
}
_connectionProperties.CustomHeaders = customeHeaders;
}
catch (Exception ex)
{
MessageBox.Show($"Something went wrong \n{ex.Message}. Please try again!");
}
}
}
}
27 changes: 27 additions & 0 deletions CustomHeadersDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Window x:Class="OData4.LINQPadDriver.CustomHeadersDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OData4.LINQPadDriver"
mc:Ignorable="d"
Background="{x:Static SystemColors.ControlBrush}"
Width="450"
WindowStartupLocation="CenterScreen"
SizeToContent="Height"
ResizeMode="NoResize"
Title="CustomHeaders" >
<StackPanel Orientation="Vertical" Margin="4" >
<DataGrid AutoGenerateColumns="False" MinHeight="200" ItemsSource="{Binding CustomHeaders}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Name" Binding="{Binding Name}"/>
<DataGridTextColumn Width="*" Header="Value" Binding="{Binding Value}"/>
</DataGrid.Columns>
</DataGrid>
<DockPanel >
<Button Padding="4" Content="Cancel" Margin="4 0 0 0" Width="60" DockPanel.Dock="Right" Click="Cancel_Click" />
<Button Padding="4" Width="60" Margin="0,0,4,0" Click="OK_Click" Content="OK" DockPanel.Dock="Right"/>
<Grid/>
</DockPanel>
</StackPanel>
</Window>
36 changes: 36 additions & 0 deletions CustomHeadersDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Windows;

namespace OData4.LINQPadDriver
{
/// <summary>
/// Interaction logic for CustomHeadersDialog.xaml
/// </summary>
public partial class CustomHeadersDialog : Window
{
public List<CustomHeader> CustomHeaders { get; set; } = new List<CustomHeader>();
public CustomHeadersDialog()
{
InitializeComponent();
DataContext = this;
}

private void OK_Click(object sender, RoutedEventArgs e)
{
this.Close();
}

private void Cancel_Click(object sender, RoutedEventArgs e)
{
CustomHeaders.Clear();
this.Close();
}
}

public class CustomHeader
{
public string Name { get; set; }

public string Value { get; set; }
}
}

0 comments on commit d340c07

Please sign in to comment.