Added coloration to log window and removed URI format check in browser control.
This commit is contained in:
parent
939bc7f79a
commit
a8025ad2a1
10 changed files with 89 additions and 51 deletions
|
@ -54,7 +54,7 @@ namespace SafeExamBrowser.Browser
|
||||||
|
|
||||||
public void NavigateTo(string address)
|
public void NavigateTo(string address)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrWhiteSpace(address) && Uri.IsWellFormedUriString(address, UriKind.RelativeOrAbsolute))
|
if (!String.IsNullOrWhiteSpace(address))
|
||||||
{
|
{
|
||||||
Load(address);
|
Load(address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new log window which runs on its own thread.
|
/// Creates a new log window which runs on its own thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IWindow CreateLogWindow(ILogger logger, ILogContentFormatter formatter, IText text);
|
IWindow CreateLogWindow(ILogger logger, IText text);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a taskbar notification, initialized with the given notification information.
|
/// Creates a taskbar notification, initialized with the given notification information.
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
public void Perform()
|
public void Perform()
|
||||||
{
|
{
|
||||||
logger.Info("Initializing browser...");
|
logger.Info("Initializing browser...");
|
||||||
SplashScreen.UpdateText(TextKey.SplashScreen_InitializeBrowser);
|
SplashScreen.UpdateText(TextKey.SplashScreen_InitializeBrowser, true);
|
||||||
|
|
||||||
var browserButton = uiFactory.CreateApplicationButton(browserInfo);
|
var browserButton = uiFactory.CreateApplicationButton(browserInfo);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
public void Revert()
|
public void Revert()
|
||||||
{
|
{
|
||||||
logger.Info("Terminating browser...");
|
logger.Info("Terminating browser...");
|
||||||
SplashScreen.UpdateText(TextKey.SplashScreen_TerminateBrowser);
|
SplashScreen.UpdateText(TextKey.SplashScreen_TerminateBrowser, true);
|
||||||
|
|
||||||
browserController.Terminate();
|
browserController.Terminate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
public class TaskbarOperation : IOperation
|
public class TaskbarOperation : IOperation
|
||||||
{
|
{
|
||||||
private ILogger logger;
|
private ILogger logger;
|
||||||
private ILogContentFormatter formatter;
|
|
||||||
private INotificationController aboutController, logController;
|
private INotificationController aboutController, logController;
|
||||||
private ITaskbar taskbar;
|
private ITaskbar taskbar;
|
||||||
private IUserInterfaceFactory uiFactory;
|
private IUserInterfaceFactory uiFactory;
|
||||||
|
@ -29,14 +28,12 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
|
|
||||||
public TaskbarOperation(
|
public TaskbarOperation(
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
ILogContentFormatter formatter,
|
|
||||||
ISettings settings,
|
ISettings settings,
|
||||||
ITaskbar taskbar,
|
ITaskbar taskbar,
|
||||||
IText text,
|
IText text,
|
||||||
IUserInterfaceFactory uiFactory)
|
IUserInterfaceFactory uiFactory)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.formatter = formatter;
|
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.taskbar = taskbar;
|
this.taskbar = taskbar;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
|
@ -78,7 +75,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
var logInfo = new LogNotificationInfo(text);
|
var logInfo = new LogNotificationInfo(text);
|
||||||
var logNotification = uiFactory.CreateNotification(logInfo);
|
var logNotification = uiFactory.CreateNotification(logInfo);
|
||||||
|
|
||||||
logController = new LogNotificationController(logger, formatter, text, uiFactory);
|
logController = new LogNotificationController(logger, text, uiFactory);
|
||||||
logController.RegisterNotification(logNotification);
|
logController.RegisterNotification(logNotification);
|
||||||
|
|
||||||
taskbar.AddNotification(logNotification);
|
taskbar.AddNotification(logNotification);
|
||||||
|
|
|
@ -17,15 +17,13 @@ namespace SafeExamBrowser.Core.Notifications
|
||||||
{
|
{
|
||||||
private ITaskbarNotification notification;
|
private ITaskbarNotification notification;
|
||||||
private ILogger logger;
|
private ILogger logger;
|
||||||
private ILogContentFormatter formatter;
|
|
||||||
private IText text;
|
private IText text;
|
||||||
private IUserInterfaceFactory uiFactory;
|
private IUserInterfaceFactory uiFactory;
|
||||||
private IWindow window;
|
private IWindow window;
|
||||||
|
|
||||||
public LogNotificationController(ILogger logger, ILogContentFormatter formatter, IText text, IUserInterfaceFactory uiFactory)
|
public LogNotificationController(ILogger logger, IText text, IUserInterfaceFactory uiFactory)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.formatter = formatter;
|
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.uiFactory = uiFactory;
|
this.uiFactory = uiFactory;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +44,7 @@ namespace SafeExamBrowser.Core.Notifications
|
||||||
{
|
{
|
||||||
if (window == null)
|
if (window == null)
|
||||||
{
|
{
|
||||||
window = uiFactory.CreateLogWindow(logger, formatter, text);
|
window = uiFactory.CreateLogWindow(logger, text);
|
||||||
|
|
||||||
window.Closing += () => window = null;
|
window.Closing += () => window = null;
|
||||||
window.Show();
|
window.Show();
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
<SolidColorBrush Color="Black" Opacity="0.8" />
|
<SolidColorBrush Color="Black" Opacity="0.8" />
|
||||||
</Window.Background>
|
</Window.Background>
|
||||||
<Grid>
|
<Grid>
|
||||||
<TextBox x:Name="LogContent" AcceptsReturn="True" Background="Transparent" FontFamily="Consolas" Foreground="ForestGreen"
|
<ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
|
||||||
HorizontalScrollBarVisibility="Auto" IsReadOnly="True" Text="{Binding Path=Text, Mode=OneWay}"
|
<TextBlock x:Name="LogContent" Background="Transparent" FontFamily="Consolas" Foreground="ForestGreen" />
|
||||||
VerticalScrollBarVisibility="Auto" TextChanged="LogContent_TextChanged" />
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using SafeExamBrowser.Contracts.I18n;
|
using SafeExamBrowser.Contracts.I18n;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
|
@ -26,12 +27,13 @@ namespace SafeExamBrowser.UserInterface
|
||||||
remove { closing -= value; }
|
remove { closing -= value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogWindow(ILogger logger, ILogContentFormatter formatter, IText text)
|
public LogWindow(ILogger logger, IText text)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
|
||||||
this.model = new LogViewModel(logger.GetLog(), formatter, text);
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
this.logger = logger;
|
||||||
|
this.model = new LogViewModel(text, ScrollViewer, LogContent);
|
||||||
|
|
||||||
InitializeLogWindow();
|
InitializeLogWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,22 +52,27 @@ namespace SafeExamBrowser.UserInterface
|
||||||
Dispatcher.Invoke(base.Show);
|
Dispatcher.Invoke(base.Show);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogContent_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
|
||||||
{
|
|
||||||
LogContent.ScrollToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitializeLogWindow()
|
private void InitializeLogWindow()
|
||||||
{
|
{
|
||||||
DataContext = model;
|
DataContext = model;
|
||||||
LogContent.DataContext = model;
|
|
||||||
Closing += LogWindow_Closing;
|
Closing += LogWindow_Closing;
|
||||||
|
Loaded += LogWindow_Loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogWindow_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var log = logger.GetLog();
|
||||||
|
|
||||||
|
foreach (var content in log)
|
||||||
|
{
|
||||||
|
model.Notify(content);
|
||||||
|
}
|
||||||
|
|
||||||
logger.Subscribe(model);
|
logger.Subscribe(model);
|
||||||
logger.Info("Opened log window.");
|
logger.Info("Opened log window.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
private void LogWindow_Closing(object sender, CancelEventArgs e)
|
||||||
{
|
{
|
||||||
logger.Unsubscribe(model);
|
logger.Unsubscribe(model);
|
||||||
logger.Info("Closed log window.");
|
logger.Info("Closed log window.");
|
||||||
|
|
|
@ -34,13 +34,13 @@ namespace SafeExamBrowser.UserInterface
|
||||||
return new BrowserWindow(control, settings);
|
return new BrowserWindow(control, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWindow CreateLogWindow(ILogger logger, ILogContentFormatter formatter, IText text)
|
public IWindow CreateLogWindow(ILogger logger, IText text)
|
||||||
{
|
{
|
||||||
LogWindow logWindow = null;
|
LogWindow logWindow = null;
|
||||||
var logWindowReadyEvent = new AutoResetEvent(false);
|
var logWindowReadyEvent = new AutoResetEvent(false);
|
||||||
var logWindowThread = new Thread(() =>
|
var logWindowThread = new Thread(() =>
|
||||||
{
|
{
|
||||||
logWindow = new LogWindow(logger, formatter, text);
|
logWindow = new LogWindow(logger, text);
|
||||||
logWindow.Closed += (o, args) => logWindow.Dispatcher.InvokeShutdown();
|
logWindow.Closed += (o, args) => logWindow.Dispatcher.InvokeShutdown();
|
||||||
logWindow.Show();
|
logWindow.Show();
|
||||||
|
|
||||||
|
|
|
@ -6,44 +6,80 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.Windows.Controls;
|
||||||
using System.Text;
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Media;
|
||||||
using SafeExamBrowser.Contracts.I18n;
|
using SafeExamBrowser.Contracts.I18n;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
|
|
||||||
namespace SafeExamBrowser.UserInterface.ViewModels
|
namespace SafeExamBrowser.UserInterface.ViewModels
|
||||||
{
|
{
|
||||||
class LogViewModel : INotifyPropertyChanged, ILogObserver
|
internal class LogViewModel : ILogObserver
|
||||||
{
|
{
|
||||||
private ILogContentFormatter formatter;
|
|
||||||
private IText text;
|
private IText text;
|
||||||
private StringBuilder builder = new StringBuilder();
|
private ScrollViewer scrollViewer;
|
||||||
|
private TextBlock textBlock;
|
||||||
public string Text
|
|
||||||
{
|
|
||||||
get { return builder.ToString(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string WindowTitle => text.Get(TextKey.LogWindow_Title);
|
public string WindowTitle => text.Get(TextKey.LogWindow_Title);
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public LogViewModel(IText text, ScrollViewer scrollViewer, TextBlock textBlock)
|
||||||
|
|
||||||
public LogViewModel(IList<ILogContent> initial, ILogContentFormatter formatter, IText text)
|
|
||||||
{
|
{
|
||||||
this.formatter = formatter;
|
|
||||||
this.text = text;
|
this.text = text;
|
||||||
|
this.scrollViewer = scrollViewer;
|
||||||
foreach (var content in initial)
|
this.textBlock = textBlock;
|
||||||
{
|
|
||||||
Notify(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Notify(ILogContent content)
|
public void Notify(ILogContent content)
|
||||||
{
|
{
|
||||||
builder.AppendLine(formatter.Format(content));
|
if (content is ILogText)
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Text)));
|
{
|
||||||
|
AppendLogText(content as ILogText);
|
||||||
|
}
|
||||||
|
else if (content is ILogMessage)
|
||||||
|
{
|
||||||
|
AppendLogMessage(content as ILogMessage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException($"The default formatter is not yet implemented for log content of type {content.GetType()}!");
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollViewer.Dispatcher.Invoke(scrollViewer.ScrollToEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AppendLogText(ILogText logText)
|
||||||
|
{
|
||||||
|
textBlock.Dispatcher.Invoke(() => textBlock.Inlines.Add(new Run($"{logText.Text}{Environment.NewLine}")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AppendLogMessage(ILogMessage message)
|
||||||
|
{
|
||||||
|
textBlock.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
var date = message.DateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||||
|
var severity = message.Severity.ToString().ToUpper();
|
||||||
|
var threadInfo = $"{message.ThreadInfo.Id}{(message.ThreadInfo.HasName ? ": " + message.ThreadInfo.Name : string.Empty)}";
|
||||||
|
|
||||||
|
var infoRun = new Run($"{date} [{threadInfo}] - ") { Foreground = Brushes.Gray };
|
||||||
|
var messageRun = new Run($"{severity}: {message.Message}{Environment.NewLine}") { Foreground = GetBrushFor(message.Severity) };
|
||||||
|
|
||||||
|
textBlock.Inlines.Add(infoRun);
|
||||||
|
textBlock.Inlines.Add(messageRun);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Brush GetBrushFor(LogLevel severity)
|
||||||
|
{
|
||||||
|
switch (severity)
|
||||||
|
{
|
||||||
|
case LogLevel.Error:
|
||||||
|
return Brushes.Red;
|
||||||
|
case LogLevel.Warning:
|
||||||
|
return Brushes.Yellow;
|
||||||
|
default:
|
||||||
|
return Brushes.White;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace SafeExamBrowser
|
||||||
StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor));
|
StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor));
|
||||||
StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor));
|
StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor));
|
||||||
StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar));
|
StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar));
|
||||||
StartupOperations.Enqueue(new TaskbarOperation(logger, logFormatter, settings, Taskbar, text, uiFactory));
|
StartupOperations.Enqueue(new TaskbarOperation(logger, settings, Taskbar, text, uiFactory));
|
||||||
StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory));
|
StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory));
|
||||||
StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, logger));
|
StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, logger));
|
||||||
StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods));
|
StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods));
|
||||||
|
|
Loading…
Reference in a new issue