2017-07-05 17:21:52 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2017-07-06 18:18:39 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser
|
|
|
|
|
{
|
|
|
|
|
public class App : Application
|
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
private static readonly Mutex mutex = new Mutex(true, "safe_exam_browser_single_instance_mutex");
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
2017-07-06 10:56:03 +02:00
|
|
|
|
try
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
StartApplication();
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
2017-07-06 10:56:03 +02:00
|
|
|
|
catch (Exception e)
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
2017-07-06 18:18:39 +02:00
|
|
|
|
MessageBox.Show(e.Message + "\n\n" + e.StackTrace, "Fatal Error");
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 15:46:32 +02:00
|
|
|
|
private static void StartApplication()
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
var root = new CompositionRoot();
|
|
|
|
|
|
|
|
|
|
root.BuildObjectGraph();
|
2017-07-06 18:18:39 +02:00
|
|
|
|
|
2017-07-07 15:46:32 +02:00
|
|
|
|
root.Logger.Log(root.Settings.LogHeader);
|
|
|
|
|
root.Logger.Log($"# Application started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}{Environment.NewLine}");
|
|
|
|
|
|
|
|
|
|
if (NoInstanceRunning(root))
|
2017-07-06 10:56:03 +02:00
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
var app = new App();
|
|
|
|
|
|
|
|
|
|
root.Logger.Info("No instance is running, initiating startup procedure.");
|
|
|
|
|
|
|
|
|
|
app.Startup += (o, args) => root.StartupController.InitializeApplication(app.Shutdown);
|
|
|
|
|
app.Exit += (o, args) => root.ShutdownController.FinalizeApplication();
|
|
|
|
|
|
|
|
|
|
app.Run(root.Taskbar);
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
root.Logger.Info("Could not start because of an already running instance.");
|
|
|
|
|
root.MessageBox.Show(root.Text.Get(Key.MessageBox_SingleInstance), root.Text.Get(Key.MessageBox_SingleInstanceTitle));
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
|
|
|
|
root.Logger.Log($"# Application terminating normally at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
2017-07-07 15:46:32 +02:00
|
|
|
|
private static bool NoInstanceRunning(CompositionRoot root)
|
2017-07-06 10:56:03 +02:00
|
|
|
|
{
|
|
|
|
|
return mutex.WaitOne(TimeSpan.Zero, true);
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|