Skip to content

Commit

Permalink
Final Stage
Browse files Browse the repository at this point in the history
  • Loading branch information
RMariowski committed Feb 6, 2018
1 parent 9810920 commit 8e205a9
Show file tree
Hide file tree
Showing 36 changed files with 1,357 additions and 161 deletions.
174 changes: 172 additions & 2 deletions ArpmarApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,176 @@
xmlns:local="clr-namespace:ArpmarApp"
StartupUri="MainWindow.xaml">
<Application.Resources>


<SolidColorBrush x:Key="BlueBackground" Color="#1F64AF"/>

<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Grid>
<Border Name="Border" BorderThickness="0" CornerRadius="6,6,0,0">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="12,2,12,2"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter TargetName="Border" Property="Background" Value="#50A760"/>
</Trigger>
<Trigger Property="IsSelected" Value="false">
<Setter Property="Foreground" Value="Gainsboro" />
<Setter TargetName="Border" Property="Background" Value="#131F2B" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="TabViewStyle" TargetType="UserControl">
<Setter Property="Foreground" Value="Black" />
</Style>

<Style TargetType="DataGrid">
<Setter Property="Background" Value="White" />
</Style>

<Style TargetType="DataGridCell">
<Setter Property="TextBlock.TextAlignment" Value="Center" />
</Style>

<Style TargetType="Button">
<Setter Property="FontSize" Value="17" />
<Setter Property="MinHeight" Value="30" />
<Setter Property="Margin" Value="5,5,5,5" />

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="8" Background="{TemplateBinding Background}">
<Grid>
<ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#50A760"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Foreground" Value="Gainsboro" />
<Setter Property="Background" Value="#131F2B" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<LinearGradientBrush x:Key="CheckedBlue" StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FF285AB3" Offset="0" />
<GradientStop Color="#FF4184EC" Offset="0.5" />
<GradientStop Color="#FF558BED" Offset="0.5" />
<GradientStop Color="#FF7DACF0" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush x:Key="CheckedBlueBorder" Color="#FF143874" />
<Style x:Key="SwitchStyle" TargetType="CheckBox">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<ControlTemplate.Resources>
<Storyboard x:Key="OnChecking">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="slider"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="53" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OnUnchecking">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="slider"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<DockPanel x:Name="dockPanel">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}"
RecognizesAccessKey="True" VerticalAlignment="Center" />
<Grid>
<Border x:Name="BackgroundBorder" BorderBrush="#FF939393" BorderThickness="1"
CornerRadius="3" Height="27" Width="94">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FFB5B5B5" Offset="0" />
<GradientStop Color="#FFDEDEDE" Offset="0.1" />
<GradientStop Color="#FFEEEEEE" Offset="0.5" />
<GradientStop Color="#FFFAFAFA" Offset="0.5" />
<GradientStop Color="#FFFEFEFE" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Ellipse x:Name="Off" Width="14" Height="14" Stroke="#FF7A7A7A"
StrokeThickness="2" Grid.Column="1" HorizontalAlignment="Center"
VerticalAlignment="Center" />
<Line x:Name="On" X1="0" Y1="0" X2="0" Y2="14" Stroke="#FF7A7A7A"
StrokeThickness="2" Grid.Column="0" HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
<Border BorderBrush="#FF939393" HorizontalAlignment="Left" x:Name="slider" Width="41"
Height="27" BorderThickness="1" CornerRadius="3"
RenderTransformOrigin="0.5,0.5" Margin="0">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<SkewTransform AngleX="0" AngleY="0" />
<RotateTransform Angle="0" />
<TranslateTransform X="0" Y="0" />
</TransformGroup>
</Border.RenderTransform>
<Border.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF0F0F0" Offset="0" />
<GradientStop Color="#FFCDCDCD" Offset="0.1" />
<GradientStop Color="#FFFBFBFB" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource OnUnchecking}"
x:Name="OnUnchecking_BeginStoryboard" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource OnChecking}"
x:Name="OnChecking_BeginStoryboard" />
</Trigger.EnterActions>
<Setter TargetName="On" Property="Stroke" Value="White" />
<Setter TargetName="Off" Property="Stroke" Value="White" />
<Setter TargetName="BackgroundBorder" Property="Background"
Value="{StaticResource CheckedBlue}" />
<Setter TargetName="BackgroundBorder" Property="BorderBrush"
Value="{StaticResource CheckedBlueBorder}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<!-- ToDo: Add Style for Isenabled == False -->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
</Application>
13 changes: 3 additions & 10 deletions ArpmarApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;

namespace ArpmarApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static void ShowMessageBox(string text)
=> MessageBox.Show(text, "arpMAR");
}
}
30 changes: 30 additions & 0 deletions ArpmarApp/ArpmarApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -54,6 +55,20 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="EntryWindow.xaml.cs">
<DependentUpon>EntryWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Models\TableEntry.cs" />
<Compile Include="Views\ArpManagementView.xaml.cs">
<DependentUpon>ArpManagementView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ServiceManagementView.xaml.cs">
<DependentUpon>ServiceManagementView.xaml</DependentUpon>
</Compile>
<Page Include="EntryWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -66,6 +81,14 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\ArpManagementView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ServiceManagementView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down Expand Up @@ -93,5 +116,12 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ArpmarCore\ArpmarCore.csproj">
<Project>{ce8f8729-db14-455c-8466-10cedafc5ecf}</Project>
<Name>ArpmarCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions ArpmarApp/EntryWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Window x:Class="ArpmarApp.EntryWindow"
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:ArpmarApp"
mc:Ignorable="d"
Height="220" Width="250" WindowStyle="ToolWindow" ResizeMode="NoResize" WindowStartupLocation="CenterOwner">
<Grid>
<StackPanel VerticalAlignment="Center" Margin="10,5,10,5">
<TextBlock Text="Interface:" />
<ComboBox Name="InterfacesComboBox"/>
<TextBlock Text="IP Address:" Margin="0,5,0,0"/>
<TextBox Name="IpTextBox"/>
<TextBlock Text="MAC Address:" Margin="0,5,0,0"/>
<TextBox Name="MacTextBox"/>
<Button Name="ActionButton" Content="Action" Margin="0,15,0,0" Click="ActionButton_OnClick"/>
</StackPanel>
</Grid>
</Window>
96 changes: 96 additions & 0 deletions ArpmarApp/EntryWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System.Net;
using System.Windows;
using ArpmarApp.Models;
using ArpmarApp.Views;
using ArpmarCore.Domain;

namespace ArpmarApp
{
public enum EntryWindowType
{
Add,
Edit
}

public partial class EntryWindow : Window
{
private readonly EntryWindowType _type;
private readonly Arp _arp;
private readonly TableEntry _originalTableEntry;

public ArpManagementView Delegate { get; set; }

public EntryWindow(EntryWindowType type, Arp arp, TableEntry tableEntry = null)
{
InitializeComponent();

_type = type;
_arp = arp;
_originalTableEntry = tableEntry;

PrepareInterfacesComboBox();
PrepareTexts(tableEntry);
}

private void PrepareTexts(TableEntry tableEntry)
{
if (_type == EntryWindowType.Add)
{
Title = "Add Entry";
ActionButton.Content = "Add";
}
else
{
Title = "Edit Entry";
ActionButton.Content = "Save";
}

if (tableEntry == null)
return;

InterfacesComboBox.SelectedIndex = InterfacesComboBox.Items.IndexOf(tableEntry.Interface);
IpTextBox.Text = tableEntry.IpAddress;
MacTextBox.Text = tableEntry.MacAddress;
}

private void PrepareInterfacesComboBox()
{
InterfacesComboBox.Items.Clear();

foreach (string @interface in _arp.Tables.Keys)
InterfacesComboBox.Items.Add(@interface);

InterfacesComboBox.SelectedIndex = 0;
}

private void ActionButton_OnClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(IpTextBox.Text) || !IPAddress.TryParse(IpTextBox.Text, out _))
{
App.ShowMessageBox("Invalid IP address!");
return;
}

if (string.IsNullOrEmpty(MacTextBox.Text))
{
App.ShowMessageBox("Invalid MAC address!");
return;
}

var @interface = (string) InterfacesComboBox.SelectedItem;

if (_type == EntryWindowType.Add)
{
_arp.ExecuteAdd(@interface, IpTextBox.Text, MacTextBox.Text);
}
else
{
_arp.ExecuteDelete(_originalTableEntry.Interface, _originalTableEntry.IpAddress);
_arp.ExecuteAdd(@interface, IpTextBox.Text, MacTextBox.Text);
}

Delegate?.Refresh();
Close();
}
}
}
Loading

0 comments on commit 8e205a9

Please sign in to comment.