예제 #1
0
        public void SetNdef(Ndef ndef)
        {
            /* Display the NDEF as raw data in the hexBox */
            /* ------------------------------------------ */

            Trace.WriteLine("SetNdef");

            byte[] b = ndef.GetBytes();
            DynamicByteProvider p = new DynamicByteProvider(b);

            hexBox.ByteProvider = p;

            /* Try to recognize the NDEF, to display it in a user-friendly control */
            /* ------------------------------------------------------------------- */

            RtdControl control = null;

            if (ndef is RtdSmartPoster)
            {
                lbDecodedType.Text = "SmartPoster";
                control            = new RtdSmartPosterControl();
                control.SetContent(ndef);
            }
            else if (ndef is RtdUri)
            {
                lbDecodedType.Text = "URI";
                control            = new RtdUriControl();
                control.SetContent(ndef);
            }
            else if (ndef is RtdText)
            {
                lbDecodedType.Text = "Text";
                control            = new RtdControl();
                control.SetContent(ndef);
            }
            else if (ndef is RtdVCard)
            {
                lbDecodedType.Text = "VCard";
                control            = new RtdVCardControl();
                control.SetContent(ndef);
            }
            else if (ndef is RtdMedia)
            {
                lbDecodedType.Text = "Media (MIME)";
                control            = new RtdMediaControl();
                control.SetContent(ndef);
            }

            if (control != null)
            {
                pDecoded.Controls.Clear();
                control.Dock = DockStyle.Fill;
                pDecoded.Controls.Add(control);
            }
        }
예제 #2
0
        void OnTagRead(NfcTag _tag)
        {
            tag = _tag;

            Trace.WriteLine("Read terminated");

            if (tag == null)
            {
                MessageBox.Show("Internal error, tag is null!");
                return;
            }

            if ((tag.Content == null) || (tag.Content.Count == 0))
            {
                if (!tag.IsLocked())
                {
                    MessageBox.Show("The Tag has no valid content yet. You may create your own content and write it onto the tag", "This NFC Tag is empty");
                    setEditable(true);
                }
                else
                {
                    MessageBox.Show("The Tag has no valid content, but is not writable", "This NFC Tag is empty");
                }
            }
            else
            {
                Unselect();

                for (int i = 0; i < tag.Content.Count; i++)
                {
                    /* Display the first record we support in the tag's content */
                    Ndef ndef = tag.Content[i];

                    if (ndef is RtdSmartPoster)
                    {
                        SelectSmartPoster();
                    }
                    else
                    if (ndef is RtdUri)
                    {
                        SelectUri();
                    }
                    else
                    if (ndef is RtdText)
                    {
                        SelectText();
                    }
                    else
                    if (ndef is RtdVCard)
                    {
                        SelectVCard();
                    }
                    else
                    if (ndef is RtdMedia)
                    {
                        SelectMedia();
                    }
                    else
                    if (ndef is RtdHandoverSelector)
                    {
                        SelectWifiHandover();
                    }

                    if (control != null)
                    {
                        control.SetContent(ndef);
                        break;
                    }
                }

                if (!tag.IsLocked())
                {
                    /* It will be possible to rewrite the tag */
                    setEditable(true);
                }

                if (control == null)
                {
                    /* No supported record has been found */
                    Unselect();
                    MessageBox.Show("This Tag contains a valid content, but this application doesn't know how to display it", "This NFC Tag is not supported");
                }
            }
        }