From 72f5fd40a866d61802238f9b79ad08a32453e2fb Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 20 Mar 2022 20:19:20 -0400 Subject: [PATCH 1/7] Reporting logic --- ITATKWinUI.csproj | 8 +++++ MainWindow.xaml | 13 ++++---- MainWindow.xaml.cs | 72 ++++++++++++++++++++++++++++++++++++++++++++- Reporting.xaml | 14 +++++++++ Reporting.xaml.cs | 31 +++++++++++++++++++ Usage.csv | Bin 0 -> 192 bytes XML/Categories.xml | 1 - 7 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 Reporting.xaml create mode 100644 Reporting.xaml.cs create mode 100644 Usage.csv diff --git a/ITATKWinUI.csproj b/ITATKWinUI.csproj index f27ecfd..f6a8844 100644 --- a/ITATKWinUI.csproj +++ b/ITATKWinUI.csproj @@ -27,6 +27,7 @@ + @@ -41,6 +42,7 @@ + @@ -106,6 +108,12 @@ PreserveNewest + + Always + + + MSBuild:Compile + Always diff --git a/MainWindow.xaml b/MainWindow.xaml index bbc3015..4fe80c5 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -49,13 +49,14 @@ - - + --> + - + @@ -180,7 +181,7 @@ - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 0ad20de..cbc82da 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -27,6 +27,8 @@ using System.Management.Automation.Runspaces; using System.Threading.Tasks; using System.Collections.ObjectModel; +using CsvHelper; +using System.Globalization; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -53,6 +55,17 @@ namespace ITATKWinUI // } //} + public class ReportingRecord + { + public string ScriptName { get; set; } + public string ScriptPath { get; set; } + public DateTime DateTime { get; set; } + public string UserExecuting { get; set; } + public string HostExecuting { get; set; } + public string FileExtension { get; set; } + public string Target { get; set; } + } + public partial class MainWindow : Window { //TODO: Need a way to reset these as well as resetting the UI @@ -432,7 +445,13 @@ void Image_Loaded(object sender, RoutedEventArgs e) tmp.Content = headerContentStackPanel; //Add Run and Explore click events - headerContentRunButton.Click += (sender, e) => LaunchScript(path, psVersion, inputType); + void RunButtonMethods() + { + LaunchScript(path, psVersion, inputType); + WriteReportingRecord(name, path, CurrentInput, psVersion); + } + + headerContentRunButton.Click += (sender, e) => RunButtonMethods(); headerContentExploreButton.Click += (sender, e) => LaunchExplorer(path); return tmp; @@ -572,6 +591,11 @@ private void MainNav_SelectionChanged(NavigationView sender, NavigationViewSelec _page = typeof(Settings); contentFrame.Navigate(_page); //TODO: Should we hide the machine input, terminal, and machine info pane here? If so ensure we show it once we navigate away below + } else if (args.SelectedItemContainer.Content.ToString() == "Reporting") + { + Type _page = null; + _page = typeof(Reporting); + contentFrame.Navigate(_page); } else { @@ -674,6 +698,51 @@ private void FullScreenTerminal_Click(object sender, RoutedEventArgs e) } } + public static string reportFilePath = Environment.CurrentDirectory + "\\Usage.csv"; + + public static void WriteReportingRecord(string ScriptTitle, string ScriptFilePath, string MachineInput, string Type) + { + //Name, Input, Time, User Executing, Host Executing + var newRecord = new List + { + new ReportingRecord { + ScriptName = ScriptTitle, + ScriptPath = ScriptFilePath, + HostExecuting = Environment.MachineName, + FileExtension = Type, + Target = MachineInput, + UserExecuting = Environment.UserName, + DateTime = DateTime.Now + } + }; + + var records = GetReportingRecords(); + + using (var writer = new StreamWriter(reportFilePath)) + using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) + { + csv.WriteHeader(); + csv.NextRecord(); + foreach (var record in records) + { + csv.WriteRecord(record); + csv.NextRecord(); + } + csv.WriteRecords(newRecord); + csv.NextRecord(); + } + } + + public static List GetReportingRecords() + { + using (var reader = new StreamReader(reportFilePath)) + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + { + var records = csv.GetRecords(); + return records.ToList(); + } + } + private void ClearTerminal_Click(object sender, RoutedEventArgs e) { //ScriptTerminal.Text = ""; @@ -806,6 +875,7 @@ PSDataCollection RunPing(string CurrentInput) } else { + CurrentInput = ""; PingSymbol.Visibility = Visibility.Collapsed; } } diff --git a/Reporting.xaml b/Reporting.xaml new file mode 100644 index 0000000..38d2173 --- /dev/null +++ b/Reporting.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/Reporting.xaml.cs b/Reporting.xaml.cs new file mode 100644 index 0000000..bd50af7 --- /dev/null +++ b/Reporting.xaml.cs @@ -0,0 +1,31 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace ITATKWinUI +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class Reporting : Page + { + public Reporting() + { + this.InitializeComponent(); + } + } +} diff --git a/Usage.csv b/Usage.csv new file mode 100644 index 0000000000000000000000000000000000000000..6ab19277d4f24c0128df46ce1fc5612a6b6c10a5 GIT binary patch literal 192 zcmZ{eO$x#=5QV?B;3cx|F=}xo1>*rq2yH;4#1uSz?W@V68yCa;d~e>&cQIUXBmyro z7X}`942@z>dXdaj$(bi_^(Q`3J7(2^$XI!&?k=+NtQ@5d+KH80xh1K+Xt{Nh!fW== PvHjimSoxF>j~rM5)Kwxk literal 0 HcmV?d00001 diff --git a/XML/Categories.xml b/XML/Categories.xml index 2a1e8f3..70f7da1 100644 --- a/XML/Categories.xml +++ b/XML/Categories.xml @@ -5,7 +5,6 @@ - From a6920e607b01dd5cfe4214b4cb68f8ca59bf1d4e Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 31 Jul 2022 09:29:38 -0400 Subject: [PATCH 2/7] 1.0.5 changelog note --- Changelog.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.xml b/Changelog.xml index ed0fb7c..fbec1c0 100644 --- a/Changelog.xml +++ b/Changelog.xml @@ -3,4 +3,5 @@ + \ No newline at end of file From 4d0acd47cbc00b36d1a404b6fc5d922ef49c967d Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 31 Jul 2022 09:30:05 -0400 Subject: [PATCH 3/7] Bumped window size to 1250 by default to support reporting table UI --- App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App.xaml.cs b/App.xaml.cs index 3eeb82e..01634da 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -109,7 +109,7 @@ void LoadIcon(string iconName) // The Window object doesn't have Width and Height properties in WInUI 3 Desktop yet. // To set the Width and Height, you can use the Win32 API SetWindowPos. // Note, you should apply the DPI scale factor if you are thinking of dpi instead of pixels. - SetWindowSize(m_windowHandle, 1200, 680); + SetWindowSize(m_windowHandle, 1250, 680); } public static string Title; From ad8f6d898a2e0ff8b68d10c8814dc5eddc3a6e76 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 31 Jul 2022 09:30:26 -0400 Subject: [PATCH 4/7] Windows App Runtime Redist version currency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9af387c..61c892b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ - Eventually, explore cross-platform support for macOS and Linux. **Prerequisites (In-Progress):** -- At a minimum if you just want to run the built app you will need the proper [Windows App Runtime Redist](https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/downloads#current-releases) (Currently: Version 1.0.1) installed, this project is primarily targeted towards x64 but please feel free to open an Issue or PR for other platforms if you find they aren't working. +- At a minimum if you just want to run the built app you will need the proper [Windows App Runtime Redist](https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/downloads#current-releases) (Currently: Version 1.1.3) installed, this project is primarily targeted towards x64 but please feel free to open an Issue or PR for other platforms if you find they aren't working. - For development - environmental requirements can be found [here](https://docs.microsoft.com/en-us/windows/apps/winui/winui3/create-your-first-winui3-app#unpackaged-create-a-new-project-for-an-unpackaged-c-or-c-winui-3-desktop-app) - Currently, this project is intended to be unpackaged if you are running the .sln from Visual Studio - Other potential things to check: From f611e0396c24e405b2c601972cd947cb8d179b79 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 31 Jul 2022 09:30:54 -0400 Subject: [PATCH 5/7] General version currency, added CommunityToolkit.WinUI.UI.Controls to enable use with DataGrid control --- ITATKWinUI.csproj | 11 ++++++----- Reporting.xaml | 5 ++--- Reporting.xaml.cs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ITATKWinUI.csproj b/ITATKWinUI.csproj index f6a8844..7db2162 100644 --- a/ITATKWinUI.csproj +++ b/ITATKWinUI.csproj @@ -42,11 +42,12 @@ - - - - - + + + + + + diff --git a/Reporting.xaml b/Reporting.xaml index 38d2173..577138e 100644 --- a/Reporting.xaml +++ b/Reporting.xaml @@ -5,10 +5,9 @@ xmlns:local="using:ITATKWinUI" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - - - + diff --git a/Reporting.xaml.cs b/Reporting.xaml.cs index bd50af7..7c7b584 100644 --- a/Reporting.xaml.cs +++ b/Reporting.xaml.cs @@ -23,9 +23,40 @@ namespace ITATKWinUI /// public sealed partial class Reporting : Page { + System.Collections.ObjectModel.ObservableCollection ReportData = new System.Collections.ObjectModel.ObservableCollection(); + public Reporting() { this.InitializeComponent(); + + var records = MainWindow.GetReportingRecords(); + + foreach(ReportingRecord record in records) + { + ReportData.Add(new ReportingData(record.ScriptName, record.ScriptPath, record.HostExecuting, record.FileExtension, record.Target, record.UserExecuting, record.DateTime)); + } + } + } + + public class ReportingData + { + public string ScriptName { get; set; } + public string ScriptPath { get; set; } + public string HostExecuting { get; set; } + public string FileExtension { get; set; } + public string Target { get; set; } + public string UserExecuting { get; set; } + public DateTime DateTime { get; set; } + + public ReportingData(string ScriptName, string ScriptPath, string HostExecuting, string FileExtension, string Target, string UserExecuting, DateTime DateTime) + { + this.ScriptName = ScriptName; + this.ScriptPath = ScriptPath; + this.HostExecuting = HostExecuting; + this.FileExtension = FileExtension; + this.Target = Target; + this.UserExecuting = UserExecuting; + this.DateTime = DateTime; } } } From a7caad9f07bda8913dd14cdd9c35954734c246e1 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 31 Jul 2022 09:31:50 -0400 Subject: [PATCH 6/7] Revert "General version currency, added CommunityToolkit.WinUI.UI.Controls to enable use with DataGrid control" This reverts commit f611e0396c24e405b2c601972cd947cb8d179b79. --- ITATKWinUI.csproj | 11 +++++------ Reporting.xaml | 5 +++-- Reporting.xaml.cs | 31 ------------------------------- 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/ITATKWinUI.csproj b/ITATKWinUI.csproj index 7db2162..f6a8844 100644 --- a/ITATKWinUI.csproj +++ b/ITATKWinUI.csproj @@ -42,12 +42,11 @@ - - - - - - + + + + + diff --git a/Reporting.xaml b/Reporting.xaml index 577138e..38d2173 100644 --- a/Reporting.xaml +++ b/Reporting.xaml @@ -5,9 +5,10 @@ xmlns:local="using:ITATKWinUI" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - + + + diff --git a/Reporting.xaml.cs b/Reporting.xaml.cs index 7c7b584..bd50af7 100644 --- a/Reporting.xaml.cs +++ b/Reporting.xaml.cs @@ -23,40 +23,9 @@ namespace ITATKWinUI /// public sealed partial class Reporting : Page { - System.Collections.ObjectModel.ObservableCollection ReportData = new System.Collections.ObjectModel.ObservableCollection(); - public Reporting() { this.InitializeComponent(); - - var records = MainWindow.GetReportingRecords(); - - foreach(ReportingRecord record in records) - { - ReportData.Add(new ReportingData(record.ScriptName, record.ScriptPath, record.HostExecuting, record.FileExtension, record.Target, record.UserExecuting, record.DateTime)); - } - } - } - - public class ReportingData - { - public string ScriptName { get; set; } - public string ScriptPath { get; set; } - public string HostExecuting { get; set; } - public string FileExtension { get; set; } - public string Target { get; set; } - public string UserExecuting { get; set; } - public DateTime DateTime { get; set; } - - public ReportingData(string ScriptName, string ScriptPath, string HostExecuting, string FileExtension, string Target, string UserExecuting, DateTime DateTime) - { - this.ScriptName = ScriptName; - this.ScriptPath = ScriptPath; - this.HostExecuting = HostExecuting; - this.FileExtension = FileExtension; - this.Target = Target; - this.UserExecuting = UserExecuting; - this.DateTime = DateTime; } } } From b17c87013a8f3386ed85820b2374e9ceaf49421c Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 31 Jul 2022 09:30:54 -0400 Subject: [PATCH 7/7] General version currency, added CommunityToolkit.WinUI.UI.Controls to enable use with DataGrid control --- ITATKWinUI.csproj | 11 ++++++----- Reporting.xaml | 5 ++--- Reporting.xaml.cs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ITATKWinUI.csproj b/ITATKWinUI.csproj index f6a8844..7db2162 100644 --- a/ITATKWinUI.csproj +++ b/ITATKWinUI.csproj @@ -42,11 +42,12 @@ - - - - - + + + + + + diff --git a/Reporting.xaml b/Reporting.xaml index 38d2173..577138e 100644 --- a/Reporting.xaml +++ b/Reporting.xaml @@ -5,10 +5,9 @@ xmlns:local="using:ITATKWinUI" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - - - + diff --git a/Reporting.xaml.cs b/Reporting.xaml.cs index bd50af7..7c7b584 100644 --- a/Reporting.xaml.cs +++ b/Reporting.xaml.cs @@ -23,9 +23,40 @@ namespace ITATKWinUI /// public sealed partial class Reporting : Page { + System.Collections.ObjectModel.ObservableCollection ReportData = new System.Collections.ObjectModel.ObservableCollection(); + public Reporting() { this.InitializeComponent(); + + var records = MainWindow.GetReportingRecords(); + + foreach(ReportingRecord record in records) + { + ReportData.Add(new ReportingData(record.ScriptName, record.ScriptPath, record.HostExecuting, record.FileExtension, record.Target, record.UserExecuting, record.DateTime)); + } + } + } + + public class ReportingData + { + public string ScriptName { get; set; } + public string ScriptPath { get; set; } + public string HostExecuting { get; set; } + public string FileExtension { get; set; } + public string Target { get; set; } + public string UserExecuting { get; set; } + public DateTime DateTime { get; set; } + + public ReportingData(string ScriptName, string ScriptPath, string HostExecuting, string FileExtension, string Target, string UserExecuting, DateTime DateTime) + { + this.ScriptName = ScriptName; + this.ScriptPath = ScriptPath; + this.HostExecuting = HostExecuting; + this.FileExtension = FileExtension; + this.Target = Target; + this.UserExecuting = UserExecuting; + this.DateTime = DateTime; } } }