public static int Execute(List <string> args) { var logger = new LoggerFactory().CreateLogger("Test"); try { var param = new ServerParam(); try { param.Parse(args); } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); Console.WriteLine("Error while parsing arguments"); Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); return(1); } // Transport TServerTransport trans; if (param.pipe != null) { trans = new TNamedPipeServerTransport(param.pipe); } else { if (param.useEncryption) { var certPath = "../../keys/server.p12"; trans = new TTlsServerSocketTransport(param.port, param.useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls); } else { trans = new TServerSocketTransport(param.port, 0, param.useBufferedSockets); } } ITProtocolFactory proto; if (param.compact) { proto = new TCompactProtocol.Factory(); } else if (param.json) { proto = new TJsonProtocol.Factory(); } else { proto = new TBinaryProtocol.Factory(); } ITProcessorFactory processorFactory; // Processor var testHandler = new TestHandlerAsync(); var testProcessor = new ThriftAsync.Test.ThriftTest.AsyncProcessor(testHandler); processorFactory = new SingletonTProcessorFactory(testProcessor); TTransportFactory transFactory; if (param.useFramed) { throw new NotImplementedException("framed"); // transFactory = new TFramedTransport.Factory(); } else { transFactory = new TTransportFactory(); } TBaseServer serverEngine = new AsyncBaseServer(processorFactory, trans, transFactory, transFactory, proto, proto, logger); //Server event handler var serverEvents = new MyServerEventHandler(); serverEngine.SetEventHandler(serverEvents); // Run it var where = (!string.IsNullOrEmpty(param.pipe)) ? "on pipe " + param.pipe : "on port " + param.port; Console.WriteLine("Starting the AsyncBaseServer " + where + " with processor TPrototypeProcessorFactory prototype factory " + (param.useBufferedSockets ? " with buffered socket" : "") + (param.useFramed ? " with framed transport" : "") + (param.useEncryption ? " with encryption" : "") + (param.compact ? " with compact protocol" : "") + (param.json ? " with json protocol" : "") + "..."); serverEngine.ServeAsync(CancellationToken.None).GetAwaiter().GetResult(); Console.ReadLine(); } catch (Exception x) { Console.Error.Write(x); return(1); } Console.WriteLine("done."); return(0); }
public static int Execute(List <string> args) { var loggerFactory = new LoggerFactory();//.AddConsole().AddDebug(); var logger = new LoggerFactory().CreateLogger("Test"); try { var param = new ServerParam(); try { param.Parse(args); } catch (Exception ex) { Console.WriteLine("*** FAILED ***"); Console.WriteLine("Error while parsing arguments"); Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); return(1); } // Transport TServerTransport trans; if (param.pipe != null) { trans = new TNamedPipeServerTransport(param.pipe); } // else if (param.useFramed) // { // trans = new TServerFramedTransport(param.port); // } else { if (param.useEncryption) { var cert = GetServerCert(); if (cert == null || !cert.HasPrivateKey) { throw new InvalidOperationException("Certificate doesn't contain private key"); } trans = new TTlsServerSocketTransport(param.port, param.useBufferedSockets, param.useFramed, cert, (sender, certificate, chain, errors) => true, null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12); } else { trans = new TServerSocketTransport(param.port, 0, param.useBufferedSockets, param.useFramed); } } ITProtocolFactory proto; if (param.compact) { proto = new TCompactProtocol.Factory(); } else if (param.json) { proto = new TJsonProtocol.Factory(); } else { proto = new TBinaryProtocol.Factory(); } ITProcessorFactory processorFactory; // Processor var testHandler = new TestHandlerAsync(); var testProcessor = new ThriftTest.AsyncProcessor(testHandler); processorFactory = new SingletonTProcessorFactory(testProcessor); TTransportFactory transFactory = new TTransportFactory(); TBaseServer serverEngine = new AsyncBaseServer(processorFactory, trans, transFactory, transFactory, proto, proto, logger); //Server event handler var serverEvents = new MyServerEventHandler(); serverEngine.SetEventHandler(serverEvents); // Run it var where = (!string.IsNullOrEmpty(param.pipe)) ? "on pipe " + param.pipe : "on port " + param.port; Console.WriteLine("Starting the AsyncBaseServer " + where + " with processor TPrototypeProcessorFactory prototype factory " + (param.useBufferedSockets ? " with buffered socket" : "") + (param.useFramed ? " with framed transport" : "") + (param.useEncryption ? " with encryption" : "") + (param.compact ? " with compact protocol" : "") + (param.json ? " with json protocol" : "") + "..."); serverEngine.ServeAsync(CancellationToken.None).GetAwaiter().GetResult(); Console.ReadLine(); } catch (Exception x) { Console.Error.Write(x); return(1); } Console.WriteLine("done."); return(0); }