本文整理汇总了C#中NdefLibrary.Ndef.NdefRecord类的典型用法代码示例。如果您正苦于以下问题:C# NdefRecord类的具体用法?C# NdefRecord怎么用?C# NdefRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NdefRecord类属于NdefLibrary.Ndef命名空间,在下文中一共展示了NdefRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NdefHandoverErrorRecord
/// <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);
}
示例2: Main
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);
}
示例3: NdefVcardRecordBase
/// <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);
}
示例4: NdefTelRecord
/// <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);
}
示例5: IsRecordType
/// <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));
}
示例6: ConvertTypeNameFormatToString
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;
}
示例7: NdefIcalendarRecordBase
/// <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);
}
示例8: NdefSpRecord
/// <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);
}
}
示例9: IsRecordType
/// <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));
}
示例10: PublishRecord
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();
}
示例11: PublishRecord
// 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));
}
示例12: NdefVcardRecord
/// <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);
}
示例13: NdefNearSpeakRecord
/// <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);
}
示例14: IsRecordType
/// <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);
}
示例15: WriteTagFile
private static void WriteTagFile(string pathName, string tagName, NdefRecord ndefRecord)
{
WriteTagFile(pathName, tagName, new NdefMessage { ndefRecord });
}