Except Assemblies

Oct 15, 2010 at 9:49 AM

Hello,

 

i wrote a littele patch to have the ability NOT to load a list of assemblies.

We had some problem with Interop Assemblies, that threw exceptions.

 

Index: MEFedMVVMDemo/MEFedMVVM.WPF/ViewModelLocator/DefaultComposer.cs
===================================================================
--- MEFedMVVMDemo/MEFedMVVM.WPF/ViewModelLocator/DefaultComposer.cs	(revision 62190)
+++ MEFedMVVMDemo/MEFedMVVM.WPF/ViewModelLocator/DefaultComposer.cs	(working copy)
@@ -1,11 +1,15 @@
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
 using System.Linq;
 using System.ComponentModel.Composition.Hosting;
 using System.Diagnostics;
 using System.IO;
 using System.ComponentModel.Composition.Primitives;
 using System.Reflection;
+using System.Windows;
+using System.Xml.Linq;
 
 namespace MEFedMVVM.ViewModelLocator
 {
@@ -119,8 +123,30 @@
             var catalog = new AggregateCatalog();
             var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
             var extensionPath = String.Format(@"{0}\Extensions\", baseDirectory);
-            catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory));
-            catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));
+
+            try
+            {
+                // try block new to handle assemblies not to use
+                XDocument xmlExcludes = XDocument.Load(String.Format(@"{0}\mefassemblies.xml", baseDirectory));
+                var excludeQuery = from excludes in xmlExcludes.Descendants("excludelist").Descendants("exclude")
+                                   select String.Concat(baseDirectory, excludes.Value).ToUpper();
+                DirectoryCatalog directoryCatalog = new DirectoryCatalog(baseDirectory, "*.dll");
+                var files = directoryCatalog.LoadedFiles.AsQueryable().Except(excludeQuery.AsQueryable());
+
+                foreach (string file in files)
+                {
+                    Assembly assembly = Assembly.LoadFrom(file);
+                    AssemblyCatalog ac = new AssemblyCatalog(assembly);
+                    catalog.Catalogs.Add(ac);
+                }
+                catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));
+            }
+            catch (Exception exception)
+            {
+                catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory));
+                catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));
+            }
+
             if (Directory.Exists(extensionPath))
                 catalog.Catalogs.Add(new DirectoryCatalog(extensionPath));
             return catalog;

Coordinator
Oct 15, 2010 at 10:09 AM
You can add your own IComposer to do this... 

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/
Microsoft MVP for Client App



On Fri, Oct 15, 2010 at 10:49 AM, heilmannseder <notifications@codeplex.com> wrote:

From: heilmannseder

Hello,

 

i wrote a littele patch to have the ability NOT to load a list of assemblies.

We had some problem with Interop Assemblies, that threw exceptions.

 

Index: MEFedMVVMDemo/MEFedMVVM.WPF/ViewModelLocator/DefaultComposer.cs
===================================================================
--- MEFedMVVMDemo/MEFedMVVM.WPF/ViewModelLocator/DefaultComposer.cs	(revision 62190)
+++ MEFedMVVMDemo/MEFedMVVM.WPF/ViewModelLocator/DefaultComposer.cs	(working copy)
@@ -1,11 +1,15 @@
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
 using System.Linq;
 using System.ComponentModel.Composition.Hosting;
 using System.Diagnostics;
 using System.IO;
 using System.ComponentModel.Composition.Primitives;
 using System.Reflection;
+using System.Windows;
+using System.Xml.Linq;
 
 namespace MEFedMVVM.ViewModelLocator
 {
@@ -119,8 +123,30 @@
             var catalog = new AggregateCatalog();
             var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
             var extensionPath = String.Format(@"{0}\Extensions\", baseDirectory);
-            catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory));
-            catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));
+
+            try
+            {
+                // try block new to handle assemblies not to use
+                XDocument xmlExcludes = XDocument.Load(String.Format(@"{0}\mefassemblies.xml", baseDirectory));
+                var excludeQuery = from excludes in xmlExcludes.Descendants("excludelist").Descendants("exclude")
+                                   select String.Concat(baseDirectory, excludes.Value).ToUpper();
+                DirectoryCatalog directoryCatalog = new DirectoryCatalog(baseDirectory, "*.dll");
+                var files = directoryCatalog.LoadedFiles.AsQueryable().Except(excludeQuery.AsQueryable());
+
+                foreach (string file in files)
+                {
+                    Assembly assembly = Assembly.LoadFrom(file);
+                    AssemblyCatalog ac = new AssemblyCatalog(assembly);
+                    catalog.Catalogs.Add(ac);
+                }
+                catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));
+            }
+            catch (Exception exception)
+            {
+                catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory));
+                catalog.Catalogs.Add(new DirectoryCatalog(baseDirectory, "*.exe"));
+            }
+
             if (Directory.Exists(extensionPath))
                 catalog.Catalogs.Add(new DirectoryCatalog(extensionPath));
             return catalog;

Read the full discussion online.

To add a post to this discussion, reply to this email (MEFedMVVM@discussions.codeplex.com)

To start a new discussion for this project, email MEFedMVVM@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Oct 15, 2010 at 11:50 AM

Thanks for this suggestion.

i am trying to redesign....