Beispiel #1
0
        // This private .ctor handles both of the public overloads which take connectionString
        HybridConnectionListener(string connectionString, string path, bool pathFromConnectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw RelayEventSource.Log.ArgumentNull(nameof(connectionString), this);
            }

            var builder = new RelayConnectionStringBuilder(connectionString);

            builder.Validate();

            if (pathFromConnectionString)
            {
                if (string.IsNullOrWhiteSpace(builder.EntityPath))
                {
                    // connectionString did not have required EntityPath
                    throw RelayEventSource.Log.Argument(nameof(connectionString), SR.GetString(SR.ConnectionStringMustIncludeEntityPath, nameof(HybridConnectionClient)), this);
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(path))
                {
                    // path parameter is required
                    throw RelayEventSource.Log.ArgumentNull(nameof(path), this);
                }
                else if (!string.IsNullOrWhiteSpace(builder.EntityPath))
                {
                    // EntityPath must not appear in connectionString
                    throw RelayEventSource.Log.Argument(nameof(connectionString), SR.GetString(SR.ConnectionStringMustNotIncludeEntityPath, nameof(HybridConnectionListener)), this);
                }

                builder.EntityPath = path;
            }

            this.Address = new Uri(builder.Endpoint, builder.EntityPath);
            this.ConnectionBufferSize = DefaultConnectionBufferSize;
            this.OperationTimeout     = builder.OperationTimeout;
            this.proxy                     = DefaultWebProxy.Instance;
            this.TrackingContext           = TrackingContext.Create(this.Address);
            this.connectionInputQueue      = new InputQueue <HybridConnectionStream>();
            this.controlConnection         = new ControlConnection(this);
            this.useBuiltInClientWebSocket = HybridConnectionConstants.DefaultUseBuiltInClientWebSocket;
            this.ClientWebSocketFactory    = Microsoft.Azure.Relay.ClientWebSocketFactory.Default;
            this.KeepAliveInterval         = HybridConnectionConstants.KeepAliveInterval;

            this.TokenProvider = builder.CreateTokenProvider();
            if (this.TokenProvider == null)
            {
                throw RelayEventSource.Log.Argument(nameof(connectionString), SR.CannotCreateTokenProviderFromConnectionString, this);
            }
        }
Beispiel #2
0
        // This private .ctor handles both of the public overloads which take connectionString
        HybridConnectionClient(string connectionString, string path, bool pathFromConnectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw RelayEventSource.Log.ArgumentNull(nameof(connectionString), this);
            }

            var builder = new RelayConnectionStringBuilder(connectionString);

            builder.Validate();

            if (pathFromConnectionString)
            {
                if (string.IsNullOrWhiteSpace(builder.EntityPath))
                {
                    // EntityPath is required in connectionString.
                    throw RelayEventSource.Log.Argument(nameof(connectionString), SR.GetString(SR.ConnectionStringMustIncludeEntityPath, nameof(HybridConnectionClient)), this);
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(path))
                {
                    // path is required outside of connectionString
                    throw RelayEventSource.Log.ArgumentNull(nameof(path), this);
                }
                else if (!string.IsNullOrWhiteSpace(builder.EntityPath))
                {
                    // connectionString is not allowed to include EntityPath
                    throw RelayEventSource.Log.Argument(nameof(connectionString), SR.GetString(SR.ConnectionStringMustNotIncludeEntityPath, nameof(HybridConnectionClient)), this);
                }

                builder.EntityPath = path;
            }

            TokenProvider tokenProvider = null;

            if (!string.IsNullOrEmpty(builder.SharedAccessSignature) || !string.IsNullOrEmpty(builder.SharedAccessKeyName))
            {
                tokenProvider = builder.CreateTokenProvider();
            }

            TimeSpan connectTimeout = DefaultConnectTimeout;

            if (builder.OperationTimeout != RelayConstants.DefaultOperationTimeout)
            {
                // Only change from our default (70 seconds) if it appears user has changed the OperationTimeout in the connectionString.
                connectTimeout = builder.OperationTimeout;
            }

            this.Initialize(new Uri(builder.Endpoint, builder.EntityPath), connectTimeout, tokenProvider, tokenProvider != null);
        }
        // This private .ctor handles both of the public overloads which take connectionString
        HybridConnectionListener(string connectionString, string path, bool pathFromConnectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw RelayEventSource.Log.ArgumentNull(nameof(connectionString), this);
            }

            var builder = new RelayConnectionStringBuilder(connectionString);

            builder.Validate();

            if (pathFromConnectionString)
            {
                if (string.IsNullOrWhiteSpace(builder.EntityPath))
                {
                    // connectionString did not have required EntityPath
                    throw RelayEventSource.Log.Argument(nameof(connectionString), SR.GetString(SR.ConnectionStringMustIncludeEntityPath, nameof(HybridConnectionClient)), this);
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(path))
                {
                    // path parameter is required
                    throw RelayEventSource.Log.ArgumentNull(nameof(path), this);
                }
                else if (!string.IsNullOrWhiteSpace(builder.EntityPath))
                {
                    // EntityPath must not appear in connectionString
                    throw RelayEventSource.Log.Argument(nameof(connectionString), SR.GetString(SR.ConnectionStringMustNotIncludeEntityPath, nameof(HybridConnectionListener)), this);
                }

                builder.EntityPath = path;
            }

            this.Address              = new Uri(builder.Endpoint, builder.EntityPath);
            this.TokenProvider        = builder.CreateTokenProvider();
            this.ConnectionBufferSize = DefaultConnectionBufferSize;
            this.OperationTimeout     = builder.OperationTimeout;
            this.proxy           = WebRequest.DefaultWebProxy;
            this.TrackingContext = TrackingContext.Create(this.Address);

            this.clientConnections    = new Dictionary <string, DataConnection>();
            this.connectionInputQueue = new InputQueue <HybridConnectionStream>();
            this.controlConnection    = new ControlConnection(this);
        }