Files
FSI.BT.IR.Tools/FSI.BT.Tools/App.xaml.cs
Maier Stephan SI d01747f75a Sicherung
2023-01-02 04:33:49 +01:00

104 lines
3.7 KiB
C#

using Hardcodet.Wpf.TaskbarNotification;
using NHotkey;
using NHotkey.Wpf;
using System.Windows;
using System.Windows.Input;
using FSI.Lib.CompareNetObjects;
using Config.Net.Stores;
using System.IO;
using Config.Net;
namespace FSI.BT.Tools
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : System.Windows.Application
{
private static readonly KeyGesture RadialMenu = new KeyGesture(Key.OemBackslash, ModifierKeys.Control);
private static readonly KeyGesture TimeStamp = new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Alt);
public void Application_Startup(object sender, StartupEventArgs e)
{
Global.Log.Info("Anwendung wurde gestartet!");
Global.Settings = new AppSettings(GetType().Namespace.ToString() + ".xml");
Global.Settings.Load();
JsonConfigStore _store = new JsonConfigStore(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "config.json"), true);
Global.AppSettings = new ConfigurationBuilder<Settings.AppSettings.IAppSettings>()
.UseConfigStore(_store)
.Build();
Global.TaskbarIcon = (TaskbarIcon)FindResource("FSINotifyIcon");
Global.AdminRights = Admin.CheckAdminRight();
Global.SuperAdminRights = Admin.CheckSuperAdminRight();
Global.UserRights = Admin.CheckUserRight();
HotkeyManager.Current.AddOrReplace("RadialMenu", RadialMenu, ShowRadialMenu);
HotkeyManager.Current.AddOrReplace("TimeStampToClipboard", TimeStamp, TimeStampToClipboard);
Global.FrmRadialMenu = new FrmRadialMenu();
Global.WinCC = new Lib.Guis.SieTiaWinCCMsgMgt.ViewModel.ViewModelWinCC(
Global.Settings.SieTiaWinCCMsgMgtAutostart,
Global.Settings.SieTiaWinCCMsgMgtUpdateIntervall,
Global.Settings.SieTiaWinCCMsgMgtWindowsName,
Global.Settings.SieTiaWinCCMsgMgtClassName,
Global.Settings.SieTiaWinCCMsgMgtBtnName
);
Global.Iba = new Lib.Guis.IbaDirSync.ViewModel.ViewModelIba(
Global.Settings.IbaRecordDestinationath,
Global.Settings.IbaRecordSourcePath,
Global.Settings.IbaAutoSync
);
Global.WindowMgt = new Lib.Guis.SetSizePosExWindow.ViewModel.ViewModelWindow();
Global.WindowMgt.AutoStart = Global.Settings.WindowMgtAutostart;
Global.WindowMgt.UpdateIntervall = Global.Settings.WindowMgtUpdateInterval;
}
private void ShowRadialMenu(object sender, HotkeyEventArgs e)
{
var cmd = new Commands.RadialMenuCommand();
if (cmd.CanExecute(null))
cmd.Execute(null);
e.Handled = true;
}
private void TimeStampToClipboard(object sender, HotkeyEventArgs e)
{
var cmd = new Commands.TimeStampToClipboardCommand();
cmd.Execute(null);
e.Handled = true;
}
private void Application_Exit(object sender, ExitEventArgs e)
{
AppSettings tmpSetting = new AppSettings(Global.Settings.FileName);
tmpSetting.Load();
CompareLogic compareLogic = new CompareLogic();
ComparisonResult result = compareLogic.Compare(Global.Settings, tmpSetting);
if (!result.AreEqual)
{
Global.Settings.Save();
}
if (Global.Iba.RoboCopy != null)
{
Global.Iba.RoboCopy.Stop();
Global.Iba.RoboCopy.Dispose();
}
}
}
}