Christian Specht avatar Christian Specht committed b73574f Draft

load launcher model from WPF launcher's App.config

Comments (0)

Files changed (7)

src/MissileSharp.Launcher/App.config

+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+  <appSettings>
+    <add key="LauncherName" value="MissileSharp.ThunderMissileLauncher"/>
+  </appSettings>
+</configuration>

src/MissileSharp.Launcher/MissileSharp.Launcher.csproj

       <HintPath>..\packages\Autofac.2.6.3.862\lib\NET40\Autofac.Configuration.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.configuration" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
+    <None Include="App.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>

src/MissileSharp.Launcher/Services/ConfigService.cs

-using System.IO;
+using System.Configuration;
+using System.IO;
 using MissileSharp.Launcher.Properties;
 
 namespace MissileSharp.Launcher.Services
 
             return configFileLines;
         }
+
+        public string LauncherName
+        {
+            get { return ConfigurationManager.AppSettings["LauncherName"]; }
+        }
+
+        public string LauncherAssembly
+        {
+            get { return ConfigurationManager.AppSettings["LauncherAssembly"]; }
+        }
     }
 }

src/MissileSharp.Launcher/Services/IConfigService.cs

     public interface IConfigService
     {
         string[] GetConfig();
+        string LauncherName { get; }
+        string LauncherAssembly { get; }
     }
 }

src/MissileSharp.Launcher/ViewModels/MainWindowViewModel.cs

             this.configService = configService;
             this.messageService = messageService;
 
-            var launcher = LauncherModelFactory.GetLauncher("MissileSharp.ThunderMissileLauncher");
+            var launcher = LauncherModelFactory.GetLauncher(configService.LauncherName, configService.LauncherAssembly);
 
             this.model = new CommandCenter(launcher);
 

src/MissileSharp.Tests/Launcher/MainWindowViewModelTests.cs

         {
             var config = new StubConfigService();
             config.SetConfig(new string[] { "[name2]", "up,5", "[name1]", "up,5" });
+            config.LauncherAssembly = "MissileSharp.Tests.dll";
+            config.LauncherName = "MissileSharp.Tests.StubMissileLauncher";
 
             var messageService = new StubMessageService();
 
         public void Constructor_ConfigIsEmpty_ThrowsException()
         {
             var config = new StubConfigService();
-            Assert.Throws<NullReferenceException>(() => new MainWindowViewModel(config, new StubMessageService()));
+            Assert.Throws<ArgumentNullException>(() => new MainWindowViewModel(config, new StubMessageService()));
         }
     }
 }

src/MissileSharp.Tests/Launcher/StubConfigService.cs

         {
             return this.config;
         }
+
+        public string LauncherName { get; set; }
+
+        public string LauncherAssembly { get; set; }
     }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.