Example #1
0
        public ClientBase(ClientEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            _endpoint = endpoint;
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
                }
            }
        }