Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions ConnectForm.xaml

This file was deleted.

71 changes: 0 additions & 71 deletions ConnectForm.xaml.cs

This file was deleted.

63 changes: 63 additions & 0 deletions DefaultUI/ConnectForm.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Window x:Class="GetWMIBasic.DefaultUI.ConnectForm"
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:GetWMIBasic"
mc:Ignorable="d"
Title="Connect To Another Computer"
Height="180"
Width="400"
MinHeight="180"
MinWidth="400"
MaxHeight="180"
MaxWidth="400"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="3*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.Margin>
<Thickness Left="5" Right="5"></Thickness>
</Grid.Margin>
<Label VerticalAlignment="Center">Connect to another computer using domain or IP</Label>
</Grid>
<Grid Grid.Row="1">
<Grid.Margin>
<Thickness Left="5" Right="5"></Thickness>
</Grid.Margin>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Computer Name</Label>
<TextBox Grid.Row="0" Grid.Column="1" x:Name="ComputerName_TextBox" VerticalAlignment="Center"/>
<Label Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">User Name</Label>
<TextBox Grid.Row="1" Grid.Column="1" x:Name="UserName_TextBox" VerticalAlignment="Center"/>
<Label Grid.Row="2" Grid.Column="0" VerticalAlignment="Center">Password</Label>
<PasswordBox Grid.Row="2" Grid.Column="1" x:Name="Password_TextBox" VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Row="2">
<Grid.Margin>
<Thickness Left="5" Right="5" Bottom="5"></Thickness>
</Grid.Margin>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Margin="0,0,5,0" Grid.Column="0" VerticalAlignment="Center" Click="ConnetToExternal_Button">Connect</Button>
<Button Margin="5,0,5,0" Grid.Column="1" VerticalAlignment="Center" Click="ConnectToLocal_Button">Connect to Local Computer</Button>
<Button Margin="5,0,0,0" Grid.Column="2" VerticalAlignment="Center" Click="Cancel_Button">Cancel</Button>
</Grid>
</Grid>
</Window>
110 changes: 110 additions & 0 deletions DefaultUI/ConnectForm.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Security;
using System.Windows;

/* The Default UI includes
* 1. ConnectForm.xaml - A form to connect to a local or remote computer
* 2. ExceptionView.xaml - A window to handle exception messages
*/
namespace GetWMIBasic.DefaultUI
{
/*
* Connection Form class
* It is used to get connection information from the user
* Expected behaviour:
* 1. User enter the computer name, username, and password to connect to a remote computer
* 2. The application tries verify the connection information
* 3. If what user enters is valid, the form closes and returns the information
*/
public partial class ConnectForm : Window
{
/*
* Global properties
* isConnectLocally: A boolean to indicate whether the user wants to connect to the local computer
* - false when the user wants to connect to a remote computer
* - true when the user wants to connect to the local computer
*/
private bool isConnectLocally;

// Constructor of the ConnectForm class
public ConnectForm()
{
// Set the default value of isConnectLocally to false
isConnectLocally = false;

// Initialize the components of the form
InitializeComponent();
}

// Button-based methods

/*
* Connect to External Button Click Event - The "Connect" button
* Validates the input fields and sets the DialogResult to true if valid
*/
private void ConnetToExternal_Button(object sender, RoutedEventArgs e)
{
// Validate that none of the input fields are empty
if (
ComputerName_TextBox.Text.Length == 0 ||
UserName_TextBox.Text.Length == 0 ||
Password_TextBox.Password.Length == 0)
{
_ = MessageBox.Show("Please don't leave anything empty", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
// Close the form with a DialogResult of true
DialogResult = true;
}
}

/*
* Connect to Local Button Click Event - The "Connect to Local" button
* Sets the isConnectLocally flag to true and sets the DialogResult to true
*/
private void ConnectToLocal_Button(object sender, RoutedEventArgs e)
{
isConnectLocally = true;
DialogResult = true;
}

/*
* Cancel Button Click Event - The "Cancel" button
* Closes the form without setting a DialogResult
*/
private void Cancel_Button(object sender, RoutedEventArgs e)
{
Close();
}


// Non-button methods

/*
* Return Value Method
* Returns a tuple containing the computer name, username, and password as a SecureString
*/
public (string, string, SecureString) ReturnValue()
{
// Show the dialog and wait for user interaction
_ = ShowDialog();

// Prepare the return values based on whether connecting locally or remotely
string computerName = (isConnectLocally) ? "localhost" : ComputerName_TextBox.Text;
string userName = (isConnectLocally) ? "" : UserName_TextBox.Text;
SecureString password = new SecureString();

// Only populate the password if connecting remotely
if (!isConnectLocally)
{
foreach (char c in Password_TextBox.Password)
{
password.AppendChar(c);
}
}

// Return the collected values as a tuple
return (computerName, userName, password);
}
}
}
47 changes: 47 additions & 0 deletions DefaultUI/ExceptionView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Window x:Class="GetWMIBasic.DefaultUI.ExceptionView"
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:GetWMIBasic"
mc:Ignorable="d"
Title="An error occurred"
Height="300"
Width="500"
ResizeMode="NoResize" WindowStyle="SingleBorderWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.Margin>
<Thickness Left="5" Right="5" Top="5"></Thickness>
</Grid.Margin>
<TextBlock Grid.Row="0" x:Name="ExceptionMessage_TextBlock" TextWrapping="NoWrap">
An exception has occurred in the application.
<LineBreak/>
You may choose to close the application or ignore the error.
</TextBlock>
</Grid>
<Grid Grid.Row="1">
<Grid.Margin>
<Thickness Left="5" Right="5"></Thickness>
</Grid.Margin>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" MinWidth="50" Margin="5,0,5,0" Click="Click_IgnoreException" x:Name="Button_Ignore" HorizontalAlignment="Right" VerticalAlignment="Center">Ignore</Button>
<Button Grid.Column="2" MinWidth="50" Margin="5,0,0,0" Click="Click_CloseApp" HorizontalAlignment="Right" VerticalAlignment="Center">Close Application</Button>
</Grid>
<Grid Grid.Row="2">
<Grid.Margin>
<Thickness Left="5" Right="5" Bottom="5"></Thickness>
</Grid.Margin>
<TextBox x:Name="DetailedExceptionDetail_TextBox" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" IsReadOnly="True" Background="LightGray"/>
</Grid>
</Grid>
</Window>
Loading
Loading