Permalink
Browse files

Implement MEF composition interfaces

  • Loading branch information...
1 parent 91a63a0 commit 625f7a61855879b097225eff1eec008f29de54b5 @paulcbetts committed Dec 28, 2009
Showing with 116 additions and 2 deletions.
  1. +3 −0 InstallQueuer.csproj
  2. +34 −0 Interfaces.cs
  3. +1 −1 MainWindow.xaml
  4. +24 −1 MainWindow.xaml.cs
  5. +54 −0 PackageInstallers.cs
View
3 InstallQueuer.csproj
@@ -37,6 +37,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
@@ -63,12 +64,14 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Interfaces.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
+ <Compile Include="PackageInstallers.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
View
34 Interfaces.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace InstallQueuer
+{
+ [Flags]
+ public enum PackageInstallerSupportedFeatures {
+ SupportsUnattendInstall = 0x01,
+ ValidFlagMask = 0x01,
+ }
+
+ public interface IPackageInstallerFactory {
+ int AffinityForPackage(string FilePath);
+ IPackageInstaller CreateInstallerForPackage(string FilePath);
+ }
+
+ public interface IPackageInstaller {
+ string FilePath { get; }
+ PackageInstallerSupportedFeatures SupportedFeatures { get; }
+ }
+}
+
+// vim: ts=4:sts=4:sw=4:et
View
2 MainWindow.xaml
@@ -1,4 +1,4 @@
-<Window x:Class="InstallQueuer.MainWindow"
+<Window x:Class="InstallQueuer.Ui.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="350" Height="525">
View
25 MainWindow.xaml.cs
@@ -11,19 +11,42 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using System.ComponentModel.Composition;
+using System.ComponentModel;
+using System.Collections.ObjectModel;
-namespace InstallQueuer
+namespace InstallQueuer.Ui
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
+ [ImportMany]
+ public IEnumerable<IPackageInstallerFactory> PackageInstallers { get; set; }
+
+ readonly ObservableCollection<InstallableItem> InstallQueue = new ObservableCollection<InstallableItem>();
+
public MainWindow()
{
InitializeComponent();
}
}
+
+ class InstallableItem : INotifyPropertyChanged
+ {
+ //
+ // INotifyPropertyChanged stuff
+ //
+
+ private void NotifyPropertyChanged(String property)
+ {
+ if (PropertyChanged != null) {
+ PropertyChanged(this, new PropertyChangedEventArgs(property));
+ }
+ }
+ public event PropertyChangedEventHandler PropertyChanged;
+ }
}
// vim: ts=4:sts=4:sw=4:et
View
54 PackageInstallers.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.ComponentModel.Composition;
+
+namespace InstallQueuer
+{
+ public abstract class BasePackageInstaller : IPackageInstaller
+ {
+ public BasePackageInstaller(string FilePath) { _FilePath = FilePath; }
+
+ private readonly string _FilePath;
+ public string FilePath { get { return _FilePath; } }
+
+ public abstract PackageInstallerSupportedFeatures SupportedFeatures {get;}
+ }
+
+ [Export(typeof(IPackageInstallerFactory))]
+ public class MsiPackageInstallerFactory : IPackageInstallerFactory
+ {
+ public int AffinityForPackage(string FilePath)
+ {
+ return (FilePath.ToLowerInvariant().EndsWith(".msi") ? 1 : 0);
+ }
+
+ public IPackageInstaller CreateInstallerForPackage(string FilePath)
+ {
+ return new MsiPackageInstaller(FilePath);
+ }
+ }
+
+ public class MsiPackageInstaller : BasePackageInstaller
+ {
+ public MsiPackageInstaller(string FilePath) : base(FilePath) {}
+
+ public override PackageInstallerSupportedFeatures SupportedFeatures {
+ get {
+ return PackageInstallerSupportedFeatures.SupportsUnattendInstall;
+ }
+ }
+ }
+}
+
+// vim: ts=4:sts=4:sw=4:et

0 comments on commit 625f7a6

Please sign in to comment.