Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow custom UIs by exporting the IoC kernel to other DLLs

  • Loading branch information...
commit 623905c3981d6cafe630b1e3af2b057fe0f9af9b 1 parent dea6615
@paulcbetts paulcbetts authored
View
1  src/Shimmer.Client/Shimmer.Client.csproj
@@ -126,6 +126,7 @@
<Compile Include="WiXUi\EngineWrapper.cs" />
<Compile Include="IAppSetup.cs" />
<Compile Include="IUpdateManager.cs" />
+ <Compile Include="WiXUi\IWiXCustomUi.cs" />
<Compile Include="WiXUi\IWiXEvents.cs" />
<Compile Include="WiXUi\IWixUiBootstrapper.cs" />
<Compile Include="PostInstallInfo.cs" />
View
13 src/Shimmer.Client/WiXUi/IWiXCustomUi.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TinyIoC;
+
+namespace Shimmer.Client.WiXUi
+{
+ interface IWiXCustomUi
+ {
+ void RegisterTypes(TinyIoCContainer kernel);
+ }
+}
View
8 src/Shimmer.Tests/Shimmer.Tests.csproj
@@ -157,8 +157,14 @@
<Project>{3D17D46A-A411-4922-B932-9EBE2AAE0ED7}</Project>
<Name>Shimmer.Core</Name>
</ProjectReference>
+ <ProjectReference Include="..\Shimmer.WiXUi\Shimmer.WiXUi.csproj">
+ <Project>{5f84c302-8216-47e0-b822-b83b65d81309}</Project>
+ <Name>Shimmer.WiXUi</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="WiXUi\" />
</ItemGroup>
- <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
22 src/Shimmer.Tests/TestHelpers/IntegrationTestHelper.cs
@@ -6,6 +6,7 @@
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
+using System.Threading;
using Shimmer.Core;
using ReactiveUI;
@@ -35,5 +36,26 @@ public static bool SkipTestOnXPAndVista()
int osVersion = Environment.OSVersion.Version.Major*100 + Environment.OSVersion.Version.Minor;
return (osVersion < 601);
}
+
+ public static void RunBlockAsSTA(Action block)
+ {
+ Exception ex = null;
+ var t = new Thread(() => {
+ try {
+ block();
+ } catch (Exception e) {
+ ex = e;
+ }
+ });
+
+ t.SetApartmentState(ApartmentState.STA);
+ t.Start();
+ t.Join();
+
+ if (ex != null) {
+ // NB: If we don't do this, the test silently passes
+ throw new Exception("", ex);
+ }
+ }
}
}
View
1  src/Shimmer.WiXUi/App.cs
@@ -7,6 +7,7 @@
using Microsoft.Tools.WindowsInstallerXml.Bootstrapper;
using ReactiveUI.Routing;
using Shimmer.Client;
+using Shimmer.Client.WiXUi;
using Shimmer.Core;
using Shimmer.WiXUi.ViewModels;
using Shimmer.WiXUi.Views;
View
37 src/Shimmer.WiXUi/ViewModels/WixUiBootstrapper.cs
@@ -1,6 +1,11 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Reflection;
using ReactiveUI;
using ReactiveUI.Routing;
using Shimmer.Client;
+using Shimmer.Client.WiXUi;
using TinyIoC;
namespace Shimmer.WiXUi.ViewModels
@@ -21,11 +26,43 @@ public WixUiBootstrapper(IWiXEvents wixEvents, TinyIoCContainer testKernel = nul
Router = router ?? new RoutingState();
WiXEvents = wixEvents;
+ registerExtensionDlls(Kernel);
+
RxApp.ConfigureServiceLocator(
(type, contract) => Kernel.Resolve(type, contract),
(type, contract) => Kernel.ResolveAll(type));
}
+ void registerExtensionDlls(TinyIoCContainer kernel)
+ {
+ var di = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
+
+ var extensions = di.GetFiles("*.dll")
+ .Where(x => x.FullName != Assembly.GetExecutingAssembly().Location)
+ .SelectMany(x => {
+ try {
+ return new[] {Assembly.LoadFile(x.FullName)};
+ } catch (Exception ex) {
+ this.Log().WarnException("Couldn't load " + x.Name, ex);
+ return Enumerable.Empty<Assembly>();
+ }
+ })
+ .SelectMany(x => x.GetModules()).SelectMany(x => x.GetTypes())
+ .Where(x => typeof(IWiXCustomUi).IsAssignableFrom(x) && !x.IsAbstract)
+ .SelectMany(x => {
+ try {
+ return new[] {(IWiXCustomUi) Activator.CreateInstance(x)};
+ } catch (Exception ex) {
+ this.Log().WarnException("Couldn't create instance: " + x.FullName, ex);
+ return Enumerable.Empty<IWiXCustomUi>();
+ }
+ });
+
+ foreach (var extension in extensions) {
+ extension.RegisterTypes(kernel);
+ }
+ }
+
TinyIoCContainer createDefaultKernel()
{
var ret = new TinyIoCContainer();

0 comments on commit 623905c

Please sign in to comment.
Something went wrong with that request. Please try again.