SEBWIN-312: Implemented auto-start mechanism for applications.
This commit is contained in:
		
							parent
							
								
									5ccbd2aae4
								
							
						
					
					
						commit
						d7a4dc8782
					
				
					 6 changed files with 50 additions and 5 deletions
				
			
		|  | @ -15,6 +15,11 @@ namespace SafeExamBrowser.Applications.Contracts | ||||||
| 	/// </summary> | 	/// </summary> | ||||||
| 	public class ApplicationInfo | 	public class ApplicationInfo | ||||||
| 	{ | 	{ | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// Indicates whether the application should be automatically started. | ||||||
|  | 		/// </summary> | ||||||
|  | 		public bool AutoStart { get; set; } | ||||||
|  | 
 | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
| 		/// The name of the application. | 		/// The name of the application. | ||||||
| 		/// </summary> | 		/// </summary> | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ namespace SafeExamBrowser.Applications | ||||||
| 		private IApplication BuildApplication(string executablePath, WhitelistApplication settings) | 		private IApplication BuildApplication(string executablePath, WhitelistApplication settings) | ||||||
| 		{ | 		{ | ||||||
| 			var icon = new IconResource { Type = IconResourceType.Embedded, Uri = new Uri(executablePath) }; | 			var icon = new IconResource { Type = IconResourceType.Embedded, Uri = new Uri(executablePath) }; | ||||||
| 			var info = new ApplicationInfo { Icon = icon, Name = settings.DisplayName, Tooltip = settings.Description ?? settings.DisplayName }; | 			var info = new ApplicationInfo { AutoStart = settings.AutoStart, Icon = icon, Name = settings.DisplayName, Tooltip = settings.Description ?? settings.DisplayName }; | ||||||
| 			var application = new ExternalApplication(executablePath, info, logger.CloneFor(settings.DisplayName), processFactory); | 			var application = new ExternalApplication(executablePath, info, logger.CloneFor(settings.DisplayName), processFactory); | ||||||
| 
 | 
 | ||||||
| 			return application; | 			return application; | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ | ||||||
| using System; | using System; | ||||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||||
| using Moq; | using Moq; | ||||||
|  | using SafeExamBrowser.Applications.Contracts; | ||||||
| using SafeExamBrowser.Browser.Contracts; | using SafeExamBrowser.Browser.Contracts; | ||||||
| using SafeExamBrowser.Browser.Contracts.Events; | using SafeExamBrowser.Browser.Contracts.Events; | ||||||
| using SafeExamBrowser.Communication.Contracts.Data; | using SafeExamBrowser.Communication.Contracts.Data; | ||||||
|  | @ -624,6 +625,28 @@ namespace SafeExamBrowser.Client.UnitTests | ||||||
| 			taskbar.Verify(t => t.Show(), Times.Never); | 			taskbar.Verify(t => t.Show(), Times.Never); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		[TestMethod] | ||||||
|  | 		public void Startup_MustAutoStartApplications() | ||||||
|  | 		{ | ||||||
|  | 			var application1 = new Mock<IApplication>(); | ||||||
|  | 			var application2 = new Mock<IApplication>(); | ||||||
|  | 			var application3 = new Mock<IApplication>(); | ||||||
|  | 
 | ||||||
|  | 			application1.SetupGet(a => a.Info).Returns(new ApplicationInfo { AutoStart = true }); | ||||||
|  | 			application2.SetupGet(a => a.Info).Returns(new ApplicationInfo { AutoStart = false }); | ||||||
|  | 			application3.SetupGet(a => a.Info).Returns(new ApplicationInfo { AutoStart = true }); | ||||||
|  | 			context.Applications.Add(application1.Object); | ||||||
|  | 			context.Applications.Add(application2.Object); | ||||||
|  | 			context.Applications.Add(application3.Object); | ||||||
|  | 			operationSequence.Setup(o => o.TryPerform()).Returns(OperationResult.Success); | ||||||
|  | 
 | ||||||
|  | 			sut.TryStart(); | ||||||
|  | 
 | ||||||
|  | 			application1.Verify(a => a.Start(), Times.Once); | ||||||
|  | 			application2.Verify(a => a.Start(), Times.Never); | ||||||
|  | 			application3.Verify(a => a.Start(), Times.Once); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void TerminationActivator_MustCorrectlyInitiateShutdown() | 		public void TerminationActivator_MustCorrectlyInitiateShutdown() | ||||||
| 		{ | 		{ | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ using Moq; | ||||||
| using SafeExamBrowser.Browser.Contracts; | using SafeExamBrowser.Browser.Contracts; | ||||||
| using SafeExamBrowser.Client.Operations; | using SafeExamBrowser.Client.Operations; | ||||||
| using SafeExamBrowser.Logging.Contracts; | using SafeExamBrowser.Logging.Contracts; | ||||||
|  | using SafeExamBrowser.Settings; | ||||||
| using SafeExamBrowser.UserInterface.Contracts; | using SafeExamBrowser.UserInterface.Contracts; | ||||||
| using SafeExamBrowser.UserInterface.Contracts.Shell; | using SafeExamBrowser.UserInterface.Contracts.Shell; | ||||||
| 
 | 
 | ||||||
|  | @ -23,6 +24,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations | ||||||
| 		private Mock<IBrowserApplication> browser; | 		private Mock<IBrowserApplication> browser; | ||||||
| 		private ClientContext context; | 		private ClientContext context; | ||||||
| 		private Mock<ILogger> logger; | 		private Mock<ILogger> logger; | ||||||
|  | 		private AppSettings settings; | ||||||
| 		private Mock<ITaskbar> taskbar; | 		private Mock<ITaskbar> taskbar; | ||||||
| 		private Mock<ITaskView> taskView; | 		private Mock<ITaskView> taskView; | ||||||
| 		private Mock<IUserInterfaceFactory> uiFactory; | 		private Mock<IUserInterfaceFactory> uiFactory; | ||||||
|  | @ -36,11 +38,13 @@ namespace SafeExamBrowser.Client.UnitTests.Operations | ||||||
| 			browser = new Mock<IBrowserApplication>(); | 			browser = new Mock<IBrowserApplication>(); | ||||||
| 			context = new ClientContext(); | 			context = new ClientContext(); | ||||||
| 			logger = new Mock<ILogger>(); | 			logger = new Mock<ILogger>(); | ||||||
|  | 			settings = new AppSettings(); | ||||||
| 			taskbar = new Mock<ITaskbar>(); | 			taskbar = new Mock<ITaskbar>(); | ||||||
| 			taskView = new Mock<ITaskView>(); | 			taskView = new Mock<ITaskView>(); | ||||||
| 			uiFactory = new Mock<IUserInterfaceFactory>(); | 			uiFactory = new Mock<IUserInterfaceFactory>(); | ||||||
| 
 | 
 | ||||||
| 			context.Browser = browser.Object; | 			context.Browser = browser.Object; | ||||||
|  | 			context.Settings = settings; | ||||||
| 
 | 
 | ||||||
| 			sut = new BrowserOperation(actionCenter.Object, context, logger.Object, taskbar.Object, taskView.Object, uiFactory.Object); | 			sut = new BrowserOperation(actionCenter.Object, context, logger.Object, taskbar.Object, taskView.Object, uiFactory.Object); | ||||||
| 		} | 		} | ||||||
|  | @ -48,6 +52,9 @@ namespace SafeExamBrowser.Client.UnitTests.Operations | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustPeformCorrectly() | 		public void MustPeformCorrectly() | ||||||
| 		{ | 		{ | ||||||
|  | 			settings.ActionCenter.EnableActionCenter = true; | ||||||
|  | 			settings.Taskbar.EnableTaskbar = true; | ||||||
|  | 
 | ||||||
| 			sut.Perform(); | 			sut.Perform(); | ||||||
| 
 | 
 | ||||||
| 			browser.Verify(c => c.Initialize(), Times.Once); | 			browser.Verify(c => c.Initialize(), Times.Once); | ||||||
|  | @ -66,6 +73,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations | ||||||
| 		public void TODO() | 		public void TODO() | ||||||
| 		{ | 		{ | ||||||
| 			// TODO: Test initialization of task view! | 			// TODO: Test initialization of task view! | ||||||
|  | 			Assert.Fail("TODO"); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -172,9 +172,9 @@ namespace SafeExamBrowser.Client.UnitTests.Operations | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void Perform_MustInitializeTaskView() | 		public void TODO() | ||||||
| 		{ | 		{ | ||||||
| 			// Only start activator if ALT+TAB enabled! | 			// TODO: Only start activator if ALT+TAB enabled! -> Perform_MustInitializeTaskView | ||||||
| 			Assert.Fail("TODO"); | 			Assert.Fail("TODO"); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -105,7 +105,7 @@ namespace SafeExamBrowser.Client | ||||||
| 			{ | 			{ | ||||||
| 				RegisterEvents(); | 				RegisterEvents(); | ||||||
| 				ShowShell(); | 				ShowShell(); | ||||||
| 				StartBrowser(); | 				AutoStartApplications(); | ||||||
| 
 | 
 | ||||||
| 				var communication = runtime.InformClientReady(); | 				var communication = runtime.InformClientReady(); | ||||||
| 
 | 
 | ||||||
|  | @ -239,10 +239,19 @@ namespace SafeExamBrowser.Client | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		private void StartBrowser() | 		private void AutoStartApplications() | ||||||
| 		{ | 		{ | ||||||
| 			logger.Info("Starting browser application..."); | 			logger.Info("Starting browser application..."); | ||||||
| 			Browser.Start(); | 			Browser.Start(); | ||||||
|  | 
 | ||||||
|  | 			foreach (var application in context.Applications) | ||||||
|  | 			{ | ||||||
|  | 				if (application.Info.AutoStart) | ||||||
|  | 				{ | ||||||
|  | 					logger.Info($"Auto-starting '{application.Info.Name}'..."); | ||||||
|  | 					application.Start(); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		private void ApplicationMonitor_ExplorerStarted() | 		private void ApplicationMonitor_ExplorerStarted() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 dbuechel
						dbuechel