Пример #1
0
        internal OysterEncoder.Command SendCommandWaitForResponse(OysterEncoder.Command cmd)
        {
            //log.Context = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;
            OysterEncoder.Command retcmd = null;
            string sLastErrorMessage = "";
            try
            {
                cmd.Write(m_TCPClient.GetStream());
            }
            catch (System.IO.IOException ioex)
            {
                if (null != ioex.InnerException)
                {
                    if (ioex.InnerException is System.Net.Sockets.SocketException)
                    {
                        int iErrorCode = ((System.Net.Sockets.SocketException)ioex.InnerException).ErrorCode;
                        string sErrorMessage = ((System.Net.Sockets.SocketException)ioex.InnerException).Message;
                        sLastErrorMessage = "SendCommand: Error Code = " + iErrorCode.ToString() + " Description = " + sErrorMessage;

                    }
                    else
                    {
                        sLastErrorMessage = "SendCommand: Unknown Error detected. Description = " + ioex.Message;
                    }
                }
                m_bDone = true;
                m_bConnected = false;
            }
            catch (System.Exception ex)
            {
                sLastErrorMessage = "SendCommand: Unknown Error detected. Description = " + ex.Message;
                m_bDone = true;
                m_bConnected = false;
            }
            if(!this.Connected)
            {
                log.WriteLog(sLastErrorMessage);
                OnConnectionErrorReceived(this,sLastErrorMessage);
            }
            #if DEBUG
            if (m_EventMessageAvailable.WaitOne(25000,false))
            #else
            if (m_EventMessageAvailable.WaitOne(3000,false))
            #endif
            {
                lock (m_qCommands.SyncRoot)
                {
                    if (m_qCommands.Count > 0)
                    {
                        retcmd = (OysterEncoder.Command)m_qCommands.Dequeue();
                    }
                }
            }
            else
            {
                log.WriteLog("WaitOne timed out waiting for a return message.");
            }
            return retcmd;
        }
Пример #2
0
        internal void SendCommand(OysterEncoder.Command cmd)
        {
            string sLastErrorMessage = "";

            try
            {
                cmd.Write(m_TCPClient.GetStream());
            }
            catch (System.IO.IOException ioex)
            {
                if (null != ioex.InnerException)
                {
                    if (ioex.InnerException is System.Net.Sockets.SocketException)
                    {
                        int iErrorCode = ((System.Net.Sockets.SocketException)ioex.InnerException).ErrorCode;
                        string sErrorMessage = ((System.Net.Sockets.SocketException)ioex.InnerException).Message;
                        sLastErrorMessage = "SendCommand: Error Code = " + iErrorCode.ToString() + " Description = " + sErrorMessage;

                    }
                    else
                    {
                        sLastErrorMessage = "SendCommand: Unknown Error detected. Description = " + ioex.Message;
                    }
                }
                m_bDone = true;
                m_bConnected = false;
            }
            catch (System.Exception ex)
            {
                sLastErrorMessage = "SendCommand: Unknown Error detected. Description = " + ex.Message;
                m_bDone = true;
                m_bConnected = false;
            }
            if(!m_bConnected)
            {
                log.WriteLog(sLastErrorMessage);
                OnConnectionErrorReceived(this,sLastErrorMessage);
            }
        }