Esempio n. 1
0
        public static bool UpdateSuperviseeBiodata(SuperviseeBiodata superviseeBiodata)
        {
            try
            {
                // validate


                // write data to smart card
                bool actionResult = SmartCardReaderUtil.Instance.WriteSuperviseeBiodata(superviseeBiodata);

                // get new data from smart card
                //if (actionResult)
                //{
                //    actionResult = ReadData_FromSmartCard();
                //}

                // return value
                return(actionResult);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("WriteHistoricalRecord exception: " + ex.ToString());
                return(false);
            }
        }
Esempio n. 2
0
        public bool WriteSuperviseeBiodata(SuperviseeBiodata data, string readerName = null)
        {
            try
            {
                if (readerName == null)
                {
                    readerName = _readerName;
                }

                // get list blocks will be read/write
                List <MifareCard_Block> lstBlocks = GetAll_Blocks_MifareClassic(EnumSmartCardTypes.MifareClassic4K);
                if (lstBlocks == null || lstBlocks.Count() == 0)
                {
                    throw new Exception("Can not get card blocks");
                }

                // calculate storage size of smartcard
                int totalBytes = lstBlocks.Count(block => block.BlockType == EnumBlockTypes.Data) * 16;

                // create SmartCardData object
                SmartCardData_Original cardData = new SmartCardData_Original()
                {
                    SuperviseeBiodata = data
                };

                // convert object to json
                var jsonData = JsonConvert.SerializeObject(cardData);

                // encrypting
                var encryptedString = CommonUtil.EncryptString(jsonData, _passphrase);

                // check length of encryptContent, remove last HistoricalRecord
                while (encryptedString.Length > totalBytes)
                {
                    // remove last activities
                    if (cardData.HistoricalRecords != null || cardData.HistoricalRecords.Count() > 0)
                    {
                        cardData.HistoricalRecords.Remove(cardData.HistoricalRecords.Last());
                    }

                    // convert new data to json
                    jsonData = JsonConvert.SerializeObject(cardData);

                    // encrypting
                    encryptedString = CommonUtil.EncryptString(jsonData, _passphrase);
                }

                // data to write
                byte[] byteData = Encoding.ASCII.GetBytes(jsonData);

                bool result = WriteData_MifareClassic(byteData, readerName);

                // return value
                return(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("WriteData_MifareClassic exception: " + ex.ToString());
                return(false);
            }
        }