コード例 #1
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Handover Select record.
 /// Checks the type and type name format.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Handover Select record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     return(record.TypeNameFormat == TypeNameFormatType.NfcRtd &&
            record.Type != null &&
            record.Type.SequenceEqual(BtHsType) &&
            record.Payload != null &&
            record.Payload.Length > 1);
 }
コード例 #2
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a LaunchApp record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a LaunchApp record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record.Type == null)
     {
         return(false);
     }
     return(record.TypeNameFormat == TypeNameFormatType.Uri && record.Type.SequenceEqual(WindowsLaunchAppType));
 }
コード例 #3
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed an Android
 /// Application Record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be an Android Application Record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record == null || record.Type == null)
     {
         return(false);
     }
     return(record.TypeNameFormat == TypeNameFormatType.ExternalRtd && record.Type.SequenceEqual(AndroidAppRecordType));
 }
コード例 #4
0
ファイル: NdefSpRecord.cs プロジェクト: somq/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed an Action record.
 /// </summary>
 /// <remarks>
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </remarks>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be an Action record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null)
     {
         return(false);
     }
     return(record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Type.SequenceEqual(new[] { (byte)'a', (byte)'c', (byte)'t' }));
 }
コード例 #5
0
 /// <summary>
 /// Create a Text record based on the record passed through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be a Text record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this Text record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a Text record
 /// based on an incompatible record type.</exception>
 public NdefTextRecord(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
     {
         throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
     }
 }
コード例 #6
0
ファイル: NdefSpRecord.cs プロジェクト: somq/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Smart Poster.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a Smart Poster, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null)
     {
         return(false);
     }
     return(record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Type.SequenceEqual(SmartPosterType));
 }
コード例 #7
0
        /// <summary>
        /// Create a Handover Error record based on the record passed
        /// through the argument.
        /// </summary>
        /// <remarks>
        /// Internalizes and parses the payload of the original record.
        /// The original record has to be a Handover Error Record as well.
        /// </remarks>
        /// <param name="other">Record to copy into this Handover Error record.</param>
        /// <exception cref="NdefException">Thrown if attempting to create a Handover Error record
        /// based on an incompatible record type.</exception>
        public NdefHandoverErrorRecord(NdefRecord other)
            : base(other)
        {
            if (!IsRecordType(this))
                throw new NdefException(NdefExceptionMessages.ExInvalidCopy);

            ParsePayloadToData(_payload);
        }
コード例 #8
0
 /// <summary>
 /// Create an Android Application Record record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an Android Application Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this Text record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create an Android
 /// Application Record based on an incompatible record type.</exception>
 public NdefAndroidAppRecord(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
     {
         throw new NdefException("NdefExceptionMessages.ExInvalidCopy");
     }
 }
コード例 #9
0
 /// <summary>
 /// Create a MIME/iCal record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be a MIME/iCal Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this iCal record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a iCal record
 /// based on an incompatible record type.</exception>
 protected NdefIcalendarRecordBase(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
     {
         throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
     }
 }
コード例 #10
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a MIME/iCal record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a MIME/iCal record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null)
     {
         return(false);
     }
     return(record.TypeNameFormat == TypeNameFormatType.Mime && record.Type.SequenceEqual(IcalType));
 }
コード例 #11
0
 /// <summary>
 /// Create a LaunchApp record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be a LaunchApp Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this LaunchApp record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a LaunchApp record
 /// based on an incompatible record type.</exception>
 public NdefLaunchAppRecord(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
     {
         throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
     }
     ParsePayloadToData(_payload);
 }
コード例 #12
0
        /// <summary>
        /// Checks if the record sent via the parameter is indeed a Windows Phone Settings record.
        /// </summary>
        /// <param name="record">Record to check.</param>
        /// <returns>True if the record has the correct type and type name format
        /// to be a WP Settings record + if its URI equals one of the allowed
        /// scheme names. False if it's a different record.</returns>
        public new static bool IsRecordType(NdefRecord record)
        {
            if (!NdefUriRecord.IsRecordType(record))
            {
                return(false);
            }
            var testRecord = new NdefUriRecord(record);

            return(testRecord.Uri != null && SettingsSchemes.Any(curScheme => testRecord.Uri.Equals(curScheme.Value)));
        }
コード例 #13
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Nokia Accessories record.
 /// Checks the type and type name format as well as if the payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Nokia Accessories record, false if it's a different record.</returns>
 public new static bool IsRecordType(NdefRecord record)
 {
     if (record.Type == null)
     {
         return(false);
     }
     return(record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Type.SequenceEqual(UriType) &&
            record.Payload != null &&
            CheckIsValidUri(Encoding.UTF8.GetString(record.Payload, 0, record.Payload.Length)));
 }
コード例 #14
0
        /// <summary>
        /// Checks if the record sent via the parameter is indeed a MIME / Image record.
        /// Only checks the type and type name format, doesn't analyze if the
        /// payload is valid.
        /// </summary>
        /// <param name="record">Record to check.</param>
        /// <returns>True if the record has the correct type and type name format
        /// to be a MIME / Image record, false if it's a different record.</returns>
        public static bool IsRecordType(NdefRecord record)
        {
            if (record?.Type == null)
            {
                return(false);
            }

            var foundMime = record.Type != null &&
                            ImageMimeTypes.Values.Any(t => t.SequenceEqual(record.Type));

            return(record.TypeNameFormat == TypeNameFormatType.Mime && foundMime);
        }
コード例 #15
0
        /// <summary>
        /// Checks if the record sent via the parameter is indeed a NearSpeak record.
        /// Only checks the type and type name format, doesn't analyze if the
        /// payload is valid.
        /// </summary>
        /// <param name="record">Record to check.</param>
        /// <returns>True if the record has the correct type and type name format
        /// to be a NearSpeak record, false if it's a different record.</returns>
        public new static bool IsRecordType(NdefRecord record)
        {
            if (!NdefUriRecord.IsRecordType(record))
            {
                return(false);
            }
            var testRecord = new NdefUriRecord(record);

            if (testRecord.Uri == null || testRecord.Uri.Length < NearSpeakScheme.Length + 7)
            {
                return(false);
            }
            return(testRecord.Uri.StartsWith(NearSpeakScheme));
        }
コード例 #16
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Text record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a Text record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record != null)
     {
         if (record.Type == null)
         {
             return(false);
         }
         return(record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Type.SequenceEqual(TextType));
     }
     else
     {
         return(false);
     }
 }
コード例 #17
0
        public MessageViewModel(NdefLibrary.Ndef.NdefRecord message)
        {
            Type type = message.CheckSpecializedType(true);

            Type = type.Name;
            Info = "Feel free to add this mapping to the message view model";
            if (type == typeof(NdefLibrary.Ndef.NdefTextRecord))
            {
                var text = new NdefTextRecord(message);
                Info = string.Format("The message on the tag is \"{0}\". The language is \"{1}\"", text.Text,
                                     text.LanguageCode);
            }
            if (type == typeof(NdefLibrary.Ndef.NdefUriRecord))
            {
                var text = new NdefUriRecord(message);
                Info = string.Format("The URI on the tag is \"{0}\"", text.Uri);
            }
        }
コード例 #18
0
ファイル: NdefRecord.cs プロジェクト: xxzztt/ndef-nfc
 /// <summary>
 /// Create a new record, copying the information of the record sent through the parameter.
 /// </summary>
 /// <param name="other">Record to copy.</param>
 public NdefRecord(NdefRecord other)
 {
     TypeNameFormat = other.TypeNameFormat;
     if (other.Type != null)
     {
         // Can't call Type property set method from constructor, as it's virtual
         _type = new byte[other.Type.Length];
         Array.Copy(other.Type, _type, other.Type.Length);
     }
     if (other.Id != null)
     {
         Id = other.Id;
     }
     if (other.Payload != null)
     {
         // Can't call Type property set method from constructor, as it's virtual
         _payload = new byte[other.Payload.Length];
         Array.Copy(other.Payload, _payload, other.Payload.Length);
     }
 }
コード例 #19
0
ファイル: NdefMailtoRecord.cs プロジェクト: somq/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Mailto record.
 /// Checks the type and type name format and if the URI starts with the correct scheme.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Mailto record, false if it's a different record.</returns>
 public new static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null)
     {
         return(false);
     }
     if (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Payload != null)
     {
         if (record.Type.SequenceEqual(NdefUriRecord.UriType))
         {
             var testRecord = new NdefUriRecord(record);
             return(testRecord.Uri.StartsWith(MailtoScheme));
         }
         if (record.Type.SequenceEqual(SmartPosterType))
         {
             var testRecord = new NdefSpRecord(record);
             return(testRecord.Uri.StartsWith(MailtoScheme));
         }
     }
     return(false);
 }
コード例 #20
0
ファイル: NfcTagGenerator.cs プロジェクト: Doluci/ndef-nfc
        static void Main(string[] args)
        {
            // Dynamically construct some more NDEF records
            var spRecord = new NdefSpRecord
            {
                Uri = "http://andijakl.github.io/ndef-nfc/",
                NfcAction = NdefSpActRecord.NfcActionType.DoAction
            };
            spRecord.AddTitle(new NdefTextRecord { LanguageCode = "en", Text = "NFC Library" });
            spRecord.AddTitle(new NdefTextRecord { LanguageCode = "de", Text = "NFC Bibliothek" });
            NfcRecords.Add("SmartPoster", spRecord);

            // Ensure the path exists
            var tagsDirectory = Path.Combine(Environment.CurrentDirectory, FileDirectory);
            Directory.CreateDirectory(tagsDirectory);

            // Write tag contents to files
            foreach (var curNdefRecord in NfcRecords)
            {
                WriteTagFile(tagsDirectory, curNdefRecord.Key, curNdefRecord.Value);
            }

            // Multi-record file
            var record1 = new NdefUriRecord {Uri = "http://www.twitter.com"};
            var record2 = new NdefAndroidAppRecord {PackageName = "com.twitter.android"};
            var twoRecordsMsg = new NdefMessage {record1, record2};
            WriteTagFile(tagsDirectory, "TwoRecords", twoRecordsMsg);

            var record3 = new NdefRecord
            {
                TypeNameFormat = NdefRecord.TypeNameFormatType.ExternalRtd,
                Type = Encoding.UTF8.GetBytes("custom.com:myapp")
            };
            var threeRecordsMsg = new NdefMessage { record1, record3, record2 };
            WriteTagFile(tagsDirectory, "ThreeRecords", threeRecordsMsg);

            // Success message on output
            Console.WriteLine("Generated {0} tag files in {1}.", NfcRecords.Count, tagsDirectory);
            Debug.WriteLine("Generated {0} tag files in {1}.", NfcRecords.Count, tagsDirectory);
        }
コード例 #21
0
ファイル: NdefMailtoRecord.cs プロジェクト: somq/ndef-nfc
 /// <summary>
 /// Create a Mailto record based on another Mailto record, or a Smart Poster / URI
 /// record that has a Uri set that corresponds to the mailto: URI scheme.
 /// </summary>
 /// <param name="other">Other record to copy the data from.</param>
 public NdefMailtoRecord(NdefRecord other)
     : base(other)
 {
     ParseUriToData(Uri);
 }
コード例 #22
0
ファイル: NfcTagGenerator.cs プロジェクト: Doluci/ndef-nfc
 private static void WriteTagFile(string pathName, string tagName, NdefRecord ndefRecord)
 {
     WriteTagFile(pathName, tagName, new NdefMessage { ndefRecord });
 }
コード例 #23
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed an Android
 /// Application Record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be an Android Application Record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record == null || record.Type == null) return false;
     return (record.TypeNameFormat == TypeNameFormatType.ExternalRtd && record.Type.SequenceEqual(AndroidAppRecordType));
 }
コード例 #24
0
 /// <summary>
 /// Create a MIME / Image record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// The original record has to be a MIME / Image Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this Image record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create an Image record
 /// based on an incompatible record type.</exception>
 public NdefMimeImageRecord(NdefRecord other)
     : base(other)
 {
 }
コード例 #25
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a NearSpeak record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a NearSpeak record, false if it's a different record.</returns>
 public static new bool IsRecordType(NdefRecord record)
 {
     if (!NdefUriRecord.IsRecordType(record)) return false;
     var testRecord = new NdefUriRecord(record);
     if (testRecord.Uri == null || testRecord.Uri.Length < NearSpeakScheme.Length + 3)
         return false;
     return testRecord.Uri.StartsWith(NearSpeakScheme);
 }
コード例 #26
0
ファイル: NdefSpRecord.cs プロジェクト: Doluci/ndef-nfc
        /// <summary>
        /// Create a Smart Poster record based on the record passed
        /// through the argument.
        /// </summary>
        /// <remarks>
        /// Internalizes and parses the payload of the original record.
        /// The original record can be a Smart Poster or a URI record.
        /// </remarks>
        /// <param name="other">Record to copy into this smart poster record.</param>
        /// <exception cref="NdefException">Thrown if attempting to create a Smart Poster
        /// based on an incompatible record type.</exception>
        public NdefSpRecord(NdefRecord other)
            : base(other)
        {
            if (TypeNameFormat != TypeNameFormatType.NfcRtd)
                throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
            if (_type.SequenceEqual(SmartPosterType))
            {
                // Other record was a Smart Poster, so parse and internalize the Sp payload
                ParsePayloadToData(_payload);
            }
            else if (_type.SequenceEqual(NdefUriRecord.UriType))
            {
                // Create Smart Poster based on URI record
                RecordUri = new NdefUriRecord(other) {Id = null};
                // Set type of this instance to Smart Poster
                _type = new byte[SmartPosterType.Length];
                Array.Copy(SmartPosterType, _type, SmartPosterType.Length);
            }
            else
            {
                throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
            }

        }
コード例 #27
0
 /// <summary>
 /// Create an Alternative Carrier Record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an Alternative Carrier Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this Alternative Carrier Record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a Alternative Carrier Record
 /// based on an incompatible record type.</exception>
 public NdefHandoverAlternativeCarrierRecord(NdefRecord other)
     : base(other)
 {
     ParsePayloadToData(_payload);
 }
コード例 #28
0
ファイル: NdefSpRecord.cs プロジェクト: Doluci/ndef-nfc
 /// <summary>
 /// Create a size record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an action record as well.
 /// </remarks>
 /// <param name="other">Size record to copy into this record.</param>
 public NdefSpSizeRecord(NdefRecord other) : base(other) { }
コード例 #29
0
ファイル: NdefSpRecord.cs プロジェクト: Doluci/ndef-nfc
 /// <summary>
 /// Create a mime type record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an action record as well.
 /// </remarks>
 /// <param name="other">Mime type record to copy into this record.</param>
 public NdefSpMimeTypeRecord(NdefRecord other) : base(other) { }
コード例 #30
0
ファイル: NdefSpRecord.cs プロジェクト: Doluci/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed an Action record.
 /// </summary>
 /// <remarks>
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </remarks>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be an Action record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null) return false;
     return (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Type.SequenceEqual(new[] { (byte)'a', (byte)'c', (byte)'t' }));
 }
コード例 #31
0
ファイル: NdefSpRecord.cs プロジェクト: Doluci/ndef-nfc
 /// <summary>
 /// Create an action record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks> 
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an action record as well.
 /// </remarks>
 /// <param name="other">Action record to copy into this record.</param>
 public NdefSpActRecord(NdefRecord other) : base(other) { }
コード例 #32
0
ファイル: NdefSmsRecord.cs プロジェクト: Doluci/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed an Sms record.
 /// Checks the type and type name format and if the URI starts with the correct scheme.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be an Sms record, false if it's a different record.</returns>
 public new static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null) return false;
     if (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Payload != null)
     {
         if (record.Type.SequenceEqual(NdefUriRecord.UriType))
         {
             var testRecord = new NdefUriRecord(record);
             return testRecord.Uri.StartsWith(SmsScheme, StringComparison.OrdinalIgnoreCase);
         }
         if (record.Type.SequenceEqual(SmartPosterType))
         {
             var testRecord = new NdefSpRecord(record);
             return testRecord.Uri.StartsWith(SmsScheme, StringComparison.OrdinalIgnoreCase);
         }
     }
     return false;
 }
コード例 #33
0
ファイル: NdefTelRecord.cs プロジェクト: CruzerBoon/ndef-nfc
 /// <summary>
 /// Create a telephone record based on another telephone record, or Smart Poster / URI
 /// record that have a Uri set that corresponds to the tel: URI scheme.
 /// </summary>
 /// <param name="other">Other record to copy the data from.</param>
 public NdefTelRecord(NdefRecord other)
     : base(other)
 {
     ParseUriToData(Uri);
 }
コード例 #34
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Windows Phone Settings record.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a WP Settings record + if its URI equals one of the allowed
 /// scheme names. False if it's a different record.</returns>
 public static new bool IsRecordType(NdefRecord record)
 {
     if (!NdefUriRecord.IsRecordType(record)) return false;
     var testRecord = new NdefUriRecord(record);
     return testRecord.Uri != null && SettingsSchemes.Any(curScheme => testRecord.Uri.Equals(curScheme.Value));
 }
コード例 #35
0
 /// <summary>
 /// Create a MIME/vCard record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be a MIME/vCard Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this vCard record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a vCard record
 /// based on an incompatible record type.</exception>
 public NdefVcardRecordBase(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
         throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
 }
コード例 #36
0
ファイル: MainPage.xaml.cs プロジェクト: RyanAClark/Easy-NFC
        private void PublishRecord(NdefRecord record, bool writeToTag)
        {
            if (_device == null) return;
            // Make sure we're not already publishing another message
            StopPublishingMessage(false);
            // Wrap the NDEF record into an NDEF message
            var message = new NdefMessage { record };
            // Convert the NDEF message to a byte array
            var msgArray = message.ToByteArray();
            // Publish the NDEF message to a tag or to another device, depending on the writeToTag parameter
            // Save the publication ID so that we can cancel publication later
            _publishingMessageId = _device.PublishBinaryMessage((writeToTag ? "NDEF:WriteTag" : "NDEF"), msgArray.AsBuffer(), MessageWrittenHandler);
            // Update status text for UI
            SetStatusOutput(string.Format((writeToTag ? AppResources.StatusWriteToTag : AppResources.StatusWriteToDevice), msgArray.Length, _publishingMessageId));
            // Update enabled / disabled state of buttons in the User Interface
            SetStatusOutput(string.Format("You said \"{0}\"\nPlease touch a tag to write the message.", recordresult));
           



            recordresult = "";
            UpdateUiForNfcStatus();
        }
コード例 #37
0
 /// <summary>
 /// Create a telephone record based on another telephone record, or Smart Poster / URI
 /// record that have a Uri set that corresponds to the tel: URI scheme.
 /// </summary>
 /// <param name="other">Other record to copy the data from.</param>
 public NdefNearSpeakRecord(NdefRecord other)
     : base(other)
 {
     ParseUriToData(Uri);
 }
コード例 #38
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Handover Error record.
 /// Checks the type and type name format.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Handover Error record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     return record.TypeNameFormat == TypeNameFormatType.NfcRtd &&
            record.Type != null &&
            record.Type.SequenceEqual(BtHandoverErrorType) &&
            record.Payload != null;
 }
コード例 #39
0
 /// <summary>
 /// Create an Alternative Carrier Record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an Alternative Carrier Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this Alternative Carrier Record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a Alternative Carrier Record
 /// based on an incompatible record type.</exception>
 public NdefHandoverAlternativeCarrierRecord(NdefRecord other)
     : base(other)
 {
     ParsePayloadToData(_payload);
 }
コード例 #40
0
ファイル: NdefTextRecord.cs プロジェクト: SpivEgin/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Text record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a Text record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null) return false;
     return (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Type.SequenceEqual(TextType));
 }
コード例 #41
0
 /// <summary>
 /// Create a Nokia Accessories record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be a Nokia Accessories Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this Text record.</param>
 public NdefNokiaAccessoriesRecord(NdefRecord other)
     : base(other)
 {
     ParsePayloadToData(_payload);
 }
コード例 #42
0
ファイル: NdefSpRecord.cs プロジェクト: xxzztt/ndef-nfc
 /// <summary>
 /// Create a size record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an action record as well.
 /// </remarks>
 /// <param name="other">Size record to copy into this record.</param>
 public NdefSpSizeRecord(NdefRecord other) : base(other)
 {
 }
コード例 #43
0
 /// <summary>
 /// Create a WP8 settings record based on another WP8 settings record, or a URI
 /// record that has a Uri that corresponds to one of the allowed URI schemes
 /// for this record.
 /// </summary>
 /// <param name="other">Other record to copy the data from.</param>
 public NdefWpSettingsRecord(NdefRecord other)
     : base(other)
 {
     ParseUriToData(Uri);
 }
コード例 #44
0
 /// <summary>
 /// Create an Android Application Record record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an Android Application Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this AAR record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create an Android
 /// Application Record based on an incompatible record type.</exception>
 public NdefAndroidAppRecord(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
         throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
 }
コード例 #45
0
ファイル: NdefSpRecord.cs プロジェクト: xxzztt/ndef-nfc
 /// <summary>
 /// Create an action record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an action record as well.
 /// </remarks>
 /// <param name="other">Action record to copy into this record.</param>
 public NdefSpActRecord(NdefRecord other) : base(other)
 {
 }
コード例 #46
0
ファイル: eTags.xaml.cs プロジェクト: roxvicky/SmartParking
     //   private Windows.UI.Core.CoreDispatcher _dispatcher =
     //Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;

     //   private async void ProximityDeviceArrived(object sender)
     //   {
     //       await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
     //       () =>
     //       {
     //           StatusOutput.Text += "Proximate device arrived.\n";
     //       });
     //   }

     //   private async void ProximityDeviceDeparted(object sender)
     //   {
     //       await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
     //       () =>
     //       {
     //           StatusOutput.Text += "Proximate device departed.\n";
     //       });
     //   }

        private void PublishRecord(NdefRecord record, bool writeToTag)
        {
            if (_device == null) return;
            // Make sure we're not already publishing another message
            StopPublishingMessage(false);
            // Wrap the NDEF record into an NDEF message
            var message = new NdefMessage { record };
            // Convert the NDEF message to a byte array
            var msgArray = message.ToByteArray();
            // Publish the NDEF message to a tag or to another device, depending on the writeToTag parameter
            // Save the publication ID so that we can cancel publication later
            _publishingMessageId = _device.PublishBinaryMessage((writeToTag ? "NDEF:WriteTag" : "NDEF"), msgArray.AsBuffer(), MessageWrittenHandler);
            // Update status text for UI
           //_publishingMessageId = -1;
            SetStatusOutput(string.Format((writeToTag ? AppResources.StatusWriteToTag : AppResources.StatusWriteToDevice), msgArray.Length, _publishingMessageId));
           
        }
コード例 #47
0
ファイル: NdefSpRecord.cs プロジェクト: xxzztt/ndef-nfc
 /// <summary>
 /// Create a mime type record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be an action record as well.
 /// </remarks>
 /// <param name="other">Mime type record to copy into this record.</param>
 public NdefSpMimeTypeRecord(NdefRecord other) : base(other)
 {
 }
コード例 #48
0
ファイル: NdefVcardRecord.cs プロジェクト: Doluci/ndef-nfc
 /// <summary>
 /// Creates a new instance of an NdefVcardRecord and imports
 /// the payload into the ContactData instance.
 /// </summary>
 /// <param name="other">An NDEF record that contains
 /// valid vCard data as its payload and has the right type information.</param>
 public NdefVcardRecord(NdefRecord other) : base(other)
 {
     ContactData = ParseDataToContact(_payload);
 }
コード例 #49
0
 /// <summary>
 /// Create a MIME/iCal record based on the record passed
 /// through the argument.
 /// </summary>
 /// <remarks>
 /// Internalizes and parses the payload of the original record.
 /// The original record has to be a MIME/iCal Record as well.
 /// </remarks>
 /// <param name="other">Record to copy into this iCal record.</param>
 /// <exception cref="NdefException">Thrown if attempting to create a iCal record
 /// based on an incompatible record type.</exception>
 protected NdefIcalendarRecordBase(NdefRecord other)
     : base(other)
 {
     if (!IsRecordType(this))
         throw new NdefException(NdefExceptionMessages.ExInvalidCopy);
 }
コード例 #50
0
ファイル: MainPage.xaml.cs プロジェクト: Doluci/ndef-nfc
 private void PublishRecord(NdefRecord record, bool writeToTag)
 {
     if (_device == null) return;
     // Make sure we're not already publishing another message
     StopPublishingMessage(false);
     // Wrap the NDEF record into an NDEF message
     var message = new NdefMessage { record };
     // Convert the NDEF message to a byte array
     var msgArray = message.ToByteArray();
     try
     {
         // Publish the NDEF message to a tag or to another device, depending on the writeToTag parameter
         // Save the publication ID so that we can cancel publication later
         _publishingMessageId = _device.PublishBinaryMessage((writeToTag ? "NDEF:WriteTag" : "NDEF"), msgArray.AsBuffer(), MessageWrittenHandler);
         // Update status text for UI
         SetStatusOutput(string.Format(_loader.GetString(writeToTag ? "StatusWriteToTag" : "StatusWriteToDevice"), msgArray.Length, _publishingMessageId));
         // Update enabled / disabled state of buttons in the User Interface
         UpdateUiForNfcStatusAsync();
     }
     catch (Exception e)
     {
         SetStatusOutput(string.Format(_loader.GetString("StatusPublicationError"), e.Message));
     }
 }
コード例 #51
0
ファイル: NdefTelRecord.cs プロジェクト: CruzerBoon/ndef-nfc
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a Telephone record.
 /// Checks the type and type name format and if the URI starts with the correct scheme.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type, type name format and payload
 /// to be a Telephone record, false if it's a different record.</returns>
 public static new bool IsRecordType(NdefRecord record)
 {
     if (record.Type == null) return false;
     if (record.TypeNameFormat == TypeNameFormatType.NfcRtd && record.Payload != null)
     {
         if (record.Type.SequenceEqual(NdefUriRecord.UriType))
         {
             var testRecord = new NdefUriRecord(record);
             return testRecord.Uri.StartsWith(TelScheme);
         }
         if (record.Type.SequenceEqual(SmartPosterType))
         {
             var testRecord = new NdefSpRecord(record);
             return testRecord.Uri.StartsWith(TelScheme);
         }
     }
     return false;
 }
コード例 #52
0
ファイル: MainPage.xaml.cs プロジェクト: Doluci/ndef-nfc
 private string ConvertTypeNameFormatToString(NdefRecord.TypeNameFormatType tnf)
 {
     // Each record contains a type name format, which defines which format
     // the type name is actually in.
     // This method converts the constant to a human-readable string.
     string tnfString;
     switch (tnf)
     {
         case NdefRecord.TypeNameFormatType.Empty:
             tnfString = "Empty NDEF record (does not contain a payload)";
             break;
         case NdefRecord.TypeNameFormatType.NfcRtd:
             tnfString = "NFC RTD Specification";
             break;
         case NdefRecord.TypeNameFormatType.Mime:
             tnfString = "RFC 2046 (Mime)";
             break;
         case NdefRecord.TypeNameFormatType.Uri:
             tnfString = "RFC 3986 (Url)";
             break;
         case NdefRecord.TypeNameFormatType.ExternalRtd:
             tnfString = "External type name";
             break;
         case NdefRecord.TypeNameFormatType.Unknown:
             tnfString = "Unknown record type; should be treated similar to content with MIME type 'application/octet-stream' without further context";
             break;
         case NdefRecord.TypeNameFormatType.Unchanged:
             tnfString = "Unchanged (partial record)";
             break;
         case NdefRecord.TypeNameFormatType.Reserved:
             tnfString = "Reserved";
             break;
         default:
             tnfString = "Unknown";
             break;
     }
     return tnfString;
 }
コード例 #53
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a LaunchApp record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a LaunchApp record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record?.Type == null) return false;
     return (record.TypeNameFormat == TypeNameFormatType.Uri && record.Type.SequenceEqual(WindowsLaunchAppType));
 }
コード例 #54
0
 /// <summary>
 /// Create a telephone record based on another telephone record, or Smart Poster / URI
 /// record that have a Uri set that corresponds to the tel: URI scheme.
 /// </summary>
 /// <param name="other">Other record to copy the data from.</param>
 public NdefNearSpeakRecord(NdefRecord other)
     : base(other)
 {
     ParseUriToData(Uri);
 }
コード例 #55
0
 /// <summary>
 /// Checks if the record sent via the parameter is indeed a MIME/vCard record.
 /// Only checks the type and type name format, doesn't analyze if the
 /// payload is valid.
 /// </summary>
 /// <param name="record">Record to check.</param>
 /// <returns>True if the record has the correct type and type name format
 /// to be a MIME/vCard record, false if it's a different record.</returns>
 public static bool IsRecordType(NdefRecord record)
 {
     if (record.Type == null) return false;
     return (record.TypeNameFormat == TypeNameFormatType.Mime && record.Type.SequenceEqual(VcardType));
 }
コード例 #56
0
 /// <summary>
 /// Create a WP8 settings record based on another WP8 settings record, or a URI
 /// record that has a Uri that corresponds to one of the allowed URI schemes
 /// for this record.
 /// </summary>
 /// <param name="other">Other record to copy the data from.</param>
 public NdefWpSettingsRecord(NdefRecord other)
     : base(other)
 {
     ParseUriToData(Uri);
 }