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

Commit

Permalink
Can now clear the console of all text
Browse files Browse the repository at this point in the history
Set the stage for exporting console output...
  • Loading branch information
StrangeRanger committed Mar 8, 2024
1 parent 3cc28c2 commit a27a029
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 30 deletions.
39 changes: 18 additions & 21 deletions ActiveDirectoryQuerier/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
</Grid.ColumnDefinitions>

<!-- Left Side Query Bar (Content in first column) -->
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid x:Name="LeftSideQueryGrid" Grid.Column="0">
<ScrollViewer Grid.Column="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid>
<Grid.BindingGroup>
<BindingGroup/>
</Grid.BindingGroup>
Expand Down Expand Up @@ -74,9 +74,9 @@
<ColumnDefinition Width="163*"/>
<ColumnDefinition Width="856*"/>
</Grid.ColumnDefinitions>
<!-- Query Name TextBox.TODO: add a title/header to them -->
<TextBox Text="{Binding QueryName}" Margin="10,29,10,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="50" Grid.ColumnSpan="2"/>
<RichTextBox Margin="10,108,10,200" Grid.ColumnSpan="2">
<!-- Query Name TextBox. -->
<TextBox Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding QueryName}" Margin="10,29,10,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="50" />
<RichTextBox Grid.Column="0" Margin="10,108,10,200" Grid.ColumnSpan="2">
<FlowDocument>
<Paragraph>
<Run Text="{Binding QueryDescription}"/>
Expand All @@ -90,14 +90,14 @@
<Grid Background="#FFE5E5E5">
<!-- Define Rows. -->
<Grid.RowDefinitions>
<!-- TODO: Figure out why the bottom row isn't stopping at the specified min height!!! -->
<!-- TODO: Figure out why the bottom row isn't stopping at the specified min height! -->
<RowDefinition Height="Auto" MinHeight="100"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="5"/>
<RowDefinition Height="3*" MinHeight="100"/>
</Grid.RowDefinitions>
<!-- TODO: Fix the margin so that the combo boxes are not so spaced-->
<Grid Grid.Row="0" Grid.ColumnSpan="3" Margin="0,0,0,100" Grid.RowSpan="2">
<Grid Margin="0,0,0,100" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
Expand Down Expand Up @@ -130,7 +130,6 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- TODO: Fill these-->
<ItemsControl ItemsSource="{Binding DynamicParameterValuesCollection}"
Grid.Column="2">
<ItemsControl.ItemTemplate>
Expand Down Expand Up @@ -160,34 +159,32 @@

<Button Content="Add New Command Slot"
Command="{Binding AddCommandComboBoxRelay}"
Grid.Column="0"/>
Grid.Column="0" />
<Button Content="Add New Parameter Slot"
Command="{Binding AddParameterComboBoxRelay}"
Grid.Column="1"/>
Grid.Column="1 "/>
<Button Content="Remove Parameter Slot"
Command="{Binding RemoveParameterComboBoxRelay}"
Grid.Column="2"
/>
Grid.Column="2" />

<Button x:Name="SaveQueryButton"
Content="Save Query"
Command="{Binding SaveCustomQueriesRelay}"
Grid.Column="3" />
<Button Content="Save Query"
Command="{Binding SaveCustomQueriesRelay}"
Grid.Column="3" />
<Button Content="Execute"
Command="{Binding ExecuteCommandRelay}"
Grid.Column="4" />
<Button Content="Export Console Output"
Command="{Binding ExportConsoleOutput}"
Command="{Binding ExportConsoleOutputRelay}"
Grid.Column="5" />
<Button Content="Clear Console Output"
Command="{Binding ClearConsoleOutput}"
Command="{Binding ClearConsoleOutputRelay}"
Grid.Column="6" />
</Grid>

<!-- GridSplitter for resizing console area in the second row -->
<GridSplitter Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Background="White" Grid.Row="2" Grid.ColumnSpan="2"/>

<!-- TODO: Figure out why I can't get the console to be resizable to the min height... -->
<!-- TODO: Figure out why I can't get the console to be resizable to the min height! -->
<!-- TODO: Pieter refer here for the console output... try replicate for tab three -->
<Grid Grid.Row="3" Grid.ColumnSpan="2">
<!-- TextBox as Console Output -->
Expand Down Expand Up @@ -226,7 +223,7 @@
Command="{Binding ExportConsoleOutput}"
/>
<MenuItem Header="Clear Console Output"
Command="{Binding ClearConsoleOutput}"
Command="{Binding ClearConsoleOutputRelay}"
/>
<MenuItem Header="Add Button"
Command="{Binding AddButton}"
Expand All @@ -236,7 +233,7 @@

</MenuItem>
</Menu>
<CheckBox x:Name="isEditing" Content="Editing" HorizontalAlignment="Left" Margin="14,57,0,0" VerticalAlignment="Top" IsChecked="{Binding EditingEnabled}"/>
<CheckBox Grid.Row="0" x:Name="isEditing" Content="Editing" HorizontalAlignment="Left" Margin="14,57,0,0" VerticalAlignment="Top" IsChecked="{Binding EditingEnabled}"/>
</Grid>
</TabItem>
<TabItem Header="Active Directory Information">
Expand Down
64 changes: 55 additions & 9 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,29 @@ public Command? SelectedComboBoxCommand
/// Command to output to a csv when executing
/// </summary>
public ICommand OutputToCsvFileRelay { get; }

/// <summary>
/// Command to export the console output to a text file.
/// </summary>
public ICommand ExportConsoleOutputRelay { get; }

/// <summary>
/// Command to clear the console output.
/// </summary>
public ICommand ClearConsoleOutputRelay { get; }

/*
/* TODO: Info for Pieter to get started
* AD Info options combobox dropdown
* Get all AD user
* Get all IP's on domain
* Get all etc, etc.
*/

/*
/* TODO: Info for Pieter to get started
* another property to contain current AD Info selected command
*/

// [ Constructors ] ------------------------------------------------------------ //
// [ Constructors ] ------------------------------------------------------------- //

/// <summary>
/// Class constructor.
Expand All @@ -240,19 +250,21 @@ public MainWindowViewModel()
ExecuteCommandRelay = new RelayCommand(ExecuteCommandAsync);
OutputToCsvFileRelay = new RelayCommand(OutputToCsvFileAsync);
OutputToTextFileRelay = new RelayCommand(OutputToTextFileAsync);
ExportConsoleOutputRelay = new RelayCommand(ExportConsoleOutput);
AddParameterComboBoxRelay = new RelayCommand(AddParameterComboBox);
AddCommandComboBoxRelay = new RelayCommand(AddCommandComboBox);
RemoveParameterComboBoxRelay = new RelayCommand(RemoveParameterComboBox);
SaveCustomQueriesRelay = new RelayCommand(SaveCustomQueries);
EditCustomQueryRelay = new RelayCommand(EditCustomQuery);
DeleteCustomQueryRelay = new RelayCommand(DeleteCustomQuery);
ExecuteCommandButtonRelay = new RelayCommand(ExecuteCustomQueryCommandButton);
ClearConsoleOutputRelay = new RelayCommand(ClearConsoleOutput);
ClearQueryBuilderRelay = new RelayCommand(ClearQueryBuilder);

InitializeActiveDirectoryCommandsAsync(); // TODO: Maybe change this method to synchronous...

Check warning on line 264 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.
LoadCustomQueries(); // Calls method to deserialize and load buttons.

// Debug
// Uncomment to test the deserialization of the custom queries with more information
/*foreach (Button t in QueryButtonStackPanel)
{
CustomQueries.Query test = (CustomQueries.Query)t.Tag;
Expand All @@ -262,11 +274,6 @@ public MainWindowViewModel()

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

/// <summary>
/// This method will edit the Query and fill out the field with the desired query and you can edit the query
/// </summary>
/// <param name="sender">This is the object that is clicked when executing</param>

/// Pieter TODO (New Code)
/*public void ActiveDirectoryInfo()
{
Expand All @@ -276,7 +283,36 @@ public MainWindowViewModel()
Collection<PSObject> ReturnValue results = powerShell.ExecuteCommand(command);
}*/

private void ClearConsoleOutput(object _)
{
if (PowerShellOutput.ConsoleOutput.Length == 0)
{
MessageBox.Show("The console is already clear.",
"Information",
MessageBoxButton.OK,
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.ClearConsole();
}
}

/// <summary>
/// This method will edit the Query and fill out the field with the desired query and you can edit the query
/// </summary>
/// <param name="sender">This is the object that is clicked when executing</param>
private void EditCustomQuery(object sender)
{
// Get the button that we are editing
Expand Down Expand Up @@ -572,6 +608,16 @@ private async void OutputToCsvFileAsync(object _)
await File.WriteAllTextAsync(filePath, csv.ToString());
}
}

/// <summary>
/// Adds a new command selection ComboBox to the UI.
/// </summary>
/// <param name="_">This is the object that the command is bound to.</param>
private void ExportConsoleOutput(object _)
{
Trace.WriteLine("Not implemented yet.");
MessageBox.Show("Not implemented yet.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}

/// <summary>
/// This method is for getting the currently selected command at anytime
Expand Down

0 comments on commit a27a029

Please sign in to comment.