static void Main(string[] args) { _dependencyUtility = new DependencyUtility(); HandleCacheHandler(); HandleConfiguration(); HandleSecurityContainer(); HandleLogger(); HandleSignalRouter(); HandleExtensionLoader(); //Set port and host from configuration int port = Convert.ToInt32(_config.Get(PORT_CONFIGURATION_KEY)); IPAddress host = IPAddress.Parse(_config.Get(HOST_CONFIGURATION_KEY)); //Hook into our closing event AssemblyLoadContext.Default.Unloading += UnloadServer; Console.CancelKeyPress += (sender, eventArgs) => UnloadServer(AssemblyLoadContext.Default); //Start the server using (_server = new WebSocketServer("MyServerName", host, port, _dependencyUtility, 4)) { _logger.Info($"Listening on {host}:{port}"); //Initialize the router _router.Initialize(); //Disable Nagle's Algorithm _server.NoDelay = true; //Start listening and blocking the main thread _server.Run(); } }
/// <summary> /// Loads the extensions. /// </summary> /// <exception cref="ConfigurationItemMissingException"></exception> /// <exception cref="InvalidExtensionException"> /// </exception> public void LoadExtensions() { IConfigurationSection[] extensionConfigurations = _config.GetSections(EXTENSION_CONFIGURATION_KEY).ToArray(); if (extensionConfigurations.Length == 0) { return; } HashSet <IExtension> extensions = new HashSet <IExtension>(); foreach (IConfigurationSection extensionConfiguration in extensionConfigurations) { string name = extensionConfiguration.Key; string path = _config.Get($"{extensionConfiguration.Path}:path"); _logger.Debug($"Loading extension: {name}"); if (string.IsNullOrEmpty(path) || !File.Exists(path)) { throw new ConfigurationItemMissingException($"{extensionConfiguration.Path}:path"); } LoadAssembly(path, name); } foreach (var extensionType in _extensionTypes) { IExtension extension = Activator.CreateInstance(extensionType.Key.AsType(), extensionType.Value, _dependencyUtility) as IExtension; if (extension == null) { throw new InvalidExtensionException(extensionType.Value, extensionType.Key.AssemblyQualifiedName); } extension.Initialize(); extensions.Add(extension); } Extensions = extensions; }
/// <summary> /// Creates the connection resources. /// </summary> private void CreateConnectionResources() { //Create exchange connection _routerExchangeGenerator = new RabbitEventedExchangeGenerator(_dependencyUtility, new ParameterList { ["Host"] = _config.Get(CONFIGURATION_KEY_ROUTER_EXCHANGE_HOST), ["VirtualHost"] = _config.Get(CONFIGURATION_KEY_ROUTER_EXCHANGE_VHOST), ["Username"] = _config.Get(CONFIGURATION_KEY_ROUTER_EXCHANGE_USERNAME), ["Password"] = _config.Get(CONFIGURATION_KEY_ROUTER_EXCHANGE_PASSWORD) }); //Create queue connection _routerQueueGenerator = new RabbitEventedQueueGenerator(_dependencyUtility, new ParameterList { ["Host"] = _config.Get(CONFIGURATION_KEY_ROUTER_QUEUE_HOST), ["VirtualHost"] = _config.Get(CONFIGURATION_KEY_ROUTER_QUEUE_VHOST), ["Username"] = _config.Get(CONFIGURATION_KEY_ROUTER_QUEUE_USERNAME), ["Password"] = _config.Get(CONFIGURATION_KEY_ROUTER_QUEUE_PASSWORD) }); }