From cc4827169f781802a51838c38238eae3376f6d31 Mon Sep 17 00:00:00 2001 From: J0seph0 <103216770+J0seph0@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:28:37 -0700 Subject: [PATCH] Added a way to create/save a new file and converted everything to either a json or txt file --- ActiveDirectoryQuerier/MainWindow.xaml | 1 + ActiveDirectoryQuerier/MainWindowViewModel.cs | 16 ++++++++++++- .../Queries/CustomQueries.cs | 23 +++++++++++-------- ActiveDirectoryQuerier/Queries/Query.cs | 4 ---- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/ActiveDirectoryQuerier/MainWindow.xaml b/ActiveDirectoryQuerier/MainWindow.xaml index 689ac82..e39fa67 100644 --- a/ActiveDirectoryQuerier/MainWindow.xaml +++ b/ActiveDirectoryQuerier/MainWindow.xaml @@ -26,6 +26,7 @@
diff --git a/ActiveDirectoryQuerier/MainWindowViewModel.cs b/ActiveDirectoryQuerier/MainWindowViewModel.cs index d15248c..a155491 100644 --- a/ActiveDirectoryQuerier/MainWindowViewModel.cs +++ b/ActiveDirectoryQuerier/MainWindowViewModel.cs @@ -163,6 +163,7 @@ public Command? SelectedCommandFromComboBoxInActiveDirectoryInfo public ICommand ExportConsoleOutputRelay { get; } public ICommand ClearConsoleOutputInQueryBuilderRelay { get; } public ICommand ImportQueryFileRelay { get; } + public ICommand CreateNewQueryFileRelay { get; } public ICommand ClearConsoleOutputInActiveDirectoryInfoRelay { get; } // TODO: Impliment functionality..... @@ -204,6 +205,7 @@ public MainWindowViewModel() ExecuteQueryFromActiveDirectoryInfoRelay = new RelayCommand( _ => ExecuteQuery(_consoleOutputInActiveDirectoryInfo)); ImportQueryFileRelay = new RelayCommand(ImportQueryFile); + CreateNewQueryFileRelay = new RelayCommand(CreateNewQueryFile); AddCommandParameterComboBoxRelay = new RelayCommand(AddParameterComboBoxInQueryBuilder); AddCommandComboBoxRelay = new RelayCommand(AddCommandComboBoxInQueryBuilder); RemoveCommandParameterComboBoxRelay = new RelayCommand(RemoveCommandParameterComboBoxInQueryBuilder); @@ -347,6 +349,18 @@ private void DeleteQueryFromQueryStackPanel(object queryButton) } } + private void CreateNewQueryFile(object _) + { + // Saves/creates a new save file for the queries + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Json files (*.json)|*.json|Text files (*.txt)|*.txt"; + if (saveFileDialog.ShowDialog() == true) + { + File.WriteAllText(saveFileDialog.FileName, string.Empty); + _customQuery.CustomQueryFileLocation = saveFileDialog.FileName; + } + } + private void LoadSavedQueriesFromFile() { try @@ -372,7 +386,7 @@ private void ImportQueryFile(object _) { OpenFileDialog dialog = new() { FileName = "CustomQueries.dat", - Filter = "All files(*.*) | *.*" + Filter = "Json files (*.json)|*.json|Text Files (*.txt)|*.txt" }; diff --git a/ActiveDirectoryQuerier/Queries/CustomQueries.cs b/ActiveDirectoryQuerier/Queries/CustomQueries.cs index 02d9d93..511e1a3 100644 --- a/ActiveDirectoryQuerier/Queries/CustomQueries.cs +++ b/ActiveDirectoryQuerier/Queries/CustomQueries.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.IO; using System.Management.Automation.Runspaces; using System.Text.Json; @@ -9,7 +8,7 @@ namespace ActiveDirectoryQuerier.Queries; ///