/// <summary>
        ///     Hadles Elapsed event of _reconnectTimer.
        /// </summary>
        /// <param name="sender">Source of the event</param>
        /// <param name="e">Event arguments</param>
        private void ReconnectTimer_Elapsed(object sender, EventArgs e)
        {
            if (_disposed || _client.CommunicationState == CommunicationStates.Connected)
            {
                _reconnectTimer.Stop();
                return;
            }

            try {
                _client.Connect();
                _reconnectTimer.Stop();
            } catch {
                // No need to catch since it will try to re-connect again
            }
        }
        /// <summary>
        ///     Overrides message calls and translates them to messages to remote application.
        /// </summary>
        /// <param name="msg">Method invoke message (from RealProxy base class)</param>
        /// <returns>Method invoke return message (to RealProxy base class)</returns>
        public override IMessage Invoke(IMessage msg)
        {
            if (_client.CommunicationState == CommunicationStates.Connected)
            {
                // If already connected, behave as base class (RemoteInvokeProxy).
                return(base.Invoke(msg));
            }

            // Connect, call method and finally disconnect
            _client.Connect();
            try {
                return(base.Invoke(msg));
            } finally {
                _client.Disconnect();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Hadles Elapsed event of _reconnectTimer.
        /// </summary>
        /// <param name="sender">Source of the event</param>
        /// <param name="e">Event arguments</param>
        private void ReconnectTimer_Elapsed(object sender, EventArgs e)
        {
            if (_disposed || _client.CommunicationState == CommunicationStates.Connected)
            {
                _reconnectTimer.Stop();
                return;
            }

            try
            {
                _client.Connect();
                _reconnectTimer.Stop();
            }
            catch (Exception exception)
            {
                //No need to catch since it will try to re-connect again
                System.Diagnostics.Trace.Write($"ReconnectTimer_Elapsed: {exception}");
            }
        }
        /// <summary>
        /// 将方法调用转换为远程方法调用
        /// </summary>
        /// <param name="method">代理方法</param>
        /// <param name="parameters">代理参数</param>
        /// <returns>方法返回结果</returns>
        public override object Intercept(MethodInfo method, object[] parameters)
        {
            if (_client.CommunicationState == CommunicationStates.Connected)
            {
                //If already connected, behave as base class (RemoteInvokeProxy).
                return(base.Intercept(method, parameters));
            }

            //Connect, call method and finally disconnect
            _client.Connect();
            try
            {
                return(base.Intercept(method, parameters));
            }
            finally
            {
                _client.Disconnect();
            }
        }