Example #1
0
        /// <summary>
        /// Deletes any details currently stored in the Smart Poster
        /// and re-initializes them by parsing the contents of the payload.
        /// </summary>
        private void ParsePayloadToData(byte[] payload)
        {
            InitializeData();
            if (payload == null || payload.Length == 0)
            {
                return;
            }

            var message = NdefMessage.FromByteArray(payload);

            foreach (NdefRecord record in message)
            {
                var specializedType = record.CheckSpecializedType(false);
                if (specializedType == null)
                {
                    continue;
                }

                if (specializedType == typeof(NdefUriRecord))
                {
                    // URI
                    RecordUri = new NdefUriRecord(record);
                }
                else if (specializedType == typeof(NdefTextRecord))
                {
                    // Title
                    var textRecord = new NdefTextRecord(record);
                    if (Titles == null)
                    {
                        Titles = new List <NdefTextRecord>();
                    }
                    Titles.Add(textRecord);
                }
                else if (specializedType == typeof(NdefSpActRecord))
                {
                    // Action
                    _recordAction = new NdefSpActRecord(record);
                }
                else if (specializedType == typeof(NdefSpSizeRecord))
                {
                    // Size
                    _recordSize = new NdefSpSizeRecord(record);
                }
                else if (specializedType == typeof(NdefSpMimeTypeRecord))
                {
                    // Mime Type
                    _recordMimeType = new NdefSpMimeTypeRecord(record);
                }
                else if (specializedType == typeof(NdefMimeImageRecordBase))
                {
                    // Image
                    _recordImage = new NdefMimeImageRecordBase(record);
                }
                else
                {
                    Debug.WriteLine("Sp: Don't know how to handle this record: " +
                                    BitConverter.ToString(record.Type));
                }
            }
        }
Example #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));
 }
Example #3
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>
 /// <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 (NdefNokiaAccessoriesRecord.IsRecordType(this))
         {
             return(typeof(NdefNokiaAccessoriesRecord));
         }
         if (NdefNearSpeakRecord.IsRecordType(this))
         {
             return(typeof(NdefNearSpeakRecord));
         }
         if (NdefWpSettingsRecord.IsRecordType(this))
         {
             return(typeof(NdefWpSettingsRecord));
         }
     }
     // 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));
     }
     return(typeof(NdefRecord));
 }
Example #4
0
        /// <summary>
        /// Deletes any details currently stored in the Smart Poster 
        /// and re-initializes them by parsing the contents of the payload.
        /// </summary>
        private void ParsePayloadToData(byte[] payload)
        {
            InitializeData();
            if (payload == null || payload.Length == 0)
                return;

            var message = NdefMessage.FromByteArray(payload);

            foreach (NdefRecord record in message)
            {
                var specializedType = record.CheckSpecializedType(false);
                if (specializedType == null) continue;

                if (specializedType == typeof(NdefUriRecord))
                {
                    // URI
                    RecordUri = new NdefUriRecord(record);
                }
                else if (specializedType == typeof (NdefTextRecord))
                {
                    // Title
                    var textRecord = new NdefTextRecord(record);
                    if (Titles == null) Titles = new List<NdefTextRecord>();
                    Titles.Add(textRecord);
                }
                else if (specializedType == typeof (NdefSpActRecord))
                {
                    // Action
                    _recordAction = new NdefSpActRecord(record);
                }
                else if (specializedType == typeof (NdefSpSizeRecord))
                {
                    // Size
                    _recordSize = new NdefSpSizeRecord(record);
                }
                else if (specializedType == typeof (NdefSpMimeTypeRecord))
                {
                    // Mime Type
                    _recordMimeType = new NdefSpMimeTypeRecord(record);
                }
                else if (specializedType == typeof(NdefMimeImageRecordBase))
                {
                    // Image
                    _recordImage = new NdefMimeImageRecordBase(record);
                }
                else
                {
                    Debug.WriteLine("Sp: Don't know how to handle this record: " +
                                    BitConverter.ToString(record.Type));
                }
            }
        }
Example #5
0
 /// <summary>
 /// (Re)set all the stored sub records of the Smart Poster.
 /// </summary>
 private void InitializeData()
 {
     RecordUri = null;
     Titles = null;
     _recordAction = null;
     _recordSize = null;
     _recordMimeType = null;
 }