Пример #1
0
        private void btnGetStateBlock_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(txtIPAddr.Text);

            myConnection.BravaPort = Int16.Parse(txtIPPort.Text);

            RequestStateBlock myRequest = new RequestStateBlock();

            BravaSocket mySocket = new BravaSocket(myRequest, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

                myRequest.ParseResultStream();

                MessageBox.Show(myRequest.ResultXML.OuterXml);

            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Пример #2
0
        private System.Xml.XmlDocument readSwitchStateXML(System.Net.IPAddress destIPAdr, Int16 destPortNum)
        {
            RequestStateBlock myRequest = new RequestStateBlock((byte)BravaCodes.StateBlockRecords.SwitchBankLS8);
            BravaConnection myConnection = new BravaConnection();
            BravaSocket mySocket = new BravaSocket(myRequest, myConnection);

            try
            {
                // Prepare Connection Parameters.
                myConnection.BravaIP = destIPAdr;
                myConnection.BravaPort = destPortNum;

                // Enact / Transmit the Request.
                mySocket.DoTransaction();

                if (myRequest.State == BravaTransaction.TransactionState.Completed)
                {
                    myRequest.ParseResultStream();
                }

                if (myRequest.State == BravaTransaction.TransactionState.Failed)
                {
                    MessageBox.Show("Transaction Failed.");
                }

                //MessageBox.Show(myRequest.ResultXML.OuterXml);

                return myRequest.ResultXML;

            }
            catch (System.Net.Sockets.SocketException ex)
            {
                if ((ex.ErrorCode == 10061) || (ex.ErrorCode == 10060) || (ex.ErrorCode == 10065) )
                {
                    return null;
                }
                else
                {
                    throw ex;
                }

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                mySocket.SocketClient.Close();
            }
        }