protected override async ValueTask <TTransport> AcceptImplementationAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(await Task.FromCanceled <TTransport>(cancellationToken)); } if (_server == null) { throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket."); } try { var client = await _server.AcceptTcpClientAsync(); client.SendTimeout = client.ReceiveTimeout = _clientTimeout; //wrap the client in an SSL Socket passing in the SSL cert var tTlsSocket = new TTlsSocketTransport( client, _serverCertificate, true, _clientCertValidator, _localCertificateSelectionCallback, _sslProtocols); await tTlsSocket.SetupTlsAsync(); return(tTlsSocket); } catch (Exception ex) { throw new TTransportException(ex.ToString()); } }
private TTransport MakeTransport(URL url, TConfiguration configuration) { var ipaddress = IPAddress.Loopback; if (!NetUtil.IsAnyHost(url.Host) && !NetUtil.IsLocalHost(url.Host)) { ipaddress = IPAddress.Parse(url.Host); } // construct endpoint transport TTransport transport = null; Transport selectedTransport = GetTransport(url); { switch (selectedTransport) { case Transport.Tcp: transport = new TSocketTransport(ipaddress, url.Port, configuration); break; case Transport.NamedPipe: transport = new TNamedPipeTransport(".test", configuration); break; case Transport.Http: transport = new THttpTransport(new Uri($"http://{url.Host}:{url.Port}"), configuration); break; case Transport.TcpTls: transport = new TTlsSocketTransport(ipaddress, url.Port, configuration, GetCertificate(), CertValidator, LocalCertificateSelectionCallback); break; default: Console.WriteLine("unhandled case"); break; } } // optionally add layered transport(s) Buffering selectedBuffering = GetBuffering(url); switch (selectedBuffering) { case Buffering.Buffered: transport = new TBufferedTransport(transport); break; case Buffering.Framed: transport = new TFramedTransport(transport); break; default: // layered transport(s) are optional if (selectedBuffering != Buffering.None) { Console.WriteLine("unhandled case"); } break; } return(transport); }
private static TTransport GetTransport(string[] args) { TTransport transport = new TSocketTransport(IPAddress.Loopback, 9090, Configuration); // construct endpoint transport var transportArg = args.FirstOrDefault(x => x.StartsWith("-tr"))?.Split(':')?[1]; if (Enum.TryParse(transportArg, true, out Transport selectedTransport)) { switch (selectedTransport) { case Transport.Tcp: transport = new TSocketTransport(IPAddress.Loopback, 9090, Configuration); break; case Transport.NamedPipe: transport = new TNamedPipeTransport(".test", Configuration); break; case Transport.Http: transport = new THttpTransport(new Uri("http://localhost:9090"), Configuration); break; case Transport.TcpTls: transport = new TTlsSocketTransport(IPAddress.Loopback, 9090, Configuration, GetCertificate(), CertValidator, LocalCertificateSelectionCallback); break; default: Debug.Assert(false, "unhandled case"); break; } } // optionally add layered transport(s) var bufferingArg = args.FirstOrDefault(x => x.StartsWith("-bf"))?.Split(':')?[1]; if (Enum.TryParse <Buffering>(bufferingArg, out var selectedBuffering)) { switch (selectedBuffering) { case Buffering.Buffered: transport = new TBufferedTransport(transport); break; case Buffering.Framed: transport = new TFramedTransport(transport); break; default: // layered transport(s) are optional Debug.Assert(selectedBuffering == Buffering.None, "unhandled case"); break; } } return(transport); }
public TTransport CreateTransport() { // endpoint transport TTransport trans = null; switch (transport) { case TransportChoice.Http: Debug.Assert(url != null); trans = new THttpTransport(new Uri(url), Configuration); break; case TransportChoice.NamedPipe: Debug.Assert(pipe != null); trans = new TNamedPipeTransport(pipe, Configuration); break; case TransportChoice.TlsSocket: var cert = GetClientCert(); if (cert == null || !cert.HasPrivateKey) { throw new InvalidOperationException("Certificate doesn't contain private key"); } trans = new TTlsSocketTransport(host, port, Configuration, 0, cert, (sender, certificate, chain, errors) => true, null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12); break; case TransportChoice.Socket: default: trans = new TSocketTransport(host, port, Configuration); break; } // layered transport switch (layered) { case LayeredChoice.Buffered: trans = new TBufferedTransport(trans); break; case LayeredChoice.Framed: trans = new TFramedTransport(trans); break; default: Debug.Assert(layered == LayeredChoice.None); break; } return(trans); }
private static TTransport MakeTransport(string[] args) { // construct endpoint transport TTransport transport = null; Transport selectedTransport = GetTransport(args); { switch (selectedTransport) { case Transport.Tcp: transport = new TSocketTransport(IPAddress.Loopback, 9090, Configuration); break; case Transport.NamedPipe: transport = new TNamedPipeTransport(".test", Configuration); break; case Transport.Http: transport = new THttpTransport(new Uri("http://localhost:9090"), Configuration); break; case Transport.TcpTls: transport = new TTlsSocketTransport(IPAddress.Loopback, 9090, Configuration, GetCertificate(), CertValidator, LocalCertificateSelectionCallback); break; default: Debug.Assert(false, "unhandled case"); break; } } // optionally add layered transport(s) Buffering selectedBuffering = GetBuffering(args); switch (selectedBuffering) { case Buffering.Buffered: transport = new TBufferedTransport(transport); break; case Buffering.Framed: transport = new TFramedTransport(transport); break; default: // layered transport(s) are optional Debug.Assert(selectedBuffering == Buffering.None, "unhandled case"); break; } return(transport); }
public TTransport CreateTransport() { if (url == null) { // endpoint transport TTransport trans = null; if (pipe != null) { trans = new TNamedPipeTransport(pipe); } else { if (encrypted) { var cert = GetClientCert(); if (cert == null || !cert.HasPrivateKey) { throw new InvalidOperationException("Certificate doesn't contain private key"); } trans = new TTlsSocketTransport(host, port, 0, cert, (sender, certificate, chain, errors) => true, null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12); } else { trans = new TSocketTransport(host, port); } } // layered transport if (buffered) { trans = new TBufferedTransport(trans); } if (framed) { trans = new TFramedTransport(trans); } return(trans); } return(new THttpTransport(new Uri(url), null)); }
static async Task Main(string[] args) { ///Start connetion Console.WriteLine("Starting Thrift Client!"); var localost = "10.1.2.12"; var client = new TcpClient(localost, 9095); /// This is the SSL certificate to be used X509Certificate2 certificate = new X509Certificate2("C:/FM/mySrvKeystore.p12", "thrift"); Thrift.Transport.TTransport transport = new TTlsSocketTransport(client, certificate, false, null, null, SslProtocols.Tls12); var protocol = new TBinaryProtocol(transport); ///Create multiple TMultiplexedProtocol for each service that is needed TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "ReportingService"); var reportingClient = new ReportingService.Client(mp); ///the client server is now connected Console.WriteLine("connected"); //Available Report List from FM ///string reportName = "FxCashPnLReport"; ///Sales FXCash P&L ReportASIC Report ///Customer MTM Report ///SpotVolReport ///CptyWiseSpotVolReport ///CashflowReport ///TarnCashflowReport ///PnL Report ///DealSummaryReport ///SpotVolReport ///DealEnquiryReport ///CashflowReport string dealSummaryEndpointURl = "https://localhost:5001/api/Risk/ReadDealSummary"; string spotVolEndpointURl = "https://localhost:5001/api/Risk/ReadSpotVol"; string reportName = "DealSummaryReport"; string Id = string.Empty; DateTime now = DateTime.Now; string nowString = now.ToString("yyyy-mm-dd hh:mm:ss"); string reportDate = "2020-10-10 18:00:00"; ReportOutput output = await reportingClient.getBatchReportsAsync(reportName, reportDate); byte[] result = output.Result; //close the connection Console.WriteLine("done"); transport.Close(); try { Id = FMReports.Services.InsertByteArrayintoSqlDatabase.StoreByteArrayintoSqlDatabase(result, reportName); Console.WriteLine(reportName + " data has been inserted to SQL database " + Id); } catch (Exception e) { Console.WriteLine(e.Message); } ////try ////{ //// FileStream fs = new FileStream("C:\\FM\\" + reportName + ".csv", FileMode.Create, FileAccess.ReadWrite); //// BinaryWriter bw = new BinaryWriter(fs); //// bw.Write(result); //// Console.WriteLine("csv file created"); ////} ////catch (Exception e) ////{ //// Console.WriteLine(e.Message); ////} /// try { if (reportName == "DealSummaryReport") { await PostRequest(dealSummaryEndpointURl, Id); } else { await PostRequest(spotVolEndpointURl, Id); } } catch (Exception e) { Console.WriteLine(e.Message); } }