2018-01-25 11:59:44 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 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.Windows;
|
|
|
|
|
using System.Windows.Documents;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
using System.Windows.Input;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Classic.ViewModels;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.UserInterface.Classic
|
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public partial class RuntimeWindow : Window, IRuntimeWindow
|
2018-01-25 11:59:44 +01:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private bool allowClose;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
private ILogContentFormatter formatter;
|
|
|
|
|
private IRuntimeInfo runtimeInfo;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
private IText text;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private RuntimeWindowViewModel model;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
private WindowClosingEventHandler closing;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
|
2018-01-26 12:33:36 +01:00
|
|
|
|
event WindowClosingEventHandler IWindow.Closing
|
|
|
|
|
{
|
|
|
|
|
add { closing += value; }
|
|
|
|
|
remove { closing -= value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RuntimeWindow(ILogContentFormatter formatter, IRuntimeInfo runtimeInfo, IText text)
|
2018-01-25 11:59:44 +01:00
|
|
|
|
{
|
|
|
|
|
this.formatter = formatter;
|
|
|
|
|
this.runtimeInfo = runtimeInfo;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
this.text = text;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeRuntimeWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 12:33:36 +01:00
|
|
|
|
public void BringToForeground()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(Activate);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public new void Close()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
allowClose = true;
|
|
|
|
|
base.Close();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Hide()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Hide);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 11:59:44 +01:00
|
|
|
|
public void Notify(ILogContent content)
|
|
|
|
|
{
|
2018-01-26 12:33:36 +01:00
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
LogTextBlock.Text += formatter.Format(content) + Environment.NewLine;
|
|
|
|
|
LogScrollViewer.ScrollToEnd();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public new void Show()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Show);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateStatus(TextKey key, bool showBusyIndication = false)
|
2018-01-26 12:33:36 +01:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
AnimatedBorder.Visibility = showBusyIndication ? Visibility.Hidden : Visibility.Visible;
|
|
|
|
|
ProgressBar.Visibility = showBusyIndication ? Visibility.Visible : Visibility.Hidden;
|
|
|
|
|
|
|
|
|
|
model.StopBusyIndication();
|
|
|
|
|
model.Status = text.Get(key);
|
|
|
|
|
|
|
|
|
|
if (showBusyIndication)
|
|
|
|
|
{
|
|
|
|
|
model.StartBusyIndication();
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-01-25 11:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeRuntimeWindow()
|
|
|
|
|
{
|
2018-01-26 12:33:36 +01:00
|
|
|
|
Title = $"{runtimeInfo.ProgramTitle} - Version {runtimeInfo.ProgramVersion}";
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
2018-01-25 11:59:44 +01:00
|
|
|
|
InfoTextBlock.Inlines.Add(new Run($"Version {runtimeInfo.ProgramVersion}") { FontStyle = FontStyles.Italic });
|
|
|
|
|
InfoTextBlock.Inlines.Add(new LineBreak());
|
|
|
|
|
InfoTextBlock.Inlines.Add(new LineBreak());
|
|
|
|
|
InfoTextBlock.Inlines.Add(new Run(runtimeInfo.ProgramCopyright) { FontSize = 10 });
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
|
|
|
|
model = new RuntimeWindowViewModel();
|
|
|
|
|
StatusTextBlock.DataContext = model;
|
|
|
|
|
|
|
|
|
|
Closing += (o, args) => args.Cancel = !allowClose;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|