/// <summary> /// Create a new SMSAPI HTTP client. /// </summary> /// <param name="RemoteURL">The remote URL of the OICP HTTP endpoint to connect to.</param> /// <param name="VirtualHostname">An optional HTTP virtual hostname.</param> /// <param name="Description">An optional description of this CPO client.</param> /// <param name="RemoteCertificateValidator">The remote SSL/TLS certificate validator.</param> /// <param name="HTTPUserAgent">The HTTP user agent identification.</param> /// <param name="BasicAuthentication">An optional HTTP basic authentication.</param> /// <param name="Credentials">The default API authentication.</param> /// <param name="RequestTimeout">An optional request timeout.</param> /// <param name="TransmissionRetryDelay">The delay between transmission retries.</param> /// <param name="MaxNumberOfRetries">The maximum number of transmission retries for HTTP request.</param> /// <param name="DNSClient">The DNS client to use.</param> public SMSAPI(URL?RemoteURL = null, HTTPHostname?VirtualHostname = null, String Description = null, RemoteCertificateValidationCallback RemoteCertificateValidator = null, String HTTPUserAgent = DefaultHTTPUserAgent, Credentials BasicAuthentication = null, Credentials Credentials = null, TimeSpan?RequestTimeout = null, TransmissionRetryDelayDelegate TransmissionRetryDelay = null, UInt16?MaxNumberOfRetries = DefaultMaxNumberOfRetries, DNSClient DNSClient = null) : base(RemoteURL, VirtualHostname, Description, RemoteCertificateValidator, HTTPUserAgent, BasicAuthentication, Credentials, RequestTimeout, TransmissionRetryDelay, MaxNumberOfRetries, DNSClient) { }
/// <summary> /// Initialize the OCPI HTTP server using IPAddress.Any, http port 8080 and maybe start the server. /// </summary> internal GenericAPI(RoamingNetwork RoamingNetwork, HTTPServer HTTPServer, String URIPrefix = "/ext/OCPI", Func <String, Stream> GetRessources = null, String ServiceName = DefaultHTTPServerName, EMailAddress APIEMailAddress = null, PgpPublicKeyRing APIPublicKeyRing = null, PgpSecretKeyRing APISecretKeyRing = null, String APIPassphrase = null, EMailAddressList APIAdminEMail = null, SMTPClient APISMTPClient = null, String LogfileName = DefaultLogfileName) { #region Initial checks if (RoamingNetwork == null) { throw new ArgumentNullException("RoamingNetwork", "The given parameter must not be null!"); } if (HTTPServer == null) { throw new ArgumentNullException("HTTPServer", "The given parameter must not be null!"); } if (URIPrefix.IsNullOrEmpty()) { throw new ArgumentNullException("URIPrefix", "The given parameter must not be null or empty!"); } if (!URIPrefix.StartsWith("/")) { URIPrefix = "/" + URIPrefix; } #endregion #region Init data this._HTTPServer = HTTPServer; this._GetRessources = GetRessources; this._URIPrefix = URIPrefix; this._ServiceName = ServiceName; this._APIEMailAddress = APIEMailAddress; this._APIPublicKeyRing = APIPublicKeyRing; this._APISecretKeyRing = APISecretKeyRing; this._APIPassphrase = APIPassphrase; this._APIAdminEMail = APIAdminEMail; this._APISMTPClient = APISMTPClient; this._DNSClient = HTTPServer.DNSClient; #endregion RegisterURITemplates(); }
/// <summary> /// Initialize an new HTTP server for the eMIP HTTP/SOAP/XML CPO API. /// </summary> /// <param name="HTTPServerName">An optional identification string for the HTTP server.</param> /// <param name="ServiceName">An optional identification for this SOAP service.</param> /// <param name="HTTPServerPort">An optional TCP port for the HTTP server.</param> /// <param name="URLPathPrefix">An optional prefix for the HTTP URIs.</param> /// <param name="AuthorisationURL">The HTTP/SOAP/XML URI for eMIP authorization requests.</param> /// <param name="ContentType">An optional HTTP content type to use.</param> /// <param name="RegisterHTTPRootService">Register HTTP root services for sending a notice to clients connecting via HTML or plain text.</param> /// <param name="DNSClient">An optional DNS client to use.</param> /// <param name="AutoStart">Start the server immediately.</param> public CPOServer(String HTTPServerName = DefaultHTTPServerName, IPPort?HTTPServerPort = null, String ServiceName = null, HTTPPath?URLPathPrefix = null, String AuthorisationURL = DefaultAuthorisationURL, HTTPContentType ContentType = null, Boolean RegisterHTTPRootService = true, DNSClient DNSClient = null, Boolean AutoStart = false) : base(HTTPServerName.IsNotNullOrEmpty() ? HTTPServerName : DefaultHTTPServerName, HTTPServerPort ?? DefaultHTTPServerPort, ServiceName ?? "eMIP " + Version.Number + " " + nameof(CPOServer), URLPathPrefix ?? DefaultURLPathPrefix, ContentType ?? DefaultContentType, RegisterHTTPRootService, DNSClient, AutoStart: false) { this.ServiceName = ServiceName ?? "eMIP " + Version.Number + " " + nameof(CPOServer); this.AuthorisationURL = AuthorisationURL ?? DefaultAuthorisationURL; RegisterURITemplates(); if (AutoStart) { Start(); } }
/// <summary> /// Use the given HTTP server for the HTTP/SOAP/XML Server API. /// </summary> /// <param name="SOAPServer">A SOAP server.</param> /// <param name="URIPrefix">An optional URI prefix for the SOAP URI templates.</param> public ASOAPServer(SOAPServer SOAPServer, String URIPrefix = DefaultURIPrefix) { #region Initial checks if (SOAPServer == null) { throw new ArgumentNullException(nameof(SOAPServer), "The given SOAP server must not be null!"); } if (URIPrefix == null) { URIPrefix = DefaultURIPrefix; } else { URIPrefix = URIPrefix.Trim(); } if (URIPrefix.Length > 0 && !URIPrefix.StartsWith("/", StringComparison.Ordinal)) { URIPrefix = "/" + URIPrefix; } #endregion this.SOAPServer = SOAPServer; this.URIPrefix = URIPrefix; this.DNSClient = SOAPServer.DNSClient; #pragma warning disable RECS0021 RegisterURITemplates(); #pragma warning restore RECS0021 }
/// <summary> /// Create an instance of the OCPI HTTP API for Charge Point Operators /// using a newly created HTTP server. /// </summary> public CPOAPI(RoamingNetwork RoamingNetwork, String HTTPServerName = DefaultHTTPServerName, IPPort HTTPServerPort = null, String URIPrefix = "", String ServiceName = DefaultHTTPServerName, EMailAddress APIEMailAddress = null, PgpSecretKeyRing APISecretKeyRing = null, String APIPassphrase = null, EMailAddressList APIAdminEMail = null, SMTPClient APISMTPClient = null, DNSClient DNSClient = null, String LogfileName = DefaultLogfileName) : base(RoamingNetwork, HTTPServerName, HTTPServerPort != null ? HTTPServerPort : DefaultHTTPServerPort, URIPrefix, ResourceName => typeof(CPOAPI).Assembly.GetManifestResourceStream("org.GraphDefined.WWCP.OCPIv2_1.HTTPAPI.CPOAPI.HTTPRoot." + ResourceName), ServiceName, APIEMailAddress, null,//OpenPGP.ReadPublicKeyRing(typeof(CPOAPI).Assembly.GetManifestResourceStream("org.GraphDefined.WWCP.OCPIv2_1.HTTPAPI.GenericAPI.HTTPRoot.robot@offenes-jena_pubring.gpg")), APISecretKeyRing, APIPassphrase, APIAdminEMail, APISMTPClient, DNSClient, LogfileName) { RegisterCPOURITemplates(); }
/// <summary> /// Initialize a new HTTP server for the HTTP/SOAP/XML Server API using IPAddress.Any. /// </summary> /// <param name="HTTPServerName">An optional identification string for the HTTP server.</param> /// <param name="TCPPort">An optional TCP port for the HTTP server.</param> /// <param name="URIPrefix">An optional prefix for the HTTP URIs.</param> /// <param name="SOAPContentType">The HTTP content type for SOAP messages.</param> /// <param name="DNSClient">An optional DNS client to use.</param> /// <param name="RegisterHTTPRootService">Register HTTP root services for sending a notice to clients connecting via HTML or plain text.</param> /// <param name="AutoStart">Start the server immediately.</param> public ASOAPServer(String HTTPServerName = DefaultHTTPServerName, IPPort TCPPort = null, String URIPrefix = DefaultURIPrefix, HTTPContentType SOAPContentType = null, Boolean RegisterHTTPRootService = true, DNSClient DNSClient = null, Boolean AutoStart = false) : this(new SOAPServer(TCPPort ?? DefaultHTTPServerPort, HTTPServerName, SOAPContentType ?? DefaultContentType, DNSClient : DNSClient, Autostart : false), URIPrefix) { if (RegisterHTTPRootService) { RegisterRootService(); } if (AutoStart) #pragma warning disable RECS0021 { Start(); } #pragma warning restore RECS0021 }
/// <summary> /// Create a new SMSAPI HTTP client. /// </summary> /// <param name="RemoteURL">The remote URL of the OICP HTTP endpoint to connect to.</param> /// <param name="VirtualHostname">An optional HTTP virtual hostname.</param> /// <param name="Description">An optional description of this CPO client.</param> /// <param name="RemoteCertificateValidator">The remote SSL/TLS certificate validator.</param> /// <param name="HTTPUserAgent">The HTTP user agent identification.</param> /// <param name="BasicAuthentication">An optional HTTP basic authentication.</param> /// <param name="Credentials">The default API authentication.</param> /// <param name="RequestTimeout">An optional request timeout.</param> /// <param name="TransmissionRetryDelay">The delay between transmission retries.</param> /// <param name="MaxNumberOfRetries">The maximum number of transmission retries for HTTP request.</param> /// <param name="DNSClient">The DNS client to use.</param> public SMSAPIClient(URL?RemoteURL = null, HTTPHostname?VirtualHostname = null, String Description = null, RemoteCertificateValidationCallback RemoteCertificateValidator = null, String HTTPUserAgent = DefaultHTTPUserAgent, Credentials BasicAuthentication = null, Credentials Credentials = null, TimeSpan?RequestTimeout = null, TransmissionRetryDelayDelegate TransmissionRetryDelay = null, UInt16?MaxNumberOfRetries = DefaultMaxNumberOfRetries, DNSClient DNSClient = null) : base(RemoteURL ?? URL.Parse("https://api.smsapi.com/api/"), VirtualHostname, Description, RemoteCertificateValidator, null, null, HTTPUserAgent ?? DefaultHTTPUserAgent, RequestTimeout, TransmissionRetryDelay, MaxNumberOfRetries ?? DefaultMaxNumberOfRetries, false, null, DNSClient) { this.BasicAuthentication = BasicAuthentication; this.Credentials = Credentials; }
/// <summary> /// Create a new SMTP client for sending e-mails. /// </summary> /// <param name="RemoteHost"></param> /// <param name="RemotePort"></param> /// <param name="Login"></param> /// <param name="Password"></param> /// <param name="LocalDomain"></param> /// <param name="UseIPv4">Whether to use IPv4 as networking protocol.</param> /// <param name="UseIPv6">Whether to use IPv6 as networking protocol.</param> /// <param name="PreferIPv6">Prefer IPv6 (instead of IPv4) as networking protocol.</param> /// <param name="UseTLS">Whether Transport Layer Security should be used or not.</param> /// <param name="ValidateServerCertificate">A callback for validating the remote server certificate.</param> /// <param name="ConnectionTimeout">The timeout connecting to the remote service.</param> /// <param name="DNSClient">An optional DNS client used to resolve DNS names.</param> /// <param name="AutoConnect">Connect to the TCP service automatically on startup. Default is false.</param> /// <param name="CancellationToken"></param> public SMTPClient(String RemoteHost, IPPort RemotePort, String Login = null, String Password = null, String LocalDomain = null, Boolean UseIPv4 = true, Boolean UseIPv6 = false, Boolean PreferIPv6 = false, TLSUsage UseTLS = TLSUsage.STARTTLS, ValidateRemoteCertificateDelegate ValidateServerCertificate = null, TimeSpan?ConnectionTimeout = null, DNSClient DNSClient = null, Boolean AutoConnect = false, CancellationToken?CancellationToken = null) : base(RemoteHost, RemotePort, UseIPv4, UseIPv6, PreferIPv6, UseTLS, ValidateServerCertificate, ConnectionTimeout, DNSClient, AutoConnect, CancellationToken) { this._Login = Login; this._Password = Password; this._LocalDomain = (LocalDomain != null) ? LocalDomain : System.Net.Dns.GetHostName(); this._UnknownAuthMethods = new List <String>(); }
/// <summary> /// Instantiates a new instance. /// </summary> /// <param name="apiKey">The API key to use to communicate with the Vultr /// API.</param> /// <param name="apiURL">The optional Vultr API URL to use. Set this if you want /// to override the default endpoint (e.g. for testing).</param> /// <exception cref="ArgumentNullException">If <paramref name="apiKey"/> is null /// or empty.</exception> public VultrClient(string apiKey, string apiURL = VultrApiURL) { if (string.IsNullOrEmpty(apiKey)) { throw new ArgumentNullException("apiKey", "apiKey must not be null"); } Account = new AccountClient(apiKey, apiURL); Application = new ApplicationClient(apiKey, apiURL); Auth = new AuthClient(apiKey, apiURL); Backup = new BackupClient(apiKey, apiURL); Block = new BlockClient(apiKey, apiURL); DNS = new DNSClient(apiKey, apiURL); Firewall = new FirewallClient(apiKey, apiURL); ISOImage = new ISOImageClient(apiKey, apiURL); Network = new NetworkClient(apiKey, apiURL); OperatingSystem = new OperatingSystemClient(apiKey, apiURL); Plan = new PlanClient(apiKey, apiURL); Region = new RegionClient(apiKey, apiURL); ReservedIP = new ReservedIPClient(apiKey, apiURL); Server = new ServerClient(apiKey, apiURL); Snapshot = new SnapshotClient(apiKey, apiURL); SSHKey = new SSHKeyClient(apiKey, apiURL); StartupScript = new StartupScriptClient(apiKey, apiURL); User = new UserClient(apiKey, apiURL); }
internal GenericAPI(RoamingNetwork RoamingNetwork, String HTTPServerName = DefaultHTTPServerName, IPPort HTTPServerPort = null, String URIPrefix = "", Func <String, Stream> GetRessources = null, String ServiceName = DefaultHTTPServerName, EMailAddress APIEMailAddress = null, PgpPublicKeyRing APIPublicKeyRing = null, PgpSecretKeyRing APISecretKeyRing = null, String APIPassphrase = null, EMailAddressList APIAdminEMail = null, SMTPClient APISMTPClient = null, DNSClient DNSClient = null, String LogfileName = DefaultLogfileName) : this(RoamingNetwork, new HTTPServer(DefaultServerName : DefaultHTTPServerName).AttachTCPPorts(HTTPServerPort != null ? HTTPServerPort : DefaultHTTPServerPort), URIPrefix, GetRessources, ServiceName, APIEMailAddress, APIPublicKeyRing, APISecretKeyRing, APIPassphrase, APIAdminEMail, APISMTPClient, LogfileName) { }
/// <summary> /// Initialize a new HTTP server for the charge point HTTP/SOAP/XML API. /// </summary> /// <param name="HTTPServerName">An optional identification string for the HTTP server.</param> /// <param name="TCPPort">An optional TCP port for the HTTP server.</param> /// <param name="ServiceName">The TCP service name shown e.g. on service startup.</param> /// <param name="URLPrefix">An optional prefix for the HTTP URLs.</param> /// <param name="ContentType">An optional HTTP content type to use.</param> /// <param name="RegisterHTTPRootService">Register HTTP root services for sending a notice to clients connecting via HTML or plain text.</param> /// <param name="DNSClient">An optional DNS client to use.</param> /// <param name="AutoStart">Start the server immediately.</param> public ChargePointSOAPServer(String HTTPServerName = DefaultHTTPServerName, IPPort?TCPPort = null, String ServiceName = null, HTTPPath?URLPrefix = null, HTTPContentType ContentType = null, Boolean RegisterHTTPRootService = true, DNSClient DNSClient = null, Boolean AutoStart = false) : base(HTTPServerName.IsNotNullOrEmpty() ? HTTPServerName : DefaultHTTPServerName, TCPPort ?? DefaultHTTPServerPort, ServiceName ?? DefaultServiceName, URLPrefix ?? DefaultURLPrefix, ContentType ?? DefaultContentType, RegisterHTTPRootService, DNSClient, AutoStart: false) { RegisterURLTemplates(); if (AutoStart) { Start(); } }
/// <summary> /// Create a new TCPClient connecting to a remote service using DNS SRV records. /// </summary> /// <param name="DNSName">The optional DNS name of the remote service to connect to.</param> /// <param name="ServiceName">The optional DNS SRV service name of the remote service to connect to.</param> /// <param name="UseIPv4">Whether to use IPv4 as networking protocol.</param> /// <param name="UseIPv6">Whether to use IPv6 as networking protocol.</param> /// <param name="PreferIPv6">Prefer IPv6 (instead of IPv4) as networking protocol.</param> /// <param name="ConnectionTimeout">The timeout connecting to the remote service.</param> /// <param name="DNSClient">An optional DNS client used to resolve DNS names.</param> /// <param name="AutoConnect">Connect to the TCP service automatically on startup. Default is false.</param> public TCPClient(String DNSName = "", String ServiceName = "", Boolean UseIPv4 = true, Boolean UseIPv6 = false, Boolean PreferIPv6 = false, Boolean UseTLS = false, TimeSpan?ConnectionTimeout = null, DNSClient DNSClient = null, Boolean AutoConnect = false) { this._RemoteHost = DNSName; this._ServiceName = ServiceName; this._UseIPv4 = UseIPv4; this._UseIPv6 = UseIPv6; this._PreferIPv6 = PreferIPv6; this._ConnectionTimeout = (ConnectionTimeout.HasValue) ? ConnectionTimeout.Value : TimeSpan.FromSeconds(60); this._DNSClient = (DNSClient != null) ? DNSClient : new DNSClient(SearchForIPv4DNSServers: _UseIPv4, SearchForIPv6DNSServers: _UseIPv6); if (AutoConnect) { Connect(); } }
public ADataStore(IRoamingNetwork RoamingNetwork, Func <RoamingNetwork_Id, String> LogFileNameCreator, Boolean DisableLogfiles = false, IEnumerable <RoamingNetworkInfo> RoamingNetworkInfos = null, Boolean DisableNetworkSync = false, DNSClient DNSClient = null) { this.InternalData = new Dictionary <TId, TData>(); this.RoamingNetwork = RoamingNetwork ?? throw new ArgumentNullException(nameof(RoamingNetwork), "The given roaming network must not be null or empty!"); if (LogFileNameCreator == null) { throw new ArgumentNullException(nameof(LogFileNameCreator), "The given LogFileNameCreator delegate must not be null or empty!"); } this.LogfileName = LogFileNameCreator(RoamingNetwork.Id); this.DisableLogfiles = DisableLogfiles; this._RoamingNetworkInfos = RoamingNetworkInfos != null ? new List <RoamingNetworkInfo>(RoamingNetworkInfos) : new List <RoamingNetworkInfo>(); this.DisableNetworkSync = DisableNetworkSync; this.DNSClient = DNSClient ?? new DNSClient(SearchForIPv4DNSServers: true, SearchForIPv6DNSServers: false); }
/// <summary> /// Create a new WWCP importer. /// </summary> public WWCPImporter(String Id, String ConfigFilenamePrefix, DNSClient DNSClient = null, TimeSpan?UpdateEvery = null, DownloadData <T> DownloadData = null, Action <WWCPImporter <T>, Task <HTTPResponse <T> > > OnFirstRun = null, Action <WWCPImporter <T>, Task <HTTPResponse <T> > > OnEveryRun = null, UInt16 MaxNumberOfCachedXMLExports = DefaultMaxNumberOfCachedXMLExports) { #region Initial checks if (Id.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Id), "The given config file name must not be null or empty!"); } if (ConfigFilenamePrefix.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ConfigFilenamePrefix), "The given config file name must not be null or empty!"); } if (DownloadData == null) { throw new ArgumentNullException(nameof(DownloadData), "The given delegate must not be null or empty!"); } if (OnFirstRun == null) { throw new ArgumentNullException(nameof(OnFirstRun), "The given delegate must not be null or empty!"); } if (OnEveryRun == null) { throw new ArgumentNullException(nameof(OnEveryRun), "The given delegate must not be null or empty!"); } #endregion this._Id = Id; this._ConfigFilenamePrefix = ConfigFilenamePrefix; this._DNSClient = DNSClient != null ? DNSClient : new DNSClient(); this._UpdateEvery = UpdateEvery != null ? UpdateEvery.Value : DefaultImportEvery; this.DownloadData = DownloadData; this.OnFirstRun = OnFirstRun; this.OnEveryRun = OnEveryRun; this._MaxNumberOfCachedDataImports = MaxNumberOfCachedXMLExports; this._EVSEOperators = new List <EVSEOperator>(); this._AllForwardingInfos = new Dictionary <ChargingStation_Id, ImporterForwardingInfo>(); this._ImportedData = new List <Timestamped <T> >(); // Start not now but veeeeery later! UpdateEVSEDataAndStatusLock = new Object(); UpdateEVSEStatusTimer = new Timer(ImportEvery, null, TimeSpan.FromDays(30), _UpdateEvery); }
/// <summary> /// Create an abstract SOAP client. /// </summary> /// <param name="ClientId">A unqiue identification of this client.</param> /// <param name="Hostname">The hostname to connect to.</param> /// <param name="RemotePort">The remote TCP port to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="HTTPVirtualHost">An optional HTTP virtual host name to use.</param> /// <param name="URIPrefix">An default URI prefix.</param> /// <param name="WSSLoginPassword">The WebService-Security username/password.</param> /// <param name="UserAgent">An optional HTTP user agent to use.</param> /// <param name="QueryTimeout">An optional timeout for upstream queries.</param> /// <param name="DNSClient">An optional DNS client.</param> public ASOAPClient(String ClientId, String Hostname, IPPort RemotePort, RemoteCertificateValidationCallback RemoteCertificateValidator = null, X509Certificate ClientCert = null, String HTTPVirtualHost = null, String URIPrefix = null, Tuple <String, String> WSSLoginPassword = null, String UserAgent = DefaultHTTPUserAgent, TimeSpan?QueryTimeout = null, DNSClient DNSClient = null) : base(ClientId, Hostname, RemotePort, RemoteCertificateValidator, ClientCert, HTTPVirtualHost, UserAgent, QueryTimeout, DNSClient) { this.URIPrefix = URIPrefix.Trim(); this.WSSLoginPassword = WSSLoginPassword; }
/// <summary> /// Initialize a new HTTP server for the central system HTTP/SOAP/XML API. /// </summary> /// <param name="HTTPServerName">An optional identification string for the HTTP server.</param> /// <param name="TCPPort">An optional TCP port for the HTTP server.</param> /// <param name="URLPrefix">An optional prefix for the HTTP URLs.</param> /// <param name="ContentType">An optional HTTP content type to use.</param> /// <param name="RegisterHTTPRootService">Register HTTP root services for sending a notice to clients connecting via HTML or plain text.</param> /// <param name="DNSClient">An optional DNS client to use.</param> /// <param name="AutoStart">Start the server immediately.</param> public CentralSystemWSServer(String HTTPServerName = DefaultHTTPServerName, IPPort?TCPPort = null, HTTPPath?URLPrefix = null, HTTPContentType ContentType = null, Boolean RegisterHTTPRootService = true, DNSClient DNSClient = null, Boolean AutoStart = false) //: base(HTTPServerName.IsNotNullOrEmpty() // ? HTTPServerName // : DefaultHTTPServerName, // TCPPort ?? DefaultHTTPServerPort, // URLPrefix ?? DefaultURLPrefix, // ContentType ?? DefaultContentType, // RegisterHTTPRootService, // DNSClient, // AutoStart: false) : base(System.Net.IPAddress.Parse("127.0.0.1"), TCPPort.HasValue ? TCPPort.Value.ToUInt16() : 8000) { base.OnTextMessage += ProcessTextMessages; //if (AutoStart) // Start(); }
static void Main(string[] args) { DNSClient c = new DNSClient("192.168.2.86"); Console.WriteLine(c.RetrieveIpAddress("example.com")); Console.WriteLine(c.RetrieveDNSName("127.0.0.1")); Console.ReadLine(); }
/// <summary> /// Create a new TCP service allowing to attach multiple TCP servers on different IP sockets. /// </summary> /// <param name="ServiceBanner">The service banner transmitted to a TCP client after connection initialization.</param> /// <param name="X509Certificate">Use this X509 certificate for TLS.</param> /// <param name="ServerThreadName">An optional name of the TCP server threads.</param> /// <param name="ServerThreadPriority">An optional priority of the TCP server threads (default: AboveNormal).</param> /// <param name="ServerThreadIsBackground">Whether the TCP server threads are a background thread or not (default: yes).</param> /// <param name="ConnectionIdBuilder">An optional delegate to build a connection identification based on IP socket information.</param> /// <param name="ConnectionThreadsNameBuilder">An optional delegate to set the name of the TCP connection threads.</param> /// <param name="ConnectionThreadsPriorityBuilder">An optional delegate to set the priority of the TCP connection threads.</param> /// <param name="ConnectionThreadsAreBackground">Whether the TCP connection threads are background threads or not (default: yes).</param> /// <param name="ConnectionTimeout">The TCP client timeout for all incoming client connections in seconds (default: 30 sec).</param> /// <param name="MaxClientConnections">The maximum number of concurrent TCP client connections (default: 4096).</param> /// <param name="DNSClient">The DNS client to use.</param> /// <param name="Autostart">Start the TCP server threads immediately (default: no).</param> public ATCPServers(String ServiceBanner = TCPServer.__DefaultServiceBanner, X509Certificate2 X509Certificate = null, String ServerThreadName = TCPServer.__DefaultServerThreadName, ThreadPriority ServerThreadPriority = ThreadPriority.AboveNormal, Boolean ServerThreadIsBackground = true, ConnectionIdBuilder ConnectionIdBuilder = null, ConnectionThreadsNameBuilder ConnectionThreadsNameBuilder = null, ConnectionThreadsPriorityBuilder ConnectionThreadsPriorityBuilder = null, Boolean ConnectionThreadsAreBackground = true, TimeSpan?ConnectionTimeout = null, UInt32 MaxClientConnections = TCPServer.__DefaultMaxClientConnections, DNSClient DNSClient = null, Boolean Autostart = false) { this._TCPServers = new List <TCPServer>(); this._DNSClient = DNSClient; #region TCP Server this._ServiceBanner = ServiceBanner; this._X509Certificate = X509Certificate; #endregion #region Server thread related this._ServerThreadName = ServerThreadName; this._ServerThreadPriority = ServerThreadPriority; this._ServerThreadIsBackground = ServerThreadIsBackground; #endregion #region TCP Connection this._ConnectionIdBuilder = (ConnectionIdBuilder != null) ? ConnectionIdBuilder : (Sender, Timestamp, LocalSocket, RemoteIPSocket) => "TCP:" + RemoteIPSocket.IPAddress + ":" + RemoteIPSocket.Port; this._ConnectionThreadsNameBuilder = (ConnectionThreadsNameBuilder != null) ? ConnectionThreadsNameBuilder : (Sender, Timestamp, LocalSocket, RemoteIPSocket) => "TCP thread " + RemoteIPSocket.IPAddress + ":" + RemoteIPSocket.Port; this._ConnectionThreadsPriorityBuilder = (ConnectionThreadsPriorityBuilder != null) ? ConnectionThreadsPriorityBuilder : (Sender, Timestamp, LocalSocket, RemoteIPSocket) => ThreadPriority.AboveNormal; this._ConnectionThreadsAreBackground = ConnectionThreadsAreBackground; this._ConnectionTimeout = ConnectionTimeout.HasValue ? ConnectionTimeout.Value : TimeSpan.FromSeconds(30); #endregion if (Autostart) { Start(); } }
/// <summary> /// Initialize the SMTP server using the given parameters. /// </summary> /// <param name="IPPort"></param> /// <param name="DefaultServerName">The default SMTP servername.</param> /// <param name="X509Certificate">Use this X509 certificate for TLS.</param> /// <param name="UseTLS">Use TLS (implicit true, if a X509 certificate was given!).</param> /// <param name="CallingAssemblies">Calling assemblies.</param> /// <param name="ServerThreadName">The optional name of the TCP server thread.</param> /// <param name="ServerThreadPriority">The optional priority of the TCP server thread.</param> /// <param name="ServerThreadIsBackground">Whether the TCP server thread is a background thread or not.</param> /// <param name="ConnectionIdBuilder">An optional delegate to build a connection identification based on IP socket information.</param> /// <param name="ConnectionThreadsNameBuilder">An optional delegate to set the name of the TCP connection threads.</param> /// <param name="ConnectionThreadsPriorityBuilder">An optional delegate to set the priority of the TCP connection threads.</param> /// <param name="ConnectionThreadsAreBackground">Whether the TCP connection threads are background threads or not (default: yes).</param> /// <param name="ConnectionTimeout">The TCP client timeout for all incoming client connections in seconds (default: 30 sec).</param> /// <param name="MaxClientConnections">The maximum number of concurrent TCP client connections (default: 4096).</param> /// <param name="DNSClient">The DNS client to use.</param> /// <param name="Autostart">Start the SMTP server thread immediately (default: no).</param> public SMTPServer(IPPort IPPort = null, String DefaultServerName = __DefaultServerName, X509Certificate2 X509Certificate = null, Boolean?UseTLS = true, IEnumerable <Assembly> CallingAssemblies = null, String ServerThreadName = null, ThreadPriority ServerThreadPriority = ThreadPriority.AboveNormal, Boolean ServerThreadIsBackground = true, ConnectionIdBuilder ConnectionIdBuilder = null, ConnectionThreadsNameBuilder ConnectionThreadsNameBuilder = null, ConnectionThreadsPriorityBuilder ConnectionThreadsPriorityBuilder = null, Boolean ConnectionThreadsAreBackground = true, TimeSpan?ConnectionTimeout = null, UInt32 MaxClientConnections = TCPServer.__DefaultMaxClientConnections, DNSClient DNSClient = null, Boolean Autostart = false) : base(DefaultServerName, X509Certificate, ServerThreadName, ServerThreadPriority, ServerThreadIsBackground, ConnectionIdBuilder, ConnectionThreadsNameBuilder, ConnectionThreadsPriorityBuilder, ConnectionThreadsAreBackground, ConnectionTimeout, MaxClientConnections, DNSClient, false) { this._DefaultServerName = DefaultServerName; this._UseTLS = UseTLS.HasValue ? UseTLS.Value : (X509Certificate != null ? true : false); _SMTPConnection = new SMTPConnection(DefaultServerName, this._UseTLS); _SMTPConnection.MAIL_FROMFilter += Process_MAIL_FROMFilter; _SMTPConnection.RCPT_TOFilter += Process_RCPT_TOFilter; _SMTPConnection.OnNotification += ProcessNotification; _SMTPConnection.ErrorLog += (HTTPProcessor, ServerTimestamp, SMTPCommand, Request, Response, Error, LastException) => LogError(ServerTimestamp, SMTPCommand, Request, Response, Error, LastException); if (IPPort != null) { this.AttachTCPPort(IPPort); } if (Autostart) { Start(); } }
/// <summary> /// Create a new HTTPClient using the given optional parameters. /// </summary> /// <param name="RemoteSocket">The remote IP socket to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="DNSClient">An optional DNS client.</param> public HTTPSClient(IPSocket RemoteSocket, RemoteCertificateValidationCallback RemoteCertificateValidator, X509Certificate ClientCert = null, DNSClient DNSClient = null) : base(RemoteSocket, RemoteCertificateValidator, ClientCert, DNSClient) { }
/// <summary> /// Create a new HTTPClient using the given optional parameters. /// </summary> /// <param name="RemoteIPAddress">The remote IP address to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="RemotePort">An optional remote IP port to connect to [default: 443].</param> /// <param name="DNSClient">An optional DNS client.</param> public HTTPSClient(IIPAddress RemoteIPAddress, RemoteCertificateValidationCallback RemoteCertificateValidator, X509Certificate ClientCert = null, IPPort RemotePort = null, DNSClient DNSClient = null) : base(RemoteIPAddress, RemotePort != null ? RemotePort : IPPort.Parse(443), RemoteCertificateValidator, ClientCert, DNSClient) { }
/// <summary> /// Create a new HTTPClient using the given optional parameters. /// </summary> /// <param name="RemoteSocket">The remote IP socket to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="DNSClient">An optional DNS client.</param> public HTTPClient(IPSocket RemoteSocket, RemoteCertificateValidationCallback RemoteCertificateValidator = null, X509Certificate ClientCert = null, DNSClient DNSClient = null) : this(RemoteSocket.IPAddress, RemoteSocket.Port, RemoteCertificateValidator, ClientCert, DNSClient) { }
/// <summary> /// Create a new HTTPClient using the given optional parameters. /// </summary> /// <param name="RemoteHost">The remote hostname to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="RemotePort">An optional remote IP port to connect to [default: 443].</param> /// <param name="DNSClient">An optional DNS client.</param> public HTTPSClient(String RemoteHost, RemoteCertificateValidationCallback RemoteCertificateValidator, X509Certificate ClientCert = null, IPPort RemotePort = null, DNSClient DNSClient = null) : base(RemoteHost, RemotePort != null ? RemotePort : IPPort.Parse(443), RemoteCertificateValidator, ClientCert, DNSClient) { }
// public LocalCertificateSelectionCallback ClientCertificateSelector { get; set; } #endregion #region Events #endregion #region Constructor(s) #region HTTPClient(RemoteIPAddress, RemotePort, RemoteCertificateValidator = null, ClientCert = null, DNSClient = null) /// <summary> /// Create a new HTTPClient using the given optional parameters. /// </summary> /// <param name="RemoteIPAddress">The remote IP address to connect to.</param> /// <param name="RemotePort">The remote IP port to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="DNSClient">An optional DNS client.</param> public HTTPClient(IIPAddress RemoteIPAddress, IPPort RemotePort, RemoteCertificateValidationCallback RemoteCertificateValidator = null, X509Certificate ClientCert = null, DNSClient DNSClient = null) { this.RemoteIPAddress = RemoteIPAddress; this.Hostname = RemoteIPAddress.ToString(); this.RemotePort = RemotePort; this.RemoteCertificateValidator = RemoteCertificateValidator; this.ClientCert = ClientCert; this.DNSClient = DNSClient == null ? new DNSClient() : DNSClient; }
/// <summary> /// Create a new abstract remote charging station operator attached via a computer network (HTTPS/TCP/IP). /// </summary> /// <param name="Hostname">The remote hostname.</param> /// <param name="VirtualHostname">An optional remote virtual hostname.</param> /// <param name="RemotePort">An optional remote HTTPS port.</param> /// <param name="RemoteCertificateValidator">An optional remote SSL/TLS certificate validator.</param> /// <param name="RoamingNetworkId">An optional roaming network identification.</param> /// <param name="RequestTimeout">An optional request timeout.</param> /// <param name="DNSClient">An optional DNS client to use.</param> public ANetworkChargingStationOperator(HTTPHostname Hostname, HTTPHostname?VirtualHostname = null, IPPort?RemotePort = null, RemoteCertificateValidationCallback RemoteCertificateValidator = null, RoamingNetwork_Id?RoamingNetworkId = null, TimeSpan?RequestTimeout = null, DNSClient DNSClient = null) { this.Hostname = Hostname; this.VirtualHostname = VirtualHostname ?? this.Hostname; this.RemotePort = RemotePort ?? DefaultRemotePort; this.RemoteCertificateValidator = RemoteCertificateValidator ?? ((sender, certificate, chain, policyErrors) => true); this.RoamingNetworkId = RoamingNetworkId ?? DefaultRoamingNetworkId; this.RequestTimeout = RequestTimeout ?? DefaultRequestTimeout; this.DNSClient = DNSClient; }
/// <summary> /// Create a new OICP Mobile client. /// </summary> /// <param name="ClientId">A unqiue identification of this client.</param> /// <param name="Hostname">The OICP hostname to connect to.</param> /// <param name="RemotePort">An optional OICP TCP port to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCertificateSelector">A delegate to select a TLS client certificate.</param> /// <param name="HTTPVirtualHost">An optional HTTP virtual host name to use.</param> /// <param name="HTTPUserAgent">An optional HTTP user agent to use.</param> /// <param name="RequestTimeout">An optional timeout for upstream queries.</param> /// <param name="MaxNumberOfRetries">The default number of maximum transmission retries.</param> /// <param name="DNSClient">An optional DNS client.</param> /// <param name="LoggingContext">An optional context for logging client methods.</param> /// <param name="LogfileCreator">A delegate to create a log file from the given context and log file name.</param> public MobileClient(String ClientId, HTTPHostname Hostname, IPPort?RemotePort = null, RemoteCertificateValidationCallback RemoteCertificateValidator = null, LocalCertificateSelectionCallback ClientCertificateSelector = null, HTTPHostname?HTTPVirtualHost = null, HTTPPath?URLPrefix = null, String MobileAuthorizationURL = DefaultMobileAuthorizationURL, String HTTPUserAgent = DefaultHTTPUserAgent, TimeSpan?RequestTimeout = null, Byte?MaxNumberOfRetries = DefaultMaxNumberOfRetries, DNSClient DNSClient = null, String LoggingContext = MobileClientLogger.DefaultContext, LogfileCreatorDelegate LogfileCreator = null) : base(ClientId, Hostname, RemotePort ?? DefaultRemotePort, RemoteCertificateValidator, ClientCertificateSelector, HTTPVirtualHost, URLPrefix ?? DefaultURLPrefix, null, HTTPUserAgent, RequestTimeout, null, MaxNumberOfRetries, DNSClient) { #region Initial checks if (ClientId.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(ClientId), "The given client identification must not be null or empty!"); } #endregion this.MobileAuthorizationURL = MobileAuthorizationURL ?? DefaultMobileAuthorizationURL; this.Logger = new MobileClientLogger(this, LoggingContext, LogfileCreator); }
/// <summary> /// Attach the OCPP UploadAPI to the given HTTP server. /// </summary> /// <param name="HTTPServer">A HTTP server.</param> /// <param name="URLPathPrefix">An optional prefix for the HTTP URIs.</param> /// <param name="HTTPRealm">The HTTP realm, if HTTP Basic Authentication is used.</param> /// <param name="HTTPLogins">An enumeration of logins for an optional HTTP Basic Authentication.</param> public UploadAPI(TestCentralSystem TestCentralSystem, HTTPServer HTTPServer, HTTPPath? URLPathPrefix = null, HTTPPath? BasePath = null, String HTTPRealm = DefaultHTTPRealm, IEnumerable<KeyValuePair<String, String>> HTTPLogins = null, String HTMLTemplate = null) : base(HTTPServer, null, null, // ExternalDNSName, null, // HTTPServiceName, BasePath, URLPathPrefix ?? DefaultURLPathPrefix, null, // HTMLTemplate, null, // APIVersionHashes, null, // DisableMaintenanceTasks, null, // MaintenanceInitialDelay, null, // MaintenanceEvery, null, // DisableWardenTasks, null, // WardenInitialDelay, null, // WardenCheckEvery, null, // IsDevelopment, null, // DevelopmentServers, null, // DisableLogging, null, // LoggingPath, null, // LogfileName, null, // LogfileCreator, true) // Autostart { this.CentralSystem = TestCentralSystem; this.HTTPRealm = HTTPRealm.IsNotNullOrEmpty() ? HTTPRealm : DefaultHTTPRealm; this.HTTPLogins = HTTPLogins ?? new KeyValuePair<String, String>[0]; this.DNSClient = HTTPServer.DNSClient; RegisterURITemplates(); }
protected ATests() { _DNSClient = new DNSClient(SearchForIPv6DNSServers: false); if (RemoteAddress == IPv4Address.Localhost) { //HTTPAPI = new HTTPServer<RoamingNetworks, RoamingNetwork>( // TCPPort: RemotePort, // DefaultServerName: "GraphDefined WWCP Unit Tests", // DNSClient: _DNSClient // ); OpenChargingCloudAPI = new OpenChargingCloudAPI(LocalPort: IPPort.Parse(8001)); //WWCPAPI.Attach_GeoJSON_IO(); OpenChargingCloudAPI.Start(); } }
/// <summary> /// Create a new HTTPClient using the given optional parameters. /// </summary> /// <param name="RemoteHost">The remote hostname to connect to.</param> /// <param name="RemotePort">The remote IP port to connect to.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="DNSClient">An optional DNS client.</param> public HTTPClient(String RemoteHost, IPPort RemotePort = null, RemoteCertificateValidationCallback RemoteCertificateValidator = null, X509Certificate ClientCert = null, DNSClient DNSClient = null) { this.Hostname = RemoteHost; this.RemotePort = RemotePort != null ? RemotePort : IPPort.Parse(80); this.RemoteCertificateValidator = RemoteCertificateValidator; this.ClientCert = ClientCert; this.DNSClient = DNSClient != null ? DNSClient : new DNSClient(); }
/// <summary> /// Create an abstract OICP v2.0 client. /// </summary> /// <param name="ClientId">A unqiue identification of this client.</param> /// <param name="Hostname">The OICP hostname to connect to.</param> /// <param name="TCPPort">The OICP TCP port to connect to.</param> /// <param name="HTTPVirtualHost">An optional HTTP virtual host name to use.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="UserAgent">An optional HTTP user agent to use.</param> /// <param name="QueryTimeout">An optional timeout for upstream queries.</param> /// <param name="DNSClient">An optional DNS client.</param> public ASOAPClient(String ClientId, String Hostname, IPPort TCPPort, String HTTPVirtualHost = null, RemoteCertificateValidationCallback RemoteCertificateValidator = null, String UserAgent = "GraphDefined eMobility", TimeSpan?QueryTimeout = null, DNSClient DNSClient = null) { #region Initial checks if (Hostname.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Hostname), "The given parameter must not be null or empty!"); } if (TCPPort == null) { throw new ArgumentNullException(nameof(TCPPort), "The given parameter must not be null!"); } #endregion this._Hostname = Hostname; this._TCPPort = TCPPort; this._HTTPVirtualHost = (HTTPVirtualHost != null) ? HTTPVirtualHost : Hostname; this._RemoteCertificateValidator = RemoteCertificateValidator; this._UserAgent = UserAgent; this._QueryTimeout = QueryTimeout != null ? QueryTimeout.Value : DefaultQueryTimeout; this._DNSClient = (DNSClient == null) ? new DNSClient() : DNSClient; }
/// <summary> /// Initialize the SOAP server using the given parameters. /// </summary> /// <param name="TCPPort">An IP port to listen on.</param> /// <param name="DefaultServerName">The default HTTP servername, used whenever no HTTP Host-header had been given.</param> /// <param name="SOAPContentType">The default HTTP content type used for all SOAP requests/responses.</param> /// <param name="X509Certificate">Use this X509 certificate for TLS.</param> /// <param name="CallingAssemblies">A list of calling assemblies to include e.g. into embedded ressources lookups.</param> /// <param name="ServerThreadName">The optional name of the TCP server thread.</param> /// <param name="ServerThreadPriority">The optional priority of the TCP server thread.</param> /// <param name="ServerThreadIsBackground">Whether the TCP server thread is a background thread or not.</param> /// <param name="ConnectionIdBuilder">An optional delegate to build a connection identification based on IP socket information.</param> /// <param name="ConnectionThreadsNameBuilder">An optional delegate to set the name of the TCP connection threads.</param> /// <param name="ConnectionThreadsPriorityBuilder">An optional delegate to set the priority of the TCP connection threads.</param> /// <param name="ConnectionThreadsAreBackground">Whether the TCP connection threads are background threads or not (default: yes).</param> /// <param name="ConnectionTimeout">The TCP client timeout for all incoming client connections in seconds (default: 30 sec).</param> /// <param name="MaxClientConnections">The maximum number of concurrent TCP client connections (default: 4096).</param> /// <param name="DNSClient">The DNS client to use.</param> /// <param name="Autostart">Start the HTTP server thread immediately (default: no).</param> public SOAPServer(IPPort TCPPort = null, String DefaultServerName = DefaultHTTPServerName, HTTPContentType SOAPContentType = null, X509Certificate2 X509Certificate = null, IEnumerable <Assembly> CallingAssemblies = null, String ServerThreadName = null, ThreadPriority ServerThreadPriority = ThreadPriority.AboveNormal, Boolean ServerThreadIsBackground = true, ConnectionIdBuilder ConnectionIdBuilder = null, ConnectionThreadsNameBuilder ConnectionThreadsNameBuilder = null, ConnectionThreadsPriorityBuilder ConnectionThreadsPriorityBuilder = null, Boolean ConnectionThreadsAreBackground = true, TimeSpan?ConnectionTimeout = null, UInt32 MaxClientConnections = TCPServer.__DefaultMaxClientConnections, DNSClient DNSClient = null, Boolean Autostart = false) : base(TCPPort, DefaultServerName, X509Certificate, CallingAssemblies, ServerThreadName, ServerThreadPriority, ServerThreadIsBackground, ConnectionIdBuilder, ConnectionThreadsNameBuilder, ConnectionThreadsPriorityBuilder, ConnectionThreadsAreBackground, ConnectionTimeout, MaxClientConnections, DNSClient, false) { this.SOAPContentType = SOAPContentType != null ? SOAPContentType : DefaultSOAPContentType; this._SOAPDispatchers = new Dictionary <String, SOAPDispatcher>(); if (Autostart) { Start(); } }
/// <summary> /// Create an abstract HTTP/JSON client. /// </summary> /// <param name="ClientId">A unqiue identification of this client.</param> /// <param name="Hostname">The hostname to connect to.</param> /// <param name="RemotePort">The remote TCP port to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="HTTPVirtualHost">An optional HTTP virtual host name to use.</param> /// <param name="UserAgent">An optional HTTP user agent to use.</param> /// <param name="QueryTimeout">An optional timeout for upstream queries.</param> /// <param name="DNSClient">An optional DNS client.</param> public AJSONClient(String ClientId, String Hostname, IPPort RemotePort, RemoteCertificateValidationCallback RemoteCertificateValidator = null, X509Certificate ClientCert = null, String HTTPVirtualHost = null, String UserAgent = DefaultHTTPUserAgent, TimeSpan? QueryTimeout = null, DNSClient DNSClient = null) : base(ClientId, Hostname, RemotePort, RemoteCertificateValidator, ClientCert, HTTPVirtualHost, UserAgent, QueryTimeout, DNSClient) { }
/// <summary> /// Create an abstract HTTP client. /// </summary> /// <param name="ClientId">A unqiue identification of this client.</param> /// <param name="Hostname">The hostname to connect to.</param> /// <param name="RemotePort">The remote TCP port to connect to.</param> /// <param name="RemoteCertificateValidator">A delegate to verify the remote TLS certificate.</param> /// <param name="ClientCert">The TLS client certificate to use.</param> /// <param name="HTTPVirtualHost">An optional HTTP virtual host name to use.</param> /// <param name="UserAgent">An optional HTTP user agent to use.</param> /// <param name="QueryTimeout">An optional timeout for upstream queries.</param> /// <param name="DNSClient">An optional DNS client.</param> public AHTTPClient(String ClientId, String Hostname, IPPort RemotePort, RemoteCertificateValidationCallback RemoteCertificateValidator = null, X509Certificate ClientCert = null, String HTTPVirtualHost = null, String UserAgent = DefaultHTTPUserAgent, TimeSpan? QueryTimeout = null, DNSClient DNSClient = null) { #region Initial checks if (Hostname.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Hostname), "The given parameter must not be null or empty!"); #endregion this.ClientId = ClientId; this.Hostname = Hostname; this.RemotePort = RemotePort ?? DefaultRemotePort; this.RemoteCertificateValidator = RemoteCertificateValidator; this.ClientCert = ClientCert; this.HTTPVirtualHost = HTTPVirtualHost.IsNotNullOrEmpty() ? HTTPVirtualHost : Hostname; this.UserAgent = UserAgent ?? DefaultHTTPUserAgent; this.RequestTimeout = QueryTimeout != null ? QueryTimeout.Value : DefaultQueryTimeout; this.DNSClient = DNSClient == null ? new DNSClient() : DNSClient; }
/// <summary> /// Initialize a new HTTP server for the HTTP/SOAP/XML Server API using IPAddress.Any. /// </summary> /// <param name="HTTPServerName">An optional identification string for the HTTP server.</param> /// <param name="TCPPort">An optional TCP port for the HTTP server.</param> /// <param name="URIPrefix">An optional prefix for the HTTP URIs.</param> /// <param name="SOAPContentType">The HTTP content type for SOAP messages.</param> /// <param name="DNSClient">An optional DNS client to use.</param> /// <param name="RegisterHTTPRootService">Register HTTP root services for sending a notice to clients connecting via HTML or plain text.</param> /// <param name="AutoStart">Start the server immediately.</param> public ASOAPServer(String HTTPServerName = DefaultHTTPServerName, IPPort TCPPort = null, String URIPrefix = DefaultURIPrefix, HTTPContentType SOAPContentType = null, Boolean RegisterHTTPRootService = true, DNSClient DNSClient = null, Boolean AutoStart = false) : this(new SOAPServer(TCPPort ?? DefaultHTTPServerPort, HTTPServerName, SOAPContentType ?? DefaultContentType, DNSClient: DNSClient, Autostart: false), URIPrefix) { if (RegisterHTTPRootService) RegisterRootService(); if (AutoStart) #pragma warning disable RECS0021 Start(); #pragma warning restore RECS0021 }
/// <summary> /// Create a new TCPClient connecting to a remote service using DNS SRV records. /// </summary> /// <param name="DNSName">The optional DNS name of the remote service to connect to.</param> /// <param name="ServiceName">The optional DNS SRV service name of the remote service to connect to.</param> /// <param name="UseIPv4">Whether to use IPv4 as networking protocol.</param> /// <param name="UseIPv6">Whether to use IPv6 as networking protocol.</param> /// <param name="PreferIPv6">Prefer IPv6 (instead of IPv4) as networking protocol.</param> /// <param name="ConnectionTimeout">The timeout connecting to the remote service.</param> /// <param name="DNSClient">An optional DNS client used to resolve DNS names.</param> /// <param name="AutoConnect">Connect to the TCP service automatically on startup. Default is false.</param> public TCPClient(String DNSName = "", String ServiceName = "", Boolean UseIPv4 = true, Boolean UseIPv6 = false, Boolean PreferIPv6 = false, Boolean UseTLS = false, TimeSpan? ConnectionTimeout = null, DNSClient DNSClient = null, Boolean AutoConnect = false) { this._RemoteHost = DNSName; this._ServiceName = ServiceName; this._UseIPv4 = UseIPv4; this._UseIPv6 = UseIPv6; this._PreferIPv6 = PreferIPv6; this._ConnectionTimeout = (ConnectionTimeout.HasValue) ? ConnectionTimeout.Value : TimeSpan.FromSeconds(60); this._DNSClient = (DNSClient != null) ? DNSClient : new DNSClient(SearchForIPv4DNSServers: _UseIPv4, SearchForIPv6DNSServers: _UseIPv6); if (AutoConnect) Connect(); }
internal GenericAPI(RoamingNetwork RoamingNetwork, String HTTPServerName = DefaultHTTPServerName, IPPort HTTPServerPort = null, String URIPrefix = "", Func<String, Stream> GetRessources = null, String ServiceName = DefaultHTTPServerName, EMailAddress APIEMailAddress = null, PgpPublicKeyRing APIPublicKeyRing = null, PgpSecretKeyRing APISecretKeyRing = null, String APIPassphrase = null, EMailAddressList APIAdminEMail = null, SMTPClient APISMTPClient = null, DNSClient DNSClient = null, String LogfileName = DefaultLogfileName) : this(RoamingNetwork, new HTTPServer(DefaultServerName: DefaultHTTPServerName).AttachTCPPorts(HTTPServerPort != null ? HTTPServerPort : DefaultHTTPServerPort), URIPrefix, GetRessources, ServiceName, APIEMailAddress, APIPublicKeyRing, APISecretKeyRing, APIPassphrase, APIAdminEMail, APISMTPClient, LogfileName) { }
/// <summary> /// Initialize the OCPI HTTP server using IPAddress.Any, http port 8080 and maybe start the server. /// </summary> internal GenericAPI(RoamingNetwork RoamingNetwork, HTTPServer HTTPServer, String URIPrefix = "/ext/OCPI", Func<String, Stream> GetRessources = null, String ServiceName = DefaultHTTPServerName, EMailAddress APIEMailAddress = null, PgpPublicKeyRing APIPublicKeyRing = null, PgpSecretKeyRing APISecretKeyRing = null, String APIPassphrase = null, EMailAddressList APIAdminEMail = null, SMTPClient APISMTPClient = null, String LogfileName = DefaultLogfileName) { #region Initial checks if (RoamingNetwork == null) throw new ArgumentNullException("RoamingNetwork", "The given parameter must not be null!"); if (HTTPServer == null) throw new ArgumentNullException("HTTPServer", "The given parameter must not be null!"); if (URIPrefix.IsNullOrEmpty()) throw new ArgumentNullException("URIPrefix", "The given parameter must not be null or empty!"); if (!URIPrefix.StartsWith("/")) URIPrefix = "/" + URIPrefix; #endregion #region Init data this._HTTPServer = HTTPServer; this._GetRessources = GetRessources; this._URIPrefix = URIPrefix; this._ServiceName = ServiceName; this._APIEMailAddress = APIEMailAddress; this._APIPublicKeyRing = APIPublicKeyRing; this._APISecretKeyRing = APISecretKeyRing; this._APIPassphrase = APIPassphrase; this._APIAdminEMail = APIAdminEMail; this._APISMTPClient = APISMTPClient; this._DNSClient = HTTPServer.DNSClient; #endregion RegisterURITemplates(); }
/// <summary> /// /// </summary> /// <param name="RemoteHost"></param> /// <param name="RemotePort"></param> /// <param name="UseIPv4">Whether to use IPv4 as networking protocol.</param> /// <param name="UseIPv6">Whether to use IPv6 as networking protocol.</param> /// <param name="PreferIPv6">Prefer IPv6 (instead of IPv4) as networking protocol.</param> /// <param name="UseTLS">Whether Transport Layer Security should be used or not.</param> /// <param name="ValidateServerCertificate">A callback for validating the remote server certificate.</param> /// <param name="ConnectionTimeout">The timeout connecting to the remote service.</param> /// <param name="DNSClient">An optional DNS client used to resolve DNS names.</param> /// <param name="AutoConnect">Connect to the TCP service automatically on startup. Default is false.</param> /// <param name="CancellationToken"></param> public TCPClient(String RemoteHost, IPPort RemotePort, Boolean UseIPv4 = true, Boolean UseIPv6 = false, Boolean PreferIPv6 = false, TLSUsage UseTLS = TLSUsage.STARTTLS, ValidateRemoteCertificateDelegate ValidateServerCertificate = null, TimeSpan? ConnectionTimeout = null, DNSClient DNSClient = null, Boolean AutoConnect = false, CancellationToken? CancellationToken = null) { this._RemoteHost = RemoteHost; this._RemotePort = RemotePort; this.CancellationToken = CancellationToken != null ? CancellationToken : new CancellationToken(); this._UseIPv4 = UseIPv4; this._UseIPv6 = UseIPv6; this._PreferIPv6 = PreferIPv6; this._UseTLS = UseTLS; this.ValidateServerCertificate = ValidateServerCertificate != null ? ValidateServerCertificate : (TCPClient, Certificate, CertificateChain, PolicyErrors) => false; this._ConnectionTimeout = (ConnectionTimeout.HasValue) ? ConnectionTimeout.Value : TimeSpan.FromSeconds(60); this._DNSClient = (DNSClient == null) ? new DNSClient(SearchForIPv6DNSServers: true) : DNSClient; if (AutoConnect) Connect(); }
/// <summary> /// Initialize the SOAP server using the given parameters. /// </summary> /// <param name="TCPPort">An IP port to listen on.</param> /// <param name="DefaultServerName">The default HTTP servername, used whenever no HTTP Host-header had been given.</param> /// <param name="SOAPContentType">The default HTTP content type used for all SOAP requests/responses.</param> /// <param name="X509Certificate">Use this X509 certificate for TLS.</param> /// <param name="CallingAssemblies">A list of calling assemblies to include e.g. into embedded ressources lookups.</param> /// <param name="ServerThreadName">The optional name of the TCP server thread.</param> /// <param name="ServerThreadPriority">The optional priority of the TCP server thread.</param> /// <param name="ServerThreadIsBackground">Whether the TCP server thread is a background thread or not.</param> /// <param name="ConnectionIdBuilder">An optional delegate to build a connection identification based on IP socket information.</param> /// <param name="ConnectionThreadsNameBuilder">An optional delegate to set the name of the TCP connection threads.</param> /// <param name="ConnectionThreadsPriorityBuilder">An optional delegate to set the priority of the TCP connection threads.</param> /// <param name="ConnectionThreadsAreBackground">Whether the TCP connection threads are background threads or not (default: yes).</param> /// <param name="ConnectionTimeout">The TCP client timeout for all incoming client connections in seconds (default: 30 sec).</param> /// <param name="MaxClientConnections">The maximum number of concurrent TCP client connections (default: 4096).</param> /// <param name="DNSClient">The DNS client to use.</param> /// <param name="Autostart">Start the HTTP server thread immediately (default: no).</param> public SOAPServer(IPPort TCPPort = null, String DefaultServerName = DefaultHTTPServerName, HTTPContentType SOAPContentType = null, X509Certificate2 X509Certificate = null, IEnumerable<Assembly> CallingAssemblies = null, String ServerThreadName = null, ThreadPriority ServerThreadPriority = ThreadPriority.AboveNormal, Boolean ServerThreadIsBackground = true, ConnectionIdBuilder ConnectionIdBuilder = null, ConnectionThreadsNameBuilder ConnectionThreadsNameBuilder = null, ConnectionThreadsPriorityBuilder ConnectionThreadsPriorityBuilder = null, Boolean ConnectionThreadsAreBackground = true, TimeSpan? ConnectionTimeout = null, UInt32 MaxClientConnections = TCPServer.__DefaultMaxClientConnections, DNSClient DNSClient = null, Boolean Autostart = false) : base(TCPPort, DefaultServerName, X509Certificate, CallingAssemblies, ServerThreadName, ServerThreadPriority, ServerThreadIsBackground, ConnectionIdBuilder, ConnectionThreadsNameBuilder, ConnectionThreadsPriorityBuilder, ConnectionThreadsAreBackground, ConnectionTimeout, MaxClientConnections, DNSClient, false) { this.SOAPContentType = SOAPContentType != null ? SOAPContentType : DefaultSOAPContentType; this._SOAPDispatchers = new Dictionary<String, SOAPDispatcher>(); if (Autostart) Start(); }
/// <summary> /// Create a new SMTP client for sending e-mails. /// </summary> /// <param name="RemoteHost"></param> /// <param name="RemotePort"></param> /// <param name="Login"></param> /// <param name="Password"></param> /// <param name="LocalDomain"></param> /// <param name="UseIPv4">Whether to use IPv4 as networking protocol.</param> /// <param name="UseIPv6">Whether to use IPv6 as networking protocol.</param> /// <param name="PreferIPv6">Prefer IPv6 (instead of IPv4) as networking protocol.</param> /// <param name="UseTLS">Whether Transport Layer Security should be used or not.</param> /// <param name="ValidateServerCertificate">A callback for validating the remote server certificate.</param> /// <param name="ConnectionTimeout">The timeout connecting to the remote service.</param> /// <param name="DNSClient">An optional DNS client used to resolve DNS names.</param> /// <param name="AutoConnect">Connect to the TCP service automatically on startup. Default is false.</param> /// <param name="CancellationToken"></param> public SMTPClient(String RemoteHost, IPPort RemotePort, String Login = null, String Password = null, String LocalDomain = null, Boolean UseIPv4 = true, Boolean UseIPv6 = false, Boolean PreferIPv6 = false, TLSUsage UseTLS = TLSUsage.STARTTLS, ValidateRemoteCertificateDelegate ValidateServerCertificate = null, TimeSpan? ConnectionTimeout = null, DNSClient DNSClient = null, Boolean AutoConnect = false, CancellationToken? CancellationToken = null) : base(RemoteHost, RemotePort, UseIPv4, UseIPv6, PreferIPv6, UseTLS, ValidateServerCertificate, ConnectionTimeout, DNSClient, AutoConnect, CancellationToken) { this._Login = Login; this._Password = Password; this._LocalDomain = (LocalDomain != null) ? LocalDomain : System.Net.Dns.GetHostName(); this._UnknownAuthMethods = new List<String>(); }