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

Commit

Permalink
Slight refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeRanger committed Mar 21, 2024
1 parent 342ca4c commit 8e3f463
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged
private bool _isQueryEditingEnabled;
private string _queryName;
private string _queryDescription;
private string? _selectedQueryInActiveDirectoryInfo;
private Command? _selectedCommandInQueryBuilder;
private ConsoleViewModel _consoleOutputInQueryBuilder;
private ConsoleViewModel _consoleOutputInActiveDirectoryInfo;
private Command? _selectedCommandInQueryBuilder;
private string? _selectedQueryInActiveDirectoryInfo;
private ObservableCollection<Button>? _buttons; // TODO: Rename to be more descriptive.
private ObservableCollection<Button>? _queryButtonStackPanel; // TODO: Rename to be more descriptive.

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

private Query? _queryBeingEdited;
private readonly Query _currentQuery;
private readonly QueryManager _queryManager;
private readonly PSExecutor _psExecutor;
private Query? _queryBeingEdited;
private readonly ActiveDirectoryInfo _activeDirectoryInfo = new();
private readonly ActiveDirectoryInfo _activeDirectoryInfo;

// [ Properties ] --------------------------------------------------------------- //
// [[ Properties for backing fields ]] ------------------------------------------ //

public ObservableCollection<Button> QueryButtonStackPanel => _buttons ??= new ObservableCollection<Button>();
public ObservableCollection<Button> QueryButtonStackPanel => _queryButtonStackPanel ??= new ObservableCollection<Button>();

public ConsoleViewModel ConsoleViewModelOutputInQueryBuilder
{
Expand Down Expand Up @@ -190,11 +190,12 @@ public MainWindowViewModel()
{
_queryName = string.Empty;
_queryDescription = string.Empty;
_currentQuery = new Query();
_queryManager = new QueryManager();
_psExecutor = new PSExecutor();
_activeDirectoryInfo = new ActiveDirectoryInfo();
_consoleOutputInQueryBuilder = new ConsoleViewModel();
_consoleOutputInActiveDirectoryInfo = new ConsoleViewModel();
_psExecutor = new PSExecutor();
_queryManager = new QueryManager();
_currentQuery = new Query();

ADCommands = new ObservableCollection<Command>();
DynamicallyAvailableADCommandParameterComboBoxes = new ObservableCollection<ComboBoxParameterViewModel>();
Expand Down Expand Up @@ -228,7 +229,7 @@ public MainWindowViewModel()
// [ Methods ] ----------------------------------------------------------------- //

// TODO: Hunter: Re-review this method and make any necessary changes.
private async Task ExecuteQueryAsync(ConsoleViewModel consoleOuput, Command? command = null)
private async Task ExecuteQueryAsync(ConsoleViewModel consoleOutput, Command? command = null)
{
if (SelectedCommandInQueryBuilder is null && command is null)
{
Expand Down Expand Up @@ -256,21 +257,21 @@ private async Task ExecuteQueryAsync(ConsoleViewModel consoleOuput, Command? com

if (result.HadErrors)
{
consoleOuput.Append(result.StdErr);
consoleOutput.Append(result.StdErr);
return;
}

consoleOuput.Append(result.StdOut);
consoleOutput.Append(result.StdOut);
}
catch (Exception ex)
{
consoleOuput.Append($"Error executing command: {ex.Message}" + ex.Message);
consoleOutput.Append($"Error executing command: {ex.Message}" + ex.Message);
}
}

private void ClearConsoleOutput(ConsoleViewModel consoleOuput)
private void ClearConsoleOutput(ConsoleViewModel consoleOutput)
{
if (consoleOuput.ConsoleOutput.Length == 0)
if (consoleOutput.ConsoleOutput.Length == 0)
{
MessageBox.Show("The console is already clear.",
"Information",
Expand All @@ -287,7 +288,7 @@ private void ClearConsoleOutput(ConsoleViewModel consoleOuput)

if (result == MessageBoxResult.Yes)
{
consoleOuput.Clear();
consoleOutput.Clear();
}
}

Expand Down Expand Up @@ -750,7 +751,7 @@ private void ClearQueryBuilder(object _)
MessageBoxImage.Warning,
MessageBoxResult.No);

// If the user selects yes, clear the consoleOuput
// If the user selects yes, clear the consoleOutput
if (result == MessageBoxResult.Yes)
{
QueryName = "";
Expand Down

0 comments on commit 8e3f463

Please sign in to comment.