/// <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)); } } }
/// <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); } } }