예제 #1
0
        // main entry creates and launches the server
        static void Main(string[] args)
        {
            Console.WriteLine("Andl Thrift Server");
            Logger.Open(0); // no default logging
            var options = OptionParser.Create(_options, Help);

            if (!options.Parse(args))
            {
                return;
            }
            GatewayBase gateway = null;

            try {
                gateway = AppStartup(options.GetPath(0), _settings);
                Processor        processor       = new Processor(gateway);
                TServerTransport serverTransport = new TServerSocket(ServerPort);

                // There are several different servers available. They should all work.

                Server = new TThreadPoolServer(processor, serverTransport);
                //TServer server = new TThreadPoolServer(processor, serverTransport);
                //TServer server = new TThreadPoolServer(processor, serverTransport, new TTransportFactory(), new TCompactProtocol.Factory());
                //TServer server = new TThreadedServer(processor, serverTransport);
                //TServer server = new TSimpleServer(processor, serverTransport);

                Server.setEventHandler(new ServerEventHandler());
                gateway.OpenSession();
                Console.WriteLine($"Starting server...database '{gateway.DatabaseName}' {gateway.DatabaseKind}");
                Server.Serve();
                gateway.CloseSession(true);
            } catch (ProgramException ex) {
                Console.WriteLine(ex.ToString());
                if (gateway != null)
                {
                    gateway.CloseSession(false);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                if (gateway != null)
                {
                    gateway.CloseSession(false);
                }
            }
            Console.WriteLine("done.");
        }
예제 #2
0
        //-------------------------------------------------------------------------
        // mainline
        // start up web host, then run tests
        static void Main(string[] args)
        {
            Logger.Open(0); // no default logging
            Logger.WriteLine("Andl.Host");
            var options = OptionParser.Create(_options, Help);

            if (!options.Parse(args))
            {
                return;
            }
            try {
                AppStartup(options.GetPath(0), _settings);
                _gateway.OpenSession();
                string address = $"http://{Environment.MachineName}:{ServerPort}/api";
                Logger.WriteLine(1, $"Opening host with database: {_gateway.DatabaseName} ({_gateway.DatabaseKind}) address: {address}");
                var host = CreateHost(address, "");
                host.Open();
                Logger.WriteLine(1, "Host opened.");
                if (!NoTests)
                {
                    SendTests(address);
                }
                Console.WriteLine("Server is waiting for requests. Press Enter to close.");
                Console.ReadLine();
                host.Close();
                _gateway.CloseSession();
            } catch (ProgramException ex) {
                Console.WriteLine(ex.ToString());
                if (_gateway != null)
                {
                    _gateway.CloseSession(false);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                if (_gateway != null)
                {
                    _gateway.CloseSession(false);
                }
            }
        }