From bf69a64e153dc4451e2d2c8527289fc7f9517ac2 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 20 Dec 2019 17:06:28 +0100 Subject: [PATCH] SEBWIN-316: Added manufacturer, model and name to system info. --- .../ConfigurationData/DataMapper.cs | 2 +- .../VirtualMachineOperationTests.cs | 22 ++++++++++ .../SafeExamBrowser.Runtime.UnitTests.csproj | 1 + SafeExamBrowser.Runtime/CompositionRoot.cs | 16 ++++---- .../Operations/VirtualMachineOperation.cs | 41 +++++++++++++++++++ .../SafeExamBrowser.Runtime.csproj | 1 + .../ISystemInfo.cs | 17 +++++++- .../SystemInfo.cs | 28 +++++++++++-- 8 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 SafeExamBrowser.Runtime.UnitTests/Operations/VirtualMachineOperationTests.cs create mode 100644 SafeExamBrowser.Runtime/Operations/VirtualMachineOperation.cs diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs index 8689a552..a3b99abc 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs @@ -12,7 +12,7 @@ using SafeExamBrowser.Settings; namespace SafeExamBrowser.Configuration.ConfigurationData { - internal partial class DataMapper + internal class DataMapper { private BaseDataMapper[] mappers = { diff --git a/SafeExamBrowser.Runtime.UnitTests/Operations/VirtualMachineOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Operations/VirtualMachineOperationTests.cs new file mode 100644 index 00000000..1a62c852 --- /dev/null +++ b/SafeExamBrowser.Runtime.UnitTests/Operations/VirtualMachineOperationTests.cs @@ -0,0 +1,22 @@ +/* + * 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 Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SafeExamBrowser.Runtime.UnitTests.Operations +{ + [TestClass] + public class VirtualMachineOperationTests + { + [TestMethod] + public void TODO() + { + Assert.Fail(); + } + } +} diff --git a/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj b/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj index 03375eee..2de179fa 100644 --- a/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj +++ b/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj @@ -90,6 +90,7 @@ + diff --git a/SafeExamBrowser.Runtime/CompositionRoot.cs b/SafeExamBrowser.Runtime/CompositionRoot.cs index 76d56382..ee375292 100644 --- a/SafeExamBrowser.Runtime/CompositionRoot.cs +++ b/SafeExamBrowser.Runtime/CompositionRoot.cs @@ -11,30 +11,30 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; +using SafeExamBrowser.Communication.Contracts; using SafeExamBrowser.Communication.Hosts; using SafeExamBrowser.Communication.Proxies; using SafeExamBrowser.Configuration; +using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Configuration.Cryptography; using SafeExamBrowser.Configuration.DataCompression; using SafeExamBrowser.Configuration.DataFormats; using SafeExamBrowser.Configuration.DataResources; -using SafeExamBrowser.Communication.Contracts; -using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Core.Contracts.OperationModel; -using SafeExamBrowser.I18n.Contracts; -using SafeExamBrowser.Logging.Contracts; -using SafeExamBrowser.Runtime.Contracts; -using SafeExamBrowser.SystemComponents.Contracts; using SafeExamBrowser.Core.OperationModel; using SafeExamBrowser.Core.Operations; using SafeExamBrowser.I18n; +using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging; +using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Runtime.Communication; +using SafeExamBrowser.Runtime.Contracts; using SafeExamBrowser.Runtime.Operations; +using SafeExamBrowser.Settings.Logging; using SafeExamBrowser.SystemComponents; +using SafeExamBrowser.SystemComponents.Contracts; using SafeExamBrowser.UserInterface.Desktop; using SafeExamBrowser.WindowsApi; -using SafeExamBrowser.Settings.Logging; namespace SafeExamBrowser.Runtime { @@ -83,6 +83,7 @@ namespace SafeExamBrowser.Runtime sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost, sessionContext)); sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new HashAlgorithm(), logger, sessionContext)); + sessionOperations.Enqueue(new VirtualMachineOperation(sessionContext)); sessionOperations.Enqueue(new ServiceOperation(logger, runtimeHost, serviceProxy, sessionContext, THIRTY_SECONDS, userInfo)); sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS)); sessionOperations.Enqueue(new KioskModeOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext)); @@ -115,6 +116,7 @@ namespace SafeExamBrowser.Runtime logger.Log(string.Empty); logger.Log($"# Application started at {appConfig.ApplicationStartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}"); logger.Log($"# Running on {systemInfo.OperatingSystemInfo}"); + logger.Log($"# Computer '{systemInfo.Name}' is a {systemInfo.Model} manufactured by {systemInfo.Manufacturer}"); logger.Log($"# Runtime-ID: {appConfig.RuntimeId}"); logger.Log(string.Empty); } diff --git a/SafeExamBrowser.Runtime/Operations/VirtualMachineOperation.cs b/SafeExamBrowser.Runtime/Operations/VirtualMachineOperation.cs new file mode 100644 index 00000000..590d4823 --- /dev/null +++ b/SafeExamBrowser.Runtime/Operations/VirtualMachineOperation.cs @@ -0,0 +1,41 @@ +/* + * 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.Core.Contracts.OperationModel; +using SafeExamBrowser.Core.Contracts.OperationModel.Events; + +namespace SafeExamBrowser.Runtime.Operations +{ + internal class VirtualMachineOperation : SessionOperation + { + //private IVirtualMachineDetector detector; + + public VirtualMachineOperation(/*IVirtualMachineDetector detector, */SessionContext context) : base(context) + { + //this.detector = detector; + } + + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged { add { } remove { } } + + public override OperationResult Perform() + { + return OperationResult.Success; + } + + public override OperationResult Repeat() + { + return OperationResult.Success; + } + + public override OperationResult Revert() + { + return OperationResult.Success; + } + } +} diff --git a/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj b/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj index 989c75ab..cd96b8a2 100644 --- a/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj +++ b/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj @@ -106,6 +106,7 @@ + Code diff --git a/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs b/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs index 97b2d716..d155c512 100644 --- a/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs +++ b/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs @@ -9,7 +9,7 @@ namespace SafeExamBrowser.SystemComponents.Contracts { /// - /// Provides access to information about the operating system. + /// Provides access to information about the computer system. /// public interface ISystemInfo { @@ -18,6 +18,21 @@ namespace SafeExamBrowser.SystemComponents.Contracts /// bool HasBattery { get; } + /// + /// The manufacturer name of the computer system. + /// + string Manufacturer { get; } + + /// + /// The model name of the computer system. + /// + string Model { get; } + + /// + /// The machine name of the computer system. + /// + string Name { get; } + /// /// Reveals the version of the currently running operating system. /// diff --git a/SafeExamBrowser.SystemComponents/SystemInfo.cs b/SafeExamBrowser.SystemComponents/SystemInfo.cs index 77a9f1d1..0277854b 100644 --- a/SafeExamBrowser.SystemComponents/SystemInfo.cs +++ b/SafeExamBrowser.SystemComponents/SystemInfo.cs @@ -6,25 +6,33 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; +using System.Linq; +using System.Management; using System.Windows.Forms; using SafeExamBrowser.SystemComponents.Contracts; using BatteryChargeStatus = System.Windows.Forms.BatteryChargeStatus; +using OperatingSystem = SafeExamBrowser.SystemComponents.Contracts.OperatingSystem; namespace SafeExamBrowser.SystemComponents { public class SystemInfo : ISystemInfo { public bool HasBattery { get; private set; } + public string Manufacturer { get; private set; } + public string Model { get; private set; } + public string Name { get; private set; } public OperatingSystem OperatingSystem { get; private set; } public string OperatingSystemInfo { - get { return $"{OperatingSystemName()}, {System.Environment.OSVersion.VersionString} ({Architecture()})"; } + get { return $"{OperatingSystemName()}, {Environment.OSVersion.VersionString} ({Architecture()})"; } } public SystemInfo() { InitializeBattery(); + InitializeMachineInfo(); InitializeOperatingSystem(); } @@ -35,13 +43,25 @@ namespace SafeExamBrowser.SystemComponents HasBattery = !status.HasFlag(BatteryChargeStatus.NoSystemBattery) && !status.HasFlag(BatteryChargeStatus.Unknown); } + private void InitializeMachineInfo() + { + using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem")) + using (var results = searcher.Get()) + using (var system = results.Cast().FirstOrDefault()) + { + Manufacturer = Convert.ToString(system["Manufacturer"]); + Model = string.Join(" ", Convert.ToString(system["SystemFamily"]), Convert.ToString(system["Model"])); + Name = Convert.ToString(system["Name"]); + } + } + private void InitializeOperatingSystem() { // 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; + var major = Environment.OSVersion.Version.Major; + var minor = Environment.OSVersion.Version.Minor; // See https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions for mapping source... if (major == 6) @@ -84,7 +104,7 @@ namespace SafeExamBrowser.SystemComponents private string Architecture() { - return System.Environment.Is64BitOperatingSystem ? "x64" : "x86"; + return Environment.Is64BitOperatingSystem ? "x64" : "x86"; } } }