add Testmessag

This commit is contained in:
stubbfel
2013-10-23 15:26:44 +02:00
parent b21f26cfa6
commit 0cdf74b417
12 changed files with 628 additions and 136 deletions

View File

@@ -0,0 +1,272 @@
<stylecopresultscache>
<version>12</version>
<sourcecode name="TextType.cs" parser="StyleCop.CSharp.CsParser">
<timestamps>
<styleCop>2013.09.19 14:09:50.000</styleCop>
<settingsFile>2012.09.27 21:03:32.000</settingsFile>
<sourceFile>2013.10.23 10:54:09.249</sourceFile>
<parser>2013.09.19 14:09:50.000</parser>
<StyleCop.CSharp.DocumentationRules>2013.09.19 14:09:50.000</StyleCop.CSharp.DocumentationRules>
<StyleCop.CSharp.DocumentationRules.FilesHashCode>-1945363787</StyleCop.CSharp.DocumentationRules.FilesHashCode>
<StyleCop.CSharp.LayoutRules>2013.09.19 14:09:50.000</StyleCop.CSharp.LayoutRules>
<StyleCop.CSharp.LayoutRules.FilesHashCode>0</StyleCop.CSharp.LayoutRules.FilesHashCode>
<StyleCop.CSharp.MaintainabilityRules>2013.09.19 14:09:50.000</StyleCop.CSharp.MaintainabilityRules>
<StyleCop.CSharp.MaintainabilityRules.FilesHashCode>0</StyleCop.CSharp.MaintainabilityRules.FilesHashCode>
<StyleCop.CSharp.NamingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.NamingRules>
<StyleCop.CSharp.NamingRules.FilesHashCode>0</StyleCop.CSharp.NamingRules.FilesHashCode>
<StyleCop.CSharp.OrderingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.OrderingRules>
<StyleCop.CSharp.OrderingRules.FilesHashCode>0</StyleCop.CSharp.OrderingRules.FilesHashCode>
<StyleCop.CSharp.ReadabilityRules>2013.09.19 14:09:50.000</StyleCop.CSharp.ReadabilityRules>
<StyleCop.CSharp.ReadabilityRules.FilesHashCode>0</StyleCop.CSharp.ReadabilityRules.FilesHashCode>
<StyleCop.CSharp.SpacingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.SpacingRules>
<StyleCop.CSharp.SpacingRules.FilesHashCode>0</StyleCop.CSharp.SpacingRules.FilesHashCode>
</timestamps>
<violations>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="FileMustHaveHeader" ruleCheckId="SA1633">
<context>The file has no header, the header Xml is invalid, or the header is not located at the top of the file.</context>
<line>1</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="UsingDirectivesMustBePlacedWithinNamespace" ruleCheckId="SA1200">
<context>All using directives must be placed inside of the namespace.</context>
<line>1</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="UsingDirectivesMustBePlacedWithinNamespace" ruleCheckId="SA1200">
<context>All using directives must be placed inside of the namespace.</context>
<line>2</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives" ruleCheckId="SA1208">
<context>System using directives must be placed before all other using directives.</context>
<line>2</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="UsingDirectivesMustBePlacedWithinNamespace" ruleCheckId="SA1200">
<context>All using directives must be placed inside of the namespace.</context>
<line>3</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="UsingDirectivesMustBePlacedWithinNamespace" ruleCheckId="SA1200">
<context>All using directives must be placed inside of the namespace.</context>
<line>4</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="UsingDirectivesMustBePlacedWithinNamespace" ruleCheckId="SA1200">
<context>All using directives must be placed inside of the namespace.</context>
<line>5</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="UsingDirectivesMustBePlacedWithinNamespace" ruleCheckId="SA1200">
<context>All using directives must be placed inside of the namespace.</context>
<line>6</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.NamingRules" rule="ElementMustBeginWithUpperCaseLetter" ruleCheckId="SA1300">
<context>namespace names begin with an upper-case letter: ndefpclib.</context>
<line>8</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.NamingRules" rule="ElementMustBeginWithUpperCaseLetter" ruleCheckId="SA1300">
<context>namespace names begin with an upper-case letter: type.</context>
<line>8</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementsMustBeDocumented" ruleCheckId="SA1600">
<context>The class must have a documentation header.</context>
<line>10</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementsMustBeDocumented" ruleCheckId="SA1600">
<context>The constructor must have a documentation header.</context>
<line>12</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementsMustBeDocumented" ruleCheckId="SA1600">
<context>The method must have a documentation header.</context>
<line>19</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.LayoutRules" rule="ClosingCurlyBracketMustBeFollowedByBlankLine" ruleCheckId="SA1513">
<context>Statements or elements wrapped in curly brackets must be followed by a blank line.</context>
<line>24</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.ReadabilityRules" rule="CodeMustNotContainEmptyStatements" ruleCheckId="SA1106">
<context>The code contains an extra semicolon.</context>
<line>34</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.SpacingRules" rule="SemicolonsMustBeSpacedCorrectly" ruleCheckId="SA1002">
<context>Invalid spacing around the semicolon.</context>
<line>34</line>
<index>1009</index>
<endIndex>1009</endIndex>
<startLine>34</startLine>
<startColumn>50</startColumn>
<endLine>34</endLine>
<endColumn>50</endColumn>
<warning>False</warning>
</violation>
</violations>
</sourcecode>
<sourcecode name="TextMessages.cs" parser="StyleCop.CSharp.CsParser">
<timestamps>
<styleCop>2013.09.19 14:09:50.000</styleCop>
<settingsFile>2012.09.27 21:03:32.000</settingsFile>
<sourceFile>2013.10.23 15:18:02.510</sourceFile>
<parser>2013.09.19 14:09:50.000</parser>
<StyleCop.CSharp.DocumentationRules>2013.09.19 14:09:50.000</StyleCop.CSharp.DocumentationRules>
<StyleCop.CSharp.DocumentationRules.FilesHashCode>-1945363787</StyleCop.CSharp.DocumentationRules.FilesHashCode>
<StyleCop.CSharp.LayoutRules>2013.09.19 14:09:50.000</StyleCop.CSharp.LayoutRules>
<StyleCop.CSharp.LayoutRules.FilesHashCode>0</StyleCop.CSharp.LayoutRules.FilesHashCode>
<StyleCop.CSharp.MaintainabilityRules>2013.09.19 14:09:50.000</StyleCop.CSharp.MaintainabilityRules>
<StyleCop.CSharp.MaintainabilityRules.FilesHashCode>0</StyleCop.CSharp.MaintainabilityRules.FilesHashCode>
<StyleCop.CSharp.NamingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.NamingRules>
<StyleCop.CSharp.NamingRules.FilesHashCode>0</StyleCop.CSharp.NamingRules.FilesHashCode>
<StyleCop.CSharp.OrderingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.OrderingRules>
<StyleCop.CSharp.OrderingRules.FilesHashCode>0</StyleCop.CSharp.OrderingRules.FilesHashCode>
<StyleCop.CSharp.ReadabilityRules>2013.09.19 14:09:50.000</StyleCop.CSharp.ReadabilityRules>
<StyleCop.CSharp.ReadabilityRules.FilesHashCode>0</StyleCop.CSharp.ReadabilityRules.FilesHashCode>
<StyleCop.CSharp.SpacingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.SpacingRules>
<StyleCop.CSharp.SpacingRules.FilesHashCode>0</StyleCop.CSharp.SpacingRules.FilesHashCode>
</timestamps>
<violations>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="FileHeaderMustShowCopyright" ruleCheckId="SA1634">
<context>The file header must contain a copyright tag.</context>
<line>1</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.SpacingRules" rule="TabsMustNotBeUsed" ruleCheckId="SA1027">
<context>Tabs are not allowed. Use spaces instead.</context>
<line>3</line>
<index>42</index>
<endIndex>54</endIndex>
<startLine>3</startLine>
<startColumn>1</startColumn>
<endLine>3</endLine>
<endColumn>13</endColumn>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.NamingRules" rule="ElementMustBeginWithUpperCaseLetter" ruleCheckId="SA1300">
<context>namespace names begin with an upper-case letter: ndefpclib.</context>
<line>4</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.NamingRules" rule="ElementMustBeginWithUpperCaseLetter" ruleCheckId="SA1300">
<context>namespace names begin with an upper-case letter: message.</context>
<line>4</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>12</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>19</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.SpacingRules" rule="CommasMustBeSpacedCorrectly" ruleCheckId="SA1001">
<context>Invalid spacing around the comma.</context>
<line>20</line>
<index>809</index>
<endIndex>809</endIndex>
<startLine>20</startLine>
<startColumn>50</startColumn>
<endLine>20</endLine>
<endColumn>50</endColumn>
<warning>False</warning>
</violation>
</violations>
</sourcecode>
<project key="1236787186">
<configuration>DEBUG;TRACE</configuration>
</project>
<sourcecode name="NDEFMessage.cs" parser="StyleCop.CSharp.CsParser">
<timestamps>
<styleCop>2013.09.19 14:09:50.000</styleCop>
<settingsFile>2012.09.27 21:03:32.000</settingsFile>
<sourceFile>2013.10.23 15:21:08.323</sourceFile>
<parser>2013.09.19 14:09:50.000</parser>
<StyleCop.CSharp.DocumentationRules>2013.09.19 14:09:50.000</StyleCop.CSharp.DocumentationRules>
<StyleCop.CSharp.DocumentationRules.FilesHashCode>-1945363787</StyleCop.CSharp.DocumentationRules.FilesHashCode>
<StyleCop.CSharp.LayoutRules>2013.09.19 14:09:50.000</StyleCop.CSharp.LayoutRules>
<StyleCop.CSharp.LayoutRules.FilesHashCode>0</StyleCop.CSharp.LayoutRules.FilesHashCode>
<StyleCop.CSharp.MaintainabilityRules>2013.09.19 14:09:50.000</StyleCop.CSharp.MaintainabilityRules>
<StyleCop.CSharp.MaintainabilityRules.FilesHashCode>0</StyleCop.CSharp.MaintainabilityRules.FilesHashCode>
<StyleCop.CSharp.NamingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.NamingRules>
<StyleCop.CSharp.NamingRules.FilesHashCode>0</StyleCop.CSharp.NamingRules.FilesHashCode>
<StyleCop.CSharp.OrderingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.OrderingRules>
<StyleCop.CSharp.OrderingRules.FilesHashCode>0</StyleCop.CSharp.OrderingRules.FilesHashCode>
<StyleCop.CSharp.ReadabilityRules>2013.09.19 14:09:50.000</StyleCop.CSharp.ReadabilityRules>
<StyleCop.CSharp.ReadabilityRules.FilesHashCode>0</StyleCop.CSharp.ReadabilityRules.FilesHashCode>
<StyleCop.CSharp.SpacingRules>2013.09.19 14:09:50.000</StyleCop.CSharp.SpacingRules>
<StyleCop.CSharp.SpacingRules.FilesHashCode>0</StyleCop.CSharp.SpacingRules.FilesHashCode>
</timestamps>
<violations>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="FileHeaderMustShowCopyright" ruleCheckId="SA1634">
<context>The file header must contain a copyright tag.</context>
<line>1</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.SpacingRules" rule="TabsMustNotBeUsed" ruleCheckId="SA1027">
<context>Tabs are not allowed. Use spaces instead.</context>
<line>3</line>
<index>37</index>
<endIndex>49</endIndex>
<startLine>3</startLine>
<startColumn>1</startColumn>
<endLine>3</endLine>
<endColumn>13</endColumn>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.NamingRules" rule="ElementMustBeginWithUpperCaseLetter" ruleCheckId="SA1300">
<context>namespace names begin with an upper-case letter: ndefpclib.</context>
<line>4</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.NamingRules" rule="ElementMustBeginWithUpperCaseLetter" ruleCheckId="SA1300">
<context>namespace names begin with an upper-case letter: message.</context>
<line>4</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.OrderingRules" rule="SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives" ruleCheckId="SA1208">
<context>System using directives must be placed before all other using directives.</context>
<line>8</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the summary tag contains incorrectly spelled words: Ndef</context>
<line>13</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>13</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>31</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>65</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>97</line>
<warning>False</warning>
</violation>
<violation namespace="StyleCop.CSharp.DocumentationRules" rule="ElementDocumentationMustBeSpelledCorrectly" ruleCheckId="SA1650">
<context>The documentation text within the remarks tag contains incorrectly spelled words: Stubbfel</context>
<line>112</line>
<warning>False</warning>
</violation>
</violations>
</sourcecode>
</stylecopresultscache>

View File

@@ -1,10 +1,12 @@
namespace ndefpclib.message
// namespace: ndefpclib.message
//
// summary: .
namespace ndefpclib.message
{
using ndefpclib.records;
using ndefpclib.type;
using System.Collections.Generic;
using System.IO;
using System.Text;
/// <summary> Ndef message. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
@@ -15,25 +17,27 @@
/// <summary> The records. </summary>
private List<NDEFRecord> records;
/// <summary> Type of the message. </summary>
private MsgType msgType;
#endregion
#region constructors
/// <summary> Initializes a new instance of the NDEFMessage class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="content"> The content. </param>
/// <param name="type"> The type. </param>
public NDEFMessage(string content, MsgType type)
{
this.records = new List<NDEFRecord>();
float recordsCount = (float)content.Length / NDEFRecord.MaxRecordPayLoad;
NDEFRecord tmpRecord = null;
string praefix = type.PayloadPrefix;
MsgType.TNFVAL tnf = type.TNFValue;
MsgType.TYPEVAL typeVal = type.TypeValue;
this.msgType = type;
for (int i = 0; recordsCount > 0; i++)
{
tmpRecord = new NDEFShortRecord();
tmpRecord.Type = typeVal;
tmpRecord.TNF = tnf;
tmpRecord.PayloadPraefix = praefix;
tmpRecord = new NDEFShortRecord(type);
int recordsize = 255;
if (content.Length < (i + 1) * recordsize)
@@ -58,14 +62,14 @@
/// <summary> Initializes a new instance of the NDEFMessage class. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <param name="array"> The array. </param>
public NDEFMessage(byte[] array, Encoding payLoadEncoding)
public NDEFMessage(byte[] array)
{
this.records = new List<NDEFRecord>();
NDEFRecord tmpRecord = null;
for (int i = 0; i < array.Length; i += tmpRecord.RecordSize)
{
tmpRecord = new NDEFShortRecord(array, payLoadEncoding, i);
tmpRecord = new NDEFShortRecord(array, i);
this.records.Add(tmpRecord);
}
@@ -73,6 +77,18 @@
#endregion
#region property
/// <summary> Gets or sets the type of the message. </summary>
/// <value> The type of the message. </value>
protected MsgType MsgType
{
get { return this.msgType; }
set { this.msgType = value; }
}
#endregion
#region Methods
/// <summary> Gets the content. </summary>
@@ -93,12 +109,12 @@
/// <summary> Converts this object to a byte array. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <returns> This object as a byte[]. </returns>
public virtual byte[] ToByteArray(Encoding payLoadEncoding)
public virtual byte[] ToByteArray()
{
MemoryStream ms = new MemoryStream();
foreach (NDEFRecord record in this.records)
{
ms.Write(record.ToByteArray(payLoadEncoding), 0, record.RecordSize);
ms.Write(record.ToByteArray(), 0, record.RecordSize);
}
return ms.ToArray();

View File

@@ -0,0 +1,23 @@

// namespace: ndefpclib.message.Text
//
// summary: .
namespace ndefpclib.message.Text
{
using ndefpclib.type.Const;
/// <summary> A text message UTF 16. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <seealso cref="T:ndefpclib.message.Text.TextMessage"/>
public class TextMessageUTF16 : TextMessage
{
/// <summary> Initializes a new instance of the TextMessageUTF16 class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="content"> The content. </param>
/// <param name="lang"> The language. </param>
public TextMessageUTF16(string content, string lang)
: base(content, TextEncoding.UTF16, lang)
{
}
}
}

View File

@@ -0,0 +1,22 @@
// namespace: ndefpclib.message.Text
//
// summary: .
namespace ndefpclib.message.Text
{
using ndefpclib.type.Const;
/// <summary> A text message UTF 8. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <seealso cref="T:ndefpclib.message.Text.TextMessage"/>
public class TextMessageUTF8 : TextMessage
{
/// <summary> Initializes a new instance of the TextMessageUTF8 class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="content"> The content. </param>
/// <param name="lang"> The language. </param>
public TextMessageUTF8(string content, string lang)
: base(content, TextEncoding.UTF8, lang)
{
}
}
}

View File

@@ -0,0 +1,23 @@
// namespace: ndefpclib.message.Text
//
// summary: .
namespace ndefpclib.message.Text
{
using ndefpclib.type;
/// <summary> A text message. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <seealso cref="T:ndefpclib.message.NDEFMessage"/>
public class TextMessage : NDEFMessage
{
/// <summary> Initializes a new instance of the TextMessage class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="content"> The content. </param>
/// <param name="encoding"> The encoding. </param>
/// <param name="lang"> The language. </param>
public TextMessage(string content, string encoding, string lang)
: base(content, new TextType(encoding,lang))
{
}
}
}

View File

@@ -38,6 +38,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="message\NDEFMessage.cs" />
<Compile Include="message\Text\TextMessageUTF16.cs" />
<Compile Include="message\Text\TextMessages.cs" />
<Compile Include="message\Text\TextMessageUTF8.cs" />
<Compile Include="record\NDEFRecord.cs" />
<Compile Include="record\NDEFShortRecord.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -46,6 +49,7 @@
<Compile Include="type\Const\TextEncoding.cs" />
<Compile Include="type\TextType.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -1,9 +1,9 @@
namespace ndefpclib.records
// namespace: ndefpclib.records
//
// summary: .
namespace ndefpclib.records
{
using ndefpclib.message;
using ndefpclib.type;
using System.IO;
using System.Text;
/// <summary> Ndef record of a NDEFMessage. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
@@ -17,9 +17,13 @@
/// <summary> Size of the type. </summary>
protected const byte TypeSize = 0x01;
/// <summary> Type of the message. </summary>
private MsgType msgType;
#endregion
#region Constructors
/// <summary> Initializes a new instance of the NDEFRecord class. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
public NDEFRecord()
@@ -29,10 +33,24 @@
/// <summary> Initializes a new instance of the NDEFRecord class. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <param name="array"> The array. </param>
/// <param name="headerSize"> The size of the header. </param>
/// <param name="index"> (Optional) zero-based index of the. </param>
public NDEFRecord(byte[] array, int index = 0)
public NDEFRecord(byte[] array, int headerSize,int index = 0)
{
this.msgType = MsgType.GetType(array, index);
this.HeaderSize = headerSize;
this.FormatFlags = array[index];
int payLoadSize = array[index + 2] - this.PayloadPraefix.Length;
this.Payload = msgType.Encoder.GetString(array, index + this.HeaderSize + this.PayloadPraefix.Length, payLoadSize);
}
/// <summary> Initializes a new instance of the NDEFRecord class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="type"> The type. </param>
public NDEFRecord(MsgType type)
{
this.msgType = type;
this.PayloadPraefix = type.PayloadPrefix;
}
#endregion
@@ -68,6 +86,7 @@
#endregion
#region Properties
/// <summary> Gets or sets the MBFlag. </summary>
/// <value> The MBFlag. </value>
public NDEFFlags MB { get; set; }
@@ -90,13 +109,13 @@
/// <summary> Gets or sets the TNFField. </summary>
/// <value> The TNFField. </value>
public MsgType.TNFVAL TNF { get; set; }
public MsgType.TNFVAL TNF { get { return this.MsgType.TNFValue; } set { this.MsgType.TNFValue = value; } }
/// <summary> Gets or sets the type. </summary>
/// <value> The type. </value>
public MsgType.TYPEVAL Type { get; set; }
public MsgType.TYPEVAL Type { get { return this.MsgType.TypeValue; } set { this.MsgType.TypeValue = value; } }
/// <summary>Gets or sets the format flags.</summary>
/// <summary> Gets the format flags. </summary>
/// <value> The format flags. </value>
public byte FormatFlags
{
@@ -132,12 +151,20 @@
/// <summary> Gets or sets the payload praefix. </summary>
/// <value> The payload praefix. </value>
public string PayloadPraefix { get; set; }
public string PayloadPraefix { get { return this.MsgType.PayloadPrefix; } set { this.MsgType.PayloadPrefix = value; } }
/// <summary> Gets or sets the size of the header. </summary>
/// <value> The size of the header. </value>
protected int HeaderSize { get; set; }
/// <summary> Gets the type of the message. </summary>
/// <value> The type of the message. </value>
public MsgType MsgType
{
get { return msgType; }
protected set { msgType = value; }
}
#endregion
#region Methods
@@ -145,7 +172,7 @@
/// <summary> Converts the record to a byte array. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <returns> This object as a byte[]. </returns>
public abstract byte[] ToByteArray(Encoding payLoadEncoding);
public abstract byte[] ToByteArray();
#endregion
}

View File

@@ -1,4 +1,7 @@
namespace ndefpclib.records
// namespace: ndefpclib.records
//
// summary: .
namespace ndefpclib.records
{
using ndefpclib.message;
using ndefpclib.type;
@@ -6,6 +9,7 @@
/// <summary> Ndef short record. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <seealso cref="T:ndefpclib.records.NDEFRecord"/>
public class NDEFShortRecord : NDEFRecord
{
/// <summary> Initializes a new instance of the NDEFShortRecord class. </summary>
@@ -22,22 +26,31 @@
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <param name="array"> The array. </param>
/// <param name="index"> (Optional) zero-based index of the. </param>
public NDEFShortRecord(byte[] array, Encoding payLoadEncoding, int index = 0)
: base(array)
public NDEFShortRecord(byte[] array, int index = 0)
: base(array, 4)
{
this.SR = NDEFFlags.SRSET;
this.IL = NDEFFlags.UNSET;
this.CF = NDEFFlags.UNSET;
}
/// <summary> Initializes a new instance of the NDEFShortRecord class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="type"> The type. </param>
public NDEFShortRecord(MsgType type) : base(type)
{
this.HeaderSize = 4;
this.Type = (MsgType.TYPEVAL)array[index + 3];
this.PayloadPraefix = MsgType.GetPraefix(this.Type);
int payLoadSize = array[index + 2] - this.PayloadPraefix.Length;
this.Payload = payLoadEncoding.GetString(array, index + this.HeaderSize + this.PayloadPraefix.Length, payLoadSize);
this.SR = NDEFFlags.SRSET;
this.IL = NDEFFlags.UNSET;
this.CF = NDEFFlags.UNSET;
}
/// <summary> Converts this NDEFShortRecord to a byte array. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <returns>This object as a byte[].</returns>
public override byte[] ToByteArray(Encoding payLoadEncoding)
/// <seealso cref="M:ndefpclib.records.NDEFRecord.ToByteArray()"/>
public override byte[] ToByteArray()
{
byte[] payloadAr = payLoadEncoding.GetBytes(this.PayloadPraefix + this.Payload);
byte[] payloadAr = this.MsgType.Encoder.GetBytes(this.PayloadPraefix + this.Payload);
byte[] array = new byte[payloadAr.Length + this.HeaderSize];
array[0] = this.FormatFlags;

View File

@@ -1,15 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// namespace: ndefpclib.type.Const
//
// summary: .
namespace ndefpclib.type.Const
{
/// <summary> A language. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
public class Language
{
/// <summary> The de. </summary>
public const string DE ="de";
/// <summary> The en. </summary>
public const string EN = "en";
}
}

View File

@@ -1,15 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// namespace: ndefpclib.type.Const
//
// summary: .
namespace ndefpclib.type.Const
{
using System.Text;
/// <summary> A text encoding. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
public class TextEncoding
{
/// <summary> The UTF 8. </summary>
public const string UTF8 = "\x02";
//public const string UTF16 = "\x82";
/// <summary> The UTF 16. </summary>
public const string UTF16 = "\x82";
/// <summary> Gets an encoding. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="input"> The input. </param>
/// <returns> The encoding. </returns>
public static Encoding GetEncoding(string input)
{
switch (input)
{
case UTF8:
return Encoding.UTF8;
case UTF16:
return Encoding.Unicode;
default:
return null;
}
}
}
}

View File

@@ -1,19 +1,51 @@
using ndefpclib.type.Const;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// namespace: ndefpclib.type
//
// summary: .
namespace ndefpclib.type
{
using ndefpclib.type.Const;
using System.Text;
/// <summary> A text type. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <seealso cref="T:ndefpclib.type.MsgType"/>
public class TextType : MsgType
{
/// <summary> Initializes a new instance of the TextType class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="encoding"> (Optional) the encoding. </param>
/// <param name="lang"> (Optional) the language. </param>
public TextType(string encoding = TextEncoding.UTF8, string lang = Language.DE)
{
this.TNFValue = TNFVAL.WKT;
this.TypeValue = TYPEVAL.TEXT;
this.Encoder = TextEncoding.GetEncoding(encoding);
this.PayloadPrefix = encoding + lang;
}
/// <summary> Gets text type. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="array"> The array. </param>
/// <param name="index"> Zero-based index of the. </param>
/// <returns> The text type. </returns>
public static TextType GetTextType(byte[] array, int index)
{
if (index + 6 >= array.Length)
{
return null;
}
string encoding = string.Format("{0}", (char)array[index + 4]);
Encoding encoder = TextEncoding.GetEncoding(encoding);
if (encoder == null)
{
return null;
}
string lang = encoder.GetString(array, 5, 2);
return new TextType(encoding, lang);
}
}
}

View File

@@ -1,15 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// namespace: ndefpclib.type
//
// summary: .
namespace ndefpclib.type
{
using System.Text;
/// <summary> A message type. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
public abstract class MsgType
{
#region enum
/// <summary> Values that represent TYPEVAL. </summary>
@@ -57,9 +58,23 @@ namespace ndefpclib.type
#endregion
#region property
public TYPEVAL TypeValue { get; protected set; }
public string PayloadPrefix { get; protected set; }
public TNFVAL TNFValue { get; protected set; }
/// <summary> Gets or sets the type value. </summary>
/// <value> The type value. </value>
public TYPEVAL TypeValue { get; set; }
/// <summary> Gets or sets the payload prefix. </summary>
/// <value> The payload prefix. </value>
public string PayloadPrefix { get; set; }
/// <summary> Gets or sets the tnf value. </summary>
/// <value> The tnf value. </value>
public TNFVAL TNFValue { get; set; }
/// <summary> Gets or sets the encoder. </summary>
/// <value> The encoder. </value>
public Encoding Encoder { get; set; }
#endregion
@@ -87,6 +102,28 @@ namespace ndefpclib.type
return praefix;
}
/// <summary> Gets a type. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="array"> The array. </param>
/// <param name="index"> Zero-based index of the. </param>
/// <returns> The type. </returns>
public static MsgType GetType(byte[] array, int index)
{
MsgType result = null;
MsgType.TYPEVAL typeEval = (MsgType.TYPEVAL)array[index + 3];
switch (typeEval)
{
case MsgType.TYPEVAL.TEXT:
result = TextType.GetTextType(array, index);
break;
default:
break;
}
return result;
}
#endregion
}
}