public void Context() { results = new AssemblyScanner() .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { var assemblyScanner = new AssemblyScanner(AssemblyLocation.CurrentDirectory) { IncludeAppDomainAssemblies = false }; assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly); results = assemblyScanner .GetScannableAssemblies(); }
public void Context() { var assemblyScanner = new AssemblyScanner(AssemblyLocation.CurrentDirectory) { AssembliesToInclude = new List<string> { "NServiceBus.Core.Tests.dll" } }; results = assemblyScanner .GetScannableAssemblies(); }
public void Context() { var assemblyScanner = new AssemblyScanner(AssemblyLocation.CurrentDirectory) { IncludeAppDomainAssemblies = false }; assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages <>).Assembly); results = assemblyScanner .GetScannableAssemblies(); }
public void Context() { results = new AssemblyScanner(testDllDirectory) { AssembliesToSkip = new List <string> { "Rebus.dll" } } .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { var someDir = Path.Combine(Path.GetTempPath(), "empty"); Directory.CreateDirectory(someDir); results = new AssemblyScanner(someDir) { IncludeAppDomainAssemblies = true, } .GetScannableAssemblies(); }
public void when_endpoint_type_is_found_via_assembly_scanning_it_should_have_second_priority() { AssemblyScannerResults = new AssemblyScannerResults(); Type endpointTypeInAssembly; Assembly dynamicAssembly = BuildTestEndpointAssembly(out endpointTypeInAssembly); AssemblyScannerResults.Assemblies.Add(dynamicAssembly); Sut = new EndpointTypeDeterminer(AssemblyScannerResults, () => null); RetrievedEndpointType = Sut.GetEndpointConfigurationType().Type; Assert.AreEqual(endpointTypeInAssembly, RetrievedEndpointType); }
public void Context() { var assemblyScanner = new AssemblyScanner(AssemblyLocation.CurrentDirectory) { AssembliesToInclude = new List <string> { "NServiceBus.Core.Tests.dll" } }; results = assemblyScanner .GetScannableAssemblies(); }
/// <summary> /// Initializes a new instance of the <see cref="EndpointTypeDeterminer" /> class. /// </summary> /// <param name="assemblyScannerResults">The assembly scanner results.</param> /// <param name="getEndpointConfigurationTypeFromConfig">A func to retrieve the endpoint configuration type from config.</param> /// <exception cref="System.ArgumentNullException">assemblyScannerResults</exception> public EndpointTypeDeterminer(AssemblyScannerResults assemblyScannerResults, Func <string> getEndpointConfigurationTypeFromConfig) { if (assemblyScannerResults == null) { throw new ArgumentNullException("assemblyScannerResults"); } if (getEndpointConfigurationTypeFromConfig == null) { throw new ArgumentNullException("getEndpointConfigurationTypeFromConfig"); } this.assemblyScannerResults = assemblyScannerResults; this.getEndpointConfigurationTypeFromConfig = getEndpointConfigurationTypeFromConfig; }
/// <summary> /// Initializes a new instance of the <see cref="EndpointTypeDeterminer" /> class. /// </summary> /// <param name="assemblyScannerResults">The assembly scanner results.</param> /// <param name="getEndpointConfigurationTypeFromConfig">A func to retrieve the endpoint configuration type from config.</param> /// <exception cref="System.ArgumentNullException">assemblyScannerResults</exception> public EndpointTypeDeterminer(AssemblyScannerResults assemblyScannerResults, Func<string> getEndpointConfigurationTypeFromConfig) { if (assemblyScannerResults == null) { throw new ArgumentNullException("assemblyScannerResults"); } if (getEndpointConfigurationTypeFromConfig == null) { throw new ArgumentNullException("getEndpointConfigurationTypeFromConfig"); } this.assemblyScannerResults = assemblyScannerResults; this.getEndpointConfigurationTypeFromConfig = getEndpointConfigurationTypeFromConfig; }
public void Context() { var loadThisIntoAppDomain = new SomeHandlerThatEnsuresThatWeKeepReferencingNsbCore(); var someDir = Path.Combine(Path.GetTempPath(), "empty"); Directory.CreateDirectory(someDir); results = new AssemblyScanner(someDir) { IncludeAppDomainAssemblies = true, } .GetScannableAssemblies(); }
public void Context() { var assemblyScanner = new AssemblyScanner(testDllDirectory) { IncludeAppDomainAssemblies = false }; assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages <>).Assembly); results = assemblyScanner .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { Directory.CreateDirectory(BaseDirectoryToScan); var dllFilePath = Path.Combine(BaseDirectoryToScan, "NotAProper.exe"); File.WriteAllText(dllFilePath, "This is not a proper EXE"); results = new AssemblyScanner(BaseDirectoryToScan) { IncludeAppDomainAssemblies = true, IncludeExesInScan = false, } .GetScannableAssemblies(); }
public void Context() { Directory.CreateDirectory(baseDirectoryToScan); Directory.CreateDirectory(someSubDirectory); var dllFilePath = Path.Combine(someSubDirectory, "NotAProper.dll"); File.WriteAllText(dllFilePath, "This is not a proper DLL"); results = new AssemblyScanner(baseDirectoryToScan) { IncludeAppDomainAssemblies = true, ScanNestedDirectories = false } .GetScannableAssemblies(); }
public void Context() { var assemblyScanner = new AssemblyScanner(testDllDirectory) { AssembliesToInclude = new List <string> { "NServiceBus.Core.Tests.dll" } }; results = assemblyScanner .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var uri = new UriBuilder(codeBase); var path = Uri.UnescapeDataString(uri.Path); var directoryName = Path.GetDirectoryName(path); var testDllDirectory = Path.Combine(directoryName, "TestDlls"); results = new AssemblyScanner(testDllDirectory) { AssembliesToSkip = new List<string> { "dotNet.dll" } } .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var uri = new UriBuilder(codeBase); var path = Uri.UnescapeDataString(uri.Path); var directoryName = Path.GetDirectoryName(path); var testDllDirectory = Path.Combine(directoryName, "TestDlls"); var assemblyScanner = new AssemblyScanner(testDllDirectory) { IncludeAppDomainAssemblies = false }; assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly); results = assemblyScanner .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var uri = new UriBuilder(codeBase); var path = Uri.UnescapeDataString(uri.Path); var directoryName = Path.GetDirectoryName(path); var testDllDirectory = Path.Combine(directoryName, "TestDlls"); results = new AssemblyScanner(testDllDirectory) { AssembliesToSkip = new List <string> { "dotNet.dll" } } .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
public void Context() { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var uri = new UriBuilder(codeBase); var path = Uri.UnescapeDataString(uri.Path); var directoryName = Path.GetDirectoryName(path); var testDllDirectory = Path.Combine(directoryName, "TestDlls"); var assemblyScanner = new AssemblyScanner(testDllDirectory) { IncludeAppDomainAssemblies = false }; assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages <>).Assembly); results = assemblyScanner .GetScannableAssemblies(); skippedFiles = results.SkippedFiles; }
static void Main(string[] args) { Parser.Args commandLineArguments = Parser.ParseArgs(args); var arguments = new HostArguments(commandLineArguments); if (arguments.Help != null) { DisplayHelpContent(); return; } assemblyScannerResults = AssemblyScanner.GetScannableAssemblies(); var endpointConfigurationType = GetEndpointConfigurationType(arguments); if (endpointConfigurationType == null) { if (arguments.InstallInfrastructure == null) { throw new InvalidOperationException("No endpoint configuration found in scanned assemblies. " + "This usually happens when NServiceBus fails to load your assembly containing IConfigureThisEndpoint." + " Try specifying the type explicitly in the NServiceBus.Host.exe.config using the appsetting key: EndpointConfigurationType, " + "Scanned path: " + AppDomain.CurrentDomain.BaseDirectory); } Console.WriteLine("Running infrastructure installers and exiting (ignoring other command line parameters if exist)."); InstallInfrastructure(); return; } AssertThatEndpointConfigurationTypeHasDefaultConstructor(endpointConfigurationType); string endpointConfigurationFile = GetEndpointConfigurationFile(endpointConfigurationType); var endpointName = GetEndpointName(endpointConfigurationType, arguments); var endpointVersion = GetEndpointVersion(endpointConfigurationType); var serviceName = endpointName; if (arguments.ServiceName != null) { serviceName = arguments.ServiceName.Value; } var displayName = serviceName + "-" + endpointVersion; if (arguments.SideBySide != null) { serviceName += "-" + endpointVersion; displayName += " (SideBySide)"; } //Add the endpoint name so that the new appdomain can get it if (arguments.EndpointName == null) { args = args.Concat(new[] { "/endpointName:" + endpointName }).ToArray(); } //Add the ScannedAssemblies name so that the new appdomain can get it if (arguments.ScannedAssemblies == null) { args = args.Concat(new[] { "/scannedassemblies:" + string.Join(";", assemblyScannerResults.Assemblies.Select(s => s.ToString()).ToArray()) }).ToArray(); } //Add the endpointConfigurationType name so that the new appdomain can get it if (arguments.EndpointConfigurationType == null) { args = args.Concat(new[] { "/endpointConfigurationType:" + endpointConfigurationType.AssemblyQualifiedName }).ToArray(); } AppDomain.CurrentDomain.SetupInformation.AppDomainInitializerArguments = args; if ((commandLineArguments.Install) || (arguments.InstallInfrastructure != null)) { WindowsInstaller.Install(args, endpointConfigurationFile); } if (arguments.InstallInfrastructure != null) { return; } IRunConfiguration cfg = RunnerConfigurator.New(x => { x.ConfigureServiceInIsolation <WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c => { c.ConfigurationFile(endpointConfigurationFile); c.CommandLineArguments(args, () => SetHostServiceLocatorArgs); c.WhenStarted(service => service.Start()); c.WhenStopped(service => service.Stop()); c.CreateServiceLocator(() => new HostServiceLocator()); }); if (arguments.Username != null && arguments.Password != null) { x.RunAs(arguments.Username.Value, arguments.Password.Value); } else { x.RunAsLocalSystem(); } if (arguments.StartManually != null) { x.DoNotStartAutomatically(); } x.SetDisplayName(arguments.DisplayName != null ? arguments.DisplayName.Value : displayName); x.SetServiceName(serviceName); x.SetDescription(arguments.Description != null ? arguments.Description.Value : "NServiceBus Message Endpoint Host Service for " + displayName); var serviceCommandLine = commandLineArguments.CustomArguments.AsCommandLine(); serviceCommandLine += " /serviceName:\"" + serviceName + "\""; serviceCommandLine += " /endpointName:\"" + endpointName + "\""; x.SetServiceCommandLine(serviceCommandLine); if (arguments.DependsOn == null) { x.DependencyOnMsmq(); } else { foreach (var dependency in arguments.DependsOn.Value.Split(',')) { x.DependsOn(dependency); } } }); Runner.Host(cfg, args); }
static void Main(string[] args) { var arguments = new HostArguments(args); if (arguments.Help) { arguments.PrintUsage(); return; } var assemblyScanner = new AssemblyScanner(); //TODO: re-enable when we make message scanning lazy //assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly); //assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IConfigureThisEndpoint).Assembly); //assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(Program).Assembly); assemblyScannerResults = assemblyScanner.GetScannableAssemblies(); var endpointTypeDeterminer = new EndpointTypeDeterminer(assemblyScannerResults, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); var endpointConfigurationType = endpointTypeDeterminer.GetEndpointConfigurationTypeForHostedEndpoint(arguments); var endpointConfigurationFile = endpointConfigurationType.EndpointConfigurationFile; var endpointName = endpointConfigurationType.EndpointName; var serviceName = endpointConfigurationType.ServiceName; var endpointVersion = endpointConfigurationType.EndpointVersion; var displayName = serviceName + "-" + endpointVersion; if (arguments.SideBySide) { serviceName += "-" + endpointVersion; } //Add the endpoint name so that the new appDomain can get it if (arguments.EndpointName == null && !String.IsNullOrEmpty(endpointName)) { args = args.Concat(new[] { String.Format(@"/endpointName={0}", endpointName) }).ToArray(); } //Add the ScannedAssemblies name so that the new appDomain can get it if (arguments.ScannedAssemblies.Count == 0) { args = assemblyScannerResults.Assemblies.Select(s => s.ToString()).Aggregate(args, (current, result) => current.Concat(new[] { String.Format(@"/scannedAssemblies={0}", result) }).ToArray()); } //Add the endpointConfigurationType name so that the new appDomain can get it if (arguments.EndpointConfigurationType == null) { args = args.Concat(new[] { String.Format(@"/endpointConfigurationType={0}", endpointConfigurationType.AssemblyQualifiedName) }).ToArray(); } if (arguments.Install) { WindowsInstaller.Install(args, endpointConfigurationFile); } var cfg = RunnerConfigurator.New(x => { x.ConfigureServiceInIsolation<WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c => { c.ConfigurationFile(endpointConfigurationFile); c.WhenStarted(service => service.Start()); c.WhenStopped(service => service.Stop()); c.CommandLineArguments(args, () => SetHostServiceLocatorArgs); c.CreateServiceLocator(() => new HostServiceLocator()); }); if (arguments.Username != null && arguments.Password != null) { x.RunAs(arguments.Username, arguments.Password); } else { x.RunAsLocalSystem(); } if (arguments.StartManually) { x.DoNotStartAutomatically(); } x.SetDisplayName(arguments.DisplayName ?? displayName); x.SetServiceName(serviceName); x.SetDescription(arguments.Description ?? string.Format("NServiceBus Endpoint Host Service for {0}", displayName)); var serviceCommandLine = new List<string>(); if (!String.IsNullOrEmpty(arguments.EndpointConfigurationType)) { serviceCommandLine.Add(String.Format(@"/endpointConfigurationType:""{0}""", arguments.EndpointConfigurationType)); } if (!String.IsNullOrEmpty(endpointName)) { serviceCommandLine.Add(String.Format(@"/endpointName:""{0}""", endpointName)); } if (!String.IsNullOrEmpty(serviceName)) { serviceCommandLine.Add(String.Format(@"/serviceName:""{0}""", serviceName)); } if (arguments.ScannedAssemblies.Count > 0) { serviceCommandLine.AddRange(arguments.ScannedAssemblies.Select(assembly => String.Format(@"/scannedAssemblies:""{0}""", assembly))); } if (arguments.OtherArgs.Any()) { serviceCommandLine.AddRange(arguments.OtherArgs); } var commandLine = String.Join(" ", serviceCommandLine); x.SetServiceCommandLine(commandLine); if (arguments.DependsOn == null) x.DependencyOnMsmq(); else foreach (var dependency in arguments.DependsOn) x.DependsOn(dependency); }); try { Runner.Host(cfg, args); } catch (StateMachineException exception) { var innerException = exception.InnerException; innerException.PreserveStackTrace(); throw innerException; } }
static void Main(string[] args) { var arguments = new HostArguments(args); if (arguments.Help) { arguments.PrintUsage(); return; } assemblyScannerResults = AssemblyScanner.GetScannableAssemblies(); var endpointTypeDeterminer = new EndpointTypeDeterminer(assemblyScannerResults, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); var endpointConfigurationType = endpointTypeDeterminer.GetEndpointConfigurationTypeForHostedEndpoint(arguments); var endpointConfigurationFile = endpointConfigurationType.EndpointConfigurationFile; var endpointName = endpointConfigurationType.EndpointName; var serviceName = endpointConfigurationType.ServiceName; var endpointVersion = endpointConfigurationType.EndpointVersion; var displayName = serviceName + "-" + endpointVersion; if (arguments.SideBySide) { serviceName += "-" + endpointVersion; } //Add the endpoint name so that the new appdomain can get it if (arguments.EndpointName == null && !String.IsNullOrEmpty(endpointName)) { args = args.Concat(new[] { String.Format(@"/endpointName={0}", endpointName) }).ToArray(); } //Add the ScannedAssemblies name so that the new appdomain can get it if (arguments.ScannedAssemblies.Count == 0) { args = assemblyScannerResults.Assemblies.Select(s => s.ToString()).Aggregate(args, (current, result) => current.Concat(new[] { String.Format(@"/scannedAssemblies={0}", result) }).ToArray()); } //Add the endpointConfigurationType name so that the new appdomain can get it if (arguments.EndpointConfigurationType == null) { args = args.Concat(new[] { String.Format(@"/endpointConfigurationType={0}", endpointConfigurationType.AssemblyQualifiedName) }).ToArray(); } if (arguments.Install) { WindowsInstaller.Install(args, endpointConfigurationFile); } IRunConfiguration cfg = RunnerConfigurator.New(x => { x.ConfigureServiceInIsolation <WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c => { c.ConfigurationFile(endpointConfigurationFile); c.WhenStarted(service => service.Start()); c.WhenStopped(service => service.Stop()); c.CommandLineArguments(args, () => SetHostServiceLocatorArgs); c.CreateServiceLocator(() => new HostServiceLocator()); }); if (arguments.Username != null && arguments.Password != null) { x.RunAs(arguments.Username, arguments.Password); } else { x.RunAsLocalSystem(); } if (arguments.StartManually) { x.DoNotStartAutomatically(); } x.SetDisplayName(arguments.DisplayName ?? displayName); x.SetServiceName(serviceName); x.SetDescription(arguments.Description ?? string.Format("NServiceBus Endpoint Host Service for {0}", displayName)); var serviceCommandLine = new List <string>(); if (!String.IsNullOrEmpty(arguments.EndpointConfigurationType)) { serviceCommandLine.Add(String.Format(@"/endpointConfigurationType:""{0}""", arguments.EndpointConfigurationType)); } if (!String.IsNullOrEmpty(endpointName)) { serviceCommandLine.Add(String.Format(@"/endpointName:""{0}""", endpointName)); } if (!String.IsNullOrEmpty(serviceName)) { serviceCommandLine.Add(String.Format(@"/serviceName:""{0}""", serviceName)); } if (arguments.ScannedAssemblies.Count > 0) { serviceCommandLine.AddRange(arguments.ScannedAssemblies.Select(assembly => String.Format(@"/scannedAssemblies:""{0}""", assembly))); } if (arguments.OtherArgs.Any()) { serviceCommandLine.AddRange(arguments.OtherArgs); } var commandLine = String.Join(" ", serviceCommandLine); x.SetServiceCommandLine(commandLine); if (arguments.DependsOn == null) { x.DependencyOnMsmq(); } else { foreach (var dependency in arguments.DependsOn) { x.DependsOn(dependency); } } }); try { Runner.Host(cfg, args); } catch (StateMachineException exception) { var innerException = exception.InnerException; innerException.PreserveStackTrace(); throw innerException; } }
IEnumerable<Type> ScanAssembliesForEndpoints() { assemblyScannerResults = assemblyScanner.GetScannableAssemblies(); var scannableAssemblies = assemblyScannerResults.Assemblies; return scannableAssemblies.SelectMany(assembly => assembly.GetTypes().Where( t => typeof(IConfigureThisEndpoint).IsAssignableFrom(t) && t != typeof(IConfigureThisEndpoint) && !t.IsAbstract)); }