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

Commit

Permalink
Format with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeRanger committed Mar 12, 2024
1 parent eb29b9b commit d5453ad
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 58 deletions.
98 changes: 55 additions & 43 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged

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

public bool QueryEditingEnabled
{
get => _queryEditingEnabled;
Expand All @@ -49,7 +49,7 @@ public bool QueryEditingEnabled
OnPropertyChanged(nameof(QueryEditingEnabled));
}
}

public AppConsole ConsoleOutputInQueryBuilder
{
get => _consoleOutputInQueryBuilder;
Expand All @@ -67,7 +67,7 @@ public AppConsole ConsoleOutputInActiveDirectoryInfo
OnPropertyChanged(nameof(ConsoleOutputInActiveDirectoryInfo));
}
}

public string QueryName
{
get => _queryName;
Expand All @@ -79,7 +79,7 @@ public string QueryName
}
}
}

public string QueryDescription
{
get => _queryDescription;
Expand All @@ -91,7 +91,7 @@ public string QueryDescription
}
}
}

public Command? SelectedCommandFromComboBoxInQueryBuilder
{
get => _selectedCommandFromComboBoxInQueryBuilder;
Expand All @@ -106,11 +106,11 @@ public Command? SelectedCommandFromComboBoxInQueryBuilder
}
}
}

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

// [[ Other properties ]] ------------------------------------------------------- //

// ReSharper disable once InconsistentNaming
public ObservableCollection<Command> ADCommands { get; private set; }
// ReSharper disable once InconsistentNaming
Expand All @@ -119,16 +119,16 @@ public Command? SelectedCommandFromComboBoxInQueryBuilder
public ObservableCollection<ComboBoxParameterViewModel> DynamicallyAvailableADCommandParametersComboBox { get; }
// ReSharper disable once InconsistentNaming
public ObservableCollection<TextBoxViewModel> DynamicallyAvailableADCommandParameterValueTextBox { get; }

// [[ GUI element relays ]] ----------------------------------------------------- //
// [[[ Dynamically created elements ]]] ----------------------------------------- //

private ICommand EditQueryFromQueryStackPanelRelay { get; }
private ICommand DeleteQueryFromQueryStackPanelRelay { get; }
private ICommand ExecuteQueryFromQueryStackPanelRelay { get; }

// [[[ Existing GUI elements ]]] ------------------------------------------------ //

public ICommand SaveQueryRelay { get; }
public ICommand ClearQueryBuilderRelay { get; }
public ICommand ExecuteQueryFromQueryBuilderRelay { get; }
Expand All @@ -140,8 +140,9 @@ public Command? SelectedCommandFromComboBoxInQueryBuilder
public ICommand OutputToCsvFileRelay { get; }
public ICommand ExportConsoleOutputRelay { get; }
public ICommand ClearConsoleOutputInQueryBuilderRelay { get; }
public ICommand ClearConsoleOutputInActiveDirectoryInfoRelay { get; } // TODO: Pieter use this for clear console button

public ICommand ClearConsoleOutputInActiveDirectoryInfoRelay {
get;
} // TODO: Pieter use this for clear console button

/* TODO: for Pieter
*
Expand All @@ -153,7 +154,7 @@ public Command? SelectedCommandFromComboBoxInQueryBuilder
*/

// [ Constructor ] ------------------------------------------------------------- //

public MainWindowViewModel()
{
_queryName = string.Empty;
Expand All @@ -167,29 +168,32 @@ public MainWindowViewModel()
ADCommands = new ObservableCollection<Command>();
DynamicallyAvailableADCommandParametersComboBox = new ObservableCollection<ComboBoxParameterViewModel>();
DynamicallyAvailableADCommandParameterValueTextBox = new ObservableCollection<TextBoxViewModel>();

OutputToCsvFileRelay = new RelayCommand(OutputExecutionResultsToCsvFileAsync);
OutputToTextFileRelay = new RelayCommand(OutputExecutionResultsToTextFileAsync);
ExportConsoleOutputRelay = new RelayCommand(ExportConsoleOutputToFile);
// TODO: Figure out how resolve the warning about the async method not being awaited.
ExecuteQueryFromQueryBuilderRelay = new RelayCommand(_ => ExecuteQuery(_consoleOutputInQueryBuilder));
ExecuteQueryFromQueryBuilderRelay = new RelayCommand(
_ => ExecuteQuery(_consoleOutputInQueryBuilder));
// TODO: Figure out how resolve the warning about the async method not being awaited.
ExecuteQueryFromActiveDirectoryInfoRelay = new RelayCommand(_ => ExecuteQuery(_consoleOutputInActiveDirectoryInfo));
ExecuteQueryFromActiveDirectoryInfoRelay = new RelayCommand(
_ => ExecuteQuery(_consoleOutputInActiveDirectoryInfo));
AddCommandParameterComboBoxRelay = new RelayCommand(AddParameterComboBoxInQueryBuilder);
AddCommandComboBoxRelay = new RelayCommand(AddCommandComboBoxInQueryBuilder);
RemoveCommandParameterComboBoxRelay = new RelayCommand(RemoveCommandParameterComboBoxInQueryBuilder);
SaveQueryRelay = new RelayCommand(SaveQuery);
EditQueryFromQueryStackPanelRelay = new RelayCommand(EditQueryFromQueryStackPanel);
DeleteQueryFromQueryStackPanelRelay = new RelayCommand(DeleteQueryFromQueryStackPanel);
ExecuteQueryFromQueryStackPanelRelay = new RelayCommand(ExecuteQueryFromQueryStackPanel);
ClearConsoleOutputInQueryBuilderRelay = new RelayCommand(_ => ClearConsoleOutput(_consoleOutputInQueryBuilder));
ClearConsoleOutputInActiveDirectoryInfoRelay = new RelayCommand(_ => ClearConsoleOutput(_consoleOutputInActiveDirectoryInfo));
ClearConsoleOutputInQueryBuilderRelay = new RelayCommand(
_ => ClearConsoleOutput(_consoleOutputInQueryBuilder));
ClearConsoleOutputInActiveDirectoryInfoRelay = new RelayCommand(
_ => ClearConsoleOutput(_consoleOutputInActiveDirectoryInfo));
ClearQueryBuilderRelay = new RelayCommand(ClearQueryBuilder);

/* TODO: For Pieter
* Connect the relay property to for the execute button to you method that performs the execution.
*/


// TODO: Figure out how resolve the warning about the async method not being awaited.
InitializeActiveDirectoryCommandsAsync();
Expand All @@ -210,7 +214,7 @@ public MainWindowViewModel()
*
* In this class, create a method or two, that will be used to execute the specific selected action.
*/

private void ClearConsoleOutput(AppConsole appConsole)
{
if (appConsole.ConsoleOutput.Length == 0)
Expand All @@ -233,7 +237,7 @@ private void ClearConsoleOutput(AppConsole appConsole)
appConsole.Clear();
}
}

private void EditQueryFromQueryStackPanel(object queryButton)
{
var currentQuery = (Query)((Button)queryButton).Tag;
Expand All @@ -244,8 +248,7 @@ private void EditQueryFromQueryStackPanel(object queryButton)
QueryDescription = currentQuery.QueryDescription;

// Fill in the commandName
Command chosenCommand =
ADCommands.FirstOrDefault(item => item.CommandText == currentQuery.PSCommandName)!;
Command chosenCommand = ADCommands.FirstOrDefault(item => item.CommandText == currentQuery.PSCommandName)!;
SelectedCommandFromComboBoxInQueryBuilder = chosenCommand;

// Load the Possible Parameters Synchronously
Expand All @@ -267,14 +270,15 @@ private void EditQueryFromQueryStackPanel(object queryButton)
Trace.WriteLine(currentQuery.PSCommandParameters[i]);

// Adds the Parameters boxes
AddParameterComboBoxInQueryBuilder(null!); // Null is never used, so we use null forgiveness operator.
AddParameterComboBoxInQueryBuilder(null!); // Null is never used, so we use null forgiveness operator.

// Fill in the parameter boxes
DynamicallyAvailableADCommandParametersComboBox[i].SelectedParameter = currentQuery.PSCommandParameters[i];
DynamicallyAvailableADCommandParameterValueTextBox[i].SelectedParameterValue = currentQuery.PSCommandParameterValues[i];
DynamicallyAvailableADCommandParameterValueTextBox[i].SelectedParameterValue =
currentQuery.PSCommandParameterValues[i];
}
}

private async void ExecuteQueryFromQueryStackPanel(object queryButton)
{
if (queryButton is not Button currentButton)
Expand All @@ -290,7 +294,7 @@ private async void ExecuteQueryFromQueryStackPanel(object queryButton)
var buttonQuery = (Query)currentButton.Tag;
await ExecuteQueryCoreAsync(ConsoleOutputInQueryBuilder, buttonQuery.Command);
}

private void DeleteQueryFromQueryStackPanel(object queryButton)
{
if (queryButton is not Button currentButton)
Expand All @@ -307,7 +311,7 @@ private void DeleteQueryFromQueryStackPanel(object queryButton)
_customQuery.Queries.Remove((Query)currentButton.Tag);
_customQuery.SaveQueriesToJson();
}

private void LoadSavedQueriesFromFile()
{
try
Expand All @@ -328,13 +332,13 @@ private void LoadSavedQueriesFromFile()
Trace.WriteLine(ex);
}
}

// TODO: Possibly change Task to void?
private async Task ExecuteQuery(AppConsole appConsole, Command? command = null)
{
await ExecuteQueryCoreAsync(appConsole, command);
}

// TODO: Possibly change Task to void?
private async Task InitializeActiveDirectoryCommandsAsync()
{
Expand All @@ -351,12 +355,13 @@ private async Task LoadCommandParametersAsync(Command? selectedCommand)
OnPropertyChanged(nameof(AvailableADCommandParameters));

// Update the possible properties of the ComboBoxParameterViewModels.
foreach (ComboBoxParameterViewModel comboBoxParameterViewModel in DynamicallyAvailableADCommandParametersComboBox)
foreach (ComboBoxParameterViewModel comboBoxParameterViewModel in
DynamicallyAvailableADCommandParametersComboBox)
{
comboBoxParameterViewModel.AvailableParameters = AvailableADCommandParameters;
}
}

// TODO: Hunter: Re-review this method and make any necessary changes.
private async Task ExecuteQueryCoreAsync(AppConsole appConsole, Command? command = null)
{
Expand Down Expand Up @@ -411,7 +416,8 @@ private void AddParameterComboBoxInQueryBuilder(object _)
return;
}

DynamicallyAvailableADCommandParametersComboBox.Add(new ComboBoxParameterViewModel(AvailableADCommandParameters));
DynamicallyAvailableADCommandParametersComboBox.Add(
new ComboBoxParameterViewModel(AvailableADCommandParameters));
DynamicallyAvailableADCommandParameterValueTextBox.Add(new TextBoxViewModel());
}

Expand Down Expand Up @@ -551,15 +557,16 @@ private void GetCurrentQuery()
string[] commandParameters;
string[] commandParameterValues;

if (SelectedCommandFromComboBoxInQueryBuilder is not null && SelectedCommandFromComboBoxInQueryBuilder.Parameters is not null)
if (SelectedCommandFromComboBoxInQueryBuilder is not null &&
SelectedCommandFromComboBoxInQueryBuilder.Parameters is not null)
{
commandParameters = new string[SelectedCommandFromComboBoxInQueryBuilder.Parameters.Count];
commandParameterValues = new string[SelectedCommandFromComboBoxInQueryBuilder.Parameters.Count];

_currentQuery.QueryDescription = QueryDescription;
_currentQuery.QueryName = QueryName;
_currentQuery.PSCommandName = SelectedCommandFromComboBoxInQueryBuilder.CommandText;

for (int i = 0; i < SelectedCommandFromComboBoxInQueryBuilder.Parameters.Count; i++)
{
CommandParameter commandParameter = SelectedCommandFromComboBoxInQueryBuilder.Parameters[i];
Expand All @@ -582,8 +589,10 @@ private void RemoveCommandParameterComboBoxInQueryBuilder(object _)
{
if (DynamicallyAvailableADCommandParametersComboBox.Count != 0)
{
DynamicallyAvailableADCommandParametersComboBox.RemoveAt(DynamicallyAvailableADCommandParametersComboBox.Count - 1);
DynamicallyAvailableADCommandParameterValueTextBox.RemoveAt(DynamicallyAvailableADCommandParameterValueTextBox.Count - 1);
DynamicallyAvailableADCommandParametersComboBox.RemoveAt(
DynamicallyAvailableADCommandParametersComboBox.Count - 1);
DynamicallyAvailableADCommandParameterValueTextBox.RemoveAt(
DynamicallyAvailableADCommandParameterValueTextBox.Count - 1);
}
else
{
Expand Down Expand Up @@ -638,7 +647,8 @@ private void SaveQuery(object commandParameter)

private void ClearQueryBuilder(object _)
{
if (SelectedCommandFromComboBoxInQueryBuilder is null && DynamicallyAvailableADCommandParametersComboBox.Count == 0)
if (SelectedCommandFromComboBoxInQueryBuilder is null &&
DynamicallyAvailableADCommandParametersComboBox.Count == 0)
{
MessageBox.Show("The query builder is already clear.",
"Information",
Expand Down Expand Up @@ -694,7 +704,8 @@ private Button CreateCustomButton(Query? query = null)

GetCurrentQuery();
newButton.Height = 48;
newButton.Content = QueryName.Length != 0 ? QueryName : SelectedCommandFromComboBoxInQueryBuilder.CommandText;
newButton.Content =
QueryName.Length != 0 ? QueryName : SelectedCommandFromComboBoxInQueryBuilder.CommandText;
newButton.Tag = _currentQuery;
}

Expand All @@ -712,7 +723,8 @@ private Button CreateCustomButton(Query? query = null)
menuItem1.Items.Add(outputToText);
menuItem1.Items.Add(outputToConsole);

MenuItem menuItem2 = new() { Header = "Edit", Command = EditQueryFromQueryStackPanelRelay, CommandParameter = newButton };
MenuItem menuItem2 =
new() { Header = "Edit", Command = EditQueryFromQueryStackPanelRelay, CommandParameter = newButton };

MenuItem menuItem3 =
new() { Header = "Delete", Command = DeleteQueryFromQueryStackPanelRelay, CommandParameter = newButton };
Expand All @@ -728,7 +740,7 @@ private Button CreateCustomButton(Query? query = null)
}

// [[ Event Handlers ]] --------------------------------------------------------- //

private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
Expand Down
4 changes: 2 additions & 2 deletions ActiveDirectoryQuerier/PowerShell/PSExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public PSExecutor()
private void PrepareCommand(Command psCommand)
{
ArgumentNullException.ThrowIfNull(psCommand);

_powerShell.Commands.AddCommand(psCommand.CommandText);

foreach (var parameter in psCommand.Parameters)
{
_powerShell.Commands.AddParameter(parameter.Name, parameter.Value);
Expand Down
12 changes: 4 additions & 8 deletions ActiveDirectoryQuerier/Queries/CustomQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ public void SerializeCommand(Command? psCommand, string queryName, string queryD
string[] commandParameters = new string[psCommand.Parameters.Count];
string[] commandParameterValues = new string[psCommand.Parameters.Count];
CustomQueries customQueries = new();
Query newQuery = new(psCommand.CommandText)
{
QueryName = queryName,
QueryDescription = queryDescription
};

Query newQuery = new(psCommand.CommandText) { QueryName = queryName, QueryDescription = queryDescription };

// TODO: Determine if this line is necessary.
Trace.WriteLine(psCommand.Parameters.Count);

Expand All @@ -69,13 +65,13 @@ public void SerializeCommand(Command? psCommand, string queryName, string queryD
commandParameters[i] = param.Name;
commandParameterValues[i] = param.Value.ToString();
}

newQuery.PSCommandParameters = commandParameters;
newQuery.PSCommandParameterValues = commandParameterValues;

Queries.Add(newQuery);
customQueries.SaveQueriesToJson();

try
{
string serializedJsonQueries = JsonSerializer.Serialize(Queries, _options);
Expand Down
10 changes: 5 additions & 5 deletions ActiveDirectoryQuerier/RelayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ public class RelayCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Predicate<object?>? _canExecute;

/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action<object> execute, Predicate<object?>? canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}

public bool CanExecute(object? parameter)
{
return _canExecute?.Invoke(parameter) ?? true;
}

public void Execute(object? parameter)
{
// For now, we are ignoring the warning about the parameter being null.
_execute(parameter!);
}

public event EventHandler? CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}

public void RaiseCanExecuteChanged()
{
CommandManager.InvalidateRequerySuggested();
Expand Down

0 comments on commit d5453ad

Please sign in to comment.