コード例 #1
0
        private void ReadFIDODevices()
        {
            //Read all FIDO devices
            var devPaths = new List <string>();

            devPaths.AddRange(HIDAuthenticatorConnector.GetAllFIDODevicePaths());

            //Any new devices, add a new connector object for it to the collection
            foreach (var devPath in devPaths)
            {
                if (!fidoDevices.ContainsKey(devPath))
                {
                    fidoDevices[devPath]            = new HIDAuthenticatorConnector(devPath);
                    fidoDevices[devPath].KeepAlive += OnKeepAlive;
                }
            }

            //Remove devices from the collection that are no longer present
            List <string> removedDevices = new List <string>();

            removedDevices.AddRange(fidoDevices.Keys.Where(k => !devPaths.Contains(k)));
            foreach (var toRemove in removedDevices)
            {
                fidoDevices[toRemove].KeepAlive -= OnKeepAlive;
                fidoDevices.Remove(toRemove);
            }
        }
コード例 #2
0
        private void GetFirstUSBDevice()
        {
            List <string> fidoDevices = HIDAuthenticatorConnector.GetAllFIDODevicePaths();

            if (fidoDevices.Count == 0)
            {
                //If there are no devices then we have no need for a connector
                con = null;
                return;
            }

            //If we already have a connector linked to this device then no further action is required
            if (fidoDevices.Contains(con?.GetDevicePath()))
            {
                return;
            }

            //Configure a new connector using the first returned device
            if (!(con is null))
            {
                con.KeepAlive -= OnKeepAlive;
            }

            con            = new HIDAuthenticatorConnector(fidoDevices[0]);
            con.KeepAlive += OnKeepAlive;
        }