-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9810920
commit 8e205a9
Showing
36 changed files
with
1,357 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.