2017-07-05 17:21:52 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2017-07-28 14:52:15 +02:00
|
|
|
|
*
|
2017-07-05 17:21:52 +02:00
|
|
|
|
* 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;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
using System.Collections.Generic;
|
2017-10-09 12:11:33 +02:00
|
|
|
|
using System.ComponentModel;
|
2017-07-21 12:05:31 +02:00
|
|
|
|
using System.Linq;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
2018-01-18 08:16:20 +01:00
|
|
|
|
namespace SafeExamBrowser.Runtime
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
public class App : Application
|
|
|
|
|
{
|
2018-01-16 08:14:57 +01:00
|
|
|
|
private static readonly Mutex Mutex = new Mutex(true, "safe_exam_browser_runtime_mutex");
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private CompositionRoot instances = new CompositionRoot();
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
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-19 14:43:54 +02:00
|
|
|
|
MessageBox.Show(e.Message + "\n\n" + e.StackTrace, "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2017-07-28 14:52:15 +02:00
|
|
|
|
Mutex.Close();
|
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-10 15:47:12 +02:00
|
|
|
|
if (NoInstanceRunning())
|
|
|
|
|
{
|
|
|
|
|
new App().Run();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-19 14:43:54 +02:00
|
|
|
|
MessageBox.Show("You can only run one instance of SEB at a time.", "Startup Not Allowed", MessageBoxButton.OK, MessageBoxImage.Information);
|
2017-07-10 15:47:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-10 15:47:12 +02:00
|
|
|
|
private static bool NoInstanceRunning()
|
|
|
|
|
{
|
2017-07-28 14:52:15 +02:00
|
|
|
|
return Mutex.WaitOne(TimeSpan.Zero, true);
|
2017-07-10 15:47:12 +02:00
|
|
|
|
}
|
2017-07-06 18:18:39 +02:00
|
|
|
|
|
2017-07-10 15:47:12 +02:00
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnStartup(e);
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-17 08:28:18 +02:00
|
|
|
|
instances.BuildObjectGraph();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
LogStartupInformation();
|
2017-07-17 08:28:18 +02:00
|
|
|
|
|
2017-07-21 12:05:31 +02:00
|
|
|
|
var success = instances.StartupController.TryInitializeApplication(instances.StartupOperations);
|
2017-07-17 08:28:18 +02:00
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
2018-01-17 08:26:44 +01:00
|
|
|
|
// TODO: Probably needs new window to display status of running application...
|
2018-01-17 14:08:39 +01:00
|
|
|
|
//MainWindow = instances.SplashScreen;
|
|
|
|
|
//MainWindow.Closing += MainWindow_Closing;
|
|
|
|
|
//MainWindow.Show();
|
2017-07-17 08:28:18 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Shutdown();
|
|
|
|
|
}
|
2017-07-19 14:43:54 +02:00
|
|
|
|
}
|
2017-07-17 08:28:18 +02:00
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
protected override void OnExit(ExitEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
instances.Logger?.Log($"{Environment.NewLine}# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
|
|
|
|
|
|
|
|
|
base.OnExit(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LogStartupInformation()
|
|
|
|
|
{
|
|
|
|
|
var runtimeInfo = instances.RuntimeInfo;
|
|
|
|
|
var logger = instances.Logger;
|
|
|
|
|
var titleLine = $"/* {runtimeInfo.ProgramTitle}, Version {runtimeInfo.ProgramVersion}{Environment.NewLine}";
|
|
|
|
|
var copyrightLine = $"/* {runtimeInfo.ProgramCopyright}{Environment.NewLine}";
|
|
|
|
|
var emptyLine = $"/* {Environment.NewLine}";
|
|
|
|
|
var githubLine = $"/* Please visit https://github.com/SafeExamBrowser for more information.";
|
|
|
|
|
|
|
|
|
|
logger.Log($"{titleLine}{copyrightLine}{emptyLine}{githubLine}");
|
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
logger.Log($"# Application started at {runtimeInfo.ApplicationStartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
|
|
|
|
logger.Log($"# Running on {instances.SystemInfo.OperatingSystemInfo}");
|
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 12:11:33 +02:00
|
|
|
|
private void MainWindow_Closing(object sender, CancelEventArgs e)
|
2017-07-19 14:43:54 +02:00
|
|
|
|
{
|
2017-07-21 12:05:31 +02:00
|
|
|
|
var operations = new Queue<IOperation>(instances.StartupOperations.Reverse());
|
|
|
|
|
|
2017-07-19 14:43:54 +02:00
|
|
|
|
MainWindow.Hide();
|
2017-07-21 10:04:27 +02:00
|
|
|
|
instances.ShutdownController.FinalizeApplication(operations);
|
2017-07-17 08:28:18 +02:00
|
|
|
|
}
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|