Exemplo n.º 1
0
        public ClientBase(ClientEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            _endpoint = endpoint;
        }
Exemplo n.º 2
0
        public ClientBase Create(ClientEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            var type = Build();

            return(Activator.CreateInstance(type, new object[] { endpoint }) as ClientBase);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create dynamic client
        /// </summary>
        /// <typeparam name="T">client interface type</typeparam>
        /// <param name="endpoint">server remote endpoint</param>
        /// <param name="credentials">credentials</param>
        /// <returns></returns>
        public static T Create <T>(ClientEndpoint endpoint, IClientCredentials?credentials = null)
            where T : class
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (!typeof(T).IsInterface)
            {
                throw new ArgumentException("T must be an interface");
            }

            var factory = _kvTypeBuilder.GetOrAdd(typeof(T), _kvTypeBuilderFactory);
            var client  = factory.Create(endpoint);

            client._credentials = credentials;
            return((T)(object)client);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create dynamic client
        /// </summary>
        /// <param name="clientType">client interface type</param>
        /// <param name="endpoint">server remote endpoint</param>
        /// <param name="credentials">credentials</param>
        /// <returns></returns>
        public static object Create(Type clientType, ClientEndpoint endpoint, IClientCredentials?credentials = null)
        {
            if (clientType == null)
            {
                throw new ArgumentNullException(nameof(clientType));
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (!clientType.IsInterface)
            {
                throw new ArgumentException("T must be an interface");
            }

            var factory = _kvTypeBuilder.GetOrAdd(clientType, _kvTypeBuilderFactory);
            var client  = factory.Create(endpoint);

            client._credentials = credentials;
            return(client);
        }
Exemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                try
                {
                    Connected    = null;
                    Disconnected = null;

                    if (Active)
                    {
                        DoClosed();
                    }
                    if (disposing)
                    {
                        _endpoint = null;
                    }
                }
                catch
                {
                    base.Dispose(disposing);
                }
            }
        }