-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
GUI Rewrite + More
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; |
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(" ")); | ||
} | ||
} | ||
} |
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 | ||
{ } |
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) | ||
)] |
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 GitHub Actions / build (x64)
Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
Check warning on line 20 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
|
||
|
||
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 GitHub Actions / build (x64)
Check warning on line 28 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
Check warning on line 28 in FAFB-PowerShell-Tool/Command.cs GitHub Actions / build (x64)
|
||
{ | ||
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]; | ||
} | ||
} |