Exemplo n.º 1
0
        static void Initialized(object sender, CardStatusEventArgs args)
        {
            SCardMonitor monitor = (SCardMonitor)sender;

            Console.WriteLine(">> Initialized Event for reader: "
                + args.ReaderName);
            Console.WriteLine("   ATR: " + StringAtr(args.Atr));
            Console.WriteLine("   State: " + args.State + "\n");
        }
 private void CardEvent(object sender, CardStatusEventArgs args)
 {
   if (this.Dispatcher.CheckAccess())
   {
     UpdateDataGrid();
   }
   else
   {
     this.Dispatcher.Invoke((Action)(() =>
     {
       UpdateDataGrid();
     }));
   }
 }
Exemplo n.º 3
0
 private void _cardRemoved(object sender, CardStatusEventArgs e)
 {
 }
Exemplo n.º 4
0
 private void _cardInserted(object sender, CardStatusEventArgs e)
 {
     ReadCard();
 }
Exemplo n.º 5
0
        private void _cardInitalised(object sender, CardStatusEventArgs e)
        {
            string temp_message = string.Empty;

            if (string.IsNullOrEmpty(_connectedReader) || _monitor == null) return;
            if (_monitor.Monitoring)
            {
                _monitoredReaders = _monitor.ReaderNames;
                string monitoredReaders = _monitor.ReaderNames.Aggregate(string.Empty, (current, reader) => current + " " + reader);
                temp_message = string.Format("Now monitoring {0}", monitoredReaders);
                // TODO: Update the UI
            }
            else
            {
                temp_message = "Not monitoring any card readers, won't detect that a new card is inserted.";
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Invoked when a new card was inserted into the reader
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void CardInserted( object sender, CardStatusEventArgs args )
        {
            Log.Info( "Card detected." );
            try {
                byte[] uid = UidFromConnectedCard( args.ReaderName );

                // We only care about the first 4 bytes
                byte[] shortUid = new byte[4];
                Array.Copy( uid, shortUid, 4 );
                string uidString = BitConverter.ToString( shortUid ).Replace( "-", string.Empty );
                Log.InfoFormat( "Read UID '{0}' from '{1}'.", uidString, args.ReaderName );
                BroadcastUidEvent( shortUid );
            } catch( Exception ex ) {
                Log.Error( ex.Message );
                BroadcastErrorEvent( new byte[] {0} );
            }
        }
Exemplo n.º 7
0
 private static void DisplayEvent(string eventName, CardStatusEventArgs unknown) {
     Console.WriteLine(">> {0} Event for reader: {1}", eventName, unknown.ReaderName);
     Console.WriteLine("ATR: {0}", BitConverter.ToString(unknown.Atr ?? new byte[0]));
     Console.WriteLine("State: {0}\n", unknown.State);
 }
Exemplo n.º 8
0
 private void ReaderInitializedEvent(CardStatusEventArgs args)
 {
     Debug.WriteLine("Reader {0} initialized", args.ReaderName);
 }
Exemplo n.º 9
0
        private void CardInsertedEvent(CardStatusEventArgs args)
        {
            int readerId = -1;
            for (int i = 0; i < readerNames.Length; i++)
            {
                if(readerNames[i].Equals(args.ReaderName)){
                    readerId = i;
                    break;
                }
            }
            if(readerId < 0) return;

            NdefMessage message = GetNdefMessage(args.ReaderName);

            if(message != null){
                _newNdefMessageDetected(message, readerId);
            }
        }
Exemplo n.º 10
0
        private void OnInitialized(byte[] atr, string readerName, SCRState initState)
        {
            var handler = Initialized;

            if (handler == null) {
                return;
            }

            var args = new CardStatusEventArgs(
                readerName,
                initState,
                atr);

            handler(this, args);
        }
Exemplo n.º 11
0
        private void OnCardRemoved(byte[] atr, string readerName, SCRState newState)
        {
            var handler = CardRemoved;

            if (handler == null) {
                return;
            }

            var args = new CardStatusEventArgs(
                readerName,
                newState,
                atr);

            handler(this, args);
        }
Exemplo n.º 12
0
 private void CardRemoved(object sender, CardStatusEventArgs e)
 {
     //throw new NotImplementedException();
 }
Exemplo n.º 13
0
        private void CardInserted(object sender, CardStatusEventArgs e)
        {
            Log.Debug("Card inserted");

            try
            {
                using (var reader = new IsoReader(CardContext, GetReader(), SCardShareMode.Shared, SCardProtocol.Any, false))
                {
                    var id = GetCardId(reader);
                    var status = GetReaderStatus(reader);

                    var cardName = GetCardName(status.Atr);
                    var cardType = GetInt16(cardName);

                    var isMifare = cardType == Mifare1KCard || cardType == Mifare4KCard;
                    var isMifareUltralight = cardType == MifareUltralightCard;

                    //var bytes = GetAllCardBytes(reader, isMifareUltralight ? 4 : 16);
                    var isShopCard = true; // IsShopCard(bytes);

                    Log.Debug(String.Format("Card Id: {0}, Shop Card: {1}", BitConverter.ToString(id), isShopCard));

                    if (isShopCard)
                    {
                        var cardString = BitConverter.ToString(cardName.Concat(id).ToArray()).Replace("-", "");

                        EventAggregator.Publish(new CardInserted { CardId = cardString });
                    }
                    else
                    {
                        EventAggregator.Publish(new InvalidCardInserted { });
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);

                EventAggregator.Publish(new InvalidCardInserted { });
            }
        }
Exemplo n.º 14
0
 private void _Removed(string eventName, CardStatusEventArgs unknown)
 {
     if (eventCardRemoved != null)
     {
         eventCardRemoved();
     }
 }