Exemplo n.º 1
0
        /// <summary>
        /// Go through the records stored in this message, parse them and assign
        /// them to the individual properties. This also checks if the child records
        /// are actually valid for a Handover Select message.
        /// </summary>
        public void SetAndAssignChildRecords(byte[] payloadToParse)
        {
            // Create NDEF message based on payload
            var childRecordsMsg = NdefMessage.FromByteArray(payloadToParse);

            // Clear previous child records
            _handoverAlternativeCarrierRecords = null;
            _handoverErrorRecord = null;

            // Assign new child records from the source message
            if (childRecordsMsg.Count < 1)
            {
                throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
            }

            foreach (var curChildRecord in childRecordsMsg)
            {
                // Alternate carrier record
                if (curChildRecord.CheckSpecializedType(false) == typeof(NdefHandoverAlternativeCarrierRecord))
                {
                    if (HandoverErrorRecord != null)
                    {
                        // Error record needs to be last - there can't be an AC record
                        // after we have already found an error record.
                        throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
                    }
                    if (_handoverAlternativeCarrierRecords == null)
                    {
                        _handoverAlternativeCarrierRecords = new List <NdefHandoverAlternativeCarrierRecord>();
                    }
                    _handoverAlternativeCarrierRecords.Add(new NdefHandoverAlternativeCarrierRecord(curChildRecord));
                }
                else if (curChildRecord.CheckSpecializedType(false) == typeof(NdefHandoverErrorRecord))
                {
                    if (_handoverErrorRecord != null)
                    {
                        // Only one error record is allowed
                        throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
                    }
                    _handoverErrorRecord = new NdefHandoverErrorRecord(curChildRecord);
                }
                else
                {
                    // Unknown record found that should not be in this message
                    throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Checks the type name format and type of this record and returns
 /// the appropriate specialized class, if one is available and known
 /// for this record type.
 /// </summary>
 /// <param name="checkForSubtypes">If set to true, also checks for
 /// subtypes of the URL / SmartPoster record where the library offers
 /// a convenient handling class - e.g. for SMS or Mailto records,
 /// which are actually URL schemes.</param>
 /// <returns>Type name of the specialized class that can understand
 /// and manipulate the payload through convenience methods.</returns>
 public Type CheckSpecializedType(bool checkForSubtypes)
 {
     // Note: can't check for specialized types like the geo record
     // or the SMS record yet, as these are just convenience classes
     // for creating URI / Smart Poster records.
     if (checkForSubtypes)
     {
         // Need to check specialized URI / Sp records before checking for base types.
         if (NdefSmsRecord.IsRecordType(this))
         {
             return(typeof(NdefSmsRecord));
         }
         if (NdefMailtoRecord.IsRecordType(this))
         {
             return(typeof(NdefMailtoRecord));
         }
         if (NdefTelRecord.IsRecordType(this))
         {
             return(typeof(NdefTelRecord));
         }
         if (NdefWindowsSettingsRecord.IsRecordType(this))
         {
             return(typeof(NdefWindowsSettingsRecord));
         }
     }
     // Unique / base record types
     if (NdefUriRecord.IsRecordType(this))
     {
         return(typeof(NdefUriRecord));
     }
     if (NdefSpRecord.IsRecordType(this))
     {
         return(typeof(NdefSpRecord));
     }
     if (NdefTextRecord.IsRecordType(this))
     {
         return(typeof(NdefTextRecord));
     }
     if (NdefSpActRecord.IsRecordType(this))
     {
         return(typeof(NdefSpActRecord));
     }
     if (NdefSpSizeRecord.IsRecordType(this))
     {
         return(typeof(NdefSpSizeRecord));
     }
     if (NdefSpMimeTypeRecord.IsRecordType(this))
     {
         return(typeof(NdefSpMimeTypeRecord));
     }
     if (NdefLaunchAppRecord.IsRecordType(this))
     {
         return(typeof(NdefLaunchAppRecord));
     }
     if (NdefAndroidAppRecord.IsRecordType(this))
     {
         return(typeof(NdefAndroidAppRecord));
     }
     if (NdefVcardRecordBase.IsRecordType(this))
     {
         return(typeof(NdefVcardRecordBase));
     }
     if (NdefIcalendarRecordBase.IsRecordType(this))
     {
         return(typeof(NdefIcalendarRecordBase));
     }
     if (NdefBtSecureSimplePairingRecord.IsRecordType(this))
     {
         return(typeof(NdefBtSecureSimplePairingRecord));
     }
     if (NdefHandoverSelectRecord.IsRecordType(this))
     {
         return(typeof(NdefHandoverSelectRecord));
     }
     if (NdefHandoverErrorRecord.IsRecordType(this))
     {
         return(typeof(NdefHandoverErrorRecord));
     }
     if (NdefHandoverAlternativeCarrierRecord.IsRecordType(this))
     {
         return(typeof(NdefHandoverAlternativeCarrierRecord));
     }
     if (NdefMimeImageRecordBase.IsRecordType(this))
     {
         return(typeof(NdefMimeImageRecordBase));
     }
     return(typeof(NdefRecord));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Go through the records stored in this message, parse them and assign
        /// them to the individual properties. This also checks if the child records
        /// are actually valid for a Handover Select message.
        /// </summary>
        public void SetAndAssignChildRecords(byte[] payloadToParse)
        {
            // Create NDEF message based on payload
            var childRecordsMsg = NdefMessage.FromByteArray(payloadToParse);

            // Clear previous child records
            _handoverAlternativeCarrierRecords = null;
            _handoverErrorRecord = null;

            // Assign new child records from the source message
            if (childRecordsMsg.Count < 1)
            {
                throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
            }

            foreach (var curChildRecord in childRecordsMsg)
            {
                // Alternate carrier record
                if (curChildRecord.CheckSpecializedType(false) == typeof(NdefHandoverAlternativeCarrierRecord))
                {
                    if (HandoverErrorRecord != null)
                    {
                        // Error record needs to be last - there can't be an AC record
                        // after we have already found an error record.
                        throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
                    }
                    if (_handoverAlternativeCarrierRecords == null)
                    {
                        _handoverAlternativeCarrierRecords = new List<NdefHandoverAlternativeCarrierRecord>();
                    }
                    _handoverAlternativeCarrierRecords.Add(new NdefHandoverAlternativeCarrierRecord(curChildRecord));
                }
                else if (curChildRecord.CheckSpecializedType(false) == typeof(NdefHandoverErrorRecord))
                {
                    if (_handoverErrorRecord != null)
                    {
                        // Only one error record is allowed
                        throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
                    }
                    _handoverErrorRecord = new NdefHandoverErrorRecord(curChildRecord);
                }
                else
                {
                    // Unknown record found that should not be in this message
                    throw new NdefException(NdefExceptionMessages.ExHandoverSelectMsgInvalidRecords);
                }
            }
        }