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

Commit

Permalink
Added a way to create/save a new file and converted everything to eit…
Browse files Browse the repository at this point in the history
…her a json or txt file
  • Loading branch information
J0seph0 committed Mar 14, 2024
1 parent 1cd9b48 commit cc48271
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions ActiveDirectoryQuerier/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Menu Width="50" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top">
<MenuItem Header="File" Width="Auto" Height="Auto" >
<MenuItem Header="Import Queries" Command="{Binding ImportQueryFileRelay}"/>
<MenuItem Header="New Query File" Command="{Binding CreateNewQueryFileRelay}" />
</MenuItem>
</Menu>
</Border>
Expand Down
16 changes: 15 additions & 1 deletion ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.....
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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"
};


Expand Down
23 changes: 13 additions & 10 deletions ActiveDirectoryQuerier/Queries/CustomQueries.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Management.Automation.Runspaces;
using System.Text.Json;
Expand All @@ -9,7 +8,7 @@
namespace ActiveDirectoryQuerier.Queries;

/// <summary>
/// This class is used to save a json file named "CustomQueries.dat" inside of
/// This class is used to save a json file named "CustomQueries.json" inside of
/// \ActiveDirectoryQuerier\ActiveDirectoryQuerier\bin\Debug\net6.0-windows This
/// </summary>
public class CustomQueries
Expand Down Expand Up @@ -37,7 +36,7 @@ public void SaveQueriesToJson()
string serializedJsonQueries = JsonSerializer.Serialize(Queries, _options);
if(CustomQueryFileLocation == "")
{
File.WriteAllText("CustomQueries.dat", serializedJsonQueries);
File.WriteAllText("CustomQueries.json", serializedJsonQueries);

} else
{
Expand All @@ -46,7 +45,6 @@ public void SaveQueriesToJson()
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
Expand Down Expand Up @@ -83,7 +81,7 @@ public void SerializeCommand(Command? psCommand, string queryName, string queryD
string serializedJsonQueries = JsonSerializer.Serialize(Queries, _options);
if (CustomQueryFileLocation == "")
{
File.WriteAllText("CustomQueries.dat", serializedJsonQueries);
File.WriteAllText("CustomQueries.json", serializedJsonQueries);

}
else
Expand All @@ -107,8 +105,14 @@ public void LoadData()
string json;
if (CustomQueryFileLocation == "")
{
json = File.ReadAllText("CustomQueries.dat");

if (File.Exists("CustomeQueries.json"))
{
json = File.ReadAllText("CustomQueries.json");
}
else
{
return;
}
}
else
{
Expand Down Expand Up @@ -136,8 +140,7 @@ public void LoadData()
}
catch (Exception exception)
{

Trace.WriteLine(exception.Message);
MessageBox.Show(exception.Message);
}
}
}
4 changes: 0 additions & 4 deletions ActiveDirectoryQuerier/Queries/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace ActiveDirectoryQuerier.Queries;

// TODO: Remove property descriptions if name is descriptive enough, or provide a detailed description if it is not.
public class Query
{
/// <summary>
Expand All @@ -15,19 +14,16 @@ public class Query
/// <summary>
/// Used for serializing the Command Name
/// </summary>
// ReSharper disable once InconsistentNaming
public string? PSCommandName { get; set; }

/// <summary>
/// Used for Serializing the Commands parameters
/// </summary>
// ReSharper disable once InconsistentNaming
public string[]? PSCommandParameters { get; set; }

/// <summary>
/// Used for Serializing the Commands parameters
/// </summary>
// ReSharper disable once InconsistentNaming
public string[]? PSCommandParameterValues { get; set; }

/// <summary>
Expand Down

0 comments on commit cc48271

Please sign in to comment.