internal SortedList <string, Type> internal_GetInMemoryServices(Type addInType, CompositeLoaderFilter filter) { SortedList <string, Type> validAddIns = new SortedList <string, Type>(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { Type[] types = assembly.GetTypes(); foreach (Type type in types) { switch (filter) { case CompositeLoaderFilter.ImplementsInterface: if (type.GetInterface(addInType.Name) != null) { validAddIns.Add(type.FullName, type); } break; case CompositeLoaderFilter.InheritsBaseClass: if (type.BaseType == addInType) { validAddIns.Add(type.FullName, type); } break; } } } catch (FileLoadException flex) { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0} Wms.Common.CompositeManager: {1}", DateTime.Now.ToString(), flex.Message)); } catch (Exception ex) { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0} Wms.Common.CompositeManager: {1}", DateTime.Now.ToString(), ex.Message)); } } return(validAddIns); }
public int GetComponents(string addInPath, string addInSearchPattern, SearchOption addInSearchOption, Type addInType, CompositeLoaderFilter filter) { AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; setup.PrivateBinPath = addInPath; setup.ShadowCopyFiles = "false"; AppDomain m_appDomain = AppDomain.CreateDomain("MyNamespace.CompositeManager", null, setup); CompositeManager m_remoteLoader = (CompositeManager)m_appDomain.CreateInstanceFromAndUnwrap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MyAssembly.dll"), "MyNamespace.CompositeManager"); m_addIns = m_remoteLoader.RemoteGetServices(addInPath, addInSearchPattern, addInSearchOption, addInType, filter); #if DEBUG DebugLoadedAssemblies(); #endif AppDomain.Unload(m_appDomain); return(m_addIns.Count); }
public int GetComponents(string addInPath, string addInSearchPattern, Type addInType, CompositeLoaderFilter filter) { return(GetComponents(addInPath, addInSearchPattern, SearchOption.TopDirectoryOnly, addInType, filter)); }
public int GetComponents(string addInSearchPattern, Type addInType, CompositeLoaderFilter filter) { string addInPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); return(GetComponents(addInPath, addInSearchPattern, SearchOption.TopDirectoryOnly, addInType, filter)); }
public int GetInMemoryComponents(Type addInType, CompositeLoaderFilter filter) { m_addIns = internal_GetInMemoryServices(addInType, filter); return(m_addIns.Count); }
internal SortedList <string, Type> RemoteGetServices(string addInPath, string addInSearchPattern, SearchOption addInSearchOption, Type addInType, CompositeLoaderFilter filter) { string[] files = Directory.GetFiles(addInPath, addInSearchPattern, addInSearchOption); SortedList <string, Type> validAddIns = new SortedList <string, Type>(); if (files.Length > 0) { foreach (string file in files) { if (String.CompareOrdinal(addInPath, file) != 0) { try { Assembly assembly = Assembly.LoadFrom(file); Type[] types = assembly.GetTypes(); foreach (Type type in types) { switch (filter) { case CompositeLoaderFilter.ImplementsInterface: if (type.GetInterface(addInType.Name) != null) { validAddIns.Add(type.FullName, type); } break; case CompositeLoaderFilter.InheritsBaseClass: if (type.BaseType == addInType) { validAddIns.Add(type.FullName, type); } break; } } } catch (FileLoadException flex) { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0} MyNamespace.CompositeManager: {1}", DateTime.Now.ToString(), flex.Message)); } catch (Exception ex) { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0} MyNamespace.CompositeManager: {1}", DateTime.Now.ToString(), ex.Message)); } } } } #if DEBUG DebugLoadedAssemblies(); #endif return(validAddIns); }