Пример #1
0
        public String PostRequest(Iso8583Request req)
        {
            byte[] reqMsg = null;
            if (req.RequestString != null)
            {
                String sReq = req.RequestString.Trim();
                if (String.IsNullOrEmpty(sReq))
                {
                    throw new HttpResponseException(HttpStatusCode.NoContent);
                }
                System.Text.RegularExpressions.Regex ws = new System.Text.RegularExpressions.Regex(@"\s+");
                sReq   = ws.Replace(sReq, "");
                reqMsg = MessageUtility.StringToHex(sReq, true);
                if (reqMsg == null)
                {
                    //throw new HttpResponseException(HttpStatusCode.InternalServerError);
                    _outputData = "Error: Invalid request message string (not valid hexadecimal)";
                }
            }

            try
            {
                MessageClient client = new MessageClient(req.ServerHost, req.ServerPort, null, this.PrintModel);
                client.IsSslEnabled = req.IsSSL;

                if (req.RequestString != null)
                {
                    if (reqMsg != null)
                    {
                        client.SendBytes(reqMsg);
                    }
                }
                else
                {
                    client.Model = HttpContext.Current.Session != null ? HttpContext.Current.Session["model"] : null;
                    if (client.Model != null)
                    {
                        _iso8583ResponseEvent.Reset();
                        client.SendModel();
                        _iso8583ResponseEvent.WaitOne();
                    }
                    else
                    {
                        _outputData = "Error: Invalid request message (cannot be null value)";
                    }
                }
            }
            catch
            {
                //throw new HttpResponseException(HttpStatusCode.InternalServerError);
                _outputData = "Error: Cannot send request message to ISO 8583 server.";
            }

            if (_outputData.IndexOf("Error: ") == 0)
            {
                Logger.GetInstance().WriteLine(_outputData);
            }

            return(_outputData);
        }
Пример #2
0
        private void SetMediaCode(Object value)
        {
            byte val = 0;

            if (value is byte[])
            {
                _bytes = (byte[])value;
                val    = (byte)((_bytes[0] << 4) | (_bytes[1] >> 4));
            }
            else
            {
                if (value is PosEntryMediaModeBytes)
                {
                    val = (byte)value;
                }
                else if (value is String)
                {
                    byte[] vals = MessageUtility.StringToHex(value.ToString());
                    if (vals == null || vals.Length != 1)
                    {
                        throw new MessageProcessorException("POSEntryMode.MediaCodeString: Invalid value.");
                    }
                    val = vals[0];
                }
                else
                {
                    return;
                }
                _bytes[0] = (byte)(val >> 4);
                _bytes[1] = (byte)((_bytes[1] & 0x0f) | (val << 4));
            }
            _mediaCode        = (PosEntryMediaModeBytes)val;
            _mediaCodeString  = MessageUtility.HexToString(val);
            _mediaDescription = MEDIA.ContainsKey(_mediaCode) ? MEDIA[_mediaCode] : null;
        }
Пример #3
0
        private void SetPinEntryCode(Object value)
        {
            byte val = 0;

            if (value is byte[])
            {
                _bytes = (byte[])value;
                val    = (byte)(_bytes[1] & 0x0f);
            }
            else
            {
                if (value is PosEntryPinModeBytes)
                {
                    val = (byte)value;
                }
                else if (value is String)
                {
                    byte[] vals = MessageUtility.StringToHex(value.ToString());
                    if (vals == null || vals.Length != 1 || ((vals[0] & 0xf0) != 0))
                    {
                        throw new MessageProcessorException("POSEntryMode.PinEntryCodeString: Invalid value.");
                    }
                    val = vals[0];
                }
                else
                {
                    return;
                }
                _bytes[1] = (byte)((_bytes[1] & 0xf0) | val);
            }
            _pinEntryCode        = (PosEntryPinModeBytes)val;
            _pinEntryCodeString  = MessageUtility.HexToString(val).Substring(1);
            _pinEntryDescription = PIN_ENTRY.ContainsKey(_pinEntryCode) ? PIN_ENTRY[_pinEntryCode] : null;
        }
Пример #4
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (_isAttributeConfig != chkConfig.Checked)
            {
                if (!LoadConfig())
                {
                    return;
                }
            }

            byte[] reqMsg = null;
            if (_reqModel == null)
            {
                String sReq = txtRequest.Text.Trim();
                if (String.IsNullOrEmpty(sReq))
                {
                    return;
                }
                Regex ws = new Regex(@"\s+");
                sReq   = ws.Replace(sReq, "");
                reqMsg = MessageUtility.StringToHex(sReq, true);
                if (reqMsg == null)
                {
                    MessageBox.Show("Invalid hexadecimal string.");
                }
            }

            try
            {
                _client = new MessageClient(txtServerHost.Text, int.Parse(txtServerPort.Text), null, this.PrintModel);
                _client.IsSslEnabled = chkSsl.Checked;

                /*if (_client.IsSslEnabled)
                 * {
                 *  _client.ClientCertificates = _certificates;
                 *  _client.CertificateSelectionCallback = this.LocalCertificateSelectionCallback;
                 *  _client.CertificateValidationCallback = this.RemoteCertificateValidationCallback;
                 * }*/

                if (_reqModel == null)
                {
                    Thread thread = new Thread(_client.SendBytes);
                    thread.Start(reqMsg);
                }
                else
                {
                    _client.Model = _reqModel;
                    _client.SendModel();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot connect to the server." + Environment.NewLine + ex.Message);
            }
            finally
            {
                btnStop_Click(sender, e);
            }
        }
Пример #5
0
        public static Response0810 ProcessRequest(Request0800 request)
        {
            Console.WriteLine("==== Begin: Request ====");
            Console.WriteLine(Util.GetReadableStringFromModel(request));
            Console.WriteLine("==== End: Request ====");

            Response0810 resp = new Response0810
            {
                TransmissionDateTime = DateTime.Now,

                /*SystemAuditTraceNumber = request.SystemAuditTraceNumber,
                 * AdditionalData = request.AdditionalData,
                 * NetworkManagementInformationCode = request.NetworkManagementInformationCode,*/
                ResponseCode = "00",
                MessageAuthenticationCode = MessageUtility.StringToHex("0102030405060708")
            };

            return(resp);
        }
        public ActionResult Index()
        {
            Type   modelType = EditedItems.Item[Request.Form["_EditedItem"]].DefaultModel.GetType();
            Object model     = Activator.CreateInstance(modelType);

            String[] inputNames = Request.Form.AllKeys;
            foreach (String inputName in inputNames)
            {
                if (inputName.IndexOf("chk") == 0 || inputName == "_EditedItem" || String.IsNullOrEmpty(inputName))
                {
                    continue;
                }
                Object       obj       = model;
                String       value     = Request.Form[inputName];
                String[]     propNames = inputName.Split('.');
                PropertyInfo propInfo  = modelType.GetProperty(propNames[0]);
                if (Request.Form["chk" + propNames[0]] != null) //The property value is null
                {
                    propInfo.SetValue(model, null, null);
                }
                else
                {
                    Type propType = propInfo.PropertyType;
                    if (propNames.Length > 1)
                    {
                        if (propNames[0] == "AdditionalData")
                        {
                            propType = typeof(RequestDataEntry48);
                        }
                        if (propInfo.GetValue(model, null) == null)
                        {
                            obj = Activator.CreateInstance(propType);
                            propInfo.SetValue(model, obj, null);
                        }
                        else
                        {
                            obj = propInfo.GetValue(model, null);
                        }
                        propInfo = propType.GetProperty(propNames[1]);
                        propType = propInfo.PropertyType;
                    }

                    //propType.IsValueType

                    if (propType == typeof(String))
                    {
                        propInfo.SetValue(obj, value, null);
                    }
                    else if (propType == typeof(int) || propType == typeof(int?))
                    {
                        propInfo.SetValue(obj, int.Parse("0" + value), null);
                    }
                    else if (propType == typeof(decimal) || propType == typeof(decimal?))
                    {
                        propInfo.SetValue(obj, decimal.Parse("0" + value), null);
                    }
                    else if (propType == typeof(DateTime) || propType == typeof(DateTime?))
                    {
                        propInfo.SetValue(obj, DateTimeConverter.GetDateTime(value), null);
                    }
                    else if (propType == typeof(byte[]))
                    {
                        propInfo.SetValue(obj, MessageUtility.StringToHex(value), null);
                    }
                }
            }

            Session["model"] = model;
            return(Redirect("~/"));
        }
Пример #7
0
 public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
 {
     return(MessageUtility.StringToHex(existingValue.ToString(), true));
 }