Example #1
0
        public async Task InitFromParameters(StartupParameters parameters)
        {
            this.startupParams = parameters;
            if (parameters.BuildMode)
            {
                Uri        passthroughUri = new Uri(parameters.PassthroughRoute);
                ServerData newServer      = new ServerData
                {
                    Name = parameters.ServerName,
                    Path = parameters.ServerRoute,
                    PassthroughOnFail = true,
                    PassthroughPath   = new Microsoft.AspNetCore.Builder.ProxyOptions {
                        Host = passthroughUri.Host,
                        Port = passthroughUri.IsDefaultPort ? "80" : passthroughUri.Port.ToString()
                    },
                    BuildMode = true
                };
                TryAddServer(newServer);
                await ActivateServer(newServer.Name, newServer);

                return;
            }

            if (parameters.ServerFiles.Any())
            {
                foreach (string serverFile in parameters.ServerFiles)
                {
                    var server = ServerData.LoadFrom(serverFile);
                    if (TryAddServer(server))
                    {
                        await ActivateServer(server.Name, server);
                    }
                }
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            StartupParameters parameters;
            var manager = BuildWebHost();

            manager.Start();
            try
            {
                parameters = new StartupParameters(args);
                MockServerBroker.Instance.InitFromParameters(parameters).Wait();
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("-server-files|sf <server-file-path>.json -buildmode|b -server-route|s <server route> -fallback-route|f <passthrough route> -server-name|n <server name> -server-path|p <server file path>");
            }


            while (!MockServerBroker.Instance.ShutdownRequired)
            {
                Thread.Sleep(1000);
            }

            manager.StopAsync().Wait();
        }