using System.Diagnostics; using System.Drawing; using System.ServiceModel; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using PatcherServer.FileCheck; using PatcherServer.Helper; using PatcherServer.XAML; using PatcherServer.Services; using Hardcodet.Wpf.TaskbarNotification; namespace PatcherServer { /// /// Interaction logic for App.xaml /// public partial class App { private ServiceHost[] hosts; private TaskbarIcon trayIcon; private void InitializeServices() { hosts = new[] { new ServiceHost(typeof(LauncherService)), new ServiceHost(typeof(PatcherService)), new ServiceHost(typeof(AdminService)), }; } private void OpenHosts() { foreach (var host in hosts) { host.Open(); } } private void CloseHosts() { foreach (var host in hosts) { if(host != null) host.Close(); } } private void InitializeTrayIcon() { trayIcon = new TaskbarIcon { Icon = new Icon("Images/041_Sort.ico"), ContextMenu = (ContextMenu) FindResource("TrayMenu"), ToolTipText = "Patchserver", TrayPopup = (Popup) FindResource("TrayPopup"), PopupActivation = PopupActivationMode.LeftClick, }; } protected override void OnStartup(StartupEventArgs e) { // Initialize stuff. LogHelper.Initialize(); Trace.Listeners.Add(LogHelper.Instance); DatabaseHelper.Initialize(); DataProvider.Initialize(); TrackerHelper.Initialize(); TrackerHelper.LoadTorrents(); TrackerHelper.Start(); FileSecurity.Start(); InitializeServices(); InitializeTrayIcon(); OpenHosts(); base.OnStartup(e); Trace.WriteLine("Successfully started server."); } protected override void OnExit(ExitEventArgs e) { DataProvider.Save(); CloseHosts(); base.OnExit(e); } private void ExitClick(object sender, RoutedEventArgs e) { this.Shutdown(); } private void PopupCloseClick(object sender, RoutedEventArgs e) { Popup parent = (Popup) FindResource("TrayPopup"); parent.IsOpen = false; } } }