Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument ();
            doc.Load (@"../../../update_request.xml");
            XmlNode node = doc.SelectSingleNode ("./Message/ISO8583Message");

            //Create the on us values
            Dictionary<string, string> OnUsValues = new Dictionary<string, string> ();
            OnUsValues.Add ("AccountNumber", "1234567890123456");
            OnUsValues.Add ("UpdateRequest", "1234567890123456 20120701 20120801");
            OnUsValues.Add ("DeviceID", "0000000012345678");
            OnUsValues.Add ("SerialNumber", "000012345678");
            OnUsValues.Add ("BranchCode", "1512");
            OnUsValues.Add ("BankId", "1234");

            //Initialize the parser engine
            parser = new ISO8583Parser (node);

            //Create the ISO8583 request
            ISO8583Message Message = parser.CreateISO8583Request ("Common:AccountInfo", OnUsValues, "1200"); //Combine the categories to populate the object with required values
            Message.LogMessageEvent += new EventHandler<DebugNotify> (parser_LogMessageEvent);
            byte[] t = Message.Serialize ();
            Console.WriteLine (ASCIIEncoding.ASCII.GetString (t));
            Console.WriteLine (Message.DumpISO8583State ());
            Console.WriteLine ();
            ISO8583Message ParsedMessage = new ISO8583Message ();
            if (ParsedMessage.ParseResponse (t)) {
                Console.WriteLine (ParsedMessage.DumpISO8583State ());
            }
            Console.ReadKey ();
        }
Exemplo n.º 2
0
        public ISO8583Message CreateRequest(string Categories, Dictionary<string, string> NewOnUsValues, string MTIValue, bool IsSecondaryBitmapPresent)
        {
            ISO8583Message Message = new ISO8583Message(this.BitmapRegionType, IsSecondaryBitmapPresent);
            this._OnUsValues = NewOnUsValues;
            if (string.IsNullOrEmpty(Categories))
                throw new ArgumentException("Category cannot be null");
            else if (Categories.Contains("Response"))
                throw new ArgumentException("Cannot use the Response category to create requests");
            else {
                Message.IsoFields.Clear();
                string[] IndividualCategories = Categories.Trim().Split(':');
                Message.MessageType = MTIValue;
                foreach (string item in IndividualCategories) {
                    if (AllCategories.ContainsKey(item.Trim())) {
                        List<ISO8583Field> CategoryFields = AllCategories[item];
                        foreach (ISO8583Field field in CategoryFields) {

                            //Resolve the dynamic values just before creating the request
                            if (IsDynamicField(field.FieldValue))
                                field.FieldValue = ResolveDynamicValue(field.FieldValue);

                            try {
                                Message.AddField(field);
                            } catch (ArgumentException) {
                                throw new ArgumentException("The Categories supplied have one or more common "+
                                                            "fields...failed to create ISO8583Message");
                            }
                        }
                    } else
                        throw new ArgumentException("Invalid Category " + item + " requested");
                }
                return Message;
            }
        }