Exemplo n.º 1
0
        private static void Main()
        {
            Trace.Listeners.Add(new System.Diagnostics.ConsoleTraceListener());
            StonehengeLogger.DefaultLevel = LogLevel.Trace;
            var logger = LoggerFactory.CreateLogger("stonehenge");

            Console.WriteLine(@"");
            Console.WriteLine(@"Stonehenge 3 sample");
            Console.WriteLine(@"");
            logger.LogInformation("Vue.SampleCore started");

            // select hosting options
            var options = new StonehengeHostOptions
            {
                Title = "VueSample",

                ServerPushMode      = ServerPushModes.LongPolling,
                PollIntervalSec     = 10,
                SessionIdMode       = SessionIdModes.Automatic,
                HandleWindowResized = true
                                      // SslCertificatePath = Path.Combine(StonehengeApplication.BaseDirectory, "stonehenge.pfx"),
                                      // SslCertificatePassword = "******"
            };

            // Select client framework
            Console.WriteLine(@"Using client framework vue");
            var vue    = new VueResourceProvider(logger);
            var loader = StonehengeResourceLoader.CreateDefaultLoader(logger, vue);

            loader.Services.AddService(typeof(ILogger), logger);

            // Select hosting technology
            var hosting = "kestrel";

            if (Environment.CommandLine.Contains("/simple"))
            {
                hosting = "simple";
            }
            switch (hosting)
            {
            case "kestrel":
                Console.WriteLine(@"Using Kestrel hosting");
                _server = new KestrelHost(loader, options);
                break;

            case "simple":
                Console.WriteLine(@"Using simple http hosting");
                _server = new SimpleHttpHost(loader, options);
                break;
            }

            Console.WriteLine(@"Starting server");
            var terminate = new AutoResetEvent(false);

            Console.CancelKeyPress += (_, _) => { terminate.Set(); };

            var host = Environment.CommandLine.Contains("/localhost") ? "localhost" : "*";

            if (_server.Start(host, 32000))
            {
                Console.WriteLine(@"Server reachable on: " + _server.BaseUrl);

                if (Environment.CommandLine.Contains("/window"))
                {
                    using var wnd = new HostWindow(_server.BaseUrl, options.Title);
                    if (!wnd.Open())
                    {
                        logger.LogError("Failed to open main window");
                        terminate.Set();
                    }
                }
                else
                {
                    terminate.WaitOne();
                }
                Console.WriteLine(@"Server terminated.");
            }
            else
            {
                Console.WriteLine(@"Failed to start server on: " + _server.BaseUrl);
            }

#pragma warning disable 0162
            // ReSharper disable once HeuristicUnreachableCode
            _server.Terminate();

            Console.WriteLine(@"Exit sample app");
            Environment.Exit(0);
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     Server.Terminate();
 }
Exemplo n.º 3
0
        private static void Main()
        {
            var consoleListener = new ConsoleTraceListener();

            Trace.Listeners.Add(consoleListener);

            Console.WriteLine(@"");
            Console.WriteLine(@"Stonehenge 3 sample");
            Console.WriteLine(@"");

            // Select client framework
            Console.WriteLine(@"Using client framework aurelia");
            var loader  = StonehengeResourceLoader.CreateDefaultLoader(new AureliaResourceProvider());
            var options = new StonehengeHostOptions
            {
                Title         = "Sample",
                StartPage     = "start",
                SessionIdMode = SessionIdModes.CookiesOnly
            };

            // Select hosting technology
            var hosting = "kestrel";

            if (Environment.CommandLine.Contains("/Simple"))
            {
                hosting = "simple";
            }

            switch (hosting)
            {
            case "kestrel":
                Console.WriteLine(@"Using Kestrel hosting");
                _server = new KestrelHost(loader, options);
                break;

            case "simple":
                Console.WriteLine(@"Using simple http hosting");
                _server = new SimpleHttpHost(loader, options);
                break;
            }

            Console.WriteLine(@"Starting server");
            var terminate = new AutoResetEvent(false);

            Console.CancelKeyPress += (sender, eventArgs) => { terminate.Set(); };

            var host = Environment.CommandLine.Contains("/localhost") ? "localhost" : "*";

            if (_server.Start(host, 32000))
            {
                Console.WriteLine(@"Started server on: " + _server.BaseUrl);

                var wnd = new HostWindow(_server);
                if (!wnd.Open())
                {
                    Trace.TraceError("Failed to open main window.");
                    terminate.WaitOne();
                }

                Console.WriteLine(@"Server terminated.");
            }
            else
            {
                Console.WriteLine(@"Failed to start server on: " + _server.BaseUrl);
            }

#pragma warning disable 0162
            // ReSharper disable once HeuristicUnreachableCode
            _server.Terminate();

            Environment.Exit(0);
        }
Exemplo n.º 4
0
 public void Dispose()
 {
     _server?.Terminate();
 }