Exemple #1
0
        /// <summary>
        /// Returns an awaitable task that sets the fingerprint threshold on the terminal.
        /// </summary>
        /// <param name="threshold">The fingerprint threshold.</param>
        public async Task SetThresholdAsync(FingerprintThreshold threshold)
        {
            string val;

            switch (threshold)
            {
            case FingerprintThreshold.VeryHigh:
                val = "1-VERYHIGH";
                break;

            case FingerprintThreshold.High:
                val = "2-HIGH----";
                break;

            case FingerprintThreshold.Medium:
                val = "3-MEDIUM--";
                break;

            case FingerprintThreshold.Low:
                val = "4-LOW-----";
                break;

            case FingerprintThreshold.VeryLow:
                val = "5-VERYLOW-";
                break;

            default:
                throw new ArgumentException("Invalid fingerprint threshold.", "threshold");
            }

            var data = string.Format("H0T{0}", val);
            await _client.SendAndReceiveAsync(RequestCommand.Fingerprint, data, ACK);
        }
        private FingerprintUnitStatus(string data)
        {
            var subcode = data.Substring(0, 2);

            if (subcode != "M0")
            {
                throw new InvalidDataException(
                          string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "MO", subcode));
            }

            _comparisonMode = (FingerprintComparisonModes)data[2];

            _kernelVersion = data.Substring(3, 12);

            if (!int.TryParse(data.Substring(15, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _loadedTemplates))
            {
                throw new InvalidDataException("Couldn't parse number of templates loaded from fingerprint status data.");
            }

            // character 20 is a hardcoded slash that we can ignore

            if (!int.TryParse(data.Substring(21, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _maximumTemplates))
            {
                throw new InvalidDataException("Couldn't parse maximum number of templates from fingerprint status data.");
            }

            _fingerprintUnitMode = (FingerprintUnitModes)data[26];

            byte b;

            if (!byte.TryParse(data.Substring(27, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse global threshold from fingerprint status data.");
            }
            if (b < 1 || b > 5)
            {
                throw new InvalidDataException("Fingerprint Global Threshold should be between 1 and 5.");
            }
            _globalThreshold = (FingerprintThreshold)b;

            _enrollMode = (FingerprintEnrollModes)data[28];
        }
        /// <summary>
        /// Returns an awaitable task that sets the fingerprint threshold on the terminal.
        /// </summary>
        /// <param name="threshold">The fingerprint threshold.</param>
        public async Task SetThresholdAsync(FingerprintThreshold threshold)
        {
            string val;
            switch (threshold)
            {
                case FingerprintThreshold.VeryHigh:
                    val = "1-VERYHIGH";
                    break;
                case FingerprintThreshold.High:
                    val = "2-HIGH----";
                    break;
                case FingerprintThreshold.Medium:
                    val = "3-MEDIUM--";
                    break;
                case FingerprintThreshold.Low:
                    val = "4-LOW-----";
                    break;
                case FingerprintThreshold.VeryLow:
                    val = "5-VERYLOW-";
                    break;
                default:
                    throw new ArgumentException("Invalid fingerprint threshold.", "threshold");
            }

            var data = string.Format("H0T{0}", val);
            await _client.SendAndReceiveAsync(RequestCommand.Fingerprint, data, ACK);
        }
        private FingerprintUnitStatus(string data)
        {
            var subcode = data.Substring(0, 2);
            if (subcode != "M0")
                throw new InvalidDataException(
                    string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "MO", subcode));

            _comparisonMode = (FingerprintComparisonModes)data[2];

            _kernelVersion = data.Substring(3, 12);

            if (!int.TryParse(data.Substring(15, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _loadedTemplates))
                throw new InvalidDataException("Couldn't parse number of templates loaded from fingerprint status data.");

            // character 20 is a hardcoded slash that we can ignore

            if (!int.TryParse(data.Substring(21, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _maximumTemplates))
                throw new InvalidDataException("Couldn't parse maximum number of templates from fingerprint status data.");

            _fingerprintUnitMode = (FingerprintUnitModes)data[26];

            byte b;
            if (!byte.TryParse(data.Substring(27, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
                throw new InvalidDataException("Couldn't parse global threshold from fingerprint status data.");
            if (b < 1 || b > 5)
                throw new InvalidDataException("Fingerprint Global Threshold should be between 1 and 5.");
            _globalThreshold = (FingerprintThreshold)b;

            _enrollMode = (FingerprintEnrollModes) data[28];
        }