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."); } }
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); }
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."); } } }