Пример #1
0
        private void GetCategories()
        {
            XmlNodeList KeysXml = this.RequestXml.SelectNodes("ISO8583Fields");
            foreach (XmlNode item in KeysXml) {
                XmlAttribute CategoryAttr = item.Attributes["Category"];
                if (CategoryAttr != null) {
                    string CategoryID = CategoryAttr.Value;
                    List<ISO8583Field> CategoryFields = new List<ISO8583Field>();
                    XmlNodeList FieldsXml = item.SelectNodes("Field");
                    foreach (XmlNode Field in FieldsXml) {
                        ISO8583Field isoField = new ISO8583Field();

                        // Reading the required attributes.
                        XmlAttribute IndexAttribute = Field.Attributes["Index"];
                        XmlAttribute HeaderAttribute = Field.Attributes["Header"];
                        XmlAttribute MaxLengthAttribute = Field.Attributes["MaxLength"];

                        ISO8583MessageElement Index = (ISO8583MessageElement)(Convert.ToInt32(IndexAttribute.Value) - 1);
                        if (IndexAttribute != null && MaxLengthAttribute != null) {
                            isoField.FieldIndex = Index;
                            isoField.IsFieldEnabled = true;
                            string tmpFieldValue = Field.InnerXml;
                            if (isoField.FieldHeaderLength.Equals(0) && tmpFieldValue.Contains("|"))
                                tmpFieldValue = this.CheckForUserPadding(tmpFieldValue, ref isoField);

                            isoField.FieldValue = tmpFieldValue;
                            try {
                                Length tmp = new Length();
                                tmp.FieldLength = isoField.FieldLength = Convert.ToInt32(MaxLengthAttribute.Value);
                                tmp.HeaderLength = isoField.FieldHeaderLength =
                                    (HeaderAttribute == null) ? 0 : Convert.ToInt32(HeaderAttribute.Value);
                                if (ISO8583Message.isoFieldLengths.ContainsKey(Index))
                                    ISO8583Message.isoFieldLengths[Index] = tmp;
                                else
                                    ISO8583Message.isoFieldLengths.Add(Index, tmp);
                            } catch (Exception) {
                                throw;
                            }
                            CategoryFields.Add(isoField);
                        } else
                            throw new XmlException("Invalid XML: A field in Category " + CategoryID +
                                                   " has a missing attribute, " + Index.ToString());
                    }
                    AllCategories.Add(CategoryID, CategoryFields);
                } else {
                    throw new XmlException("Invalid XML: Invalid category provided");
                }
            }
        }
Пример #2
0
 // TODO: We should be able to ignore the '|' value escaped using '\', just like in the printf statement
 private string CheckForUserPadding(string FieldValue, ref ISO8583Field _IsoField)
 {
     string[] tmp = FieldValue.Split('|');
     if (tmp[0].Length.Equals(tmp[1].Length) && tmp[0].Length <= 1) {
         if (tmp[0].Equals(tmp[1])) {
             _IsoField.PaddingChar = '0';
             return tmp[0];
         } else
             throw new XmlException(string.Format("Invalid padding info provided in field {0}, "+
                                                     "please check the input Xml", _IsoField.FieldIndex));
     } else if (tmp[0].Length > tmp[1].Length && tmp[1].Length <= 1) { //implies that field should be right padded
         _IsoField.PaddingPlacement = Padding.Right;
         _IsoField.PaddingChar = string.IsNullOrEmpty(tmp[1]) ? ' ' : tmp[1][0];
         return tmp[0];
     } else {
         _IsoField.PaddingPlacement = Padding.Left;
         _IsoField.PaddingChar = string.IsNullOrEmpty(tmp[0]) ? ' ' : tmp[0][0];
         return tmp[1];
     }
 }