示例#1
0
        public void Start()
        {
            try
            {
                Task t = ConsoleAggregationServer();
                t.Wait();
                Console.WriteLine("Server started. Press any key to exit...");
            }
            catch (Exception ex)
            {
                Utils.Trace("ServiceResultException:" + ex.Message);
                Console.WriteLine("Exception: {0}", ex.Message);
            }

            try
            {
                Console.ReadKey(true);
            }
            catch
            {
                // wait forever if there is no console
                Thread.Sleep(Timeout.Infinite);
            }

            if (server != null)
            {
                Console.WriteLine("Server stopped. Waiting for exit...");

                server.Dispose();
                server = null;

                status.Wait();
            }
        }
示例#2
0
        private async Task StatusThread()
        {
            AggregationServer serverStatus = server;

            while (serverStatus != null)
            {
                if (DateTime.UtcNow - lastEventTime > TimeSpan.FromMilliseconds(6000))
                {
                    IList <Session> sessions = serverStatus.CurrentInstance.SessionManager.GetSessions();
                    for (int ii = 0; ii < sessions.Count; ii++)
                    {
                        Session session = sessions[ii];
                        PrintSessionStatus(session, "-Status-", true);
                    }
                    lastEventTime = DateTime.UtcNow;
                }
                await Task.Delay(1000).ConfigureAwait(false);

                serverStatus = server;
            }
        }
示例#3
0
        private async Task ConsoleAggregationServer()
        {
            ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
            ApplicationInstance application = new ApplicationInstance();

            application.ApplicationName   = "Quickstart Aggregation Server";
            application.ApplicationType   = ApplicationType.Server;
            application.ConfigSectionName = "Quickstarts.AggregationServer";

            // load the application configuration.
            ApplicationConfiguration config = await application.LoadApplicationConfiguration(false);

            // check the application certificate.
            bool haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, CertificateFactory.defaultKeySize);

            if (!haveAppCertificate)
            {
                throw new Exception("Application instance certificate invalid!");
            }

            if (!config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            }

            // start the server.
            server = new AggregationServer();
            await application.Start(server);

            // start the status thread
            status = Task.Run(new Action(StatusThread));

            // print notification on session events
            server.CurrentInstance.SessionManager.SessionActivated += EventStatus;
            server.CurrentInstance.SessionManager.SessionClosing   += EventStatus;
            server.CurrentInstance.SessionManager.SessionCreated   += EventStatus;
        }
        private async Task ConsoleAggregationServer()
        {
            ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
            ApplicationInstance application = new ApplicationInstance();

            application.ApplicationName   = "Quickstart Aggregation Server";
            application.ApplicationType   = ApplicationType.Server;
            application.ConfigSectionName = "Quickstarts.AggregationServer";

            // load the application configuration.
            ApplicationConfiguration config = await application.LoadApplicationConfiguration(false);

            // check the application certificate.
            bool haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, CertificateFactory.defaultKeySize);

            if (!haveAppCertificate)
            {
                throw new Exception("Application instance certificate invalid!");
            }

            if (!config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            }

            // start the server.
            server = new AggregationServer();
            await application.Start(server);

            // print reverse connect info
            Console.WriteLine("Reverse Connect Clients:");
            var reverseConnections = server.GetReverseConnections();

            foreach (var connection in reverseConnections)
            {
                Console.WriteLine(connection.Key);
            }

            // print endpoint info
            Console.WriteLine("Server Endpoints:");
            var endpoints = server.GetEndpoints().Select(e => e.EndpointUrl).Distinct();

            foreach (var endpoint in endpoints)
            {
                Console.WriteLine(endpoint);
            }

            // print the reverse connect host
            if (config.ClientConfiguration?.ReverseConnect != null)
            {
                var reverseConnect = config.ClientConfiguration.ReverseConnect;
                Console.WriteLine("Reverse Connect Server Endpoints:");
                foreach (var endpoint in reverseConnect.ClientEndpoints)
                {
                    Console.WriteLine(endpoint.EndpointUrl);
                }
            }

            // start the status thread
            status = Task.Run(new Action(StatusThread));

            // print notification on session events
            server.CurrentInstance.SessionManager.SessionActivated += EventStatus;
            server.CurrentInstance.SessionManager.SessionClosing   += EventStatus;
            server.CurrentInstance.SessionManager.SessionCreated   += EventStatus;
        }