示例#1
0
        private void ReadIDField(Citizen citizen)
        {
            var id = Pteid.GetID();

            citizen.Number             = Convert2UTF8(id.cardNumber);
            citizen.CardNumber         = Convert2UTF8(id.numBI);
            citizen.Nationality        = Convert2UTF8(id.nationality);
            citizen.Genre              = Convert2UTF8(id.sex);
            citizen.Country            = Convert2UTF8(id.country);
            citizen.HealthSystemNumber = Convert2UTF8(id.numSNS);
            citizen.TaxNumber          = Convert2UTF8(id.numNIF);
            citizen.LastName           = Convert2UTF8(id.name);
            citizen.FirstName          = Convert2UTF8(id.firstname);
            citizen.CardExpirationDate = Convert2UTF8(id.validityDate);
            citizen.BirthDate          = Convert2UTF8(id.birthDate);
        }
示例#2
0
        private void ReadAddress(Citizen citizen)
        {
            var addr = Pteid.GetAddr();

            citizen.Address.Street   = Convert2UTF8(addr.street);
            citizen.Address.District = Convert2UTF8(addr.districtDesc);
            citizen.Address.Building = Convert2UTF8(addr.building);
            citizen.Address.Country  = Convert2UTF8(addr.country);
            citizen.Address.Type     = Convert2UTF8(addr.addrType);
            citizen.Address.Parish   = Convert2UTF8(addr.freguesiaDesc);
            citizen.Address.Locality = Convert2UTF8(addr.locality);
            citizen.Address.Door     = Convert2UTF8(addr.door);
            citizen.Address.Floor    = Convert2UTF8(addr.floor);
            citizen.Address.ZipCode1 = Convert2UTF8(addr.cp4);
            citizen.Address.ZipCode2 = Convert2UTF8(addr.cp3);
        }
示例#3
0
        private void ReadPicture(Citizen citizen)
        {
            var pictureData = Pteid.GetPic();

            if (pictureData == null || pictureData.picture == null)
            {
                return;
            }

            var j2kImg = CSJ2K.J2kImage.FromBytes(pictureData.picture);
            var bmap   = j2kImg.As <Bitmap>();

            var imgConverter = new ImageConverter();
            var bitmapBytes  = (byte[])imgConverter.ConvertTo(bmap, typeof(byte[]));

            citizen.Picture = Convert.ToBase64String(bitmapBytes);
        }
示例#4
0
        private void ReadCertificates(Citizen citizen)
        {
            PteidCertif[] pCerts = Pteid.GetCertificates();
            if (pCerts == null)
            {
                return;
            }

            var certificates = new List <Certificate>();

            foreach (PteidCertif pCert in pCerts)
            {
                var cert = new X509Certificate2(pCert.certif);
                certificates.Add(new Certificate()
                {
                    Label = pCert.certifLabel,
                    ExpirationDateString = cert.GetExpirationDateString(),
                    KeyAlgorithm         = cert.GetKeyAlgorithm(),
                    PublicKey            = cert.GetPublicKeyString()
                });
            }
            citizen.Certificates = certificates;
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="readAddress">Reading address will promp for password, to avoid it don't read the address.</param>
        /// <returns></returns>
        public Citizen Read(bool readAddress = true)
        {
            // enable bitmap convertion for CSJ2K
            BitmapImageCreator.Register();

            // connect to card
            Pteid.Init(null);
            Pteid.SetSODChecking(0);

            // read data
            var citizen = new Citizen();

            ReadIDField(citizen);
            ReadCertificates(citizen);
            ReadPicture(citizen);

            if (readAddress)
            {
                ReadAddress(citizen);                 // will request address password
            }

            return(citizen);
        }
示例#6
0
        /// <summary>
        /// Obters the dados cartao cidadao.
        /// </summary>
        /// <param name="leitor">The leitor.</param>
        /// <returns></returns>
        private Cidadao ObterDadosCartaoCidadao(string leitor)
        {
            Cidadao cidadao = null;

            try
            {
                Pteid.Init(leitor);
                Pteid.SetSODChecking(0);

                var x =
                    Pteid.GetID();

                var pins =
                    Pteid.GetPINs();

                var pinMorada =
                    pins.Where(fi => fi.id == 131).FirstOrDefault();

                PteidAddr address = null;

                // Descomentar linhas abaixo para ler a morada.
                // Nota: Vai pedir o PIN de morada, geralmente é: 0000

                //if (pinMorada.triesLeft > 0)
                //{
                //    address =
                //        Pteid.GetAddr();
                //}

                // Obter a fotografia e converter para byte[].

                var y = Pteid.GetPic();

                byte[] photo = null;

                using (MemoryStream ms = new MemoryStream(y.picture, 0, y.piclength, false))
                {
                    BitmapImageCreator.Register();

                    var tempImage = CSJ2K.J2kImage.FromStream(ms);
                    ms.Close();

                    var img = tempImage.As <Bitmap>();
                    using (MemoryStream ms2 = new MemoryStream())
                    {
                        img.Save(ms2, ImageFormat.Jpeg);

                        photo = ms2.ToArray();
                    }
                }

                cidadao = new Cidadao()
                {
                    NomeCompleto     = ConverterString(x.firstname + " " + x.name),
                    NumBI            = x.numBI,
                    NIF              = x.numNIF,
                    SNS              = x.numSNS,
                    SS               = x.numSS,
                    Sexo             = x.sex,
                    DataValidade     = DateTime.Parse(x.validityDate),
                    DataNascimento   = DateTime.Parse(x.birthDate),
                    Nacionalidade    = ConverterString(x.nationality),
                    Fotografia       = Convert.ToBase64String(photo),
                    EntidadeEmissora = ConverterString(x.deliveryEntity),

                    //TODO: Adicionar outros campo
                };

                if (address != null)
                {
                    // TODO: Caso a prorpiedade "streettype" venha a vazio ler a rua no campo "place".

                    cidadao.Rua          = ConverterString(address.streettype) + " " + ConverterString(address.street) + ", " + ConverterString(address.door);
                    cidadao.CodigoPostal = address.cp4 + "-" + address.cp3;
                    cidadao.Localidade   = ConverterString(address.locality);
                    cidadao.Municipio    = ConverterString(address.municipalityDesc);
                    cidadao.Distrito     = ConverterString(address.districtDesc);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Pteid.Exit(0);
            }

            return(cidadao);
        }