Ejemplo n.º 1
0
        private void card_format_proc(NfcTag _tag)
        {
            try
            {
                var again = true;

FormatAgain:
                if (_tag.Format())
                {
                    var msg = "Formatted Tag with UID " + _tagUID + " Successfully.";
                    SuccessNotify("Success|" + msg);
                    this.BeginInvoke(new OnTagFormatInvoker(OnTagFormat), _tag);
                }
                else
                {
                    if (again)
                    {
                        again = false;
                        goto FormatAgain;
                    }

                    var msg = "Tag Format Failure. Please try again or contact Support.";
                    WarnNotify("Warning|" + msg);
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
Ejemplo n.º 2
0
        /*
         * card_write_proc
         * ---------------
         * This is the core function to try read a card, and maybe recognize it as an NFC tag
         * The function is executed in a background thread, so the application's window keeps
         * responding during the dialog
         */
        private void card_write_proc(object _tag)
        {
            if (_tag == null)
            {
                return;                 /* Oups */
            }
            if (!(_tag is NfcTag))
            {
                return;                 /* Oups */
            }
            NfcTag tag = _tag as NfcTag;

            if (!tag.IsFormatted() && !tag.Format())
            {
                this.BeginInvoke(new OnErrorInvoker(OnError), "This application has been unable to format the Tag", "Failed to encode the NFC Tag");
                return;
            }

            if (!tag.Write())
            {
                this.BeginInvoke(new OnErrorInvoker(OnError), "This application has been unable to write onto the Tag", "Failed to encode the NFC Tag");
                return;
            }

            if (cbLock.Visible && cbLock.Checked)
            {
                /* Try to lock the Tag */
                if (tag.IsLockable())
                {
                    if (!tag.Lock())
                    {
                        this.BeginInvoke(new OnErrorInvoker(OnError), "This application has been unable to lock the Tag in read-only state", "Failed to encode the NFC Tag");
                        return;
                    }
                }
                else
                {
                    /* This Tag is not locackable */
                    this.BeginInvoke(new OnErrorInvoker(OnError), "The Tag has been successfully written, but there's no method to put it in read-only state", "This NFC Tag can't be locked");
                    return;
                }
            }

            /* Done */
            this.BeginInvoke(new OnTagWriteInvoker(OnTagWrite), tag);
        }