public static IEnumerable <BasePortableService> GetPortableImplementors() { var typeLocator = new TypeLocator(); var types = typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(BasePortableService).IsAssignableFrom(t)); foreach (var type in types) { BasePortableService portable2Type; try { portable2Type = Activator.CreateInstance(type) as BasePortableService; } catch (Exception e) { Logger.ErrorFormat("Unable to create {0} while calling BasePortableService implementors. {1}", type.FullName, e.Message); portable2Type = null; } if (portable2Type != null) { yield return(portable2Type); } } }
private static IEnumerable <IModuleInjectionFilter> GetFilters() { var typeLocator = new TypeLocator(); IEnumerable <Type> types = typeLocator.GetAllMatchingTypes(IsValidModuleInjectionFilter); foreach (Type filterType in types) { IModuleInjectionFilter filter; try { filter = Activator.CreateInstance(filterType) as IModuleInjectionFilter; } catch (Exception e) { Logger.ErrorFormat("Unable to create {0} while registering module injection filters. {1}", filterType.FullName, e.Message); filter = null; } if (filter != null) { yield return(filter); } } }
public void LocatesAllServiceRouteMappers() { var assemblyLocator = new Mock <IAssemblyLocator>(); //including the assembly with object ensures that the assignabliity is done correctly var assembliesToReflect = new IAssembly[2]; assembliesToReflect[0] = new AssemblyWrapper(GetType().Assembly); assembliesToReflect[1] = new AssemblyWrapper(typeof(Object).Assembly); assemblyLocator.Setup(x => x.Assemblies).Returns(assembliesToReflect); var locator = new TypeLocator { AssemblyLocator = assemblyLocator.Object }; List <Type> types = locator.GetAllMatchingTypes(ServicesRoutingManager.IsValidServiceRouteMapper).ToList(); //if new ServiceRouteMapper classes are added to the assembly they willl likely need to be added here CollectionAssert.AreEquivalent( new[] { typeof(FakeServiceRouteMapper), typeof(ReflectedServiceRouteMappers.EmbeddedServiceRouteMapper), typeof(ExceptionOnCreateInstanceServiceRouteMapper), typeof(ExceptionOnRegisterServiceRouteMapper) }, types); }
private static SortedDictionary <string, Command> GetCommandsInternal() { var commands = new SortedDictionary <string, Command>(); var typeLocator = new TypeLocator(); var allCommandTypes = typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(IConsoleCommand).IsAssignableFrom(t)); foreach (var cmd in allCommandTypes) { var attr = cmd.GetCustomAttributes(typeof(ConsoleCommandAttribute), false).FirstOrDefault() ?? new ConsoleCommandAttribute(CreateCommandFromClass(cmd.Name), Constants.GeneralCategory, $"Prompt_{cmd.Name}_Description"); var assemblyName = cmd.Assembly.GetName(); var version = assemblyName.Version.ToString(); var commandAttribute = (ConsoleCommandAttribute)attr; var key = commandAttribute.Name.ToUpper(); var localResourceFile = ((IConsoleCommand)Activator.CreateInstance(cmd))?.LocalResourceFile; commands.Add(key, new Command { Category = LocalizeString(commandAttribute.Category, localResourceFile), Description = LocalizeString(commandAttribute.Description, localResourceFile), Key = key, Name = commandAttribute.Name, Version = version, CommandType = cmd }); } return(commands); }
private static void CleanupDatabaseIfDirty(IExportImportRepository repository) { var exportDto = repository.GetSingleItem <ExportDto>(); var isDirty = exportDto.IsDirty; exportDto.IsDirty = true; repository.UpdateSingleItem(exportDto); if (!isDirty) { return; } var typeLocator = new TypeLocator(); var types = typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(BasicExportImportDto).IsAssignableFrom(t)); foreach (var type in from type in types let typeName = type.Name where !CleanUpIgnoredClasses.Contains(typeName) select type) { try { repository.CleanUpLocal(type.Name); } catch (Exception e) { Logger.ErrorFormat( "Unable to clear {0} while calling CleanupDatabaseIfDirty. Error: {1}", type.Name, e.Message); } } }
private void LoadProcessors() { _processors = new Dictionary <string, IConnector>(); var typeLocator = new TypeLocator(); var types = typeLocator.GetAllMatchingTypes(IsValidFilter); foreach (var type in types) { try { var processor = Activator.CreateInstance(type) as IConnector; if (processor != null && !string.IsNullOrEmpty(processor.Name) && !_processors.ContainsKey(processor.Name)) { _processors.Add(processor.Name, processor); } } catch (Exception e) { Logger.ErrorFormat("Unable to create {0} while registering connections.{1}", type.FullName, e.Message); } } }
public void LocatesAllServiceRouteMappers() { var assemblyLocator = new Mock<IAssemblyLocator>(); //including the assembly with object ensures that the assignabliity is done correctly var assembliesToReflect = new IAssembly[2]; assembliesToReflect[0] = new AssemblyWrapper(GetType().Assembly); assembliesToReflect[1] = new AssemblyWrapper(typeof (Object).Assembly); assemblyLocator.Setup(x => x.Assemblies).Returns(assembliesToReflect); var locator = new TypeLocator {AssemblyLocator = assemblyLocator.Object}; List<Type> types = locator.GetAllMatchingTypes(ServicesRoutingManager.IsValidServiceRouteMapper).ToList(); //if new ServiceRouteMapper classes are added to the assembly they willl likely need to be added here CollectionAssert.AreEquivalent( new[] { typeof (FakeServiceRouteMapper), typeof (ReflectedServiceRouteMappers.EmbeddedServiceRouteMapper), typeof (ExceptionOnCreateInstanceServiceRouteMapper), typeof (ExceptionOnRegisterServiceRouteMapper) }, types); }
private static IEnumerable <Type> GetAllMenuItemTypes() { var typeLocator = new TypeLocator(); return(typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && typeof(BaseMenuItem).IsAssignableFrom(t))); }
private static IEnumerable <Type> GetAllApiControllers() { var typeLocator = new TypeLocator(); return(typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(PersonaBarApiController).IsAssignableFrom(t))); }
private static IEnumerable <Type> GetAllEventTypes <T>() where T : class { var typeLocator = new TypeLocator(); return(typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(T).IsAssignableFrom(t) && (IgnoreVersionMatchCheck(t) || VersionMatched(t)))); }
public void LocateAllMatchingTypes() { var assembly = new Mock<IAssembly>(); assembly.Setup(x => x.GetTypes()).Returns(new[] {typeof(TypeLocatorTests), typeof(ServiceRoutingManagerTests)}); var assemblyLocator = new Mock<IAssemblyLocator>(); assemblyLocator.Setup(x => x.Assemblies).Returns(new[] {assembly.Object}); var typeLocator = new TypeLocator {AssemblyLocator = assemblyLocator.Object}; var types = typeLocator.GetAllMatchingTypes(x => true).ToList(); CollectionAssert.AreEquivalent(new[]{typeof(TypeLocatorTests), typeof(ServiceRoutingManagerTests)}, types); assembly.Verify(x => x.GetTypes(), Times.Once()); assemblyLocator.Verify(x => x.Assemblies, Times.Once()); }
public void LocateAllMatchingTypes() { var assembly = new Mock <IAssembly>(); assembly.Setup(x => x.GetTypes()).Returns(new[] { typeof(TypeLocatorTests), typeof(ServiceRoutingManagerTests) }); var assemblyLocator = new Mock <IAssemblyLocator>(); assemblyLocator.Setup(x => x.Assemblies).Returns(new[] { assembly.Object }); var typeLocator = new TypeLocator { AssemblyLocator = assemblyLocator.Object }; var types = typeLocator.GetAllMatchingTypes(x => true).ToList(); CollectionAssert.AreEquivalent(new[] { typeof(TypeLocatorTests), typeof(ServiceRoutingManagerTests) }, types); assembly.Verify(x => x.GetTypes(), Times.Once()); assemblyLocator.Verify(x => x.Assemblies, Times.Once()); }
private static IEnumerable <IDataSource> GetDataSources() { var typeLocator = new TypeLocator(); IEnumerable <Type> types = typeLocator.GetAllMatchingTypes(IsValidDataSourceProvider); foreach (Type filterType in types) { IDataSource filter; try { filter = Activator.CreateInstance(filterType) as IDataSource; } catch (Exception e) { Logger.ErrorFormat("Unable to create {0} while GetDatasources. {1}", filterType.FullName, e.Message); filter = null; } if (filter != null) { yield return(filter); } } }
private static IEnumerable <IFileIndexer> GetFileIndexers() { var typeLocator = new TypeLocator(); IEnumerable <Type> types = typeLocator.GetAllMatchingTypes(IsValidDataSourceProvider); foreach (Type filterType in types) { IFileIndexer filter; try { filter = Activator.CreateInstance(filterType) as IFileIndexer; } catch (Exception e) { App.Services.Logger.Error($"Unable to create {filterType.FullName} while GetFileIndexers. {e.Message}"); filter = null; } if (filter != null) { yield return(filter); } } }
private SortedDictionary <string, Command> GetCommandsInternal() { var res = new SortedDictionary <string, Command>(); var typeLocator = new TypeLocator(); var types = typeLocator.GetAllMatchingTypes( t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(ConsoleCommandBase).IsAssignableFrom(t)); foreach (var cmd in types) { var attr = cmd.GetCustomAttributes(typeof(ConsoleCommandAttribute), false).FirstOrDefault(); if (attr != null) { var assy = cmd.Assembly.GetName(); var version = assy.Version.ToString(); var assyName = assy.Name; var cmdAttr = (ConsoleCommandAttribute)attr; var key = cmdAttr.NameSpace == "" ? cmdAttr.Name.ToUpper() : string.Format("{0}.{1}", cmdAttr.NameSpace.ToUpper(), cmdAttr.Name.ToUpper()); res.Add(key, new Command() { AssemblyName = assyName, CommandAttribute = cmdAttr, CommandType = cmd, Description = cmdAttr.Description, Key = key, Name = cmdAttr.Name, NameSpace = cmdAttr.NameSpace, Version = version }); } } return(res); }
private IEnumerable <Type> GetAllServiceRouteMapperTypes() { return(TypeLocator.GetAllMatchingTypes(IsValidServiceRouteMapper)); }