Пример #1
0
        } // IPWTCPort_OnReadyToSend

        private void OnDataIn(IAGWEngineWindow window, byte[] buffer, int length)
        {
            int intDataLength;

            while (true)
            {
                try
                {
                    if (buffer == null)
                    {
                        break;
                    }
                    Globals.ConcatanateByteArrays(ref bytTCPData, buffer); // Add data to buffer array
                    if (bytTCPData.Length < 36)
                    {
                        break;                                              // not a complete frame header
                    }
                    intDataLength = Globals.ComputeLengthL(bytTCPData, 28); // get and decode the data length field from the header
                    if (bytTCPData.Length < 36 + intDataLength)
                    {
                        break; // not A complete "G" frame...
                    }
                    if (((char)bytTCPData[4]).ToString() != "G")
                    {
                        bytTCPData = new byte[0];
                        return;
                    }

                    _testWaitHandle.Set();
                    window.SetRemoteButtonStatus(true, IAGWEngineWindow.ButtonStatus.SUCCESS);
                    objTCPPort.Close();
                    objTCPPort = null;
                }
                catch (Exception ex)
                {
                    _log.Error("[AGWEngine, tcpOnDataIn] " + ex.Message);
                    window.SetRemoteButtonStatus(true, IAGWEngineWindow.ButtonStatus.FAILED);
                }
                break;
            }

            Task <int> t = null;

            try
            {
                t = objTCPPort.GetStream().ReadAsync(buffer, 0, 1024);
                t.ContinueWith(k =>
                {
                    OnDataIn(window, buffer, k.Result);
                });
                t.Wait(0);
            }
            catch (Exception e)
            {
                // empty
            }
        } // objTCPPort_OnDataIn
Пример #2
0
        public void TestProposedSettings(IAGWEngineWindow window, string host, int port, string userId, string password)
        {
            if (objTCPPort != null)
            {
                objTCPPort.Close();
                objTCPPort = null;
            }

            objTCPPort = new TcpClient();
            if (Globals.strLocalIPAddress != "Default")
            {
                objTCPPort.Client.Bind(new IPEndPoint(IPAddress.Parse(Globals.strLocalIPAddress), 0));
            }

            _testWaitHandle.Reset();
            objTCPPort.ConnectAsync(host.Trim(), port).ContinueWith(t =>
            {
                OnConnected(objTCPPort, window, userId.Trim(), password.Trim());

                byte[] buffer = new byte[1024];

                Task <int> task = null;
                try
                {
                    task = objTCPPort.GetStream().ReadAsync(buffer, 0, 1024);
                    task.ContinueWith(t =>
                    {
                        OnDataIn(window, buffer, t.Result);
                    });
                    task.Wait(0);
                }
                catch (Exception e)
                {
                    // empty
                }
            }).Wait(0);

            if (!_testWaitHandle.WaitOne(10000))
            {
                throw new TimeoutException();
            }
            else
            {
                window.SetRemoteButtonStatus(true, IAGWEngineWindow.ButtonStatus.SUCCESS);
            }
        }
Пример #3
0
        } // objTCPPort_OnDataIn

        private void LoginAGWRemote(IAGWEngineWindow window, string username, string password)
        {
            // Private Sub to Login to remote AGWPE with UserID and password ("P" Frame)...

            try
            {
                var bytTemp2 = new byte[546];
                var asc      = new ASCIIEncoding(); // had to declare this to eliminate an ocasional error
                asc.GetBytes("P", 0, 1, bytTemp2, 4);
                Array.Copy(Globals.ComputeLengthB(255 + 255), 0, bytTemp2, 28, 4);
                asc.GetBytes(username, 0, username.Length, bytTemp2, 36);
                asc.GetBytes(password, 0, password.Length, bytTemp2, 36 + 255);
                objTCPPort.GetStream().Write(bytTemp2, 0, bytTemp2.Length);;
            }
            catch (Exception ex)
            {
                _log.Error("[AGWEngine, LoginAGWRemote] " + ex.Message);
                _testWaitHandle.Set();
                window.SetRemoteButtonStatus(true, IAGWEngineWindow.ButtonStatus.FAILED);
            }
        } // LoginAGWRemote
Пример #4
0
        } // LoginAGWRemote

        private void RequestAGWPortInfo(IAGWEngineWindow window)
        {
            // Private Sub to Request AGW Port Information ("G" Frame)...

            var bytTemp = new byte[36];

            try
            {
                if (!objTCPPort.Connected)
                {
                    return;
                }
                bytTemp[4] = (byte)Globals.Asc('G');
                objTCPPort.GetStream().Write(bytTemp, 0, bytTemp.Length);;
            }
            catch (Exception ex)
            {
                _log.Error("[AGWEngine, RequestAGWPortInfo] " + ex.Message);
                _testWaitHandle.Set();
                window.SetRemoteButtonStatus(true, IAGWEngineWindow.ButtonStatus.FAILED);
            }
        } // RequestAGWPortInfo