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;
|
|
|
|
|
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;
|
2018-02-15 15:42:54 +01:00
|
|
|
|
private RuntimeInfo 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; }
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 15:42:54 +01:00
|
|
|
|
public RuntimeWindow(ILogContentFormatter formatter, RuntimeInfo 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-02-02 09:18:35 +01:00
|
|
|
|
public void HideProgressBar()
|
|
|
|
|
{
|
|
|
|
|
model.ProgressBarVisibility = Visibility.Hidden;
|
|
|
|
|
}
|
|
|
|
|
|
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-02-02 09:18:35 +01:00
|
|
|
|
public void Progress(int amount = 1)
|
2018-01-30 14:41:36 +01:00
|
|
|
|
{
|
2018-02-02 09:18:35 +01:00
|
|
|
|
model.CurrentProgress += amount;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
public void Regress(int amount = 1)
|
2018-01-26 12:33:36 +01:00
|
|
|
|
{
|
2018-02-02 09:18:35 +01:00
|
|
|
|
model.CurrentProgress -= amount;
|
|
|
|
|
}
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
public void SetIndeterminate()
|
|
|
|
|
{
|
|
|
|
|
model.IsIndeterminate = true;
|
|
|
|
|
}
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
public void SetMaxValue(int max)
|
|
|
|
|
{
|
|
|
|
|
model.MaxProgress = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetValue(int value)
|
|
|
|
|
{
|
|
|
|
|
model.CurrentProgress = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowProgressBar()
|
|
|
|
|
{
|
|
|
|
|
model.ProgressBarVisibility = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateText(TextKey key, bool showBusyIndication = false)
|
|
|
|
|
{
|
|
|
|
|
model.StopBusyIndication();
|
|
|
|
|
model.Status = text.Get(key);
|
|
|
|
|
|
|
|
|
|
if (showBusyIndication)
|
|
|
|
|
{
|
|
|
|
|
model.StartBusyIndication();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Show()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Show);
|
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();
|
2018-02-02 09:18:35 +01:00
|
|
|
|
AnimatedBorder.DataContext = model;
|
|
|
|
|
ProgressBar.DataContext = model;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
StatusTextBlock.DataContext = model;
|
|
|
|
|
|
|
|
|
|
Closing += (o, args) => args.Cancel = !allowClose;
|
2018-01-25 11:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|