seb-win-refactoring/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs

113 lines
3 KiB
C#
Raw Normal View History

/*
* 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.Behaviour;
using SafeExamBrowser.Contracts.Configuration;
2017-08-02 10:13:23 +02:00
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;
2017-08-02 10:13:23 +02:00
using SafeExamBrowser.Core.Notifications;
namespace SafeExamBrowser.Core.Behaviour.Operations
{
public class TaskbarOperation : IOperation
{
private ILogger logger;
2017-08-07 12:23:56 +02:00
private INotificationController aboutController, logController;
private ISettings settings;
private ISystemComponent<ISystemPowerSupplyControl> powerSupply;
private ISystemInfo systemInfo;
private ITaskbar taskbar;
private IUserInterfaceFactory uiFactory;
2017-08-02 10:13:23 +02:00
private IText text;
public ISplashScreen SplashScreen { private get; set; }
2017-08-07 12:23:56 +02:00
public TaskbarOperation(
ILogger logger,
ISettings settings,
ISystemComponent<ISystemPowerSupplyControl> powerSupply,
ISystemInfo systemInfo,
2017-08-07 12:23:56 +02:00
ITaskbar taskbar,
IText text,
IUserInterfaceFactory uiFactory)
{
this.logger = logger;
2017-08-02 10:13:23 +02:00
this.settings = settings;
this.powerSupply = powerSupply;
this.systemInfo = systemInfo;
this.taskbar = taskbar;
2017-08-02 10:13:23 +02:00
this.text = text;
this.uiFactory = uiFactory;
}
public void Perform()
{
2017-07-24 15:29:17 +02:00
logger.Info("Initializing taskbar...");
SplashScreen.UpdateText(TextKey.SplashScreen_InitializeTaskbar);
2017-08-07 12:23:56 +02:00
if (settings.AllowApplicationLog)
{
CreateLogNotification();
}
// TODO:
//CreateAboutNotification();
//if (systemInfo.HasBattery)
//{
// CreatePowerSupplyComponent();
//}
2017-08-07 12:23:56 +02:00
}
public void Revert()
{
logController?.Terminate();
aboutController?.Terminate();
if (systemInfo.HasBattery)
{
powerSupply.Terminate();
}
}
private void CreateLogNotification()
{
var logInfo = new LogNotificationInfo(text);
var logNotification = uiFactory.CreateNotification(logInfo);
logController = new LogNotificationController(logger, text, uiFactory);
logController.RegisterNotification(logNotification);
taskbar.AddNotification(logNotification);
2017-08-07 12:23:56 +02:00
}
private void CreateAboutNotification()
{
2017-08-02 10:13:23 +02:00
var aboutInfo = new AboutNotificationInfo(text);
var aboutNotification = uiFactory.CreateNotification(aboutInfo);
2017-08-02 10:13:23 +02:00
aboutController = new AboutNotificationController(settings, text, uiFactory);
aboutController.RegisterNotification(aboutNotification);
taskbar.AddNotification(aboutNotification);
}
private void CreatePowerSupplyComponent()
{
var control = uiFactory.CreatePowerSupplyControl();
2017-08-07 12:23:56 +02:00
powerSupply.Initialize(control);
taskbar.AddSystemControl(control);
}
}
}