Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Small refactoring, comment updates, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeRanger committed Mar 10, 2024
1 parent 1dc24fa commit 786c672
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged
private string _queryName;
private string _queryDescription;
private AppConsole _powerShellOutput;
private AppConsole _activeDirectoryInfoOutput; // Pieter TODO
private AppConsole _activeDirectoryInfoOutput; // TODO: Info for Pieter to get started
private Command? _selectedComboBoxCommand;
private ObservableCollection<Button>? _buttons;

// [[ Other fields ]] ----------------------------------------------------------- //

private readonly CustomQueries _customQuery;
private readonly Query _currentQuery;
private readonly CustomQueries _customQuery;
private readonly PowerShellExecutor _powerShellExecutor;
// Probably want to add the ability to toggle editing vs not editing but filled in.
private Query? _isEditing;
private readonly PowerShellExecutor _powerShellExecutor;

// [ Properties ] --------------------------------------------------------------- //
// [[ Properties for backing fields ]] ------------------------------------------ //
Expand Down Expand Up @@ -69,7 +69,7 @@ public AppConsole PowerShellOutput
}
}

// Pieter TODO
// TODO: Info for Pieter to get started
public AppConsole ActiveDirectoryInfoOutput
{
get => _activeDirectoryInfoOutput;
Expand Down Expand Up @@ -121,7 +121,7 @@ public Command? SelectedComboBoxCommand
// No need to load parameters if the command is null.
if (value is not null)
{
// TODO: Figure out how to resolve the warning about the async method not being awaited.
// TODO: Figure out how to resolve the warning about the async method not being awaited!!!
LoadCommandParametersAsync(value);

Check warning on line 125 in ActiveDirectoryQuerier/MainWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ public MainWindowViewModel()

// [ Methods ] ----------------------------------------------------------------- //

/// Pieter TODO (New Code)
// TODO: Info for Pieter to get started
/*public void ActiveDirectoryInfo()
{
PowerShellExecutor powerShell = new PowerShellExecutor();
Expand All @@ -281,6 +281,10 @@ public MainWindowViewModel()
Collection<PSObject> ReturnValue results = powerShell.ExecuteCommand(command);
}*/

/// <summary>
/// This method will clear the console output and prompt the user if they are sure they want to clear the console.
/// </summary>
/// <param name="_">This is the object that the command is tied to.</param>
private void ClearConsoleOutput(object _)
{
if (PowerShellOutput.ConsoleOutput.Length == 0)
Expand All @@ -291,15 +295,13 @@ private void ClearConsoleOutput(object _)
MessageBoxImage.Information);
return;
}

// Display a gui box confirming if the user wants to confirm the clear

MessageBoxResult result = MessageBox.Show("Are you sure you want to clear the console output?",
"Warning",
MessageBoxButton.YesNo,
MessageBoxImage.Warning,
MessageBoxResult.No);

// If the user selects yes, clear the console

if (result == MessageBoxResult.Yes)
{
PowerShellOutput.Clear();
Expand Down Expand Up @@ -433,7 +435,7 @@ private void LoadCustomQueries()
/// <summary>
/// Executes the selected PowerShell command asynchronously.
/// </summary>
/// <param name="_">Parameter is not used, but required for the ICommand interface.</param>
/// <param name="_">This is the object that the command is bound to.</param>
private async void ExecuteCommandAsync(object _)
{
await ExecuteSelectedCommandAsync();
Expand All @@ -445,7 +447,7 @@ private async void ExecuteCommandAsync(object _)
private async Task InitializeActiveDirectoryCommandsAsync()
{
ObservableCollection<Command> list = await ActiveDirectoryCommands.GetActiveDirectoryCommands();
ActiveDirectoryCommandsList = new(list);
ActiveDirectoryCommandsList = new ObservableCollection<Command>(list);
OnPropertyChanged(nameof(ActiveDirectoryCommandsList));
}

Expand All @@ -470,10 +472,11 @@ private async Task LoadCommandParametersAsync(Command? selectedCommand)
/// <summary>
/// Executes the currently selected PowerShell command and updates the PowerShellOutput property with the result.
/// </summary>
/// <param name="command">The PowerShell command to execute.</param>
/// <returns>A Task representing the asynchronous operation of executing the command.</returns>
private async Task ExecuteSelectedCommandAsync(Command? inCommand = null)
private async Task ExecuteSelectedCommandAsync(Command? command = null)
{
if (SelectedComboBoxCommand is null && inCommand is null)
if (SelectedComboBoxCommand is null && command is null)
{
Trace.WriteLine("No command selected.");
MessageBox.Show("To execute a command, you must first select a command.",
Expand All @@ -483,13 +486,12 @@ private async Task ExecuteSelectedCommandAsync(Command? inCommand = null)
return;
}

ReturnValues result;

try
{
if (inCommand is not null)
ReturnValues result;
if (command is not null)
{
result = await _powerShellExecutor.ExecuteAsync(inCommand);
result = await _powerShellExecutor.ExecuteAsync(command);
}
else
{
Expand Down

0 comments on commit 786c672

Please sign in to comment.