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

Commit

Permalink
Merge pull request #30 from StrangeRanger/dev
Browse files Browse the repository at this point in the history
GUI Rewrite + More
  • Loading branch information
StrangeRanger authored Dec 27, 2023
2 parents dc4090e + be2c9ab commit 45f3f72
Show file tree
Hide file tree
Showing 15 changed files with 643 additions and 165 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
- name: Dotnet Build & Publish
run: |
dotnet restore
dotnet build $env:Project_File -c Debug -f net8.0-windows -r win-${{ matrix.targetplatform }} --no-restore
dotnet publish $env:Project_File -c Debug -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore
dotnet build $env:Project_File -c Debug -f net6.0-windows -r win-${{ matrix.targetplatform }} --no-restore
dotnet publish $env:Project_File -c Debug -f net6.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore
#- name: Upload Artifact
# uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
- name: Dotnet Build & Publish
run: |
dotnet restore
dotnet build $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} --no-restore
dotnet publish $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore
dotnet build $env:Project_File -c Release -f net6.0-windows -r win-${{ matrix.targetplatform }} --no-restore
dotnet publish $env:Project_File -c Release -f net6.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }} --no-restore
- name: Zip Release Files
run: Compress-Archive -Path .\publish\FAFB_PowerShell_Tool_${{ matrix.targetplatform }} -DestinationPath .\FAFB_PowerShell_Tool_${{ matrix.targetplatform }}.zip
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,11 @@ $RECYCLE.BIN/
.vscode/launch.json

.vscode/tasks.json

.idea/.idea.FAFB-PowerShell-Tool/.idea/indexLayout.xml

.idea/.idea.FAFB-PowerShell-Tool/.idea/workspace.xml

FAFB-PowerShell-Tool/FAFB-PowerShell-Tool-Output.txt

.idea/.idea.FAFB-PowerShell-Tool/.idea/
2 changes: 1 addition & 1 deletion FAFB-PowerShell-Tool.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using Microsoft.VisualStudio.TestTools.UnitTesting;
35 changes: 15 additions & 20 deletions FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FAFB_PowerShell_Tool.Tests;

namespace FAFB_PowerShell_Tool.Tests
[TestClass]
public class PowerShellExecutorTest
{
[TestClass]
public class PowerShellExecutorTest
private readonly PowerShellExecutor _powerShellExecutor = new();

[TestMethod]
public void ThrowArgumentNullExceptionWhenCommandTextIsNull()
{
[TestMethod]
public void ThrowArgumentNullExceptionWhenCommandTextIsNull()
{
Assert.ThrowsException<ArgumentNullException>(() => PowerShellExecutor.Execute(null!));
}
Assert.ThrowsException<ArgumentNullException>(() => _powerShellExecutor.Execute(null!));
}

[TestMethod]
public void ThrowArgumentExceptionWhenCommandTextIsWhitespace()
{
Assert.ThrowsException<ArgumentException>(() => PowerShellExecutor.Execute(""));
Assert.ThrowsException<ArgumentException>(() => PowerShellExecutor.Execute(" "));
}
[TestMethod]
public void ThrowArgumentExceptionWhenCommandTextIsWhitespace()
{
Assert.ThrowsException<ArgumentException>(() => _powerShellExecutor.Execute(""));
Assert.ThrowsException<ArgumentException>(() => _powerShellExecutor.Execute(" "));
}
}
}
19 changes: 7 additions & 12 deletions FAFB-PowerShell-Tool/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System.Configuration;
using System.Data;
using System.Windows;
using System.Windows;

namespace FAFB_PowerShell_Tool
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
namespace FAFB_PowerShell_Tool;

}
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{ }
15 changes: 7 additions & 8 deletions FAFB-PowerShell-Tool/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
[assembly:ThemeInfo(ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located
// (used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly // where the generic resource dictionary is located
// (used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
107 changes: 107 additions & 0 deletions FAFB-PowerShell-Tool/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Management.Automation;
using System.Windows;

namespace FAFB_PowerShell_Tool;

/// <summary>
/// This class is used to organize the all of the powershell commands
/// </summary>
///
/// <param name="CommandName">This is the root commands name ex. "get-aduser" </param>
/// <param name="Parameters">This is an array of the parameter options that the command has</param>
/// <param name="ParameterCount">This is the counr of the parameter array</param>
public class Command
{
public string CommandName { get; set; }
private string[] Parameters { get; set; }
private int ParameterCount { get; set; }
private static readonly PowerShellExecutor PowerShellExecutor = PowerShellExecutor;

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Possible null reference assignment.

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Assignment made to same variable; did you mean to assign something else?

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Possible null reference assignment.

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Assignment made to same variable; did you mean to assign something else?

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Possible null reference assignment.

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Assignment made to same variable; did you mean to assign something else?

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Possible null reference assignment.

Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Assignment made to same variable; did you mean to assign something else?

public Command(string commandName, string[] parameters, int parameterCount)
{
CommandName = commandName;
Parameters = parameters;
ParameterCount = parameterCount;
}
public Command(string commandName)

Check warning on line 28 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Non-nullable property 'Parameters' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 28 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Non-nullable property 'Parameters' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 28 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Non-nullable property 'Parameters' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 28 in FAFB-PowerShell-Tool/Command.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Non-nullable property 'Parameters' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
CommandName = commandName;
}

/// <summary>
/// This is a method for getting a list of commands from a file
/// </summary>
/// <returns> "list" this is an ObservableCollection of the Commands </returns>
public static ObservableCollection<Command> ReadFileCommandList()
{
ObservableCollection<Command> list = new ObservableCollection<Command>();

try
{
// get the file path will probably want user input eventually and to use relative paths
string srcFilePath =
"C:\\Users\\pickl\\Source\\Repos\\FAFB-PowerShell-Tool\\FAFB-PowerShell-Tool\\commands.txt";
string[] lines = File.ReadAllLines(srcFilePath);

// Trim the strings and add them to the return list
foreach (string line in lines)
{
string trimmedLine = line.Trim();
Command command = new Command(trimmedLine);

list.Add(command);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

return list;
}

/// <summary>
/// Retrieves the commands of a particular module.
/// </summary>
/// <returns>A List of Commands in an Observable Collection.</returns>
public static ObservableCollection<Command> GetPowerShellCommands()
{
return new ObservableCollection<Command>();
}

/// <summary>
/// Retrieves the parameters of a Command.
/// </summary>
/// <param name="c">The command in question.</param>
/// <returns>...</returns>
public static string[] GetParametersArray(Command c)
{
string getParameterSetNames =
"Import-Module ActiveDirectory" + "(Get-Command " + c.CommandName +
").ParameterSets | Select-Object -Property @{n='ParameterSetName';e={$_.name}}, @{n='Parameters';e={$_.ToString()}}";

// List<string> results = PowerShellExecutor.Execute(getParameterSetnames);
// Trace.WriteLine(results.Count);

try
{
List<string> commandOutput = PowerShellExecutor.Execute(getParameterSetNames);
string fullCommandOutput = "";

foreach (var str in commandOutput)
{
fullCommandOutput += str;
}

MessageBoxOutput.ShowMessageBox(fullCommandOutput);
}
catch (Exception ex)
{
MessageBoxOutput.ShowMessageBox(ex.Message, MessageBoxOutput.OutputType.InternalError);
}

return new string[1];
}
}
6 changes: 3 additions & 3 deletions FAFB-PowerShell-Tool/FAFB-PowerShell-Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RootNamespace>FAFB_PowerShell_Tool</RootNamespace>
<Nullable>enable</Nullable>
Expand All @@ -18,8 +18,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.0" />
<PackageReference Include="System.Management.Automation" Version="7.4.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.17" />
<PackageReference Include="System.Management.Automation" Version="7.2.17" />
</ItemGroup>

</Project>
101 changes: 73 additions & 28 deletions FAFB-PowerShell-Tool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,83 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FAFB_PowerShell_Tool"
mc:Ignorable="d"
Title="Active Directory Queries" Height="450" Width="800">
Title="MainWindow" Height="500" Width="800">
<Grid>
<!-- Define Rows -->
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<!-- Row for Header -->
<RowDefinition Height="*" />
<!-- Remaining space for split grid -->
</Grid.RowDefinitions>

<Grid Background="White">
<Grid Margin="155,64,0,0" Background="White">
<Button x:Name="Execute_Button" Content="Execute" HorizontalAlignment="Left" Margin="408,87,0,0" VerticalAlignment="Top" Height="49" Width="140" Click="ExecutionButton"/>
<Button x:Name="Execute_Generic_Command" Content="Execute Non-PowerShell Command" HorizontalAlignment="Left" Margin="408,28,0,0" VerticalAlignment="Top" Height="43" Width="198" Click="ExecuteGenericCommand"/>
<Border BorderThickness="1" BorderBrush="Black" RenderTransformOrigin="0.516,0.595">
<!-- Static Header Bar -->
<Border Grid.Row="0" Background="DarkGray" Height="50">
<TextBlock Text="Header" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>

</Border>
</Grid>
<Grid x:Name="Left_Side_Query_Bar" HorizontalAlignment="Left" Height="370" Margin="0,64,0,0" VerticalAlignment="Top" Width="155">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF616161" Offset="0"/>
<GradientStop Color="#FF5F5F5F" Offset="0.363"/>
<GradientStop Color="#FF898989" Offset="0.737"/>
</LinearGradientBrush>
</Grid.Background>
<Button x:Name="Command_Button_1" Content="Command 1" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Height="49" Width="140" Click="CommandButton1"/>
<Button x:Name="Command_Button_2" Content="Command 2" HorizontalAlignment="Left" Margin="0,59,0,0" VerticalAlignment="Top" Height="48" Width="140" Click="CommandButton2"/>
<Button x:Name="Command_Button_3" Content="Command 3" HorizontalAlignment="Left" Margin="0,107,0,0" VerticalAlignment="Top" Height="49" Width="140" Click="CommandButton3"/>
<Button x:Name="Command_Button_4" Content="Command 4" HorizontalAlignment="Left" Margin="0,156,0,0" VerticalAlignment="Top" Height="48" Width="140" Click="CommandButton4"/>
</Grid>
<!-- Grid for resizable content -->
<Grid Grid.Row="1">
<!-- Define Columns for resizable area -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="1" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>

<Grid x:Name="Header_Bar" HorizontalAlignment="Center" Height="64" VerticalAlignment="Top" Width="800">
<TextBlock x:Name="Title" HorizontalAlignment="Left" Margin="40,0,0,0" TextWrapping="Wrap" Text="Active Directory Queries" VerticalAlignment="Center" FontSize="18" Width="220" FontWeight="Bold"/>
<Button Content="Home" HorizontalAlignment="Left" Margin="647,28,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<Button HorizontalAlignment="Left" Margin="545,24,0,0" VerticalAlignment="Top">
<Button Content="Connect to Ad" Click="Button_Click_1"/>
</Button>
<!-- Left Side Query Bar (Content in first column) -->
<Grid x:Name="LeftSideQueryGrid" Grid.Column="0">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF616161" Offset="0"/>
<GradientStop Color="#FF5F5F5F" Offset="0.363"/>
<GradientStop Color="#FF898989" Offset="0.737"/>
</LinearGradientBrush>
</Grid.Background>

</Grid>
<!-- Predefined Queries -->
<Button x:Name="SampleOne" Content="Sample 1" Click="MSampleOne" VerticalAlignment="Top" Height="49" Grid.Row="0"/>
<Button x:Name="SampleTwo" Content="Sample 2" Click="MSampleTwo" Margin="0,49,0,0" VerticalAlignment="Top" Height="48"/>
<Button x:Name="SampleThree" Content="Sample 3" Click="MSampleThree" Margin="0,97,0,0" VerticalAlignment="Top" Height="50"/>
</Grid>

<!-- Grid Splitter for resizing -->
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Center" Background="Gray" />

<!-- TabControl Grid (Content in third column) -->
<Grid x:Name="RightSideQueryGrid" Background="White" Grid.Column="2">
<Border BorderThickness="1" BorderBrush="Black" RenderTransformOrigin="0.516,0.595">
<TabControl>
<!-- Tab Items -->
<TabItem Header="Main">
<Grid Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="91*"/>
<ColumnDefinition Width="100*"/>
<ColumnDefinition Width="446*"/>
</Grid.ColumnDefinitions>
<Button x:Name="ExecuteGenericCommand" Content="Execute Non-PowerShell Command" Click="MExecuteGenericCommand" HorizontalAlignment="Left" Margin="204,26,0,0" VerticalAlignment="Top" Height="44" Width="198" Grid.Column="2"/>
<Button x:Name="ExecutionButton" Content="Execute" Click="MExecutionButton" HorizontalAlignment="Left" Margin="206,88,0,0" VerticalAlignment="Top" Height="49" Width="140" Grid.Column="2"/>
</Grid>
</TabItem>
<!-- Tab Items -->
<TabItem Header="Query Builder">
<Grid Background="#FFE5E5E5">
<ComboBox x:Name="ComboBoxCommandList" SelectionChanged="MComboBoxSelectionChanged" HorizontalAlignment="Left" Margin="26,48,0,0" VerticalAlignment="Top" Width="216" BorderBrush="#FFD41818" Background="Black" IsEditable="True" />
<ComboBox x:Name="ComboBoxCommandParameters" HorizontalAlignment="Left" Margin="278,48,0,0" VerticalAlignment="Top" Width="212" IsEditable="True"/>
<Button x:Name="SaveQueryButton" Click="MSaveQueryButton" Content="Save Query" HorizontalAlignment="Left" Margin="459,275,0,0" VerticalAlignment="Top" Height="29" Width="83" />
</Grid>
</TabItem>
<!-- Tab Items -->
<TabItem Header="Script Editor" HorizontalAlignment="Center" >
<Grid Background="#FFE5E5E5" Height="406">
<TextBox x:Name="ScriptEditorTextBox" HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="568" Height="295" KeyboardNavigation.AcceptsReturn="True" Margin="0,10,0,0"/>
<Button Content="Execute" HorizontalAlignment="Left" Margin="508,345,0,0" VerticalAlignment="Top" Height="25" Width="70"/>
</Grid>
</TabItem>
</TabControl>
</Border>
</Grid>
</Grid>
</Grid>
</Window>
Loading

0 comments on commit 45f3f72

Please sign in to comment.