예제 #1
0
        bool getBlacklist(IntPtr sdkContext, UInt32 deviceID, List <BS2BlackList> blackList)
        {
            IntPtr blacklistObj;
            UInt32 numBlacklist;

            Console.WriteLine("Trying to get blacklists from device.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetAllBlackList(sdkContext, deviceID, out blacklistObj, out numBlacklist);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
            else if (numBlacklist > 0)
            {
                IntPtr curBlacklistObj = blacklistObj;
                int    structSize      = Marshal.SizeOf(typeof(BS2BlackList));

                for (int idx = 0; idx < numBlacklist; ++idx)
                {
                    BS2BlackList item = (BS2BlackList)Marshal.PtrToStructure(curBlacklistObj, typeof(BS2BlackList));
                    blackList.Add(item);
                    curBlacklistObj = (IntPtr)((long)curBlacklistObj + structSize);
                }

                API.BS2_ReleaseObject(blacklistObj);

                return(true);
            }
            else
            {
                Console.WriteLine(">>> There is no blacklist in the device.");
            }

            return(false);
        }
예제 #2
0
        public void getBlacklist(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            IntPtr       blacklistObj = IntPtr.Zero;
            UInt32       numBlacklist = 0;
            BS2ErrorCode result       = BS2ErrorCode.BS_SDK_SUCCESS;

            Console.WriteLine("Trying to get blacklist from device.");
            result = (BS2ErrorCode)API.BS2_GetAllBlackList(sdkContext, deviceID, out blacklistObj, out numBlacklist);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
            else if (numBlacklist > 0)
            {
                IntPtr curAccessGroupObj = blacklistObj;
                int    structSize        = Marshal.SizeOf(typeof(BS2BlackList));

                for (int idx = 0; idx < numBlacklist; ++idx)
                {
                    BS2BlackList item = (BS2BlackList)Marshal.PtrToStructure(curAccessGroupObj, typeof(BS2BlackList));
                    print(sdkContext, item);
                    curAccessGroupObj = (IntPtr)((long)curAccessGroupObj + structSize);
                }

                API.BS2_ReleaseObject(blacklistObj);
            }
            else
            {
                Console.WriteLine(">>> There is no blacklist in the device.");
            }
        }
예제 #3
0
 void print(IntPtr sdkContext, BS2BlackList blacklist)
 {
     Console.WriteLine(">>>> Blacklist issueCount[{0}] cardID[{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}]",
                       blacklist.issueCount,
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 1],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 2],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 3],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 4],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 5],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 6],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 7],
                       blacklist.cardID[BS2Environment.BS2_CARD_DATA_SIZE - 8]);
 }
예제 #4
0
        void scanAndAddBlacklist(IntPtr sdkContext, UInt32 deviceID, List <BS2BlackList> blackList, int amount)
        {
            cbCardOnReadyToScan = new API.OnReadyToScan(ReadyToScanForCard);
            BS2Card      card          = Util.AllocateStructure <BS2Card>();
            BS2BlackList blacklistItem = Util.AllocateStructure <BS2BlackList>();

            for (int idx = 0; idx < amount; ++idx)
            {
                Console.WriteLine("Trying to scan card.");
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_ScanCard(sdkContext, deviceID, out card, cbCardOnReadyToScan);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                    return;
                }
                else if (Convert.ToBoolean(card.isSmartCard))
                {
                    BS2SmartCardData smartCard = Util.ConvertTo <BS2SmartCardData>(card.cardUnion);
                    Array.Copy(smartCard.cardID, blacklistItem.cardID, BS2Envirionment.BS2_CARD_DATA_SIZE);
                    blacklistItem.issueCount = smartCard.header.issueCount;
                }
                else
                {
                    BS2CSNCard csnCard = Util.ConvertTo <BS2CSNCard>(card.cardUnion);
                    Array.Copy(csnCard.data, blacklistItem.cardID, BS2Envirionment.BS2_CARD_DATA_SIZE);
                    blacklistItem.issueCount = 0; //should set count of issue to 0
                }

                bool isDuplicated = false;
                foreach (BS2BlackList item in blackList)
                {
                    if (blacklistItem.cardID.SequenceEqual(item.cardID))
                    {
                        isDuplicated = true;
                        break;
                    }
                }

                if (isDuplicated)
                {
                    Console.WriteLine("Already exist blacklist. try again");
                    --idx;
                    continue;
                }

                blackList.Add(blacklistItem);
            }

            cbCardOnReadyToScan = null;
        }
예제 #5
0
        public void removeBlacklist(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS;

            Console.WriteLine("Do you want to remove all blacklist? [Y/n]");
            Console.Write(">>>> ");
            if (Util.IsYes())
            {
                Console.WriteLine("Trying to remove all blacklist from device.");
                result = (BS2ErrorCode)API.BS2_RemoveAllBlackList(sdkContext, deviceID);
            }
            else
            {
                IntPtr blacklistObj;
                UInt32 numBlacklist;

                Console.WriteLine("Trying to get blacklists from device.");
                result = (BS2ErrorCode)API.BS2_GetAllBlackList(sdkContext, deviceID, out blacklistObj, out numBlacklist);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                }
                else if (numBlacklist > 0)
                {
                    List <BS2BlackList> blackList = new List <BS2BlackList>();
                    IntPtr curBlacklistObj        = blacklistObj;
                    int    structSize             = Marshal.SizeOf(typeof(BS2BlackList));

                    for (int idx = 0; idx < numBlacklist; ++idx)
                    {
                        BS2BlackList item = (BS2BlackList)Marshal.PtrToStructure(curBlacklistObj, typeof(BS2BlackList));
                        blackList.Add(item);
                        curBlacklistObj = (IntPtr)((long)curBlacklistObj + structSize);
                    }

                    Console.WriteLine("+----------------------------------------------------------------------------------------------------------+");
                    for (int idx = 0; idx < numBlacklist; ++idx)
                    {
                        Console.WriteLine("[{0:000}] ==> Blacklist issueCount[{0}] cardID[{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}]",
                                          idx,
                                          blackList[idx].issueCount,
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 1],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 2],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 3],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 4],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 5],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 6],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 7],
                                          blackList[idx].cardID[BS2Environment.BS2_CARD_DATA_SIZE - 8]);
                    }
                    Console.WriteLine("+----------------------------------------------------------------------------------------------------------+");
                    Console.WriteLine("Enter the index of the blacklist which you want to remove: [INDEX_1,INDEX_2 ...]");
                    Console.Write(">>>> ");
                    char[]        delimiterChars  = { ' ', ',', '.', ':', '\t' };
                    string[]      blackListIndexs = Console.ReadLine().Split(delimiterChars);
                    HashSet <int> blackListSet    = new HashSet <int>();

                    if (blackListIndexs.Length == 0)
                    {
                        Console.WriteLine("Invalid parameter.");
                    }
                    else
                    {
                        foreach (string index in blackListIndexs)
                        {
                            if (index.Length > 0)
                            {
                                UInt32 item;
                                if (UInt32.TryParse(index, out item))
                                {
                                    if (item < numBlacklist)
                                    {
                                        blackListSet.Add((int)item);
                                    }
                                }
                            }
                        }

                        if (blackListSet.Count > 0)
                        {
                            foreach (int index in blackListSet)
                            {
                                Marshal.StructureToPtr(blackList[index], blacklistObj + structSize, false);
                            }

                            Console.WriteLine("Trying to remove blacklist from device.");
                            result = (BS2ErrorCode)API.BS2_RemoveBlackList(sdkContext, deviceID, blacklistObj, (UInt32)blackListSet.Count);
                            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                            {
                                Console.WriteLine("Got error({0}).", result);
                            }
                        }
                    }

                    API.BS2_ReleaseObject(blacklistObj);
                }
                else
                {
                    Console.WriteLine(">>> There is no blacklist in the device.");
                }
            }
        }