コード例 #1
0
        private void ParseData()
        {
            if (this.cbkANSI.Checked)
            {
                return;
            }
            Iso8583Data iso8583Data = (Iso8583Data)null;

            try
            {
                if (this.cbkSmartlinkTemplate.Checked)
                {
                    iso8583Data             = new Iso8583Data(BitTemplate.GetSmartlinkTemplate());
                    iso8583Data.HasHeader   = false;
                    iso8583Data.LengthInAsc = true;
                }
                else
                {
                    iso8583Data = new Iso8583Data(this.SpecificTemplate);
                }
                iso8583Data.EMVShowOptions = E_EMVShowOption.Len | E_EMVShowOption.VALUE | E_EMVShowOption.NAME | E_EMVShowOption.DESCRIPTION | E_EMVShowOption.BITS;
                iso8583Data.Unpack(this.DataConverted(this.txtRawMessage, this.cbkANSI.Checked));
                this.txtParsedText.Text = iso8583Data.LogFormat();
            }
            catch (Exception ex)
            {
                this.txtParsedText.Text = ex.ToString() + "\r\n" + iso8583Data.LogFormat(iso8583Data.LastBitError);
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string      str         = this.txtRawMessage.Text.Replace(" ", "").Replace("\r\n", ";");
            Iso8583Data iso8583Data = new Iso8583Data();

            string[] strArray = str.Split(';');
            for (int index = 0; index < strArray.Length; ++index)
            {
                iso8583Data.PackBit(int.Parse(strArray[index].Split(':')[0]), strArray[index].Split(':')[1]);
            }
            this.txtParsedText.Text = IsoUltil.BytesToHexString(iso8583Data.Pack(), 16, true);
        }
コード例 #3
0
 private void PackData()
 {
     if (this.cbkSmarlinkTemplate.Checked)
     {
         this.iso8583             = new Iso8583Data(BitTemplate.GetSmartlinkTemplate());
         this.iso8583.HasHeader   = false;
         this.iso8583.LengthInAsc = true;
     }
     else
     {
         this.iso8583 = new Iso8583Data(this.template);
         this.iso8583.TPDUHeader.UnPack(IsoUltil.StringToBCD(this.txtTPDU.Text, 10));
     }
     this.iso8583.MessageType = int.Parse(this.txtMTI.Text);
     foreach (DataGridViewRow row in (IEnumerable)this.grvIso8583.Rows)
     {
         if (row.IsNewRow)
         {
             break;
         }
         this.iso8583.PackBit(int.Parse(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString());
     }
 }
コード例 #4
0
        public void DoSendTCPIP()
        {
            Iso8583Data iso8583Data = (Iso8583Data)null;

            this.ParseData();
            TransmittedData transmittedData = new TransmittedData((EMessageLengthType)this.cboLengthType.SelectedIndex);

            this.btnSendTCPIP.Enabled = false;
            try
            {
                iso8583Data = new Iso8583Data();
                if (this.ckbSslEnable.Checked == true)
                {
                    for (int index = 0; (Decimal)index < this.numSendTimes.Value; ++index)
                    {
                        try
                        {
                            this.txtRawResponse.Text = "";

                            int hostBytesRead = 0;
                            int timeout       = 30;

                            string _message    = txtRawMessage.Text;
                            byte[] hostMessage = new byte[4096];
                            byte[] message     = new byte[4096];
                            hostBytesRead = 0;

                            int inLengthFormat = 0;
                            switch (this.cboLengthType.SelectedIndex)
                            {
                            case 0:
                                inLengthFormat = 2;
                                break;

                            case 1:
                                inLengthFormat = 1;
                                break;

                            default:
                                inLengthFormat = 0;
                                break;
                            }
                            string szLogMsg = "";
                            hostMessage = SslSetup.HexString2Bytes(_message, inLengthFormat, out szLogMsg);
                            SslClient sslHostClient = new SslClient(txtServer.Text.Trim(), int.Parse(txtPort.Text.Trim())
                                                                    , SslProtocols.Tls, timeout);
                            int inConnect = sslHostClient.Connect();
                            sslHostClient.Send(hostMessage);

                            hostBytesRead = sslHostClient.Receive(ref message);
                            if (hostBytesRead > 0)
                            {
                                String content = BitConverter.ToString(message, 0, hostBytesRead).Replace("-", "");

                                if (content.Length > 4)
                                {
                                    txtRawResponse.Text = content.Substring(2, content.Length - 2);
                                    iso8583Data.Unpack(message, 2, message.Length - 2);
                                    this.txtResponse.Text = iso8583Data.LogFormat();
                                }
                            }
                        }
                        catch { }
                    }
                }
                else
                {
                    TcpClient client = (TcpClient)null;

                    if (this.ckbOneConnection.Checked)
                    {
                        client = new TcpClient(this.txtServer.Text, int.Parse(this.txtPort.Text));
                    }
                    for (int index = 0; (Decimal)index < this.numSendTimes.Value; ++index)
                    {
                        try
                        {
                            if (!this.ckbOneConnection.Checked)
                            {
                                client = new TcpClient(this.txtServer.Text, int.Parse(this.txtPort.Text));
                            }
                            this.txtRawResponse.Text = "";
                            client.GetStream().ReadTimeout = 100000;
                            transmittedData.Write(client.GetStream(), this.DataConverted(this.txtRawMessage, this.cbkANSI.Checked));
                            client.GetStream().Flush();
                            if (this.cbkANSI.Checked)
                            {
                                this.txtRawResponse.Text = Encoding.Default.GetString(this.buffer, 0, client.Client.Receive(this.buffer));
                            }
                            else
                            {
                                transmittedData.Read(client, (int)this.numericUpDown1.Value, false);
                                this.txtRawResponse.Text = IsoUltil.BytesToHexString(transmittedData.ReadMessage, 20, false);
                                iso8583Data.Unpack(transmittedData.ReadMessage);
                                this.txtResponse.Text = iso8583Data.LogFormat();
                            }
                            if (!this.ckbOneConnection.Checked)
                            {
                                client.Client.Shutdown(SocketShutdown.Both);
                                client.Client.Disconnect(false);
                                client.Client.Close();
                            }
                            if (this.numInterval.Value > new Decimal(0))
                            {
                                Thread.Sleep((int)this.numInterval.Value);
                            }
                        }
                        catch (Exception ex)
                        {
                            this.txtResponse.Text = ex.ToString() + "\r\n";
                            if (iso8583Data != null)
                            {
                                this.txtResponse.Text += iso8583Data.LogFormat(iso8583Data.LastBitError);
                            }
                            if (this.cbkStopWhenError.Checked)
                            {
                                throw ex;
                            }
                        }
                    }
                    if (this.ckbOneConnection.Checked)
                    {
                        client.Client.Shutdown(SocketShutdown.Both);
                        client.Client.Disconnect(false);
                        client.Client.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                this.txtResponse.Text = ex.ToString() + "\r\n";
                if (iso8583Data != null)
                {
                    this.txtResponse.Text += iso8583Data.LogFormat(iso8583Data.LastBitError);
                }
            }
            this.btnSendTCPIP.Enabled = true;
            this.thrSending           = (Thread)null;
        }