Skip to content

Commit 6b8c4a5

Browse files
New Exception Handler + Update for comments (#2)
* move to better namespace Co-Authored-By: VLTA of @TheFlightSims <176574466+anhvlt-2k6@users.noreply.github.com> * exceptions handlers Co-Authored-By: VLTA of @TheFlightSims <176574466+anhvlt-2k6@users.noreply.github.com> * update for new files Co-Authored-By: VLTA of @TheFlightSims <176574466+anhvlt-2k6@users.noreply.github.com> * Update MachineMethods.cs * Update MainWindow.xaml.cs * update for correctness Co-Authored-By: VLTA of @TheFlightSims <176574466+anhvlttfs@users.noreply.github.com> --------- Co-authored-by: VLTA of @TheFlightSims <176574466+anhvlt-2k6@users.noreply.github.com> Co-authored-by: VLTA of @TheFlightSims <176574466+anhvlttfs@users.noreply.github.com>
1 parent e30cdba commit 6b8c4a5

File tree

10 files changed

+614
-272
lines changed

10 files changed

+614
-272
lines changed

ConnectForm.xaml

Lines changed: 0 additions & 61 deletions
This file was deleted.

ConnectForm.xaml.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

DefaultUI/ConnectForm.xaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<Window x:Class="GetWMIBasic.DefaultUI.ConnectForm"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:GetWMIBasic"
7+
mc:Ignorable="d"
8+
Title="Connect To Another Computer"
9+
Height="180"
10+
Width="400"
11+
MinHeight="180"
12+
MinWidth="400"
13+
MaxHeight="180"
14+
MaxWidth="400"
15+
ResizeMode="NoResize"
16+
SizeToContent="WidthAndHeight">
17+
<Grid>
18+
<Grid.RowDefinitions>
19+
<RowDefinition Height="*"/>
20+
<RowDefinition Height="3*"/>
21+
<RowDefinition Height="*"/>
22+
</Grid.RowDefinitions>
23+
<Grid Grid.Row="0">
24+
<Grid.Margin>
25+
<Thickness Left="5" Right="5"></Thickness>
26+
</Grid.Margin>
27+
<Label VerticalAlignment="Center">Connect to another computer using domain or IP</Label>
28+
</Grid>
29+
<Grid Grid.Row="1">
30+
<Grid.Margin>
31+
<Thickness Left="5" Right="5"></Thickness>
32+
</Grid.Margin>
33+
<Grid.ColumnDefinitions>
34+
<ColumnDefinition Width="2*"/>
35+
<ColumnDefinition Width="5*"/>
36+
</Grid.ColumnDefinitions>
37+
<Grid.RowDefinitions>
38+
<RowDefinition/>
39+
<RowDefinition/>
40+
<RowDefinition/>
41+
</Grid.RowDefinitions>
42+
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Computer Name</Label>
43+
<TextBox Grid.Row="0" Grid.Column="1" x:Name="ComputerName_TextBox" VerticalAlignment="Center"/>
44+
<Label Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">User Name</Label>
45+
<TextBox Grid.Row="1" Grid.Column="1" x:Name="UserName_TextBox" VerticalAlignment="Center"/>
46+
<Label Grid.Row="2" Grid.Column="0" VerticalAlignment="Center">Password</Label>
47+
<PasswordBox Grid.Row="2" Grid.Column="1" x:Name="Password_TextBox" VerticalAlignment="Center"/>
48+
</Grid>
49+
<Grid Grid.Row="2">
50+
<Grid.Margin>
51+
<Thickness Left="5" Right="5" Bottom="5"></Thickness>
52+
</Grid.Margin>
53+
<Grid.ColumnDefinitions>
54+
<ColumnDefinition Width="*"/>
55+
<ColumnDefinition Width="4*"/>
56+
<ColumnDefinition Width="*"/>
57+
</Grid.ColumnDefinitions>
58+
<Button Margin="0,0,5,0" Grid.Column="0" VerticalAlignment="Center" Click="ConnetToExternal_Button">Connect</Button>
59+
<Button Margin="5,0,5,0" Grid.Column="1" VerticalAlignment="Center" Click="ConnectToLocal_Button">Connect to Local Computer</Button>
60+
<Button Margin="5,0,0,0" Grid.Column="2" VerticalAlignment="Center" Click="Cancel_Button">Cancel</Button>
61+
</Grid>
62+
</Grid>
63+
</Window>

DefaultUI/ConnectForm.xaml.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System.Security;
2+
using System.Windows;
3+
4+
/* The Default UI includes
5+
* 1. ConnectForm.xaml - A form to connect to a local or remote computer
6+
* 2. ExceptionView.xaml - A window to handle exception messages
7+
*/
8+
namespace GetWMIBasic.DefaultUI
9+
{
10+
/*
11+
* Connection Form class
12+
* It is used to get connection information from the user
13+
* Expected behaviour:
14+
* 1. User enter the computer name, username, and password to connect to a remote computer
15+
* 2. The application tries verify the connection information
16+
* 3. If what user enters is valid, the form closes and returns the information
17+
*/
18+
public partial class ConnectForm : Window
19+
{
20+
/*
21+
* Global properties
22+
* isConnectLocally: A boolean to indicate whether the user wants to connect to the local computer
23+
* - false when the user wants to connect to a remote computer
24+
* - true when the user wants to connect to the local computer
25+
*/
26+
private bool isConnectLocally;
27+
28+
// Constructor of the ConnectForm class
29+
public ConnectForm()
30+
{
31+
// Set the default value of isConnectLocally to false
32+
isConnectLocally = false;
33+
34+
// Initialize the components of the form
35+
InitializeComponent();
36+
}
37+
38+
// Button-based methods
39+
40+
/*
41+
* Connect to External Button Click Event - The "Connect" button
42+
* Validates the input fields and sets the DialogResult to true if valid
43+
*/
44+
private void ConnetToExternal_Button(object sender, RoutedEventArgs e)
45+
{
46+
// Validate that none of the input fields are empty
47+
if (
48+
ComputerName_TextBox.Text.Length == 0 ||
49+
UserName_TextBox.Text.Length == 0 ||
50+
Password_TextBox.Password.Length == 0)
51+
{
52+
_ = MessageBox.Show("Please don't leave anything empty", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
53+
}
54+
else
55+
{
56+
// Close the form with a DialogResult of true
57+
DialogResult = true;
58+
}
59+
}
60+
61+
/*
62+
* Connect to Local Button Click Event - The "Connect to Local" button
63+
* Sets the isConnectLocally flag to true and sets the DialogResult to true
64+
*/
65+
private void ConnectToLocal_Button(object sender, RoutedEventArgs e)
66+
{
67+
isConnectLocally = true;
68+
DialogResult = true;
69+
}
70+
71+
/*
72+
* Cancel Button Click Event - The "Cancel" button
73+
* Closes the form without setting a DialogResult
74+
*/
75+
private void Cancel_Button(object sender, RoutedEventArgs e)
76+
{
77+
Close();
78+
}
79+
80+
81+
// Non-button methods
82+
83+
/*
84+
* Return Value Method
85+
* Returns a tuple containing the computer name, username, and password as a SecureString
86+
*/
87+
public (string, string, SecureString) ReturnValue()
88+
{
89+
// Show the dialog and wait for user interaction
90+
_ = ShowDialog();
91+
92+
// Prepare the return values based on whether connecting locally or remotely
93+
string computerName = (isConnectLocally) ? "localhost" : ComputerName_TextBox.Text;
94+
string userName = (isConnectLocally) ? "" : UserName_TextBox.Text;
95+
SecureString password = new SecureString();
96+
97+
// Only populate the password if connecting remotely
98+
if (!isConnectLocally)
99+
{
100+
foreach (char c in Password_TextBox.Password)
101+
{
102+
password.AppendChar(c);
103+
}
104+
}
105+
106+
// Return the collected values as a tuple
107+
return (computerName, userName, password);
108+
}
109+
}
110+
}

DefaultUI/ExceptionView.xaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Window x:Class="GetWMIBasic.DefaultUI.ExceptionView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:GetWMIBasic"
7+
mc:Ignorable="d"
8+
Title="An error occurred"
9+
Height="300"
10+
Width="500"
11+
ResizeMode="NoResize" WindowStyle="SingleBorderWindow">
12+
<Grid>
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="1*"/>
15+
<RowDefinition Height="1*"/>
16+
<RowDefinition Height="3*"/>
17+
</Grid.RowDefinitions>
18+
<Grid Grid.Row="0">
19+
<Grid.Margin>
20+
<Thickness Left="5" Right="5" Top="5"></Thickness>
21+
</Grid.Margin>
22+
<TextBlock Grid.Row="0" x:Name="ExceptionMessage_TextBlock" TextWrapping="NoWrap">
23+
An exception has occurred in the application.
24+
<LineBreak/>
25+
You may choose to close the application or ignore the error.
26+
</TextBlock>
27+
</Grid>
28+
<Grid Grid.Row="1">
29+
<Grid.Margin>
30+
<Thickness Left="5" Right="5"></Thickness>
31+
</Grid.Margin>
32+
<Grid.ColumnDefinitions>
33+
<ColumnDefinition/>
34+
<ColumnDefinition Width="Auto"/>
35+
<ColumnDefinition Width="Auto"/>
36+
</Grid.ColumnDefinitions>
37+
<Button Grid.Column="1" MinWidth="50" Margin="5,0,5,0" Click="Click_IgnoreException" x:Name="Button_Ignore" HorizontalAlignment="Right" VerticalAlignment="Center">Ignore</Button>
38+
<Button Grid.Column="2" MinWidth="50" Margin="5,0,0,0" Click="Click_CloseApp" HorizontalAlignment="Right" VerticalAlignment="Center">Close Application</Button>
39+
</Grid>
40+
<Grid Grid.Row="2">
41+
<Grid.Margin>
42+
<Thickness Left="5" Right="5" Bottom="5"></Thickness>
43+
</Grid.Margin>
44+
<TextBox x:Name="DetailedExceptionDetail_TextBox" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" IsReadOnly="True" Background="LightGray"/>
45+
</Grid>
46+
</Grid>
47+
</Window>

0 commit comments

Comments
 (0)