Exemple #1
0
        public bool StartSmartCardMonitor(CardInitializedEvent onCardInitialized, CardInsertedEvent onCardInserted, CardRemovedEvent onCardRemoved)
        {
            try
            {
                var contextFactory = ContextFactory.Instance;
                _sCardMonitor = new PCSC.SCardMonitor(contextFactory, SCardScope.System);
                if (onCardInitialized != null)
                {
                    _sCardMonitor.Initialized += onCardInitialized;
                }
                if (onCardInserted != null)
                {
                    _sCardMonitor.CardInserted += onCardInserted;
                }
                if (onCardRemoved != null)
                {
                    _sCardMonitor.CardRemoved += onCardRemoved;
                }

                _sCardMonitor.Start(EnumDeviceNames.SmartCardContactlessReader);

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("StartCardMonitor Exception: " + ex.Message);
                return(false);
            }
        }
Exemple #2
0
        public CardReader(CardRemovedEvent removedEvent, CardInsertedEvent insertedEvent)
        {
            TS.TraceI("Constructing CardReader object.");
            _systemCardContext = OpenSystemWideCardContext();

            if (removedEvent != null || insertedEvent != null)
            {
                _monitor = new SCardMonitor(_systemCardContext);
                if (removedEvent != null)
                {
                    TS.TraceV("Monitoring removedEvent");
                    _monitor.CardRemoved += new CardRemovedEvent(removedEvent);
                }
                if (insertedEvent != null)
                {
                    TS.TraceV("Monitoring insertedEvent");
                    _monitor.CardInserted += new CardInsertedEvent(insertedEvent);
                }

                readerNames = GetReaderNames();

                foreach (string s in readerNames)
                {
                    TS.TraceV("Reader detected: \"{0}\".", s);
                }

                this.StartMonitor();
                TS.TraceI("Monitor started.");
            }
            TS.TraceI("CardReader object constructed.");
        }
 /// <summary>
 /// 리더기를 모니터링합니다. 카드가 인식되었는지, 또는 카드가 떨어졌는지에 대한 이벤트를 연결할 수 있습니다.
 /// 이벤트에 연결하려면 반드시 실행하셔야 하는 함수입니다.
 /// </summary>
 /// <param name="CardInserted">카드가 인식되었을 때 작동하는 Callback 메서드입니다. CardInsertedEvent 델리게이트 형태의 함수를 인자로 입력하십시오.</param>
 /// <param name="CardRemoved">카드가 떼어졌을 때 작동하는 Callback 메서드입니다. CardIRemovedEvent 델리게이트 형태의 함수를 인자로 입력하십시오.</param>
 public void SCardMonitorInit(CardInsertedEvent CardInserted, CardRemovedEvent CardRemoved)
 {
     monitor = new SCardMonitor(new SCardContext(), SCardScope.System);
     monitor.CardInserted += new CardInsertedEvent(CardInserted);
     monitor.CardRemoved  += new CardRemovedEvent(CardRemoved);
     monitor.Start(readers[0].ToString());
 }
Exemple #4
0
        public CardReader(CardRemovedEvent removedEvent, CardInsertedEvent insertedEvent)
        {
            TS.TraceI("Constructing CardReader object.");
            _systemCardContext = OpenSystemWideCardContext();

            if (removedEvent != null || insertedEvent != null)
            {
                _monitor = new SCardMonitor(_systemCardContext);
                if (removedEvent != null)
                {
                    TS.TraceV("Monitoring removedEvent");
                    _monitor.CardRemoved += new CardRemovedEvent(removedEvent);
                }
                if (insertedEvent != null)
                {
                    TS.TraceV("Monitoring insertedEvent");
                    _monitor.CardInserted += new CardInsertedEvent(insertedEvent);
                }

                readerNames = GetReaderNames();

                foreach (string s in readerNames)
                {
                    TS.TraceV("Reader detected: \"{0}\".", s);
                }

                this.StartMonitor();
                TS.TraceI("Monitor started.");
            }
            TS.TraceI("CardReader object constructed.");
        }
Exemple #5
0
 public eVRCardReader(X509Certificate2 CSCA, CardRemovedEvent removedEvent, CardInsertedEvent insertedEvent)
 {
     TS.TraceI("Constructing MTVCardReader object.");
     TS.TraceI("eVRCApplicatie = {0}", Helper.ByteArrayToString(eVRCApplicatie));
     if (CSCA != null)
     {
         this.CSCA = CSCA;
         TS.TraceV("CSCA Subject : \"{0}\".", CSCA.Subject);
         TS.TraceV("CSCA Effective date : \"{0}\".", CSCA.GetEffectiveDateString());
         TS.TraceV("CSCA Expiration date : \"{0}\".", CSCA.GetExpirationDateString());
     }
     this.cardReader = new CardReader(removedEvent, insertedEvent);
     TS.TraceI("MTVCardReader constructed.");
 }
Exemple #6
0
 public eVRCardReader(X509Certificate2 CSCA, CardRemovedEvent removedEvent, CardInsertedEvent insertedEvent)
 {
     TS.TraceI("Constructing MTVCardReader object.");
     TS.TraceI("eVRCApplicatie = {0}", Helper.ByteArrayToString(eVRCApplicatie));
     if (CSCA != null)
     {
         this.CSCA = CSCA;
         TS.TraceV("CSCA Subject : \"{0}\".", CSCA.Subject);
         TS.TraceV("CSCA Effective date : \"{0}\".", CSCA.GetEffectiveDateString());
         TS.TraceV("CSCA Expiration date : \"{0}\".", CSCA.GetExpirationDateString());
     }
     this.cardReader = new CardReader(removedEvent, insertedEvent);
     TS.TraceI("MTVCardReader constructed.");
 }
Exemple #7
0
        private static async Task <CardStatusEventArgs> WaitForCardInsert(string readerName, IContextFactory contextFactory, CancellationToken ct)
        {
            var monitor = new SCardMonitor(contextFactory, SCardScope.System);
            var tcs     = new TaskCompletionSource <CardStatusEventArgs>();

            ct.Register(() => { tcs.TrySetCanceled(); });
            CardInsertedEvent onCardInserted = (sender, args) => { tcs.TrySetResult(args); };

            monitor.CardInserted += onCardInserted;
            monitor.Start(new[] { readerName });
            var cardStatus = await tcs.Task.ConfigureAwait(false);

            monitor.CardInserted -= onCardInserted;
            monitor.Cancel();
            return(cardStatus);
        }