示例#1
0
        /// <summary>
        /// wrapper for Win32 API SCardDisconnect().
        /// see http://msdn.microsoft.com/en-us/library/windows/desktop/aa379475(v=VS.85).aspx
        /// </summary>
        /// <param name="disposition">
        /// one of the disposition codes here:
        ///     http://msdn.microsoft.com/en-us/library/windows/desktop/aa379475(v=VS.85).aspx
        /// </param>
        /// <returns>a smartcard error code as defined in WinError.H; SCARD_S_SUCCESS if no error.</returns>
        public long SCardDisConnect(int disposition)
        {
            long scardResult = (long)scard_error.SCARD_F_UNKNOWN_ERROR;

            try {
                var xmlFormat               = strings.SMARTCARD_DISCONNECT_XML;
                var dispositionString       = SCard.StringFromDisposition(disposition);
                var input                   = string.Format(xmlFormat, dispositionString);
                var resultXml               = _bidiSpl.SetPrinterData(strings.SMARTCARD_DISCONNECT, input);
                var smartcardResponseValues = Util.ParseSmartcardResponseXML(resultXml);
                scardResult = ErrorFromString(smartcardResponseValues._status);
            }
            catch (scardException e) {
                Console.WriteLine("{0}: ; hresult: 0x{0:x}", e.Message, e.hresult);
            }
            return(scardResult);
        }
示例#2
0
        /// <summary>
        /// wrapper for the win32 ::SCardReconnect() function.
        /// see http://msdn.microsoft.com/en-us/library/windows/desktop/aa379797%28v=VS.85%29.aspx
        /// </summary>
        /// <param name="connectionType">
        /// one of SCard.contact, SCard.contactless
        /// </param>
        /// <param name="initialization">
        /// one of these codes:
        ///     http://msdn.microsoft.com/en-us/library/windows/desktop/aa379475(v=VS.85).aspx
        /// </param>
        /// <param name="protocol">
        /// populated with one of these values:
        ///     SCARD_PROTOCOL_UNDEFINED = 0,
        ///     SCARD_PROTOCOL_T0 = 0x1,
        ///     SCARD_PROTOCOL_T1 = 0x2,
        ///     SCARD_PROTOCOL_RAW = 0x10000,
        ///     SCARD_PROTOCOL_Tx = 0x3,
        ///     SCARD_PROTOCOL_DEFAULT = 0x80000000,
        ///     SCARD_PROTOCOL_OPTIMAL = 0
        /// </param>
        /// <returns>a smartcard error code as defined in WinError.H; SCARD_S_SUCCESS if no error.</returns>
        public long SCardReconnect(
            ChipConnection connectionType,
            int initialization,
            ref uint protocol)
        {
            long scardResult = (long)scard_error.SCARD_F_UNKNOWN_ERROR;

            try {
                var initializationString = SCard.StringFromDisposition(initialization);
                var connectionTypeString = StringFromConnectionType(connectionType);
                var xmlFormat            = strings.SMARTCARD_RECONNECT_XML;
                var input     = string.Format(xmlFormat, connectionTypeString, initializationString);
                var resultXml = _bidiSpl.SetPrinterData(strings.SMARTCARD_RECONNECT, input);
                var smartcardResponseValues = Util.ParseSmartcardResponseXML(resultXml);
                scardResult = ErrorFromString(smartcardResponseValues._status);
            }
            catch (scardException e) {
                Console.WriteLine("{0}: ; hresult: 0x{0:x}", e.Message, e.hresult);
            }
            return(scardResult);
        }