Skip to content

Commit d66f054

Browse files
Added Validation and Timeout-options
1 parent eaa3295 commit d66f054

12 files changed

Lines changed: 365 additions & 36 deletions

File tree

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<Application x:Class="ThomasClaudiusHuber.Azure.EventHub.RestClientGenerator.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
StartupUri="View/MainWindow.xaml">
5-
<Application.Resources>
6-
<BooleanToVisibilityConverter x:Key="BooleanToVisiblityConverter"/>
7-
<Style TargetType="TextBox">
8-
<Setter Property="Foreground" Value="White"/>
9-
<Setter Property="Background" Value="#444444"/>
10-
<Setter Property="BorderBrush" Value="#555555"/>
11-
<Setter Property="Margin" Value="5"/>
12-
<Style.Triggers>
13-
<Trigger Property="IsReadOnly" Value="True">
14-
<Setter Property="Background" Value="#222222"/>
15-
<Setter Property="Foreground" Value="#AAAAAA"/>
16-
</Trigger>
17-
</Style.Triggers>
18-
</Style>
19-
<Style TargetType="Label">
20-
<Setter Property="Foreground" Value="#DDDDDD"/>
21-
</Style>
4+
StartupUri="View/MainWindow.xaml"
5+
DispatcherUnhandledException="Application_DispatcherUnhandledException">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Styles/Brushes.xaml"/>
10+
<ResourceDictionary Source="Styles/Label.xaml"/>
11+
<ResourceDictionary Source="Styles/TextBox.xaml"/>
12+
<ResourceDictionary Source="Styles/ComboBox.xaml"/>
13+
<ResourceDictionary>
14+
<BooleanToVisibilityConverter x:Key="BooleanToVisiblityConverter"/>
15+
</ResourceDictionary>
16+
</ResourceDictionary.MergedDictionaries>
17+
</ResourceDictionary>
18+
2219
</Application.Resources>
2320
</Application>

EventHub.RestClientGenerator/App.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ namespace ThomasClaudiusHuber.Azure.EventHub.RestClientGenerator
77
/// </summary>
88
public partial class App : Application
99
{
10+
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
11+
{
12+
MessageBox.Show("Exception: " + e.Exception.Message);
13+
e.Handled = true;
14+
}
1015
}
1116
}

EventHub.RestClientGenerator/EventHub.RestClientGenerator.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@
8181
<Compile Include="View\UwpOutputView.xaml.cs">
8282
<DependentUpon>UwpOutputView.xaml</DependentUpon>
8383
</Compile>
84+
<Page Include="Styles\Brushes.xaml">
85+
<SubType>Designer</SubType>
86+
<Generator>MSBuild:Compile</Generator>
87+
</Page>
88+
<Page Include="Styles\ComboBox.xaml">
89+
<SubType>Designer</SubType>
90+
<Generator>MSBuild:Compile</Generator>
91+
</Page>
92+
<Page Include="Styles\Label.xaml">
93+
<SubType>Designer</SubType>
94+
<Generator>MSBuild:Compile</Generator>
95+
</Page>
96+
<Page Include="Styles\TextBox.xaml">
97+
<SubType>Designer</SubType>
98+
<Generator>MSBuild:Compile</Generator>
99+
</Page>
84100
<Page Include="View\MainWindow.xaml">
85101
<Generator>MSBuild:Compile</Generator>
86102
<SubType>Designer</SubType>

EventHub.RestClientGenerator/EventHubLogic/ConnectionStringExtractor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ public static class ConnectionDetailsExtractor
77
public static bool TryExtract(string connectionString, out ConnectionDetails details)
88
{
99
details = null;
10+
if(connectionString==null)
11+
{
12+
return false;
13+
}
14+
15+
connectionString = connectionString.Trim();
16+
1017
var connectionDetails = new ConnectionDetails();
1118
var items = connectionString.Split(';');
1219

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
4+
<!--Override of SystemColors for DataGrid and ComboBox selection-->
5+
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#999999"/>
6+
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#999999"/>
7+
<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="#999999"/>
8+
9+
<!--Other default brushes-->
10+
<SolidColorBrush x:Key="DefaultForegroundBrush" Color="White"/>
11+
<SolidColorBrush x:Key="DefaultBackgroundBrush" Color="#444444"/>
12+
<SolidColorBrush x:Key="DefaultBorderBrush" Color="#555555"/>
13+
14+
<SolidColorBrush x:Key="DisabledBorderBrush" Color="Gray"/>
15+
<SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#222222"/>
16+
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#AAAAAA"/>
17+
18+
<SolidColorBrush x:Key="ButtonMouseOverBackgroundBrush" Color="#777777"/>
19+
<SolidColorBrush x:Key="ButtonIsPressedBackgroundBrush" Color="#999999"/>
20+
<SolidColorBrush x:Key="ButtonIsPressedBorderBrush" Color="#777777"/>
21+
<SolidColorBrush x:Key="ButtonMouseOverBorderBrush" Color="#777777"/>
22+
</ResourceDictionary>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
4+
5+
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
6+
<Setter Property="IsTabStop" Value="false"/>
7+
<Setter Property="Focusable" Value="false"/>
8+
<Setter Property="ClickMode" Value="Press"/>
9+
<Setter Property="Template">
10+
<Setter.Value>
11+
<ControlTemplate TargetType="{x:Type ToggleButton}">
12+
<Border BorderBrush="{TemplateBinding BorderBrush}"
13+
BorderThickness="{TemplateBinding BorderThickness}"
14+
Background="{TemplateBinding Background}">
15+
<Border x:Name="InnerBorder" BorderBrush="Transparent"
16+
HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
17+
<Polygon x:Name="arrow"
18+
Points="0,0 8,0 4,5"
19+
Fill="{TemplateBinding Foreground}"
20+
HorizontalAlignment="Center"
21+
VerticalAlignment="Center"/>
22+
</Border>
23+
</Border>
24+
<ControlTemplate.Triggers>
25+
<Trigger Property="IsMouseOver" Value="True">
26+
<Setter Property="Background" TargetName="InnerBorder" Value="{StaticResource ButtonMouseOverBackgroundBrush}"/>
27+
</Trigger>
28+
<Trigger Property="IsPressed" Value="true">
29+
<Setter Property="Background" TargetName="InnerBorder" Value="{StaticResource ButtonIsPressedBackgroundBrush}"/>
30+
</Trigger>
31+
<Trigger Property="IsEnabled" Value="false">
32+
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource DisabledForegroundBrush}"/>
33+
</Trigger>
34+
</ControlTemplate.Triggers>
35+
</ControlTemplate>
36+
</Setter.Value>
37+
</Setter>
38+
</Style>
39+
40+
<Style TargetType="{x:Type ComboBox}">
41+
<Setter Property="Foreground" Value="{StaticResource DefaultForegroundBrush}"/>
42+
<Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}"/>
43+
<Setter Property="BorderBrush" Value="{StaticResource DefaultBorderBrush}"/>
44+
<Setter Property="BorderThickness" Value="1"/>
45+
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
46+
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
47+
<Setter Property="Padding" Value="6,3,5,3"/>
48+
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
49+
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
50+
<Setter Property="Template">
51+
<Setter.Value>
52+
<ControlTemplate TargetType="{x:Type ComboBox}">
53+
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
54+
<Grid.ColumnDefinitions>
55+
<ColumnDefinition Width="*"/>
56+
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
57+
</Grid.ColumnDefinitions>
58+
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
59+
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
60+
<ScrollViewer x:Name="DropDownScrollViewer">
61+
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
62+
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
63+
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
64+
</Canvas>
65+
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
66+
</Grid>
67+
</ScrollViewer>
68+
</Border>
69+
</Popup>
70+
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}"
71+
BorderThickness="{TemplateBinding BorderThickness}"
72+
Background="{TemplateBinding Background}"
73+
Foreground="{TemplateBinding Foreground}"
74+
Grid.ColumnSpan="2"
75+
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
76+
Style="{StaticResource ComboBoxToggleButton}"/>
77+
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
78+
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
79+
Content="{TemplateBinding SelectionBoxItem}"
80+
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
81+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
82+
IsHitTestVisible="false" Margin="{TemplateBinding Padding}"
83+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
84+
</Grid>
85+
<ControlTemplate.Triggers>
86+
<Trigger Property="HasItems" Value="false">
87+
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
88+
</Trigger>
89+
<Trigger Property="IsEnabled" Value="False">
90+
<Setter Property="Background" Value="#101010"/>
91+
</Trigger>
92+
<MultiTrigger>
93+
<MultiTrigger.Conditions>
94+
<Condition Property="IsGrouping" Value="true"/>
95+
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
96+
</MultiTrigger.Conditions>
97+
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
98+
</MultiTrigger>
99+
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
100+
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
101+
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
102+
</Trigger>
103+
</ControlTemplate.Triggers>
104+
</ControlTemplate>
105+
</Setter.Value>
106+
</Setter>
107+
<Setter Property="ItemContainerStyle">
108+
<Setter.Value>
109+
<Style TargetType="ComboBoxItem">
110+
<Setter Property="Foreground" Value="{StaticResource DefaultForegroundBrush}"/>
111+
<Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}"/>
112+
<Setter Property="BorderBrush" Value="{StaticResource DefaultBackgroundBrush}"/>
113+
</Style>
114+
</Setter.Value>
115+
</Setter>
116+
</Style>
117+
</ResourceDictionary>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
<Style TargetType="Label">
4+
<Setter Property="Foreground" Value="#DDDDDD"/>
5+
</Style>
6+
</ResourceDictionary>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:local="clr-namespace:ThomasClaudiusHuber.Azure.EventHub.RestClientGenerator.Styles">
4+
<Style TargetType="TextBox">
5+
<Setter Property="Foreground" Value="{StaticResource DefaultForegroundBrush}"/>
6+
<Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}"/>
7+
<Setter Property="BorderBrush" Value="{StaticResource DefaultBorderBrush}"/>
8+
<Setter Property="Margin" Value="5"/>
9+
<Setter Property="Validation.ErrorTemplate">
10+
<Setter.Value>
11+
<ControlTemplate>
12+
<Grid>
13+
<AdornedElementPlaceholder x:Name="placeholder"/>
14+
<Popup Placement="Left" PlacementTarget="{Binding ElementName=placeholder}" IsOpen="True">
15+
<Grid Width="150" Background="DarkRed">
16+
<TextBlock Text="{Binding ElementName=placeholder,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
17+
Foreground="White" TextWrapping="Wrap" Margin="5"/>
18+
</Grid>
19+
</Popup>
20+
</Grid>
21+
</ControlTemplate>
22+
</Setter.Value>
23+
</Setter>
24+
<Style.Triggers>
25+
<Trigger Property="IsReadOnly" Value="True">
26+
<Setter Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/>
27+
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
28+
</Trigger>
29+
</Style.Triggers>
30+
</Style>
31+
</ResourceDictionary>

EventHub.RestClientGenerator/UwpTextTemplate/EventHubClientTemplate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task<bool> PostDataAsync(string jsonObjectToSend)
5555
content.Headers.Add(""ContentType"", ""application/json"");
5656
5757
var result = await httpClient.PostAsync(url, content);
58-
58+
5959
return result.IsSuccessStatusCode;
6060
}
6161
}

EventHub.RestClientGenerator/UwpTextTemplate/EventHubClientTemplate.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace YourNamespace
2424
content.Headers.Add("ContentType", "application/json");
2525

2626
var result = await httpClient.PostAsync(url, content);
27-
27+
2828
return result.IsSuccessStatusCode;
2929
}
3030
}

0 commit comments

Comments
 (0)