static void Main() { // Initialize the user interface. System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance { ApplicationType = ApplicationType.Server, ConfigSectionName = "Opc.Ua.GlobalDiscoveryServer" }; try { // load the application configuration. application.LoadApplicationConfiguration(false).Wait(); // check the application certificate. application.CheckApplicationInstanceCertificate(false, 0).Wait(); // start the server. var server = new GlobalDiscoverySampleServer( new SqlApplicationsDatabase(), new CertificateGroup()); application.Start(server).Wait(); // run the application interactively. System.Windows.Forms.Application.Run(new ServerForm(server, application.ApplicationConfiguration)); } catch (Exception e) { ExceptionDlg.Show(application.ApplicationName, e); } }
public void Run() { try { exitCode = ExitCode.ErrorServerNotStarted; ConsoleGlobalDiscoveryServer().Wait(); Console.WriteLine("Server started. Press Ctrl-C to exit..."); exitCode = ExitCode.ErrorServerRunning; } catch (Exception ex) { Utils.Trace("ServiceResultException:" + ex.Message); Console.WriteLine("Exception: {0}", ex.Message); exitCode = ExitCode.ErrorServerException; return; } ManualResetEvent quitEvent = new ManualResetEvent(false); try { Console.CancelKeyPress += (sender, eArgs) => { quitEvent.Set(); eArgs.Cancel = true; }; } catch { } // wait for timeout or Ctrl-C quitEvent.WaitOne(); if (server != null) { Console.WriteLine("Server stopped. Waiting for exit..."); using (GlobalDiscoverySampleServer _server = server) { // Stop status thread server = null; status.Wait(); // Stop server and dispose _server.Stop(); } } exitCode = ExitCode.Ok; }