Exemplo n.º 1
0
 /// <summary>
 /// Get a copy of an existing CHPN field
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public CField GetField(int id)
 {
     try
     {
         CField f = new CField(Fields[id]);
         return(f);
     }
     catch (System.Exception) { return(null); }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an APDU from an existing buffer building a database of fields as contained inside the APDU
        /// </summary>
        /// <param name="buffer">The buffer to scan to search the fields.</param>
        public CAPDU(byte[] buffer)
        {
            int offset = 0;

            // get message ID
            ID = new CAPDUID(buffer, offset, ref offset);
            if (0 != ID.Value)
            {
                // Get the bitmap
                Bitmap = new CBitmap(buffer, offset, ref offset);
                if (Bitmap.IsSet)
                {
                    // arrived here we can process the fields described inside the bitmap
                    CFields fields = new CFields();

                    // offset now points to the beginning of the fields - WE ONLY CONSIDER BITMAP1 as bitmap2 fields are not described in the dictionary
                    for (int field = 2; field <= 0xFF && 0 < buffer.Length - offset; field++)
                    {
                        if (Bitmap.IsBitSet(field))
                        {
                            // create and retrieve field
                            //CField fg = fields.GetField(field);
                            //CField f = new CField(fg.ID, fg.Type, fg.Minlen, fg.Maxlen);
                            CField f = fields.GetField(field);
                            if (f.SetData(buffer, offset, out offset))
                            {
                                // save the field inside the list of fields
                                try
                                {
                                    AddField(f);
                                }
                                catch (Exception ex)
                                {
                                    CLog.AddException(MethodBase.GetCurrentMethod().Name, ex, "CHAMP: " + field);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add a field to the message
 /// </summary>
 /// <param name="f">The field to add <see cref="CField"/></param>
 /// <returns>The string representation of the field</returns>
 public string AddField(CField f)
 {
     try
     {
         if (0 != f.RawdataLen)
         {
             Fields.Add(f.ID, f);
             Bitmap.SetBit(f.ID);
             return(f.ToString());
         }
         else
         {
             return(string.Empty);
         }
     }
     catch (Exception ex)
     {
         CLog.AddException(MethodBase.GetCurrentMethod().Name, ex);
         return(string.Empty);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Create the list of fields defined in the CHPN protocol
        /// </summary>
        public CFields()
        {
            CField f = new CField(2, FieldType.NUMERIC, 0, 19);

            Fields.Add(f.ID, f);

            f = new CField(3, FieldType.NUMERIC, 6, 6);
            Fields.Add(f.ID, f);

            f = new CField(4, FieldType.NUMERIC, 12, 12);
            Fields.Add(f.ID, f);

            f = new CField(7, FieldType.NUMERIC, 10, 10);
            Fields.Add(f.ID, f);

            f = new CField(11, FieldType.NUMERIC, 6, 6);
            Fields.Add(f.ID, f);

            f = new CField(12, FieldType.NUMERIC, 6, 6);
            Fields.Add(f.ID, f);

            f = new CField(13, FieldType.NUMERIC, 4, 4);
            Fields.Add(f.ID, f);

            f = new CField(18, FieldType.NUMERIC, 4, 4);
            Fields.Add(f.ID, f);

            f = new CField(22, FieldType.NUMERIC, 3, 3);
            Fields.Add(f.ID, f);

            f = new CField(25, FieldType.NUMERIC, 2, 2);
            Fields.Add(f.ID, f);

            f = new CField(32, FieldType.NUMERIC, 1, 11);
            Fields.Add(f.ID, f);

            f = new CField(35, FieldType.CMC7, 0, 35);
            Fields.Add(f.ID, f);

            f = new CField(37, FieldType.ALPHA_NUMERIC, 12, 12);
            Fields.Add(f.ID, f);

            f = new CField(38, FieldType.ALPHA_NUMERIC, 6, 6);
            Fields.Add(f.ID, f);

            f = new CField(39, FieldType.ALPHA_NUMERIC, 2, 2);
            Fields.Add(f.ID, f);

            f = new CField(40, FieldType.ALPHA_NUMERIC, 3, 3);
            Fields.Add(f.ID, f);

            f = new CField(41, FieldType.EXTENDED_ALPHA_NUMERIC, 8, 8);
            Fields.Add(f.ID, f);

            f = new CField(42, FieldType.EXTENDED_ALPHA_NUMERIC, 15, 15);
            Fields.Add(f.ID, f);

            f = new CField(43, FieldType.EXTENDED_ALPHA_NUMERIC, 40, 40);
            Fields.Add(f.ID, f);

            f = new CField(44, FieldType.EXTENDED_ALPHA_NUMERIC, 20, 25);
            Fields.Add(f.ID, f);

            f = new CField(45, FieldType.NUMERIC, 15, 15);
            Fields.Add(f.ID, f);

            f = new CField(46, FieldType.NUMERIC, 4, 4);
            Fields.Add(f.ID, f);

            f = new CField(47, FieldType.BINARY, 1, 65535, true);
            Fields.Add(f.ID, f);

            f = new CField(48, FieldType.BINARY, 1, 65535, true);
            Fields.Add(f.ID, f);

            f = new CField(49, FieldType.NUMERIC, 4, 4);
            Fields.Add(f.ID, f);
        }