Exemple #1
0
        /// <summary>
        /// Starts the server connection.
        /// </summary>
        public void Start()
        {
            _embeddedFileHandlers.Clear();
            foreach (var staticFile in StaticFiles)
            {
                if (staticFile.ResourcePrefix == null)
                {
                    var handler = new EmbeddedFileHandler(staticFile.PathPrefix, staticFile.ResourceLocatorType);
                    _embeddedFileHandlers.Add(handler);
                }
                else
                {
                    var handler = new EmbeddedFileHandler(staticFile.PathPrefix, staticFile.ResourceAssembly, staticFile.ResourcePrefix);
                    _embeddedFileHandlers.Add(handler);
                }
            }

            _listener.Start();

            _disconnectHandler.Initialize();
            _webApiServer = new WebApiServer(_webAppConfiguration);

            // create a signalr routing host -- its dependency resolver uses the web api resolver
            _routingHost = new RoutingHost(new SignalrDependencyResolver(_webAppConfiguration.DependencyResolver));
            _routingHost.MapHubs();
            ReceiveLoop();
        }
Exemple #2
0
 public SmartHost(RoutingHost routingHost)
 {
     this.routingHost = routingHost;
     if (!routingHost.Domain.Equals(RoutingHostName.Empty))
     {
         this.hostName = new Hostname(routingHost.Domain);
     }
 }
        internal static void SmartHostsSetter(object value, IPropertyBag propertyBag)
        {
            if (value == null)
            {
                propertyBag[TenantOutboundConnectorSchema.SmartHostsString] = string.Empty;
                return;
            }
            MultiValuedProperty <SmartHost> routingHostWrappers = (MultiValuedProperty <SmartHost>)value;
            string value2 = RoutingHost.ConvertRoutingHostsToString <SmartHost>(routingHostWrappers, (SmartHost host) => host.InnerRoutingHost);

            propertyBag[TenantOutboundConnectorSchema.SmartHostsString] = value2;
        }
        internal static object SmartHostsGetter(IPropertyBag propertyBag)
        {
            string text = (string)propertyBag[TenantOutboundConnectorSchema.SmartHostsString];

            if (string.IsNullOrEmpty(text))
            {
                return(new MultiValuedProperty <SmartHost>(false, TenantOutboundConnectorSchema.SmartHosts, new SmartHost[0]));
            }
            List <SmartHost> routingHostsFromString = RoutingHost.GetRoutingHostsFromString <SmartHost>(text, (RoutingHost routingHost) => new SmartHost(routingHost));

            return(new MultiValuedProperty <SmartHost>(false, TenantOutboundConnectorSchema.SmartHosts, routingHostsFromString));
        }
Exemple #5
0
        public static bool TryParse(string address, out SmartHost smarthost)
        {
            smarthost = null;
            RoutingHost routingHost;

            if (RoutingHost.TryParse(address, out routingHost))
            {
                smarthost = new SmartHost(routingHost);
                return(true);
            }
            return(false);
        }
        public void AddRouter()
        {
            routerPort = ServiceManagerConfig.GetNextAvailablePort();

            _routerHost = new WebHostBuilder()
                          .UseKestrel()
                          .UseLoggerFactory(new LoggerFactory().AddConsole())
                          .UseUrls($"http://*:{routerPort}")
                          .ConfigureServices(x =>
            {
                x.AddCondenserWithBuilder()
                .WithRoutesBuiltCallback(SignalWhenAllRegistered)
                .Build();
            })
                          .Configure(app =>
            {
                _host = app.ApplicationServices.GetService <RoutingHost>();


                app.UseCondenser();
            })
                          .Build();
        }
Exemple #7
0
        /// <summary>
        /// Starts the server connection.
        /// </summary>
        public void Start()
        {
            _embeddedFileHandlers.Clear();
            foreach (var staticFile in StaticFiles)
            {
                if (staticFile.ResourcePrefix == null)
                {
                    var handler = new EmbeddedFileHandler(staticFile.PathPrefix, staticFile.ResourceLocatorType);
                    _embeddedFileHandlers.Add(handler);
                }
                else
                {
                    var handler = new EmbeddedFileHandler(staticFile.PathPrefix, staticFile.ResourceAssembly, staticFile.ResourcePrefix);
                    _embeddedFileHandlers.Add(handler);
                }
            }

            _listener.Start();

            _disconnectHandler.Initialize();
            _webApiServer = new WebApiServer(_webAppConfiguration);

            // create a signalr routing host -- its dependency resolver uses the web api resolver
            _routingHost = new RoutingHost(new SignalrDependencyResolver(_webAppConfiguration.DependencyResolver));
            _routingHost.MapHubs();
            ReceiveLoop();
        }
        public async Task CanRegisterRoutes()
        {
            var wait = new AsyncManualResetEvent <bool>();

            var agentAddress = "localhost";
            var config       = new CondenserConfiguration
            {
                AgentAddress = agentAddress,
                AgentPort    = 8500
            };
            var router = BuildRouter();

            var host = new RoutingHost(router, config, null, RoutingData.BuildDefault(),
                                       new IService[0], () => new Service(new CurrentState(), null))
            {
                OnRouteBuilt = servers =>
                {
                    {
                        if (servers.ContainsKey("Google"))
                        {
                            wait.Set(true);
                        }
                    }
                }
            };

            var google = new ServiceManager("Google",
                                            agentAddress, 8500)
            {
                ServiceAddress = "www.google.com",
                ServicePort    = 80
            };

            await google.AddApiUrl("/search")
            .RegisterServiceAsync();

            await wait.WaitAsync();

            var routeContext = await RouteRequest(router, "/search");

            Assert.Equal(200, routeContext.HttpContext.Response.StatusCode);

            google = new ServiceManager("Google", "Google2", agentAddress, 8500)
            {
                ServiceAddress = "www.google.com",
                ServicePort    = 80
            };

            wait.Reset();

            await google.AddApiUrl("/gmail")
            .AddHttpHealthCheck("/gmail", 10)
            .RegisterServiceAsync();

            await wait.WaitAsync();

            routeContext = await RouteRequest(router, "/gmail");

            Assert.Equal(200, routeContext.HttpContext.Response.StatusCode);

            routeContext = await RouteRequest(router, "/search");

            Assert.Null(routeContext);
        }