Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Jul 27, 2022
0 parents commit 780e6e4
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vs/
*.sqlite
*.user
client_secret*.json
25 changes: 25 additions & 0 deletions ESAWindowTracker.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ESAWindowTracker", "ESAWindowTracker\ESAWindowTracker.csproj", "{5F63DE6B-203C-4320-901D-2B5FE8B5B7F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5F63DE6B-203C-4320-901D-2B5FE8B5B7F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F63DE6B-203C-4320-901D-2B5FE8B5B7F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F63DE6B-203C-4320-901D-2B5FE8B5B7F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F63DE6B-203C-4320-901D-2B5FE8B5B7F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E9D7A93A-BC96-42A7-A552-57C62B4FE319}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions ESAWindowTracker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vs/
bin/
obj/
8 changes: 8 additions & 0 deletions ESAWindowTracker/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="ESAWindowTracker.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ESAWindowTracker">
<Application.Resources>

</Application.Resources>
</Application>
69 changes: 69 additions & 0 deletions ESAWindowTracker/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace ESAWindowTracker
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public IServiceProvider ServiceProvider { get; set; }
public IConfiguration Configuration { get; set; }

public App()
{
var builder = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

#if DEBUG
builder.AddUserSecrets<App>();
#endif

Configuration = builder.Build();
WriteConfig();

var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
ServiceProvider = serviceCollection.BuildServiceProvider();
}

private void ConfigureServices(ServiceCollection services)
{
services.AddTransient<MainWindow>();
}

protected override void OnStartup(StartupEventArgs e)
{
ServiceProvider.GetRequiredService<MainWindow>();
}

public void WriteConfig(Config? config = null)
{
if (config == null)
config = Configuration.Get<Config>() ?? new Config();

var jsonWriteOptions = new JsonSerializerOptions()
{
WriteIndented = true
};
var newJson = JsonSerializer.Serialize(config, jsonWriteOptions);

var appSettingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
File.WriteAllText(appSettingsPath, newJson, Encoding.UTF8);
}
}
}
10 changes: 10 additions & 0 deletions ESAWindowTracker/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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)
)]
14 changes: 14 additions & 0 deletions ESAWindowTracker/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ESAWindowTracker
{
public static class Commands
{
public static readonly RoutedCommand Show = new RoutedCommand();
}
}
26 changes: 26 additions & 0 deletions ESAWindowTracker/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESAWindowTracker
{
public class Config
{
public string EventShort { get; set; } = "default";
public string PCID { get; set; } = "undefined";

public RabbitConfig RabbitConfig { get; set; } = new RabbitConfig();
}

public class RabbitConfig
{
public string Host { get; set; } = "";
public string VHost { get; set; } = "";
public ushort Port { get; set; } = 5671;
public bool Tls { get; set; } = true;
public string User { get; set; } = "";
public string Pass { get; set; } = "";
}
}
29 changes: 29 additions & 0 deletions ESAWindowTracker/ESAWindowTracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<UserSecretsId>683dd05d-4ea0-4c89-b4c3-f39bc95d4799</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<None Remove="NetDrives.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<Resource Include="NetDrives.ico" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions ESAWindowTracker/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Window x:Class="ESAWindowTracker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:ESAWindowTracker"
mc:Ignorable="d"
Title="ESAWindowTracker" Height="450" Width="600"
Icon="/NetDrives.ico">
<Window.CommandBindings>
<CommandBinding
Command="{x:Static local:Commands.Show}"
Executed="Show_Executed"
/>
</Window.CommandBindings>
<Grid>
<tb:TaskbarIcon x:Name="ESAWindowTracker" ToolTipText="ESAWindowTracker" IconSource="/NetDrives.ico" DoubleClickCommand="{x:Static local:Commands.Show}">
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Show" Click="ShowMenu_Click" />
<Separator/>
<MenuItem Header="Exit" Click="ExitMenu_Click" />
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
</Grid>
</Window>
58 changes: 58 additions & 0 deletions ESAWindowTracker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ESAWindowTracker
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Show_Executed(object sender, ExecutedRoutedEventArgs e)
{
DoShow();
}

private void ShowMenu_Click(object sender, RoutedEventArgs e)
{
DoShow();
}

private void DoShow()
{
Visibility = Visibility.Visible;
ShowInTaskbar = true;
Show();
Focus();
}

private void ExitMenu_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}

protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
Hide();
}
}
}
Binary file added ESAWindowTracker/NetDrives.ico
Binary file not shown.

0 comments on commit 780e6e4

Please sign in to comment.