SEBWIN-342: Removed UI dependencies from notifications.

This commit is contained in:
dbuechel 2019-09-04 14:11:19 +02:00
parent 12f44edc0b
commit 363f751f55
25 changed files with 87 additions and 217 deletions

View file

@ -9,16 +9,15 @@
namespace SafeExamBrowser.Client.Contracts namespace SafeExamBrowser.Client.Contracts
{ {
/// <summary> /// <summary>
/// Controls the lifetime and functionality of a notification which is part of the <see cref="ITaskbar"/>. /// Controls the lifetime and functionality of a notification which can be activated via the UI.
/// </summary> /// </summary>
public interface INotificationController public interface INotificationController
{ {
// TODO /// <summary>
///// <summary> /// Executes the notification functionality.
///// Registers the taskbar notification. /// </summary>
///// </summary> void Activate();
//void RegisterNotification(INotificationControl notification);
/// <summary> /// <summary>
/// Instructs the controller to shut down and release all used resources. /// Instructs the controller to shut down and release all used resources.
/// </summary> /// </summary>

View file

@ -31,13 +31,12 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
[TestMethod] [TestMethod]
public void MustCloseWindowWhenTerminating() public void MustCloseWindowWhenTerminating()
{ {
var button = new NotificationButtonMock();
var window = new Mock<IWindow>(); var window = new Mock<IWindow>();
var sut = new AboutNotificationController(appConfig.Object, uiFactory.Object); var sut = new AboutNotificationController(appConfig.Object, uiFactory.Object);
uiFactory.Setup(u => u.CreateAboutWindow(It.IsAny<AppConfig>())).Returns(window.Object); uiFactory.Setup(u => u.CreateAboutWindow(It.IsAny<AppConfig>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click(); sut.Activate();
sut.Terminate(); sut.Terminate();
window.Verify(w => w.Close()); window.Verify(w => w.Close());
@ -46,34 +45,22 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
[TestMethod] [TestMethod]
public void MustOpenOnlyOneWindow() public void MustOpenOnlyOneWindow()
{ {
var button = new NotificationButtonMock();
var window = new Mock<IWindow>(); var window = new Mock<IWindow>();
var sut = new AboutNotificationController(appConfig.Object, uiFactory.Object); var sut = new AboutNotificationController(appConfig.Object, uiFactory.Object);
uiFactory.Setup(u => u.CreateAboutWindow(It.IsAny<AppConfig>())).Returns(window.Object); uiFactory.Setup(u => u.CreateAboutWindow(It.IsAny<AppConfig>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click(); sut.Activate();
button.Click(); sut.Activate();
button.Click(); sut.Activate();
button.Click(); sut.Activate();
button.Click(); sut.Activate();
uiFactory.Verify(u => u.CreateAboutWindow(It.IsAny<AppConfig>()), Times.Once); uiFactory.Verify(u => u.CreateAboutWindow(It.IsAny<AppConfig>()), Times.Once);
window.Verify(u => u.Show(), Times.Once); window.Verify(u => u.Show(), Times.Once);
window.Verify(u => u.BringToForeground(), Times.Exactly(4)); window.Verify(u => u.BringToForeground(), Times.Exactly(4));
} }
[TestMethod]
public void MustSubscribeToClickEvent()
{
var button = new NotificationButtonMock();
var sut = new AboutNotificationController(appConfig.Object, uiFactory.Object);
sut.RegisterNotification(button);
Assert.IsTrue(button.HasSubscribed);
}
[TestMethod] [TestMethod]
public void MustNotFailToTerminateIfNotStarted() public void MustNotFailToTerminateIfNotStarted()
{ {

View file

@ -31,13 +31,12 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
[TestMethod] [TestMethod]
public void MustCloseWindowWhenTerminating() public void MustCloseWindowWhenTerminating()
{ {
var button = new NotificationButtonMock();
var window = new Mock<IWindow>(); var window = new Mock<IWindow>();
var sut = new LogNotificationController(logger.Object, uiFactory.Object); var sut = new LogNotificationController(logger.Object, uiFactory.Object);
uiFactory.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>())).Returns(window.Object); uiFactory.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click(); sut.Activate();
sut.Terminate(); sut.Terminate();
window.Verify(w => w.Close()); window.Verify(w => w.Close());
@ -46,34 +45,22 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
[TestMethod] [TestMethod]
public void MustOpenOnlyOneWindow() public void MustOpenOnlyOneWindow()
{ {
var button = new NotificationButtonMock();
var window = new Mock<IWindow>(); var window = new Mock<IWindow>();
var sut = new LogNotificationController(logger.Object, uiFactory.Object); var sut = new LogNotificationController(logger.Object, uiFactory.Object);
uiFactory.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>())).Returns(window.Object); uiFactory.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click(); sut.Activate();
button.Click(); sut.Activate();
button.Click(); sut.Activate();
button.Click(); sut.Activate();
button.Click(); sut.Activate();
uiFactory.Verify(u => u.CreateLogWindow(It.IsAny<ILogger>()), Times.Once); uiFactory.Verify(u => u.CreateLogWindow(It.IsAny<ILogger>()), Times.Once);
window.Verify(u => u.Show(), Times.Once); window.Verify(u => u.Show(), Times.Once);
window.Verify(u => u.BringToForeground(), Times.Exactly(4)); window.Verify(u => u.BringToForeground(), Times.Exactly(4));
} }
[TestMethod]
public void MustSubscribeToClickEvent()
{
var button = new NotificationButtonMock();
var sut = new LogNotificationController(logger.Object, uiFactory.Object);
sut.RegisterNotification(button);
Assert.IsTrue(button.HasSubscribed);
}
[TestMethod] [TestMethod]
public void MustNotFailToTerminateIfNotStarted() public void MustNotFailToTerminateIfNotStarted()
{ {

View file

@ -1,40 +0,0 @@
/*
* Copyright (c) 2019 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 SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
namespace SafeExamBrowser.Client.UnitTests.Notifications
{
class NotificationButtonMock : INotificationControl
{
private NotificationControlClickedEventHandler clicked;
public bool HasSubscribed;
public bool HasUnsubscribed;
public event NotificationControlClickedEventHandler Clicked
{
add
{
clicked += value;
HasSubscribed = true;
}
remove
{
clicked -= value;
HasUnsubscribed = true;
}
}
public void Click()
{
clicked?.Invoke();
}
}
}

View file

@ -71,17 +71,19 @@ namespace SafeExamBrowser.Client.UnitTests.Operations
uiFactory = new Mock<IUserInterfaceFactory>(); uiFactory = new Mock<IUserInterfaceFactory>();
wirelessAdapter = new Mock<IWirelessAdapter>(); wirelessAdapter = new Mock<IWirelessAdapter>();
uiFactory.Setup(u => u.CreateNotificationControl(It.IsAny<INotificationInfo>(), It.IsAny<Location>())).Returns(new Mock<INotificationControl>().Object); uiFactory
.Setup(u => u.CreateNotificationControl(It.IsAny<INotificationController>(), It.IsAny<INotificationInfo>(), It.IsAny<Location>()))
.Returns(new Mock<INotificationControl>().Object);
sut = new ShellOperation( sut = new ShellOperation(
actionCenter.Object, actionCenter.Object,
activators, activators,
actionCenterSettings, actionCenterSettings,
audio.Object, audio.Object,
logger.Object,
aboutInfo.Object, aboutInfo.Object,
aboutController.Object, aboutController.Object,
keyboard.Object, keyboard.Object,
logger.Object,
logInfo.Object, logInfo.Object,
logController.Object, logController.Object,
powerSupply.Object, powerSupply.Object,
@ -175,7 +177,9 @@ namespace SafeExamBrowser.Client.UnitTests.Operations
taskbarSettings.EnableTaskbar = true; taskbarSettings.EnableTaskbar = true;
taskbarSettings.ShowApplicationLog = false; taskbarSettings.ShowApplicationLog = false;
uiFactory.Setup(f => f.CreateNotificationControl(It.Is<INotificationInfo>(i => i == logInfo.Object), It.IsAny<Location>())).Returns(logControl.Object); uiFactory
.Setup(f => f.CreateNotificationControl(It.IsAny<INotificationController>(), It.Is<INotificationInfo>(i => i == logInfo.Object), It.IsAny<Location>()))
.Returns(logControl.Object);
sut.Perform(); sut.Perform();

View file

@ -95,7 +95,6 @@
<Compile Include="Communication\ClientHostTests.cs" /> <Compile Include="Communication\ClientHostTests.cs" />
<Compile Include="Notifications\AboutNotificationControllerTests.cs" /> <Compile Include="Notifications\AboutNotificationControllerTests.cs" />
<Compile Include="Notifications\LogNotificationControllerTests.cs" /> <Compile Include="Notifications\LogNotificationControllerTests.cs" />
<Compile Include="Notifications\NotificationButtonMock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ClientControllerTests.cs" /> <Compile Include="ClientControllerTests.cs" />
</ItemGroup> </ItemGroup>

View file

@ -275,10 +275,10 @@ namespace SafeExamBrowser.Client
activators, activators,
configuration.Settings.ActionCenter, configuration.Settings.ActionCenter,
audio, audio,
logger,
aboutInfo, aboutInfo,
aboutController, aboutController,
keyboard, keyboard,
logger,
logInfo, logInfo,
logController, logController,
powerSupply, powerSupply,

View file

@ -9,14 +9,12 @@
using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Contracts;
using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Contracts.Windows;
namespace SafeExamBrowser.Client.Notifications namespace SafeExamBrowser.Client.Notifications
{ {
internal class AboutNotificationController : INotificationController internal class AboutNotificationController : INotificationController
{ {
private INotificationControl notification;
private AppConfig appConfig; private AppConfig appConfig;
private IUserInterfaceFactory uiFactory; private IUserInterfaceFactory uiFactory;
private IWindow window; private IWindow window;
@ -27,25 +25,13 @@ namespace SafeExamBrowser.Client.Notifications
this.uiFactory = uiFactory; this.uiFactory = uiFactory;
} }
public void RegisterNotification(INotificationControl notification) public void Activate()
{ {
this.notification = notification; if (window == default(IWindow))
notification.Clicked += Notification_Clicked;
}
public void Terminate()
{
window?.Close();
}
private void Notification_Clicked()
{
if (window == null)
{ {
window = uiFactory.CreateAboutWindow(appConfig); window = uiFactory.CreateAboutWindow(appConfig);
window.Closing += () => window = null; window.Closing += () => window = default(IWindow);
window.Show(); window.Show();
} }
else else
@ -53,5 +39,10 @@ namespace SafeExamBrowser.Client.Notifications
window.BringToForeground(); window.BringToForeground();
} }
} }
public void Terminate()
{
window?.Close();
}
} }
} }

View file

@ -9,14 +9,12 @@
using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Contracts;
using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Contracts.Windows;
namespace SafeExamBrowser.Client.Notifications namespace SafeExamBrowser.Client.Notifications
{ {
internal class LogNotificationController : INotificationController internal class LogNotificationController : INotificationController
{ {
private INotificationControl notification;
private ILogger logger; private ILogger logger;
private IUserInterfaceFactory uiFactory; private IUserInterfaceFactory uiFactory;
private IWindow window; private IWindow window;
@ -27,21 +25,9 @@ namespace SafeExamBrowser.Client.Notifications
this.uiFactory = uiFactory; this.uiFactory = uiFactory;
} }
public void RegisterNotification(INotificationControl notification) public void Activate()
{ {
this.notification = notification; if (window == default(IWindow))
notification.Clicked += Notification_Clicked;
}
public void Terminate()
{
window?.Close();
}
private void Notification_Clicked()
{
if (window == null)
{ {
window = uiFactory.CreateLogWindow(logger); window = uiFactory.CreateLogWindow(logger);
@ -53,5 +39,10 @@ namespace SafeExamBrowser.Client.Notifications
window.BringToForeground(); window.BringToForeground();
} }
} }
public void Terminate()
{
window?.Close();
}
} }
} }

View file

@ -30,10 +30,10 @@ namespace SafeExamBrowser.Client.Operations
private IEnumerable<IActionCenterActivator> activators; private IEnumerable<IActionCenterActivator> activators;
private ActionCenterSettings actionCenterSettings; private ActionCenterSettings actionCenterSettings;
private IAudio audio; private IAudio audio;
private ILogger logger;
private INotificationInfo aboutInfo; private INotificationInfo aboutInfo;
private INotificationController aboutController; private INotificationController aboutController;
private IKeyboard keyboard; private IKeyboard keyboard;
private ILogger logger;
private INotificationInfo logInfo; private INotificationInfo logInfo;
private INotificationController logController; private INotificationController logController;
private IPowerSupply powerSupply; private IPowerSupply powerSupply;
@ -53,10 +53,10 @@ namespace SafeExamBrowser.Client.Operations
IEnumerable<IActionCenterActivator> activators, IEnumerable<IActionCenterActivator> activators,
ActionCenterSettings actionCenterSettings, ActionCenterSettings actionCenterSettings,
IAudio audio, IAudio audio,
ILogger logger,
INotificationInfo aboutInfo, INotificationInfo aboutInfo,
INotificationController aboutController, INotificationController aboutController,
IKeyboard keyboard, IKeyboard keyboard,
ILogger logger,
INotificationInfo logInfo, INotificationInfo logInfo,
INotificationController logController, INotificationController logController,
IPowerSupply powerSupply, IPowerSupply powerSupply,
@ -181,10 +181,7 @@ namespace SafeExamBrowser.Client.Operations
{ {
if (actionCenterSettings.ShowApplicationInfo) if (actionCenterSettings.ShowApplicationInfo)
{ {
var notification = uiFactory.CreateNotificationControl(aboutInfo, Location.ActionCenter); actionCenter.AddNotificationControl(uiFactory.CreateNotificationControl(aboutController, aboutInfo, Location.ActionCenter));
// TODO aboutController.RegisterNotification(notification);
actionCenter.AddNotificationControl(notification);
} }
} }
@ -192,10 +189,7 @@ namespace SafeExamBrowser.Client.Operations
{ {
if (taskbarSettings.ShowApplicationInfo) if (taskbarSettings.ShowApplicationInfo)
{ {
var notification = uiFactory.CreateNotificationControl(aboutInfo, Location.Taskbar); taskbar.AddNotificationControl(uiFactory.CreateNotificationControl(aboutController, aboutInfo, Location.Taskbar));
// TODO aboutController.RegisterNotification(notification);
taskbar.AddNotificationControl(notification);
} }
} }
@ -229,10 +223,7 @@ namespace SafeExamBrowser.Client.Operations
{ {
if (actionCenterSettings.ShowApplicationLog) if (actionCenterSettings.ShowApplicationLog)
{ {
var notification = uiFactory.CreateNotificationControl(logInfo, Location.ActionCenter); actionCenter.AddNotificationControl(uiFactory.CreateNotificationControl(logController, logInfo, Location.ActionCenter));
// TODO logController.RegisterNotification(notification);
actionCenter.AddNotificationControl(notification);
} }
} }
@ -240,10 +231,7 @@ namespace SafeExamBrowser.Client.Operations
{ {
if (taskbarSettings.ShowApplicationLog) if (taskbarSettings.ShowApplicationLog)
{ {
var notification = uiFactory.CreateNotificationControl(logInfo, Location.Taskbar); taskbar.AddNotificationControl(uiFactory.CreateNotificationControl(logController, logInfo, Location.Taskbar));
// TODO logController.RegisterNotification(notification);
taskbar.AddNotificationControl(notification);
} }
} }

View file

@ -58,9 +58,9 @@ namespace SafeExamBrowser.UserInterface.Contracts
IWindow CreateLogWindow(ILogger logger); IWindow CreateLogWindow(ILogger logger);
/// <summary> /// <summary>
/// Creates a notification control for the specified location, initialized with the given notification information. /// Creates a notification control for the given notification, initialized for the specified location.
/// </summary> /// </summary>
INotificationControl CreateNotificationControl(INotificationInfo info, Location location); INotificationControl CreateNotificationControl(INotificationController controller, INotificationInfo info, Location location);
/// <summary> /// <summary>
/// Creates a password dialog with the given message and title. /// Creates a password dialog with the given message and title.

View file

@ -67,9 +67,7 @@
<Compile Include="MessageBox\MessageBoxResult.cs" /> <Compile Include="MessageBox\MessageBoxResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Shell\Events\ActivatorEventHandler.cs" /> <Compile Include="Shell\Events\ActivatorEventHandler.cs" />
<Compile Include="Shell\Events\NotificationControlClickedEventHandler.cs" />
<Compile Include="Shell\Events\QuitButtonClickedEventHandler.cs" /> <Compile Include="Shell\Events\QuitButtonClickedEventHandler.cs" />
<Compile Include="Shell\Events\WirelessNetworkSelectedEventHandler.cs" />
<Compile Include="Shell\IActionCenter.cs" /> <Compile Include="Shell\IActionCenter.cs" />
<Compile Include="Shell\IActionCenterActivator.cs" /> <Compile Include="Shell\IActionCenterActivator.cs" />
<Compile Include="Shell\IApplicationControl.cs" /> <Compile Include="Shell\IApplicationControl.cs" />

View file

@ -1,15 +0,0 @@
/*
* Copyright (c) 2019 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/.
*/
namespace SafeExamBrowser.UserInterface.Contracts.Shell.Events
{
/// <summary>
/// Indicates that the user clicked on a <see cref="INotificationControl"/> in the shell.
/// </summary>
public delegate void NotificationControlClickedEventHandler();
}

View file

@ -1,17 +0,0 @@
/*
* Copyright (c) 2019 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;
namespace SafeExamBrowser.UserInterface.Contracts.Shell.Events
{
/// <summary>
/// Indicates that a particular wireless network has been selected by the user.
/// </summary>
public delegate void WirelessNetworkSelectedEventHandler(Guid id);
}

View file

@ -6,8 +6,6 @@
* 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 SafeExamBrowser.UserInterface.Contracts.Shell.Events;
namespace SafeExamBrowser.UserInterface.Contracts.Shell namespace SafeExamBrowser.UserInterface.Contracts.Shell
{ {
/// <summary> /// <summary>
@ -15,9 +13,5 @@ namespace SafeExamBrowser.UserInterface.Contracts.Shell
/// </summary> /// </summary>
public interface INotificationControl public interface INotificationControl
{ {
/// <summary>
/// Event fired when the user clicked on the notification control.
/// </summary>
event NotificationControlClickedEventHandler Clicked;
} }
} }

View file

@ -14,7 +14,7 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid Background="{StaticResource ActionCenterDarkBrush}" Height="64" Margin="2"> <Grid Background="{StaticResource ActionCenterDarkBrush}" Height="64" Margin="2">
<Button x:Name="IconButton" Click="Icon_Click" Padding="2" Template="{StaticResource ActionCenterButton}"> <Button x:Name="IconButton" Click="IconButton_Click" Padding="2" Template="{StaticResource ActionCenterButton}">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="2*" /> <RowDefinition Height="2*" />

View file

@ -10,24 +10,25 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
using SafeExamBrowser.UserInterface.Shared.Utilities; using SafeExamBrowser.UserInterface.Shared.Utilities;
namespace SafeExamBrowser.UserInterface.Desktop.Controls namespace SafeExamBrowser.UserInterface.Desktop.Controls
{ {
public partial class ActionCenterNotificationButton : UserControl, INotificationControl public partial class ActionCenterNotificationButton : UserControl, INotificationControl
{ {
public event NotificationControlClickedEventHandler Clicked; private INotificationController controller;
public ActionCenterNotificationButton(INotificationInfo info) public ActionCenterNotificationButton(INotificationController controller, INotificationInfo info)
{ {
this.controller = controller;
InitializeComponent(); InitializeComponent();
InitializeNotificationIcon(info); InitializeNotificationIcon(info);
} }
private void Icon_Click(object sender, RoutedEventArgs e) private void IconButton_Click(object sender, RoutedEventArgs e)
{ {
Clicked?.Invoke(); controller.Activate();
} }
private void InitializeNotificationIcon(INotificationInfo info) private void InitializeNotificationIcon(INotificationInfo info)

View file

@ -14,6 +14,6 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<Button x:Name="IconButton" Background="{StaticResource BackgroundBrush}" Click="Icon_Click" Padding="7.5" Template="{StaticResource TaskbarButton}" Width="40" /> <Button x:Name="IconButton" Background="{StaticResource BackgroundBrush}" Click="IconButton_Click" Padding="7.5" Template="{StaticResource TaskbarButton}" Width="40" />
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -10,24 +10,25 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
using SafeExamBrowser.UserInterface.Shared.Utilities; using SafeExamBrowser.UserInterface.Shared.Utilities;
namespace SafeExamBrowser.UserInterface.Desktop.Controls namespace SafeExamBrowser.UserInterface.Desktop.Controls
{ {
public partial class TaskbarNotificationButton : UserControl, INotificationControl public partial class TaskbarNotificationButton : UserControl, INotificationControl
{ {
public event NotificationControlClickedEventHandler Clicked; private INotificationController controller;
public TaskbarNotificationButton(INotificationInfo info) public TaskbarNotificationButton(INotificationController controller, INotificationInfo info)
{ {
this.controller = controller;
InitializeComponent(); InitializeComponent();
InitializeNotificationIcon(info); InitializeNotificationIcon(info);
} }
private void Icon_Click(object sender, RoutedEventArgs e) private void IconButton_Click(object sender, RoutedEventArgs e)
{ {
Clicked?.Invoke(); controller.Activate();
} }
private void InitializeNotificationIcon(INotificationInfo info) private void InitializeNotificationIcon(INotificationInfo info)

View file

@ -109,15 +109,15 @@ namespace SafeExamBrowser.UserInterface.Desktop
return logWindow; return logWindow;
} }
public INotificationControl CreateNotificationControl(INotificationInfo info, Location location) public INotificationControl CreateNotificationControl(INotificationController controller, INotificationInfo info, Location location)
{ {
if (location == Location.ActionCenter) if (location == Location.ActionCenter)
{ {
return new ActionCenterNotificationButton(info); return new ActionCenterNotificationButton(controller, info);
} }
else else
{ {
return new TaskbarNotificationButton(info); return new TaskbarNotificationButton(controller, info);
} }
} }

View file

@ -14,7 +14,7 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid Background="{StaticResource ActionCenterDarkBrush}" Height="82" Margin="2"> <Grid Background="{StaticResource ActionCenterDarkBrush}" Height="82" Margin="2">
<Button x:Name="IconButton" Click="Icon_Click" Padding="2" Template="{StaticResource ActionCenterButton}"> <Button x:Name="IconButton" Click="IconButton_Click" Padding="2" Template="{StaticResource ActionCenterButton}">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="2*" /> <RowDefinition Height="2*" />

View file

@ -10,24 +10,25 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
using SafeExamBrowser.UserInterface.Shared.Utilities; using SafeExamBrowser.UserInterface.Shared.Utilities;
namespace SafeExamBrowser.UserInterface.Mobile.Controls namespace SafeExamBrowser.UserInterface.Mobile.Controls
{ {
public partial class ActionCenterNotificationButton : UserControl, INotificationControl public partial class ActionCenterNotificationButton : UserControl, INotificationControl
{ {
public event NotificationControlClickedEventHandler Clicked; private INotificationController controller;
public ActionCenterNotificationButton(INotificationInfo info) public ActionCenterNotificationButton(INotificationController controller, INotificationInfo info)
{ {
this.controller = controller;
InitializeComponent(); InitializeComponent();
InitializeNotificationIcon(info); InitializeNotificationIcon(info);
} }
private void Icon_Click(object sender, RoutedEventArgs e) private void IconButton_Click(object sender, RoutedEventArgs e)
{ {
Clicked?.Invoke(); controller.Activate();
} }
private void InitializeNotificationIcon(INotificationInfo info) private void InitializeNotificationIcon(INotificationInfo info)

View file

@ -14,6 +14,6 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<Button x:Name="IconButton" Background="{StaticResource BackgroundBrush}" Click="Icon_Click" Padding="7.5" Template="{StaticResource TaskbarButton}" Width="60" /> <Button x:Name="IconButton" Background="{StaticResource BackgroundBrush}" Click="IconButton_Click" Padding="7.5" Template="{StaticResource TaskbarButton}" Width="60" />
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -10,24 +10,25 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell;
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
using SafeExamBrowser.UserInterface.Shared.Utilities; using SafeExamBrowser.UserInterface.Shared.Utilities;
namespace SafeExamBrowser.UserInterface.Mobile.Controls namespace SafeExamBrowser.UserInterface.Mobile.Controls
{ {
public partial class TaskbarNotificationButton : UserControl, INotificationControl public partial class TaskbarNotificationButton : UserControl, INotificationControl
{ {
public event NotificationControlClickedEventHandler Clicked; private INotificationController controller;
public TaskbarNotificationButton(INotificationInfo info) public TaskbarNotificationButton(INotificationController controller, INotificationInfo info)
{ {
this.controller = controller;
InitializeComponent(); InitializeComponent();
InitializeNotificationIcon(info); InitializeNotificationIcon(info);
} }
private void Icon_Click(object sender, RoutedEventArgs e) private void IconButton_Click(object sender, RoutedEventArgs e)
{ {
Clicked?.Invoke(); controller.Activate();
} }
private void InitializeNotificationIcon(INotificationInfo info) private void InitializeNotificationIcon(INotificationInfo info)

View file

@ -109,15 +109,15 @@ namespace SafeExamBrowser.UserInterface.Mobile
return logWindow; return logWindow;
} }
public INotificationControl CreateNotificationControl(INotificationInfo info, Location location) public INotificationControl CreateNotificationControl(INotificationController controller, INotificationInfo info, Location location)
{ {
if (location == Location.ActionCenter) if (location == Location.ActionCenter)
{ {
return new ActionCenterNotificationButton(info); return new ActionCenterNotificationButton(controller, info);
} }
else else
{ {
return new TaskbarNotificationButton(info); return new TaskbarNotificationButton(controller, info);
} }
} }