예제 #1
0
        /// <inheritdoc />
        /// <summary>
        /// List reader groups existing in the system.
        /// </summary>
        /// <returns>String array with names of available reader groups.</returns>
        public IReadOnlyList <string> ListReaderGroups()
        {
            var multiNullTerminatedBytesArray = WinSCardWrapper.ListReaderGroups(Handle);

            return((IReadOnlyList <string>)BinaryHelper.ConvertByteToString(Encoding,
                                                                            multiNullTerminatedBytesArray));
        }
        public ConnectionStatus CheckConnectionStatus()
        {
            var dataConnectionStatus = WinSCardWrapper.GetConnectionStatus(Handle);

            ActiveProtocol  = dataConnectionStatus.ActiveProtocol;
            ActiveCardState = dataConnectionStatus.Status;

            return(new ConnectionStatus
            {
                ActiveProtocol = dataConnectionStatus.ActiveProtocol,
                CardAnswerToReset = dataConnectionStatus.CardAnswerToReset,
                ReaderAliases =
                    (IReadOnlyList <string>)BinaryHelper.ConvertByteToString(
                        Encoding, dataConnectionStatus.ConnectedReaderNames),
                Status = dataConnectionStatus.Status
            });
        }
예제 #3
0
        /// <inheritdoc />
        /// <summary>
        /// Lists readers within given reader groups.
        /// </summary>
        /// <param name="readerGroups">Names of the reader groups</param>
        /// <returns>String array with names of active readers.</returns>
        public IReadOnlyList <string> ListReaders(IReadOnlyList <string> readerGroups)
        {
            byte[] multiNullTerminatedBytesArray;

            try
            {
                var readerGroupsBytes = readerGroups == null
                    ? null
                    : BinaryHelper.ConvertMultiNullTerminatedByteArrayFromStringEnumerable(Encoding, readerGroups)
                                        .ToArray();

                multiNullTerminatedBytesArray = WinSCardWrapper.ListReaders(Handle, readerGroupsBytes);
            }
            catch (Win32Exception e) when(e.ErrorCodeEquals(0x8010002E))  // 0x8010002E -> SCARD_E_NO_READERS_AVAILABLE
            {
                multiNullTerminatedBytesArray = new byte [0];
            }

            return((IReadOnlyList <string>)BinaryHelper.ConvertByteToString(Encoding,
                                                                            multiNullTerminatedBytesArray));
        }