public CheckGlobalAPBViolationTask(IntPtr sdkContext, UInt32 deviceID, UInt16 seq, string userID_1, string userID_2, bool isDualAuth, GlobalAPBZoneManager zoneManager) { this.sdkContext = sdkContext; this.deviceID = deviceID; this.seq = seq; this.userID_1 = userID_1; this.userID_2 = userID_2; this.isDualAuth = isDualAuth; this.zoneManager = zoneManager; }
public void StartGlobalAPBZone(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice) { zoneManager = new GlobalAPBZoneManager(); UInt32[] connectedDeviceIDs = null; uint numDevice = 0; IntPtr deviceObjList = IntPtr.Zero; API.BS2_GetDevices(sdkContext, out deviceObjList, out numDevice); connectedDeviceIDs = new UInt32[numDevice]; for (int idx = 0; idx < numDevice; ++idx) { connectedDeviceIDs[idx] = Convert.ToUInt32(Marshal.ReadInt32(deviceObjList, (int)idx * sizeof(UInt32))); } API.BS2_ReleaseObject(deviceObjList); if (connectedDeviceIDs.Length < 2) { Console.WriteLine("Number of connected device is {0}. At least two terminals must be connected.", connectedDeviceIDs.Length); return; } Console.WriteLine("+----------------------------------------------------------------------------------------------------------+"); for (UInt32 idx = 0; idx < numDevice; ++idx) { Console.WriteLine("[{0:000}] ==> ID[{1, 10}]", idx, connectedDeviceIDs[idx]); } Console.WriteLine("+----------------------------------------------------------------------------------------------------------+"); char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; Console.WriteLine("Enter index of the readers which are used as >>>>> IN <<<<< device of global apb zone: [0,1,2 ...]"); Console.Write(">>>> "); string[] readerIndexs = Console.ReadLine().Split(delimiterChars); for (int idx = 0; idx < readerIndexs.Length; ++idx) { UInt32 indexOfReader; if (UInt32.TryParse(readerIndexs[idx], out indexOfReader) && indexOfReader < numDevice) { if (BS2ErrorCode.BS_SDK_SUCCESS == (BS2ErrorCode)API.BS2_ConnectDevice(sdkContext, connectedDeviceIDs[indexOfReader])) { zoneManager.inDeviceIDs.Add(connectedDeviceIDs[indexOfReader]); } } else { Console.WriteLine("Got error(Invaild index({0})).", readerIndexs[idx]); return; } } Console.WriteLine("Enter index of the readers which are used as <<<<< OUT >>>>> device of global apb zone: [0,1,2 ...]"); Console.Write(">>>> "); readerIndexs = Console.ReadLine().Split(delimiterChars); for (int idx = 0; idx < readerIndexs.Length; ++idx) { UInt32 indexOfReader; if (UInt32.TryParse(readerIndexs[idx], out indexOfReader) && indexOfReader < numDevice) { if (BS2ErrorCode.BS_SDK_SUCCESS == (BS2ErrorCode)API.BS2_ConnectDevice(sdkContext, connectedDeviceIDs[indexOfReader])) { if (!zoneManager.inDeviceIDs.Contains(connectedDeviceIDs[indexOfReader])) { zoneManager.outDeviceIDs.Add(connectedDeviceIDs[indexOfReader]); } else { Console.WriteLine("Got error(index({0}) is IN device already.).", readerIndexs[idx]); return; } } } else { Console.WriteLine("Got error(Invaild index({0})).", readerIndexs[idx]); return; } } Console.WriteLine("Which type is this global apb zone? [{0} : {1}, {2} : {3}(default)]", (byte)BS2APBZoneTypeEnum.HARD, BS2APBZoneTypeEnum.HARD, (byte)BS2APBZoneTypeEnum.SOFT, BS2APBZoneTypeEnum.SOFT); Console.Write(">>>> "); zoneManager.APBZoneType = (BS2APBZoneTypeEnum)Util.GetInput((byte)BS2APBZoneTypeEnum.SOFT); BS2GlobalAPBFailActionTypeEnum networkFailAction = BS2GlobalAPBFailActionTypeEnum.NONE; Console.WriteLine("Which network fail action type is this global apb zone? [{0} : {1}(default), {2} : {3}, {4} : {5}]", (byte)BS2GlobalAPBFailActionTypeEnum.NONE, BS2GlobalAPBFailActionTypeEnum.NONE, (byte)BS2GlobalAPBFailActionTypeEnum.SOFT, BS2GlobalAPBFailActionTypeEnum.SOFT, (byte)BS2GlobalAPBFailActionTypeEnum.HARD, BS2GlobalAPBFailActionTypeEnum.HARD); Console.Write(">>>> "); networkFailAction = (BS2GlobalAPBFailActionTypeEnum)Util.GetInput((byte)BS2GlobalAPBFailActionTypeEnum.NONE); Console.WriteLine("Enter the ID for the zone which you want to set"); Console.Write(">>>> "); zoneManager.zoneID = (UInt32)Util.GetInput(); SortedSet <UInt32> zoneReaders = new SortedSet <UInt32>(); zoneReaders.UnionWith(zoneManager.inDeviceIDs); zoneReaders.UnionWith(zoneManager.outDeviceIDs); BS2ErrorCode result = 0; foreach (UInt32 zoneReaderID in zoneReaders) { BS2AuthConfig authConfig; Console.WriteLine("Getting auth config. reader[{0}]", zoneReaderID); result = (BS2ErrorCode)API.BS2_GetAuthConfig(sdkContext, zoneReaderID, out authConfig); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); return; } authConfig.useGlobalAPB = 1; authConfig.globalAPBFailAction = (byte)networkFailAction; Console.WriteLine("Setting auth config. reader[{0}]", zoneReaderID); result = (BS2ErrorCode)API.BS2_SetAuthConfig(sdkContext, zoneReaderID, ref authConfig); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); return; } } this.sdkContext = sdkContext; taskExecutor = new CheckGlobalAPBViolationTaskExecutor(); Console.WriteLine("Attaching a global apb zone handler."); cbCheckGlobalAPBViolation = new API.OnCheckGlobalAPBViolation(onCheckGlobalAPBViolation); result = (BS2ErrorCode)API.BS2_SetCheckGlobalAPBViolationHandler(sdkContext, cbCheckGlobalAPBViolation); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); return; } taskExecutor.start(); Console.WriteLine("Press ESC to stop global apb zone."); while (Console.ReadKey(true).Key != ConsoleKey.Escape) { Thread.Sleep(100); } taskExecutor.stop(); Console.WriteLine("Detaching a global apb zone handler."); result = (BS2ErrorCode)API.BS2_SetCheckGlobalAPBViolationHandler(sdkContext, null); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("Got error({0}).", result); return; } cbCheckGlobalAPBViolation = null; taskExecutor = null; zoneManager = null; }