static void Main() { // Initialize the user interface. Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationType = ApplicationType.Server; application.ConfigSectionName = "Quickstarts.ReferenceServer"; try { // load the application configuration. ApplicationConfiguration config = application.LoadApplicationConfiguration(false).Result; LoggerConfiguration loggerConfiguration = new LoggerConfiguration(); #if DEBUG loggerConfiguration.WriteTo.Debug(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning); #endif SerilogTraceLogger.Create(loggerConfiguration, config); // check the application certificate. bool certOk = application.CheckApplicationInstanceCertificate(false, 0).Result; if (!certOk) { throw new Exception("Application instance certificate invalid!"); } // Create server, add additional node managers var server = new ReferenceServer(); Quickstarts.Servers.Utils.AddDefaultNodeManagers(server); // start the server. application.Start(server).Wait(); // check whether the invalid certificates dialog should be displayed. bool showCertificateValidationDialog = false; ReferenceServerConfiguration refServerconfiguration = application.ApplicationConfiguration.ParseExtension <ReferenceServerConfiguration>(); if (refServerconfiguration != null) { showCertificateValidationDialog = refServerconfiguration.ShowCertificateValidationDialog; } // run the application interactively. Application.Run(new ServerForm(application, showCertificateValidationDialog)); } catch (Exception e) { ExceptionDlg.Show(application.ApplicationName, e); } }
private async Task StartConsoleReferenceServerAsync() { ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); CertificatePasswordProvider PasswordProvider = new CertificatePasswordProvider(Password); ApplicationInstance application = new ApplicationInstance { ApplicationName = "Quickstart Reference Server", ApplicationType = ApplicationType.Server, ConfigSectionName = Utils.IsRunningOnMono() ? "Quickstarts.MonoReferenceServer" : "Quickstarts.ReferenceServer", CertificatePasswordProvider = PasswordProvider }; // load the application configuration. ApplicationConfiguration config = await application.LoadApplicationConfiguration(false).ConfigureAwait(false); var loggerConfiguration = new Serilog.LoggerConfiguration(); if (LogConsole) { loggerConfiguration.WriteTo.Console(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning); } #if DEBUG else { loggerConfiguration.WriteTo.Debug(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning); } #endif SerilogTraceLogger.Create(loggerConfiguration, config); // check the application certificate. bool haveAppCertificate = await application.CheckApplicationInstanceCertificate( false, CertificateFactory.DefaultKeySize, CertificateFactory.DefaultLifeTime).ConfigureAwait(false); if (!haveAppCertificate) { throw new Exception("Application instance certificate invalid!"); } if (!config.SecurityConfiguration.AutoAcceptUntrustedCertificates) { config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation); } // start the server. m_server = new ReferenceServer(); await application.Start(m_server).ConfigureAwait(false); // print endpoint info var endpoints = application.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct(); foreach (var endpoint in endpoints) { Console.WriteLine(endpoint); } // start the status thread m_status = Task.Run(new Action(StatusThreadAsync)); // print notification on session events m_server.CurrentInstance.SessionManager.SessionActivated += EventStatus; m_server.CurrentInstance.SessionManager.SessionClosing += EventStatus; m_server.CurrentInstance.SessionManager.SessionCreated += EventStatus; }