/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint" />. /// </summary> /// <param name="specifier"></param> /// <param name="args"></param> /// <param name="defaultProfiles"></param> /// <param name="endpointName"></param> /// <param name="scannableAssembliesFullName">Assemblies full name that were scanned.</param> public GenericHost(IConfigureThisEndpoint specifier, string[] args, List <Type> defaultProfiles, string endpointName, IEnumerable <string> scannableAssembliesFullName = null) { this.specifier = specifier; if (String.IsNullOrEmpty(endpointName)) { endpointName = specifier.GetType().Namespace ?? specifier.GetType().Assembly.GetName().Name; } Configure.GetEndpointNameAction = () => endpointName; Configure.DefineEndpointVersionRetriever = () => FileVersionRetriever.GetFileVersion(specifier.GetType()); if (scannableAssembliesFullName == null) { var assemblyScanner = new AssemblyScanner(); assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages <>).Assembly); assembliesToScan = assemblyScanner .GetScannableAssemblies() .Assemblies; } else { assembliesToScan = scannableAssembliesFullName .Select(Assembly.Load) .ToList(); } profileManager = new ProfileManager(assembliesToScan, specifier, args, defaultProfiles); ProfileActivator.ProfileManager = profileManager; configManager = new ConfigManager(assembliesToScan, specifier); wcfManager = new WcfManager(); roleManager = new RoleManager(assembliesToScan); }
/// <summary> /// Checks if the specifier contains a given role and uses it to configure the UnicastBus appropriately. /// </summary> /// <param name="specifier"></param> public void ConfigureBusForEndpoint(IConfigureThisEndpoint specifier) { ConfigUnicastBus config = null; foreach (var role in availableRoles) { var roleType = role.Key; if (!roleType.IsAssignableFrom(specifier.GetType())) { continue; } if (config != null) { throw new InvalidOperationException("Endpoints can only have one role"); } //apply role var roleConfigurer = Activator.CreateInstance(role.Value) as IConfigureRole; config = roleConfigurer.ConfigureRole(specifier); Logger.Info("Role " + roleType + " configured"); foreach (var markerProfile in GetMarkerRoles(specifier.GetType(), roleType)) { Logger.Info("Role " + markerProfile + " is marked."); } } }
public GenericHost(IConfigureThisEndpoint specifier, string[] args, List <Type> defaultProfiles, string endpointName, IEnumerable <string> scannableAssembliesFullName = null) { this.specifier = specifier; if (string.IsNullOrEmpty(endpointName)) { endpointName = specifier.GetType().Namespace ?? specifier.GetType().Assembly.GetName().Name; } endpointNameToUse = endpointName; List <Assembly> assembliesToScan; if (scannableAssembliesFullName == null || !scannableAssembliesFullName.Any()) { var assemblyScanner = new AssemblyScanner(); assembliesToScan = assemblyScanner .GetScannableAssemblies() .Assemblies; } else { assembliesToScan = scannableAssembliesFullName .Select(Assembly.Load) .ToList(); } profileManager = new ProfileManager(assembliesToScan, args, defaultProfiles); }
public GenericHost(IConfigureThisEndpoint specifier, string[] args, List<Type> defaultProfiles, string endpointName, IEnumerable<string> scannableAssembliesFullName = null) { this.specifier = specifier; if (String.IsNullOrEmpty(endpointName)) { endpointName = specifier.GetType().Namespace ?? specifier.GetType().Assembly.GetName().Name; } endpointNameToUse = endpointName; endpointVersionToUse = FileVersionRetriever.GetFileVersion(specifier.GetType()); if (scannableAssembliesFullName == null || !scannableAssembliesFullName.Any()) { var assemblyScanner = new AssemblyScanner(); assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly); assembliesToScan = assemblyScanner .GetScannableAssemblies() .Assemblies; } else { assembliesToScan = scannableAssembliesFullName .Select(Assembly.Load) .ToList(); } profileManager = new ProfileManager(assembliesToScan, args, defaultProfiles); wcfManager = new WcfManager(); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint" />. /// </summary> /// <param name="scannableAssembliesFullName">Assemblies full name that were scanned.</param> /// <param name="specifier"></param> /// <param name="args"></param> /// <param name="defaultProfiles"></param> public GenericHost(IConfigureThisEndpoint specifier, string[] args, List <Type> defaultProfiles, IEnumerable <string> scannableAssembliesFullName = null) { this.specifier = specifier; endpointNameToUse = specifier.GetType().Namespace ?? specifier.GetType().Assembly.GetName().Name; if (scannableAssembliesFullName == null || !scannableAssembliesFullName.Any()) { var assemblyScanner = new AssemblyScanner(); assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages <>).Assembly); assembliesToScan = assemblyScanner .GetScannableAssemblies() .Assemblies; } else { assembliesToScan = scannableAssembliesFullName .Select(Assembly.Load) .ToList(); } args = AddProfilesFromConfiguration(args); profileManager = new ProfileManager(assembliesToScan, args, defaultProfiles); }
/// <summary> /// Accepts the type which will specify the users custom configuration. /// This type should implement <see cref="IConfigureThisEndpoint" />. /// </summary> /// <param name="scannableAssembliesFullName">Assemblies full name that were scanned.</param> /// <param name="specifier"></param> /// <param name="args"></param> /// <param name="defaultProfiles"></param> public GenericHost(IConfigureThisEndpoint specifier, string[] args, List<Type> defaultProfiles, IEnumerable<string> scannableAssembliesFullName = null) { this.specifier = specifier; endpointNameToUse = specifier.GetType().Namespace ?? specifier.GetType().Assembly.GetName().Name; if (scannableAssembliesFullName == null || !scannableAssembliesFullName.Any()) { var assemblyScanner = new AssemblyScanner(); assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly); assembliesToScan = assemblyScanner .GetScannableAssemblies() .Assemblies; } else { assembliesToScan = scannableAssembliesFullName .Select(Assembly.Load) .ToList(); } args = AddProfilesFromConfiguration(args); profileManager = new ProfileManager(assembliesToScan, args, defaultProfiles); }
/// <summary> /// Checks if the specifier contains a given role and uses it to configure the UnicastBus appropriately. /// </summary> /// <param name="specifier"></param> public void ConfigureBusForEndpoint(IConfigureThisEndpoint specifier) { ConfigUnicastBus unicastBusConfig = null; var roleFound = false; foreach (var role in availableRoles) { var roleType = role.Key; bool handlesRole; if (roleType.IsGenericType) { handlesRole = specifier.GetType() .GetInterfaces() .Any( x => x.IsGenericType && x.GetGenericTypeDefinition() == roleType.GetGenericTypeDefinition()); } else { handlesRole = roleType.IsInstanceOfType(specifier); } if (!handlesRole) { continue; } roleFound = true; //apply role var roleConfigurer = Activator.CreateInstance(role.Value) as IConfigureRole; var config = roleConfigurer.ConfigureRole(specifier); if (config != null) { if (unicastBusConfig != null) { throw new InvalidOperationException("Only one role can configure the unicastbus"); } unicastBusConfig = config; } Logger.Info("Role " + roleType + " configured"); foreach (var markerProfile in GetMarkerRoles(specifier.GetType(), roleType)) { Logger.Info("Role " + markerProfile + " is marked."); } } if (!roleFound) { throw new Exception("Did you forget to specify the endpoint role? Please make sure you specify the endpoint role as either 'AsA_Client','AsA_Host','AsA_Publisher', 'AsA_Server' or some other custom 'IRole'."); } }
void SetSlaFromAttribute(EndpointConfiguration configuration, IConfigureThisEndpoint configureThisEndpoint) { var endpointConfigurationType = configureThisEndpoint .GetType(); TimeSpan sla; if (TryGetSlaFromEndpointConfigType(endpointConfigurationType, out sla)) { configuration.GetSettings().Set("EndpointSLA", sla); } }
public ConfigUnicastBus ConfigureRole(IConfigureThisEndpoint specifier) { var transportDefinitionType = specifier.GetType() .GetInterfaces() .SelectMany(i => i.GetGenericArguments()) .Single(t => typeof(TransportDefinition).IsAssignableFrom(t)); Configure.Instance.UseTransport(transportDefinitionType); return(null); }
/// <summary> /// Checks if the specifier contains a given role and uses it to configure the UnicastBus appropriately. /// </summary> /// <param name="specifier"></param> public void ConfigureBusForEndpoint(IConfigureThisEndpoint specifier) { ConfigUnicastBus config = null; foreach (var role in availableRoles) { var roleType = role.Key; if (!roleType.IsAssignableFrom(specifier.GetType())) continue; if (config != null) throw new InvalidOperationException("Endpoints can only have one role"); //apply role var roleConfigurer = Activator.CreateInstance(role.Value) as IConfigureRole; config = roleConfigurer.ConfigureRole(specifier); Logger.Info("Role " + roleType + " configured"); foreach (var markerProfile in GetMarkerRoles(specifier.GetType(), roleType)) Logger.Info("Role " + markerProfile + " is marked."); } }
/// <summary> /// Checks if the specifier contains a given role and uses it to configure the UnicastBus appropriately. /// </summary> public void ConfigureBusForEndpoint(IConfigureThisEndpoint specifier) { ConfigUnicastBus unicastBusConfig = null; var roleFound = false; foreach (var role in availableRoles) { var roleType = role.Key; bool handlesRole; if (roleType.IsGenericType) { handlesRole = specifier.GetType() .GetInterfaces() .Any( x => x.IsGenericType && x.GetGenericTypeDefinition() == roleType.GetGenericTypeDefinition()); } else { handlesRole = roleType.IsInstanceOfType(specifier); } if (!handlesRole) continue; roleFound = true; //apply role var roleConfigurer = Activator.CreateInstance(role.Value) as IConfigureRole; var config = roleConfigurer.ConfigureRole(specifier); if (config != null) { if (unicastBusConfig != null) throw new InvalidOperationException("Only one role can configure the UnicastBus"); unicastBusConfig = config; } Logger.Info("Role " + roleType + " configured"); foreach (var markerProfile in GetMarkerRoles(specifier.GetType(), roleType)) Logger.Info("Role " + markerProfile + " is marked."); } if (!roleFound) { throw new Exception("Did you forget to specify the endpoint role? Please make sure you specify the endpoint role as either 'AsA_Client','AsA_Host','AsA_Publisher', 'AsA_Server' or some other custom 'IRole'."); } }
static bool TryGetTransportDefinitionType(IConfigureThisEndpoint specifier, out Type transportDefinitionType) { var transportType= specifier.GetType() .GetInterfaces() .Where(x => x.IsGenericType) .SingleOrDefault(x => x.GetGenericTypeDefinition() == typeof(UsingTransport<>)); if (transportType != null) { transportDefinitionType = transportType.GetGenericArguments().First(); return true; } transportDefinitionType = null; return false; }
static bool TryGetTransportDefinitionType(IConfigureThisEndpoint specifier, out Type transportDefinitionType) { var transportType = specifier.GetType() .GetInterfaces() .Where(x => x.IsGenericType) .SingleOrDefault(x => x.GetGenericTypeDefinition() == typeof(UsingTransport <>)); if (transportType != null) { transportDefinitionType = transportType.GetGenericArguments().First(); return(true); } transportDefinitionType = null; return(false); }
public GenericHost(IConfigureThisEndpoint specifier) { this.specifier = specifier; endpointNameToUse = specifier.GetType().Namespace ?? specifier.GetType().Assembly.GetName().Name; }