Example #1
0
 public void SetFieldEncoder(int fieldNumber, ISOFieldEncoder encoder)
 {
     if (_fields != null)
     {
         if (_fields.ContainsKey(fieldNumber))
         {
             _fields[fieldNumber] = encoder;
         }
     }
 }
Example #2
0
        protected void ReadConfigurationData(string xmlData)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(xmlData);

            XmlNodeList fields = xDoc.GetElementsByTagName("isofield");

            if (fields != null)
            {
                _fields = new Hashtable(fields.Count);

                // Read xml file content and create the list with the configuration for each field
                for (int i = 0; i < fields.Count; i++)
                {
                    try {
                        int    id        = Convert.ToInt32(fields[i].Attributes["id"].Value);
                        int    len       = Convert.ToInt32(fields[i].Attributes["len"].Value);
                        string name      = fields[i].Attributes["name"].Value;
                        string className = fields[i].Attributes["class"].Value;

                        // Create encoder instance
                        // TODO: Change for a more generic method capable of loading classes from other assemblies
                        ISOFieldEncoder fEncoder = (ISOFieldEncoder)Activator.CreateInstance(Type.GetType(className), len, name);

                        _fields.Add(id, fEncoder);
                    }
                    catch (Exception e) {
                        throw new ISOException(string.Format("Exception loading iso field configuration (Index={0})", i), e);
                    }
                }
            }
            else
            {
                throw new ISOException(string.Format("Packager configuration file {0} is not valid", FileName));
            }
        }
Example #3
0
 public void SetFieldEncoder(int fieldNumber, ISOFieldEncoder encoder)
 {
     if (_fields != null) {
         if (_fields.ContainsKey(fieldNumber)) {
             _fields[fieldNumber] = encoder;
         }
     }
 }
Example #4
0
        public byte[] Encode(ISOComponent component)
        {
            // Loop in each field, encode it a put into a list, where the maximum number may be 128
            List <byte[]> list = new List <byte[]>(128);

            SortedList <int, object> children = component.GetChildren();

            if (children != null)
            {
                int          len = 0;
                byte[]       b;
                byte[]       header = null;
                ISOComponent c;

                // if it's message get header length
                if (component is ISOMessage)
                {
                    if (HeaderLength > 0 && ((ISOMessage)component).Header != null)
                    {
                        header = ((ISOMessage)component).Header.Value;
                        if (header != null)
                        {
                            len += header.Length;
                        }
                    }
                }

                // MTI
                c = (ISOComponent)children[0];
                if (FirstField > 0 && c != null)
                {
                    b    = ((ISOFieldEncoder)_fields[0]).Encode(c);
                    len += b.Length;
                    list.Add(b);
                }

                // Bitmap
                if (HasBitmap)
                {
                    c = (ISOComponent)children[-1];
                    if (c != null)
                    {
                        b    = GetBitmapEncoder().Encode(c);
                        len += b.Length;
                        list.Add(b);
                    }
                }

                // Fields
                foreach (int k in children.Keys)
                {
                    if (k >= FirstField)
                    {
                        if ((c = (ISOComponent)children[k]) != null)
                        {
                            ISOFieldEncoder fe = (ISOFieldEncoder)_fields[k];
                            if (fe == null)
                            {
                                throw new ISOException(string.Format("No encoder defined for field {0}", k));
                            }

                            b    = fe.Encode(c);
                            len += b.Length;
                            list.Add(b);
                        }
                    }
                }



                // TODO: ++ Process Extended Bitmap ++



                // Build final message
                int    count = 0;
                byte[] msg   = new byte[len];

                if (header != null)
                {
                    Array.Copy(header, 0, msg, 0, header.Length);
                    count += header.Length;
                }

                for (int i = 0; i < list.Count; i++)
                {
                    Array.Copy(list[i], 0, msg, count, list[i].Length);
                    count += list[i].Length;
                }

                return(msg);
            }

            return(null);
        }