public IHttpActionResult Get([Metadata("Base64 NDEF Message",
            "Base64 encoded NDEF message which contains a vCard record as the first record")] string b64Content)
        {
            NdefMessage ndefMessage = null;

            try
            {
                ndefMessage = NdefMessage.FromByteArray(Convert.FromBase64String(b64Content));
            }
            catch
            {
                return BadRequest("Could not parse NDEF message");
            }

            var firstRecord = ndefMessage.FirstOrDefault();

            if (firstRecord.CheckSpecializedType(true) != typeof(NdefVcardRecordBase))
                return BadRequest("First record in NDEF message was not a vCard record");

            using (var contentStream = new MemoryStream(firstRecord.Payload))
            {
                using (var reader = new StreamReader(contentStream))
                {
                    vCard card = new vCard(reader);

                    return Ok(new VCardModel()
                    {
                        EmailAddress = card.EmailAddresses.Any() ? card.EmailAddresses.FirstOrDefault().Address : string.Empty,
                        FamilyName = card.FamilyName,
                        GivenName = card.GivenName

                    });
                }

            }
        }
Esempio n. 2
0
 /// <summary>
 ///     Writes a vCard to an I/O stream using the format
 ///     implemented by the class.
 /// </summary>
 /// <param name="card">
 ///     The vCard to write the I/O string.
 /// </param>
 /// <param name="output">
 ///     The text writer to use for output.
 /// </param>
 /// <remarks>
 ///     The implementor should not close or flush the stream.
 ///     The caller owns the stream and may not wish for the
 ///     stream to be closed (e.g. the caller may call the
 ///     function again with a different vCard).
 /// </remarks>
 public abstract void Write(vCard card, TextWriter output);
Esempio n. 3
0
 /// <summary>
 ///     Reads vCard information from a text reader and
 ///     populates into an existing vCard object.
 /// </summary>
 /// <param name="card">
 ///     An initialized vCard object.
 /// </param>
 /// <param name="reader">
 ///     A text reader containing vCard data in the format
 ///     expected by the card reader class.
 /// </param>
 public abstract void ReadInto(vCard card, TextReader reader);
Esempio n. 4
0
 /// <summary>
 ///     Reads a vCard from the specified input stream.
 /// </summary>
 /// <param name="reader">
 ///     A text reader that points to the beginning of
 ///     a vCard in the format expected by the implementor.
 /// </param>
 /// <returns>
 ///     An initialized <see cref="vCard"/> object.
 /// </returns>
 public vCard Read(TextReader reader)
 {
     vCard card = new vCard();
     ReadInto(card, reader);
     return card;
 }
Esempio n. 5
0
 /// <summary>
 ///     Reads vCard information from a text reader and
 ///     populates into an existing vCard object.
 /// </summary>
 /// <param name="card">
 ///     An initialized vCard object.
 /// </param>
 /// <param name="reader">
 ///     A text reader containing vCard data in the format
 ///     expected by the card reader class.
 /// </param>
 public abstract void ReadInto(vCard card, TextReader reader);
Esempio n. 6
0
 /// <summary>
 ///     Writes a vCard to an I/O stream using the format
 ///     implemented by the class.
 /// </summary>
 /// <param name="card">
 ///     The vCard to write the I/O string.
 /// </param>
 /// <param name="output">
 ///     The text writer to use for output.
 /// </param>
 /// <remarks>
 ///     The implementor should not close or flush the stream.
 ///     The caller owns the stream and may not wish for the
 ///     stream to be closed (e.g. the caller may call the
 ///     function again with a different vCard).
 /// </remarks>
 public abstract void Write(vCard card, TextWriter output);