Exemple #1
0
        private async void DoMapCard(System.Threading.CancellationToken token)
        {
            //acr33u    "ACS ACR33U-A1 3SAM ICC Reader ICC 0"
            //acr38     "ACS CCID USB Reader 0"

            //using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosNoCardDetectionFactory("ACS ACR33U-A1 3SAM ICC Reader ICC 0")))
            //using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosNoCardDetectionFactory("ACS CCID USB Reader 0")))
            using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosCardReaderFactory()))
            {
                mgr.CardRemoved += mgr_CardRemoved;
                while (!token.IsCancellationRequested)
                {
                    try
                    {
                        var cardReader = await mgr.ConnectToReaderWhenNextCardInserted(token);

                        if (cardReader == null)
                        {
                            continue;
                        }

                        var res = TheS.SmartCard.Formatters.ThaiIdCardFormatter.IsThaiIdCard(cardReader);
                        if (!res)
                        {
                            string pid = string.Empty;
                            if (TheS.SmartCard.Formatters.SimpleMemoryCardFormatter.IsMemoryCard(cardReader))
                            {
                                using (var fmt = new TheS.SmartCard.Formatters.SimpleMemoryCardFormatter(cardReader))
                                {
                                    pid = fmt.ReadString();
                                    fmt.WriteString(NewCode.Text);
                                }
                            }
                            else
                            {
                                using (var fmt = new TheS.SmartCard.Formatters.SimpleCardBinaryFileFormatter(cardReader))
                                {
                                    pid = fmt.ReadString();
                                    fmt.WriteString(NewCode.Text);
                                }
                            }

                            OldCode.Text = NewCode.Text;
                            this.LoadTab2(NewCode.Text);
                            this.LoadTab3(NewCode.Text);
                            MessageBox.Show("ระบบอัพเดท Wild Card    " + pid + "   To   " + NewCode.Text);

                            cts.Cancel();
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Exemple #2
0
        private async void DoReadCard(System.Threading.CancellationToken token)
        {
            //acr33u    "ACS ACR33U-A1 3SAM ICC Reader ICC 0"
            //acr38     "ACS CCID USB Reader 0"

            using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosNoCardDetectionFactory("ACS CCID USB Reader 0")))
            //using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosCardReaderFactory()))
            {
                mgr.CardRemoved += mgr_CardRemoved;
                while (true != this.cts.Token.IsCancellationRequested)
                {
                    try
                    {
                        var cardReader = await mgr.ConnectToReaderWhenNextCardInserted(token);

                        if (cardReader == null)
                        {
                            continue;
                        }

                        var res = TheS.SmartCard.Formatters.ThaiIdCardFormatter.IsThaiIdCard(cardReader);
                        Console.WriteLine(res);
                        if (!res)
                        {
                            if (TheS.SmartCard.Formatters.SimpleMemoryCardFormatter.IsMemoryCard(cardReader))
                            {
                                using (var fmt = new TheS.SmartCard.Formatters.SimpleMemoryCardFormatter(cardReader))
                                {
                                    var pid = fmt.ReadString();
                                    ViewModel.CheckExam(pid, navigateMethod);
                                    //this.LicenList.Focus();
                                    fmt.Dispose();
                                    //this.LicenList.Focus();
                                }
                            }
                            else
                            {
                                using (var fmt = new TheS.SmartCard.Formatters.SimpleCardBinaryFileFormatter(cardReader))
                                {
                                    var pid = fmt.ReadString();

                                    ViewModel.CheckExam(pid, navigateMethod);

                                    this.cts.Cancel();
                                    fmt.Dispose();
                                    //this.LicenList.Focus();
                                }
                            }
                        }
                        else
                        {
                            using (var thaiCard = new TheS.SmartCard.Formatters.ThaiIdCardFormatter(cardReader))
                            {
                                var info = await thaiCard.GetPersonalInfo();

                                var imgData = await thaiCard.GetPictureData();

                                using (var ms = new System.IO.MemoryStream(imgData))
                                {
                                    var decoder = new JpegBitmapDecoder(ms,
                                                                        BitmapCreateOptions.PreservePixelFormat,
                                                                        BitmapCacheOption.OnLoad);

                                    WriteableBitmap writable = new WriteableBitmap(decoder.Frames.Single());
                                    writable.Freeze();

                                    profileImg.Source = writable;
                                }
                                //Console.WriteLine(info.PID);

                                ViewModel.CheckExam(info.PID, navigateMethod);
                                //this.LicenList.Focus();

                                this.cts.Cancel();
                                thaiCard.Dispose();
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                    }
                }
                mgr.CardRemoved -= mgr_CardRemoved;
            }
        }
Exemple #3
0
        private async void DoReadCard(System.Threading.CancellationToken token)
        {
            //acr33u    "ACS ACR33U-A1 3SAM ICC Reader ICC 0"
            //acr38     "ACS CCID USB Reader 0"

            //using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosNoCardDetectionFactory("ACS ACR33U-A1 3SAM ICC Reader ICC 0")))
            //using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosNoCardDetectionFactory("ACS CCID USB Reader 0")))
            using (var mgr = new SmartCardReaderManager(new TheS.SmartCard.ACOSx86.AcosCardReaderFactory()))
            {
                mgr.CardRemoved += mgr_CardRemoved;
                while (!token.IsCancellationRequested)
                {
                    try
                    {
                        var cardReader = await mgr.ConnectToReaderWhenNextCardInserted(token);

                        if (cardReader == null)
                        {
                            continue;
                        }

                        var res = TheS.SmartCard.Formatters.ThaiIdCardFormatter.IsThaiIdCard(cardReader);
                        if (!res)
                        {
                            if (TheS.SmartCard.Formatters.SimpleMemoryCardFormatter.IsMemoryCard(cardReader))
                            {
                                using (var fmt = new TheS.SmartCard.Formatters.SimpleMemoryCardFormatter(cardReader))
                                {
                                    if (MyInfo == null)
                                    {
                                        MyInfo = new PersonalCardInfo();
                                    }
                                    MyInfo.PID = fmt.ReadString();
                                }
                            }
                            else
                            {
                                using (var fmt = new TheS.SmartCard.Formatters.SimpleCardBinaryFileFormatter(cardReader))
                                {
                                    if (MyInfo == null)
                                    {
                                        MyInfo = new PersonalCardInfo();
                                    }
                                    MyInfo.PID = fmt.ReadString();
                                }
                            }
                        }
                        else
                        {
                            using (var thaiCard = new TheS.SmartCard.Formatters.ThaiIdCardFormatter(cardReader))
                            {
                                MyInfo = await thaiCard.GetPersonalInfo();

                                if (MyInfo == null)
                                {
                                    MyInfo = new PersonalCardInfo();
                                }

                                //var imgData = await thaiCard.GetPictureData();
                                //using (var ms = new System.IO.MemoryStream(imgData))
                                //{
                                //    //var decoder = new JpegBitmapDecoder(ms,
                                //    //                                BitmapCreateOptions.PreservePixelFormat,
                                //    //                                BitmapCacheOption.OnLoad);

                                //    //WriteableBitmap writable = new WriteableBitmap(decoder.Frames.Single());
                                //    //writable.Freeze();
                                //}
                            }
                        }
                        OldCode.Text = MyInfo.PID;
                        this.LoadTab2(MyInfo.PID);
                        this.LoadTab3(MyInfo.PID);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
                //mgr.CardRemoved -= mgr_CardRemoved;
            }
        }