コード例 #1
0
        /// <summary>
        /// Creates a new Client instance with the specified parameters
        /// </summary>
        /// <param name="listener">The Listener used for callbacks</param>
        /// <param name="uri">The URI of the GDS instance</param>
        /// <param name="userName">The username used for communication. Cannot be null or empty</param>
        /// <param name="userPassword">The password used for password authentication. Null otherwise</param>
        /// <param name="timeout">Timeout used for the connection establishment. Value most be strictly positive</param>
        /// <param name="cert">The certificate used for TLS authentication</param>
        /// <param name="log">The log used by the client.</param>
        /// <param name="PingPongInterval">The interval used to send automatic ping-pong in seconds</param>
        public AsyncGDSClient(IGDSMessageListener listener, string uri, string userName, SecureString userPassword, int timeout, X509Certificate2 cert, ILog log, int PingPongInterval)
        {
            this.listener = Utils.RequireNonNull(listener, "The message listener cannot be set to null!");

            Utils.RequireNonNull(uri, "The URI cannot be set to null!");
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("The username cannot be null, empty or set to only whitespaces!");
            }

            if (timeout < 1)
            {
                throw new ArgumentOutOfRangeException(string.Format("The timeout must be to positive! (Specified: {0})", timeout));
            }

            countdown = new CountdownEvent(1);
            if (log == null)
            {
                log4net.Config.BasicConfigurator.Configure(LogManager.GetRepository(System.Reflection.Assembly.GetEntryAssembly()));
                this.log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            }
            else
            {
                this.log = log;
            }
            this.userName     = userName;
            this.userPassword = userPassword;
            this.timeout      = timeout;

            if (PingPongInterval < 1)
            {
                throw new ArgumentOutOfRangeException(string.Format("The ping-pong interval must be to positive! (Specified: {0})", PingPongInterval));
            }
            this.PingPongInterval = PingPongInterval;

            state = ConnectionState.NOT_CONNECTED;

            websocketClient = new WebSocket(uri, sslProtocols: SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13);
            if (cert != null)
            {
                //The GDS uses self-signed certificate therefore we have to enable them to be used for the protocol
                websocketClient.Security.AllowCertificateChainErrors  = true;
                websocketClient.Security.AllowNameMismatchCertificate = true;

                websocketClient.Security.Certificates.Add(cert);
            }
        }
コード例 #2
0
 /// <summary>
 /// Sets the listener for the builder to be used when instantiating the client
 /// </summary>
 /// <param name="value">The new value to be used</param>
 /// <returns>itself</returns>
 public AsyncGDSClientBuilder WithListener(IGDSMessageListener value)
 {
     listener = value;
     return(this);
 }