Skip to content

Commit

Permalink
- Added MAC address table reset button
Browse files Browse the repository at this point in the history
 - fixed user score calculation
  • Loading branch information
Philipp Albrecht committed Mar 1, 2021
1 parent a3a4b3b commit bdefa06
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions MacTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public SwitchPort this[string mac]

public override string ToString()
{
var output = " MAC | Port\n";
var output = " MAC | Port\n";
output += "--------------\n";
foreach(var e in macAddressToSwichPort)
{
output += String.Format("{0,-5} | {1,-5}\n", e.Key, e.Value.Num.ToString());
output += String.Format(" {0,-5}| {1,-5}\n", e.Key, e.Value.Num.ToString());
}
return output;
}
Expand Down
5 changes: 3 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VLANSimulator"
mc:Ignorable="d"
Title="VLAN Switch Simulator by Philipp Albrecht <[email protected]> https://github.com/muqiuq/vlansimulator" Height="600" Width="930">
Title="VLAN Switch Simulator by Philipp Albrecht <[email protected]> https://github.com/muqiuq/vlansimulator" Height="630" Width="930" ResizeMode="NoResize">
<Grid x:Name="mainGrid">
<Button x:Name="buttonCheck" Content="Start" HorizontalAlignment="Left" Margin="320,449,0,0" VerticalAlignment="Top" Click="buttonCheckClick" Width="270" Height="41" FontSize="16"/>
<TextBox x:Name="textBoxMacTables" HorizontalAlignment="Left" Margin="320,10,0,0" Text="MAC Address Tables are empty" TextWrapping="Wrap" VerticalAlignment="Top" Width="270" Height="433" FontFamily="Courier New" FontSize="14"/>
<TextBox x:Name="textBoxMacTables" HorizontalAlignment="Left" Margin="320,10,0,0" Text="MAC address tables are empty" TextWrapping="Wrap" VerticalAlignment="Top" Width="270" Height="433" FontFamily="Courier New" FontSize="14"/>
<Rectangle Margin="10,0,475,10" VerticalAlignment="Bottom" Height="44" Fill="LightGreen" Stroke="LightGray"/>
<TextBlock x:Name="textBlockAction" Margin="15,0,480,15" Text="" TextWrapping="Wrap" VerticalAlignment="Bottom" Height="35" FontFamily="Courier New" FontSize="14"/>
<Rectangle Margin="460,0,10,10" VerticalAlignment="Bottom" Height="44" Fill="LightYellow" Stroke="LightGray"/>
<TextBlock x:Name="textBlockPoints" Margin="460,0,15,15" Text="" TextWrapping="Wrap" VerticalAlignment="Bottom" Height="35" FontFamily="Courier New" FontSize="14"/>
<Button x:Name="buttonClearMacTable" Content="Clear MAC address tables" Margin="374,505,394,0" VerticalAlignment="Top" Click="buttonClearMacTable_Click"/>

</Grid>
</Window>
6 changes: 5 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ private void buttonCheckClick(object sender, RoutedEventArgs e)
}
}


private void buttonClearMacTable_Click(object sender, RoutedEventArgs e)
{
switchEngine.ClearMacAddressTables();
textBoxMacTables.Text = "MAC address tables are empty.";
}
}
}
5 changes: 5 additions & 0 deletions SwitchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public string GetMacTablesAsPrettyString()
return output;
}

public void ClearMacAddressTables()
{
macTablePerVlan.Clear();
}

public SwitchAction ProcessEthernetFrame(EthernetFrame ethernetFrame)
{
if (ethernetFrame.AttachedCurrentlyToSwitchPort == null) return null;
Expand Down
4 changes: 2 additions & 2 deletions UserScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void WrongAnswer()
public override string ToString()
{
if (correctAnswers + wrongAnswers == 0) return "";
return String.Format("{0} points ({1}/{2}, {3}% correct)", Score.ToString("#,##0"), correctAnswers, wrongAnswers,
((correctAnswers/(correctAnswers+wrongAnswers))* 100).ToString("0.##")
return String.Format("{0} points ({1}/{2}, {3}% correct)", Score.ToString("#,##0"), correctAnswers, correctAnswers + wrongAnswers,
(((decimal)correctAnswers/(correctAnswers+wrongAnswers))* 100).ToString("0.##")
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions VLANSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<PackageIcon>networkswitch.png</PackageIcon>
<RepositoryUrl>https://github.com/muqiuq/vlansimulator</RepositoryUrl>
<StartupObject>VLANSimulator.App</StartupObject>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<FileVersion>1.3.0.0</FileVersion>
<Version>1.3.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit bdefa06

Please sign in to comment.