Refactored taskbar components (moved contracts to separate namespace and introduced XAML control templates) and started implementing system components.

This commit is contained in:
dbuechel 2017-08-15 15:30:31 +02:00
parent 1c26d54e34
commit 7baf826e5a
38 changed files with 464 additions and 120 deletions

View file

@ -15,12 +15,13 @@ using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Browser
{
public class BrowserApplicationController : IApplicationController
{
private ITaskbarButton button;
private IApplicationButton button;
private IList<IApplicationInstance> instances = new List<IApplicationInstance>();
private ISettings settings;
private IUserInterfaceFactory uiFactory;
@ -49,7 +50,7 @@ namespace SafeExamBrowser.Browser
}
}
public void RegisterApplicationButton(ITaskbarButton button)
public void RegisterApplicationButton(IApplicationButton button)
{
this.button = button;
this.button.Clicked += Button_OnClick;

View file

@ -36,10 +36,13 @@ namespace SafeExamBrowser.Configuration
private void InitializeOperatingSystem()
{
// See https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions for mapping source...
// IMPORTANT:
// In order to be able to retrieve the correct operating system version via System.Environment.OSVersion, the executing
// assembly needs to define an application manifest where the supported Windows versions are specified!
var major = System.Environment.OSVersion.Version.Major;
var minor = System.Environment.OSVersion.Version.Minor;
// See https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions for mapping source...
if (major == 6)
{
if (minor == 1)

View file

@ -7,6 +7,7 @@
*/
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Contracts.Behaviour
{
@ -20,7 +21,7 @@ namespace SafeExamBrowser.Contracts.Behaviour
/// <summary>
/// Registers the taskbar button for this application.
/// </summary>
void RegisterApplicationButton(ITaskbarButton button);
void RegisterApplicationButton(IApplicationButton button);
/// <summary>
/// Performs any termination work, e.g. freeing of resources.

View file

@ -7,6 +7,7 @@
*/
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Contracts.Behaviour
{
@ -15,7 +16,7 @@ namespace SafeExamBrowser.Contracts.Behaviour
/// <summary>
/// Registers the taskbar notification.
/// </summary>
void RegisterNotification(ITaskbarNotification notification);
void RegisterNotification(INotificationButton notification);
/// <summary>
/// Instructs the controller to shut down and release all used resources.

View file

@ -86,15 +86,18 @@
<Compile Include="Monitoring\KeyModifier.cs" />
<Compile Include="Monitoring\KeyState.cs" />
<Compile Include="Monitoring\MouseButton.cs" />
<Compile Include="SystemComponents\ISystemComponent.cs" />
<Compile Include="UserInterface\IBrowserControl.cs" />
<Compile Include="UserInterface\IBrowserWindow.cs" />
<Compile Include="UserInterface\IMessageBox.cs" />
<Compile Include="UserInterface\ITaskbarNotification.cs" />
<Compile Include="UserInterface\Taskbar\INotificationButton.cs" />
<Compile Include="UserInterface\ISplashScreen.cs" />
<Compile Include="UserInterface\ITaskbar.cs" />
<Compile Include="UserInterface\Taskbar\ISystemPowerSupplyControl.cs" />
<Compile Include="UserInterface\Taskbar\ISystemControl.cs" />
<Compile Include="UserInterface\Taskbar\ITaskbar.cs" />
<Compile Include="I18n\ITextResource.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserInterface\ITaskbarButton.cs" />
<Compile Include="UserInterface\Taskbar\IApplicationButton.cs" />
<Compile Include="UserInterface\IUserInterfaceFactory.cs" />
<Compile Include="UserInterface\IWindow.cs" />
<Compile Include="UserInterface\MessageBoxAction.cs" />

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2017 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.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Contracts.SystemComponents
{
public interface ISystemComponent<TControl> where TControl : ISystemControl
{
/// <summary>
/// Initializes the resources used by the component and starts its operations, if applicable.
/// </summary>
void Initialize();
/// <summary>
/// Registers the taskbar control for the system component.
/// </summary>
void RegisterControl(TControl control);
/// <summary>
/// Instructs the component to stop any running operations and release all used resources.
/// </summary>
void Terminate();
}
}

View file

@ -10,6 +10,7 @@ using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Contracts.UserInterface
{
@ -23,7 +24,7 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// <summary>
/// Creates a taskbar button, initialized with the given application information.
/// </summary>
ITaskbarButton CreateApplicationButton(IApplicationInfo info);
IApplicationButton CreateApplicationButton(IApplicationInfo info);
/// <summary>
/// Creates a new browser window loaded with the given browser control and settings.
@ -38,7 +39,12 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// <summary>
/// Creates a taskbar notification, initialized with the given notification information.
/// </summary>
ITaskbarNotification CreateNotification(INotificationInfo info);
INotificationButton CreateNotification(INotificationInfo info);
/// <summary>
/// Creates a system control displaying the power supply status of the computer.
/// </summary>
ISystemPowerSupplyControl CreatePowerSupplyControl();
/// <summary>
/// Creates a new splash screen which runs on its own thread.

View file

@ -9,17 +9,17 @@
using System;
using SafeExamBrowser.Contracts.Configuration;
namespace SafeExamBrowser.Contracts.UserInterface
namespace SafeExamBrowser.Contracts.UserInterface.Taskbar
{
public delegate void TaskbarButtonClickedEventHandler(Guid? instanceId = null);
public delegate void ApplicationButtonClickedEventHandler(Guid? instanceId = null);
public interface ITaskbarButton
public interface IApplicationButton
{
/// <summary>
/// Event fired when the user clicked on the application button. If multiple instances of an application
/// are active, the handler is only executed when the user selects one of the instances.
/// Event fired when the user clicked on the application button. If multiple instances of an application are active,
/// the handler is only executed when the user selects one of the instances.
/// </summary>
event TaskbarButtonClickedEventHandler Clicked;
event ApplicationButtonClickedEventHandler Clicked;
/// <summary>
/// Registers a new instance of an application, to be started / displayed if the user clicked the taskbar button.

View file

@ -6,15 +6,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Contracts.UserInterface
namespace SafeExamBrowser.Contracts.UserInterface.Taskbar
{
public delegate void TaskbarNotificationClickedEventHandler();
public delegate void NotificationButtonClickedEventHandler();
public interface ITaskbarNotification
public interface INotificationButton
{
/// <summary>
/// Event fired when the user clicked on the notification icon.
/// </summary>
event TaskbarNotificationClickedEventHandler Clicked;
event NotificationButtonClickedEventHandler Clicked;
}
}

View file

@ -0,0 +1,18 @@
/*
* Copyright (c) 2017 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.Contracts.UserInterface.Taskbar
{
public interface ISystemControl
{
/// <summary>
/// Sets the tooltip text of the system control.
/// </summary>
void SetTooltip(string text);
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2017 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.Contracts.UserInterface.Taskbar
{
public interface ISystemPowerSupplyControl : ISystemControl
{
/// <summary>
/// Sets the current charge of the system battery, if available. <c>0.0</c> means the battery is empty, <c>1.0</c> means it's
/// fully charged. Pass <c>null</c> to indicate that the computer system has no battery.
/// </summary>
void SetBatteryCharge(double? percentage);
/// <summary>
/// Sets the power supply status, i.e. whether the computer system is connected to the power grid or not.
/// </summary>
void SetPowerGridConnection(bool connected);
}
}

View file

@ -6,19 +6,24 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Contracts.UserInterface
namespace SafeExamBrowser.Contracts.UserInterface.Taskbar
{
public interface ITaskbar
{
/// <summary>
/// Adds the given application button to the taskbar.
/// </summary>
void AddButton(ITaskbarButton button);
void AddApplication(IApplicationButton button);
/// <summary>
/// Adds the given notification button to the taskbar.
/// </summary>
void AddNotification(ITaskbarNotification notification);
void AddNotification(INotificationButton button);
/// <summary>
/// Adds the given system control to the taskbar.
/// </summary>
void AddSystemControl(ISystemControl control);
/// <summary>
/// Returns the absolute height of the taskbar (i.e. in physical pixels).

View file

@ -12,7 +12,7 @@ using Moq;
using SafeExamBrowser.Contracts.Behaviour;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.Core.Behaviour;
namespace SafeExamBrowser.Core.UnitTests.Behaviour

View file

@ -11,6 +11,7 @@ using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Core.Behaviour.Operations
{
@ -48,7 +49,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
browserController.Initialize();
browserController.RegisterApplicationButton(browserButton);
taskbar.AddButton(browserButton);
taskbar.AddApplication(browserButton);
}
public void Revert()

View file

@ -11,6 +11,7 @@ using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Core.Behaviour.Operations
{

View file

@ -11,7 +11,9 @@ using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.SystemComponents;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.Core.Notifications;
namespace SafeExamBrowser.Core.Behaviour.Operations
@ -21,6 +23,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
private ILogger logger;
private INotificationController aboutController, logController;
private ISettings settings;
private ISystemComponent<ISystemPowerSupplyControl> powerSupply;
private ISystemInfo systemInfo;
private ITaskbar taskbar;
private IUserInterfaceFactory uiFactory;
@ -31,6 +34,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
public TaskbarOperation(
ILogger logger,
ISettings settings,
ISystemComponent<ISystemPowerSupplyControl> powerSupply,
ISystemInfo systemInfo,
ITaskbar taskbar,
IText text,
@ -38,6 +42,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
{
this.logger = logger;
this.settings = settings;
this.powerSupply = powerSupply;
this.systemInfo = systemInfo;
this.taskbar = taskbar;
this.text = text;
@ -55,21 +60,15 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
}
CreateAboutNotification();
if (systemInfo.HasBattery)
{
CreateBatteryNotification();
}
CreateNetworkNotification();
CreateAudioNotification();
CreateKeyboardNotification();
CreatePowerSupplyComponent();
}
public void Revert()
{
logController?.Terminate();
aboutController?.Terminate();
powerSupply.Terminate();
}
private void CreateLogNotification()
@ -94,25 +93,14 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
taskbar.AddNotification(aboutNotification);
}
private void CreateBatteryNotification()
private void CreatePowerSupplyComponent()
{
// TODO: Are these specializations of INotification -> ISystemNotification? If yes, is this the right place, or do they
// need to go to a separate assembly?
}
var control = uiFactory.CreatePowerSupplyControl();
private void CreateNetworkNotification()
{
// TODO
}
powerSupply.RegisterControl(control);
powerSupply.Initialize();
private void CreateAudioNotification()
{
// TODO
}
private void CreateKeyboardNotification()
{
// TODO
taskbar.AddSystemControl(control);
}
}
}

View file

@ -10,7 +10,7 @@ using System;
using SafeExamBrowser.Contracts.Behaviour;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Core.Behaviour
{

View file

@ -91,7 +91,7 @@ namespace SafeExamBrowser.Core.Behaviour
logger.Log($"{titleLine}{copyrightLine}{emptyLine}{githubLine}");
logger.Log($"{Environment.NewLine}# Application started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
logger.Log($"# Operating system: {systemInfo.OperatingSystemInfo}{Environment.NewLine}");
logger.Log($"# Running on {systemInfo.OperatingSystemInfo}{Environment.NewLine}");
logger.Info("--- Initiating startup procedure ---");
splashScreen = uiFactory.CreateSplashScreen(settings, text);

View file

@ -10,12 +10,13 @@ using SafeExamBrowser.Contracts.Behaviour;
using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Core.Notifications
{
public class AboutNotificationController : INotificationController
{
private ITaskbarNotification notification;
private INotificationButton notification;
private ISettings settings;
private IText text;
private IUserInterfaceFactory uiFactory;
@ -28,7 +29,7 @@ namespace SafeExamBrowser.Core.Notifications
this.uiFactory = uiFactory;
}
public void RegisterNotification(ITaskbarNotification notification)
public void RegisterNotification(INotificationButton notification)
{
this.notification = notification;

View file

@ -10,12 +10,13 @@ using SafeExamBrowser.Contracts.Behaviour;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.Core.Notifications
{
public class LogNotificationController : INotificationController
{
private ITaskbarNotification notification;
private INotificationButton notification;
private ILogger logger;
private IText text;
private IUserInterfaceFactory uiFactory;
@ -28,7 +29,7 @@ namespace SafeExamBrowser.Core.Notifications
this.uiFactory = uiFactory;
}
public void RegisterNotification(ITaskbarNotification notification)
public void RegisterNotification(INotificationButton notification)
{
this.notification = notification;

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2017 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.Contracts.Logging;
using SafeExamBrowser.Contracts.SystemComponents;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.SystemComponents
{
public class PowerSupply : ISystemComponent<ISystemPowerSupplyControl>
{
private ILogger logger;
private ISystemPowerSupplyControl control;
public PowerSupply(ILogger logger)
{
this.logger = logger;
}
public void Initialize()
{
}
public void RegisterControl(ISystemPowerSupplyControl control)
{
this.control = control;
}
public void Terminate()
{
}
}
}

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SafeExamBrowser.SystemComponents")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SafeExamBrowser.SystemComponents")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("acee2ef1-14d2-4b52-8994-5c053055bb51")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{ACEE2EF1-14D2-4B52-8994-5C053055BB51}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SafeExamBrowser.SystemComponents</RootNamespace>
<AssemblyName>SafeExamBrowser.SystemComponents</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="PowerSupply.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SafeExamBrowser.Contracts\SafeExamBrowser.Contracts.csproj">
<Project>{47DA5933-BEF8-4729-94E6-ABDE2DB12262}</Project>
<Name>SafeExamBrowser.Contracts</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -5,8 +5,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls"
xmlns:s="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="50">
mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="50">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/ButtonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Popup x:Name="InstancePopup" IsOpen="False" Placement="Top" PlacementTarget="{Binding ElementName=Button}" AllowsTransparency="True">
<ScrollViewer x:Name="InstanceScrollViewer" VerticalScrollBarVisibility="Auto">
@ -19,23 +25,8 @@
<StackPanel x:Name="InstanceStackPanel" />
</ScrollViewer>
</Popup>
<Button x:Name="Button" Background="#00000000" BorderThickness="0" Click="Button_Click" Width="50">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border x:Name="ButtonContent" Background="{TemplateBinding Background}" Padding="5">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Content" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="#2AFFFFFF" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="#10FFFFFF" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button x:Name="Button" Background="#00000000" BorderThickness="0" Click="Button_Click" Padding="5"
Template="{StaticResource ResourceKey=TaskbarButton}" Width="50" />
<Grid Panel.ZIndex="10">
<Rectangle x:Name="ActiveBar" Height="2" Width="40" VerticalAlignment="Bottom" Fill="LightSteelBlue" Visibility="Collapsed" />
</Grid>

View file

@ -13,17 +13,17 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.UserInterface.Utilities;
namespace SafeExamBrowser.UserInterface.Controls
{
public partial class ApplicationButton : UserControl, ITaskbarButton
public partial class ApplicationButton : UserControl, IApplicationButton
{
private IApplicationInfo info;
private IList<IApplicationInstance> instances = new List<IApplicationInstance>();
public event TaskbarButtonClickedEventHandler Clicked;
public event ApplicationButtonClickedEventHandler Clicked;
public ApplicationButton(IApplicationInfo info)
{

View file

@ -0,0 +1,17 @@
<UserControl x:Class="SafeExamBrowser.UserInterface.Controls.NotificationButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls"
mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="28">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/ButtonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Button x:Name="IconButton" Click="Icon_Click" Background="#00000000" BorderThickness="0" Padding="5,0"
Template="{StaticResource ResourceKey=TaskbarButton}" Width="28"/>
</UserControl>

View file

@ -9,16 +9,16 @@
using System.Windows;
using System.Windows.Controls;
using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.UserInterface.Utilities;
namespace SafeExamBrowser.UserInterface.Controls
{
public partial class NotificationIcon : UserControl, ITaskbarNotification
public partial class NotificationButton : UserControl, INotificationButton
{
public event TaskbarNotificationClickedEventHandler Clicked;
public event NotificationButtonClickedEventHandler Clicked;
public NotificationIcon(INotificationInfo info)
public NotificationButton(INotificationInfo info)
{
InitializeComponent();
InitializeNotificationIcon(info);

View file

@ -1,25 +0,0 @@
<UserControl x:Class="SafeExamBrowser.UserInterface.Controls.NotificationIcon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls"
mc:Ignorable="d" d:DesignHeight="16" d:DesignWidth="26">
<Button x:Name="IconButton" Click="Icon_Click" Background="#00000000" BorderThickness="0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border x:Name="ButtonContent" Background="{TemplateBinding Background}" Padding="5,0">
<ContentPresenter ContentSource="Content" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="18" RenderOptions.BitmapScalingMode="HighQuality" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="#2AFFFFFF" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="#10FFFFFF" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</UserControl>

View file

@ -0,0 +1,26 @@
<UserControl x:Class="SafeExamBrowser.UserInterface.Controls.PowerSupplyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls"
mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="28">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/ButtonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Button x:Name="Button" Background="#00000000" BorderThickness="0" Foreground="White" Padding="5,0"
Template="{StaticResource ResourceKey=TaskbarButton}" Width="28">
<Canvas Height="18" Width="18">
<Path Stroke="White" Data="M3,6 H17 V9 H18 V11 H17 V9 H17 V14 H3 Z" Panel.ZIndex="2" />
<Rectangle x:Name="BatteryCharge" Canvas.Left="3" Canvas.Top="6" Fill="Green" Height="8" Width="14" />
<Grid x:Name="PowerPlug" Panel.ZIndex="3">
<Path Stroke="White" Fill="Black" Data="M2.5,14.5 V10 Q5,10 5,6 H4 V4 H4 V6 H1 V4 H1 V6 H0 Q0,10 2.5,10" Panel.ZIndex="2" />
<Path Stroke="Black" Data="M4,14.5 V10 Q6,10 6,5.5" Panel.ZIndex="1" />
</Grid>
</Canvas>
</Button>
</UserControl>

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2017 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.Controls;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
namespace SafeExamBrowser.UserInterface.Controls
{
public partial class PowerSupplyControl : UserControl, ISystemPowerSupplyControl
{
public PowerSupplyControl()
{
InitializeComponent();
InitializePowerSupplyControl();
}
public void SetBatteryCharge(double? percentage)
{
throw new NotImplementedException();
}
public void SetPowerGridConnection(bool connected)
{
throw new NotImplementedException();
}
public void SetTooltip(string text)
{
throw new NotImplementedException();
}
private void InitializePowerSupplyControl()
{
Button.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source = (new Uri("/SafeExamBrowser.UserInterface;component/Styles/ButtonStyles.xaml", UriKind.RelativeOrAbsolute))
});
}
}
}

View file

@ -77,8 +77,11 @@
<Compile Include="Controls\ApplicationButton.xaml.cs">
<DependentUpon>ApplicationButton.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\NotificationIcon.xaml.cs">
<DependentUpon>NotificationIcon.xaml</DependentUpon>
<Compile Include="Controls\NotificationButton.xaml.cs">
<DependentUpon>NotificationButton.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\PowerSupplyControl.xaml.cs">
<DependentUpon>PowerSupplyControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\QuitButton.xaml.cs">
<DependentUpon>QuitButton.xaml</DependentUpon>
@ -141,7 +144,11 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\NotificationIcon.xaml">
<Page Include="Controls\NotificationButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\PowerSupplyControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@ -157,6 +164,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\ButtonStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Taskbar.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View file

@ -0,0 +1,17 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Styles">
<ControlTemplate x:Key="TaskbarButton" TargetType="Button">
<Border x:Name="ButtonContent" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
<ContentPresenter ContentSource="Content" HorizontalAlignment="Center" VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="#2AFFFFFF" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="#10FFFFFF" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ResourceDictionary>

View file

@ -17,6 +17,7 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" x:Name="ApplicationScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
@ -26,8 +27,9 @@
<StackPanel x:Name="ApplicationStackPanel" Orientation="Horizontal" />
</ScrollViewer>
<StackPanel Grid.Column="1" x:Name="NotificationStackPanel" Margin="5,0,0,0" Orientation="Horizontal" VerticalAlignment="Stretch" />
<local:DateTimeControl Grid.Column="2" />
<local:QuitButton Grid.Column="3" />
<StackPanel Grid.Column="2" x:Name="SystemControlStackPanel" Orientation="Horizontal" VerticalAlignment="Stretch" />
<local:DateTimeControl Grid.Column="3" />
<local:QuitButton Grid.Column="4" />
</Grid>
</Border>
</Window>

View file

@ -8,7 +8,7 @@
using System.Windows;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.UserInterface.Utilities;
namespace SafeExamBrowser.UserInterface
@ -26,7 +26,7 @@ namespace SafeExamBrowser.UserInterface
Loaded += (o, args) => InitializeBounds();
}
public void AddButton(ITaskbarButton button)
public void AddApplication(IApplicationButton button)
{
if (button is UIElement)
{
@ -34,7 +34,7 @@ namespace SafeExamBrowser.UserInterface
}
}
public void AddNotification(ITaskbarNotification button)
public void AddNotification(INotificationButton button)
{
if (button is UIElement)
{
@ -42,6 +42,14 @@ namespace SafeExamBrowser.UserInterface
}
}
public void AddSystemControl(ISystemControl control)
{
if (control is UIElement)
{
SystemControlStackPanel.Children.Add(control as UIElement);
}
}
public int GetAbsoluteHeight()
{
return Dispatcher.Invoke(() =>

View file

@ -13,6 +13,7 @@ using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.UserInterface.Controls;
namespace SafeExamBrowser.UserInterface
@ -24,7 +25,7 @@ namespace SafeExamBrowser.UserInterface
return new AboutWindow(settings, text);
}
public ITaskbarButton CreateApplicationButton(IApplicationInfo info)
public IApplicationButton CreateApplicationButton(IApplicationInfo info)
{
return new ApplicationButton(info);
}
@ -59,9 +60,14 @@ namespace SafeExamBrowser.UserInterface
return logWindow;
}
public ITaskbarNotification CreateNotification(INotificationInfo info)
public INotificationButton CreateNotification(INotificationInfo info)
{
return new NotificationIcon(info);
return new NotificationButton(info);
}
public ISystemPowerSupplyControl CreatePowerSupplyControl()
{
return new PowerSupplyControl();
}
public ISplashScreen CreateSplashScreen(ISettings settings, IText text)

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser", "SafeExamBrowser\SafeExamBrowser.csproj", "{E3AED2F8-B5DF-45D1-AC19-48066923D6D8}"
EndProject
@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Configurati
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.WindowsApi", "SafeExamBrowser.WindowsApi\SafeExamBrowser.WindowsApi.csproj", "{73724659-4150-4792-A94E-42F5F3C1B696}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.SystemComponents", "SafeExamBrowser.SystemComponents\SafeExamBrowser.SystemComponents.csproj", "{ACEE2EF1-14D2-4B52-8994-5C053055BB51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -107,6 +109,14 @@ Global
{73724659-4150-4792-A94E-42F5F3C1B696}.Release|Any CPU.Build.0 = Release|Any CPU
{73724659-4150-4792-A94E-42F5F3C1B696}.Release|x86.ActiveCfg = Release|x86
{73724659-4150-4792-A94E-42F5F3C1B696}.Release|x86.Build.0 = Release|x86
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Debug|x86.ActiveCfg = Debug|x86
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Debug|x86.Build.0 = Debug|x86
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Release|Any CPU.Build.0 = Release|Any CPU
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Release|x86.ActiveCfg = Release|Any CPU
{ACEE2EF1-14D2-4B52-8994-5C053055BB51}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -15,7 +15,9 @@ using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.Contracts.SystemComponents;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
using SafeExamBrowser.Contracts.WindowsApi;
using SafeExamBrowser.Core.Behaviour;
using SafeExamBrowser.Core.Behaviour.Operations;
@ -26,6 +28,7 @@ using SafeExamBrowser.Monitoring.Keyboard;
using SafeExamBrowser.Monitoring.Mouse;
using SafeExamBrowser.Monitoring.Processes;
using SafeExamBrowser.Monitoring.Windows;
using SafeExamBrowser.SystemComponents;
using SafeExamBrowser.UserInterface;
using SafeExamBrowser.WindowsApi;
@ -44,6 +47,7 @@ namespace SafeExamBrowser
private IProcessMonitor processMonitor;
private IRuntimeController runtimeController;
private ISettings settings;
private ISystemComponent<ISystemPowerSupplyControl> powerSupply;
private ISystemInfo systemInfo;
private IText text;
private ITextResource textResource;
@ -74,6 +78,7 @@ namespace SafeExamBrowser
displayMonitor = new DisplayMonitor(new ModuleLogger(logger, typeof(DisplayMonitor)), nativeMethods);
keyboardInterceptor = new KeyboardInterceptor(settings.Keyboard, new ModuleLogger(logger, typeof(KeyboardInterceptor)));
mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, typeof(MouseInterceptor)), settings.Mouse);
powerSupply = new PowerSupply(new ModuleLogger(logger, typeof(PowerSupply)));
processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods);
windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods);
@ -86,7 +91,7 @@ namespace SafeExamBrowser
StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor));
StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor));
StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar));
StartupOperations.Enqueue(new TaskbarOperation(logger, settings, systemInfo, Taskbar, text, uiFactory));
StartupOperations.Enqueue(new TaskbarOperation(logger, settings, powerSupply, systemInfo, Taskbar, text, uiFactory));
StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory));
StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, logger));
StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods));

View file

@ -135,6 +135,10 @@
<Project>{ef563531-4eb5-44b9-a5ec-d6d6f204469b}</Project>
<Name>SafeExamBrowser.Monitoring</Name>
</ProjectReference>
<ProjectReference Include="..\SafeExamBrowser.SystemComponents\SafeExamBrowser.SystemComponents.csproj">
<Project>{ACEE2EF1-14D2-4B52-8994-5C053055BB51}</Project>
<Name>SafeExamBrowser.SystemComponents</Name>
</ProjectReference>
<ProjectReference Include="..\SafeExamBrowser.UserInterface\SafeExamBrowser.UserInterface.csproj">
<Project>{e1be031a-4354-41e7-83e8-843ded4489ff}</Project>
<Name>SafeExamBrowser.UserInterface</Name>