Skip to content

Commit

Permalink
Merge pull request #18 from nkasco/feature-reporting
Browse files Browse the repository at this point in the history
Feature reporting
  • Loading branch information
nkasco authored Jul 31, 2022
2 parents 8fda4de + b17c870 commit 0a2bb5b
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 14 deletions.
2 changes: 1 addition & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<Item version="1.0" detail="Initial Launch (Material Design in XAML UI)" />
<Item version="1.0.2" detail="First WinUI app revamp preview" />
<Item version="1.0.4" detail="Automatic updates now available" />
<Item version="1.0.5" detail="Upgraded Windows App SDK to 1.1.3, basic reporting functionality implemented" />
</Changelog>
17 changes: 13 additions & 4 deletions ITATKWinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<None Remove="Assets\Powershell7.ico" />
<None Remove="Loading.xaml" />
<None Remove="MachineInfo.ps1" />
<None Remove="Reporting.xaml" />
<None Remove="Settings.xaml" />
</ItemGroup>

Expand All @@ -41,10 +42,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="microsoft.powershell.sdk" Version="7.2.1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.194" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.1" />
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="CsvHelper" Version="28.0.1" />
<PackageReference Include="microsoft.powershell.sdk" Version="7.2.5" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.3" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down Expand Up @@ -106,6 +109,12 @@
<None Update="Modules\PSDiagnostics\PSDiagnostics.psm1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Usage.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Page Update="Reporting.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<None Update="Scripts\MultiLineTestScript.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
13 changes: 7 additions & 6 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@
<NavigationViewItemHeader Content="Categories"/>
</NavigationView.MenuItems>

<!-- TODO: Add in extra reporting and scheduling functionality -->
<!--<NavigationView.FooterMenuItems>
<NavigationViewItem Content="Reporting" />
<NavigationView.FooterMenuItems>
<NavigationViewItem Content="Reporting" Icon="Page2" />
<!-- TODO: Add in extra scheduling functionality
<NavigationViewItem Content="Scheduler" />
</NavigationView.FooterMenuItems>-->
-->
</NavigationView.FooterMenuItems>

<NavigationView.AutoSuggestBox>
<NavigationView.AutoSuggestBox>
<AutoSuggestBox QueryIcon="Find" PlaceholderText="Search" TextChanged="AutoSuggestBox_TextChanged" QuerySubmitted="AutoSuggestBox_QuerySubmitted" SuggestionChosen="AutoSuggestBox_SuggestionChosen"/>
</NavigationView.AutoSuggestBox>

Expand Down Expand Up @@ -180,7 +181,7 @@
<ToggleButton Name="HideScriptTerminal" Click="HideScriptTerminal_Click" ToolTipService.ToolTip="Toggle Terminal" Width="25" Height="25" Padding="0" Grid.Column="0" IsChecked="false" Margin="1" Visibility="Collapsed">
<SymbolIcon Symbol="GoToStart"/>
</ToggleButton>
<ProgressBar Width="100" x:Name="StatusProgressBar" IsIndeterminate="True" Grid.Column="1" HorizontalAlignment="Right"/>
<ProgressBar Width="100" x:Name="StatusProgressBar" IsIndeterminate="True" Grid.Column="1" HorizontalAlignment="Right" Visibility="Collapsed"/>
</Grid>
</Grid>
</SplitView>
Expand Down
72 changes: 71 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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<ReportingRecord>
{
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<ReportingRecord>();
csv.NextRecord();
foreach (var record in records)
{
csv.WriteRecord(record);
csv.NextRecord();
}
csv.WriteRecords(newRecord);
csv.NextRecord();
}
}

public static List<ReportingRecord> GetReportingRecords()
{
using (var reader = new StreamReader(reportFilePath))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var records = csv.GetRecords<ReportingRecord>();
return records.ToList();
}
}

private void ClearTerminal_Click(object sender, RoutedEventArgs e)
{
//ScriptTerminal.Text = "";
Expand Down Expand Up @@ -806,6 +875,7 @@ PSDataCollection<PSObject> RunPing(string CurrentInput)
}
else
{
CurrentInput = "";
PingSymbol.Visibility = Visibility.Collapsed;
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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:
Expand Down
13 changes: 13 additions & 0 deletions Reporting.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Page
x:Class="ITATKWinUI.Reporting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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}">

<controls:DataGrid x:Name="ReportingGrid" AutoGenerateColumns="True" Margin="5" ItemsSource="{x:Bind ReportData}"/>
</Page>
62 changes: 62 additions & 0 deletions Reporting.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Reporting : Page
{
System.Collections.ObjectModel.ObservableCollection<ReportingData> ReportData = new System.Collections.ObjectModel.ObservableCollection<ReportingData>();

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;
}
}
}
Binary file added Usage.csv
Binary file not shown.
1 change: 0 additions & 1 deletion XML/Categories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<Item category="User Management" icon="Contact" foreground="LightPink" />
<Item category="Software" icon="OpenWith" foreground="DarkGreen" />
<Item category="Log Files" icon="TwoBars" foreground="SkyBlue" />
<Item category="Troubleshoot" icon="Library" foreground="SandyBrown" />
<Item category="Remediate" icon="Repair" foreground="PaleVioletRed" />
<Item category="Security" icon="Admin" foreground="LightGoldenrodYellow" />
<Item category="Database" icon="Page2" foreground="Honeydew" />
Expand Down

0 comments on commit 0a2bb5b

Please sign in to comment.