/// <summary>
 /// Extracts the data from the given record and places it into the
 /// given URI RTD.
 /// </summary>
 /// <param name="record">The record containing the URI data.</param>
 /// <param name="uri">Where the data is placed.</param>
 public static void ReadUriRtd(NdefRecord record, NdefUriRtd uri)
 {
     byte[] buf = record.Payload;
     uri.Identifier = GetUriIdentifier(buf[0]);
     uri.Uri= System.Text.Encoding.UTF8.GetString(buf, 1, buf.Length-1);
 }
        /// <summary>
        /// Parses the details from the given message. The output is a string
        /// that can be appended into the log.
        /// </summary>
        /// <param name="message">The message to parse.</param>
        /// <returns>The parsed details as a string.</returns>
        private string ParseNDEF(ProximityMessage message)
        {
            var output = "";

            using (var buf = DataReader.FromBuffer(message.Data)) {
                NdefRecordUtility.ReadNdefRecord(buf, recordList);

                for (int i = 0, recordNumber = 0, spRecordNumber = 0; i < recordList.Count; i++)
                {
                    NdefRecord record = recordList.ElementAt(i);

                    if (!record.IsSpRecord)
                    {
                        if (System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength) == "Sp")
                        {
                            output = output + "\n --End of Record No." + recordNumber; spRecordNumber = 0;
                            continue;
                        }
                        else
                        {
                            recordNumber++;
                            output = output + "\n --Record No." + recordNumber;
                        }
                    }
                    else
                    {
                        if (spRecordNumber == 0)
                        {
                            recordNumber++;
                            output = output + "\n --Record No." + recordNumber;
                        }

                        spRecordNumber++;
                        output = output + "\n Sp sub-record No." + spRecordNumber;
                    }

                    output = output + "\n MB:" + ((record.Mb) ? "1;" : "0;");
                    output = output + " ME:" + ((record.Me) ? "1;" : "0;");
                    output = output + " CF:" + ((record.Cf) ? "1;" : "0;");
                    output = output + " SR:" + ((record.Sr) ? "1;" : "0;");
                    output = output + " IL:" + ((record.Il) ? "1;" : "0;");

                    string typeName = NdefRecordUtility.GetTypeNameFormat(record);

                    if (record.TypeLength > 0)
                    {
                        output = output + "\n Type: " + typeName + ":"
                                 + System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength);
                    }

                    if ((record.Il) && (record.IdLength > 0))
                    {
                        output = output + "\n Id:"
                                 + System.Text.Encoding.UTF8.GetString(record.Id, 0, record.IdLength);
                    }

                    if ((record.PayloadLength > 0) && (record.Payload != null))
                    {
                        if ((record.Tnf == 0x01) &&
                            (System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength) == "U"))
                        {
                            NdefUriRtd uri = new NdefUriRtd();
                            NdefRecordUtility.ReadUriRtd(record, uri);
                            output = output + "\n Uri: " + uri.GetFullUri();
                        }
                        else if ((record.Tnf == 0x01) &&
                                 (System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength) == "T"))
                        {
                            NdefTextRtd text = new NdefTextRtd();
                            NdefRecordUtility.ReadTextRtd(record, text);
                            output = output + "\n Language: " + text.Language;
                            output = output + "\n Encoding: " + text.Encoding;
                            output = output + "\n Text: " + text.Text;
                        }
                        else
                        {
                            if (record.Tnf == 0x01)
                            {
                                output = output + "\n Payload:"
                                         + System.Text.Encoding.UTF8.GetString(record.Payload, 0, record.Payload.Length);
                            }
                        }
                    }

                    if (!record.IsSpRecord)
                    {
                        output = output + "\n --End of Record No." + recordNumber;
                    }
                }
            }

            return(output);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses the details from the given message. The output is a string
        /// that can be appended into the log.
        /// </summary>
        /// <param name="message">The message to parse.</param>
        /// <returns>The parsed details as a string.</returns>
        private string ParseNDEF(ProximityMessage message)
        {
            var output = "";

            using (var buf = DataReader.FromBuffer(message.Data)) {
                NdefRecordUtility.ReadNdefRecord(buf,recordList);

                for (int i = 0, recordNumber = 0, spRecordNumber = 0; i < recordList.Count; i++)
                {
                    NdefRecord record = recordList.ElementAt(i);

                    if (!record.IsSpRecord )
                    {
                        if (System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength) == "Sp")
                        {
                            output = output + "\n --End of Record No." + recordNumber; spRecordNumber = 0;
                            continue;
                        }
                        else
                        {
                            recordNumber++;
                            output = output + "\n --Record No." + recordNumber;
                        }
                    }
                    else
                    {
                        if (spRecordNumber == 0)
                        {
                            recordNumber++;
                            output = output + "\n --Record No." + recordNumber;
                        }

                        spRecordNumber++;
                        output = output + "\n Sp sub-record No." + spRecordNumber;
                    }

                    output = output + "\n MB:" + ((record.Mb) ? "1;" : "0;");
                    output = output + " ME:" + ((record.Me) ? "1;" : "0;");
                    output = output + " CF:" + ((record.Cf) ? "1;" : "0;");
                    output = output + " SR:" + ((record.Sr) ? "1;" : "0;");
                    output = output + " IL:" + ((record.Il) ? "1;" : "0;");

                    string typeName = NdefRecordUtility.GetTypeNameFormat(record);

                    if (record.TypeLength > 0)
                    {
                        output = output + "\n Type: " + typeName + ":"
                            + System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength);
                    }

                    if ((record.Il) && (record.IdLength > 0))
                    {
                        output = output + "\n Id:"
                            + System.Text.Encoding.UTF8.GetString(record.Id, 0, record.IdLength);
                    }

                    if ((record.PayloadLength > 0) && (record.Payload != null))
                    {
                        if ((record.Tnf == 0x01)
                            && (System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength) == "U"))
                        {
                            NdefUriRtd uri = new NdefUriRtd();
                            NdefRecordUtility.ReadUriRtd(record, uri);
                            output = output + "\n Uri: " + uri.GetFullUri();
                        }
                        else if ((record.Tnf == 0x01)
                            && (System.Text.Encoding.UTF8.GetString(record.Type, 0, record.TypeLength) == "T"))
                        {
                            NdefTextRtd text = new NdefTextRtd();
                            NdefRecordUtility.ReadTextRtd(record, text);
                            output = output + "\n Language: " + text.Language;
                            output = output + "\n Encoding: " + text.Encoding;
                            output = output + "\n Text: " + text.Text;
                        }
                        else
                        {
                            if (record.Tnf==0x01)
                            {
                                output = output + "\n Payload:"
                                    + System.Text.Encoding.UTF8.GetString(record.Payload, 0, record.Payload.Length);
                            }
                        }
                    }

                    if (!record.IsSpRecord)
                    {
                        output = output + "\n --End of Record No." + recordNumber;
                    }
                }
            }

            return output;
        }
 /// <summary>
 /// Extracts the data from the given record and places it into the
 /// given URI RTD.
 /// </summary>
 /// <param name="record">The record containing the URI data.</param>
 /// <param name="uri">Where the data is placed.</param>
 static public void ReadUriRtd(NdefRecord record, NdefUriRtd uri)
 {
     byte[] buf = record.Payload;
     uri.Identifier = GetUriIdentifier(buf[0]);
     uri.Uri        = System.Text.Encoding.UTF8.GetString(buf, 1, buf.Length - 1);
 }