Ejemplo n.º 1
0
 /// <summary>
 /// Releases all resources used by the SmartcardReader.
 /// </summary>
 /// <param name="disposition">Action to take on the card in the connected reader on close.</param>
 public void Dispose(SmartcardDisposition disposition)
 {
     if (!m_Disposed)
     {
         Disconnect(disposition);
         NativeMethods.SCardReleaseContext(m_Context);
         m_Disposed = true;
         GC.SuppressFinalize(this);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Disconnects the connection with the smartcard.
 /// </summary>
 /// <param name="disposition">Action to take on the card in the connected reader on close.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 public void Disconnect(SmartcardDisposition disposition)
 {
     if (m_Disposed)
     {
         throw new ObjectDisposedException(this.GetType().FullName);
     }
     if (m_Card != IntPtr.Zero)
     {
         NativeMethods.SCardDisconnect(m_Card, (int)disposition);
         m_Card = IntPtr.Zero;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Completes a previously declared transaction, allowing other applications to resume interactions with the card.
        /// </summary>
        /// <param name="disposition">Action to take on the card in the connected reader on close.</param>
        /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
        /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
        public void Unlock(SmartcardDisposition disposition)
        {
            if (m_Disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (m_Card == IntPtr.Zero)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardNotConnected"));
            }
            int ret = NativeMethods.SCardEndTransaction(m_Card, (int)disposition);

            if (ret != NativeMethods.SCARD_S_SUCCESS)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardUnlock"), ret);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reconnects to the card in the smartcard reader.
        /// </summary>
        /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
        /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
        /// <param name="disposition">Type of initialization that should be performed on the card.</param>
        /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
        /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
        public void Reconnect(SmartcardShare share, SmartcardProtocols protocol, SmartcardDisposition disposition)
        {
            if (m_Disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (m_Card == IntPtr.Zero)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardNotConnected"));
            }
            int ret = NativeMethods.SCardReconnect(m_Card, (int)share, (int)protocol, (int)disposition, out m_ActiveProtocol);

            if (ret != NativeMethods.SCARD_S_SUCCESS)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardReconnect"), ret);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Releases all resources used by the SmartcardReader.
 /// </summary>
 /// <param name="disposition">Action to take on the card in the connected reader on close.</param>
 public void Dispose(SmartcardDisposition disposition) {
     if (!m_Disposed) {
         Disconnect(disposition);
         NativeMethods.SCardReleaseContext(m_Context);
         m_Disposed = true;
         GC.SuppressFinalize(this);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Disconnects the connection with the smartcard.
 /// </summary>
 /// <param name="disposition">Action to take on the card in the connected reader on close.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 public void Disconnect(SmartcardDisposition disposition) {
     if (m_Disposed)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (m_Card != IntPtr.Zero) {
         NativeMethods.SCardDisconnect(m_Card, (int)disposition);
         m_Card = IntPtr.Zero;
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Completes a previously declared transaction, allowing other applications to resume interactions with the card.
 /// </summary>
 /// <param name="disposition">Action to take on the card in the connected reader on close.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public void Unlock(SmartcardDisposition disposition) {
     if (m_Disposed)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (m_Card == IntPtr.Zero)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardNotConnected"));
     int ret = NativeMethods.SCardEndTransaction(m_Card, (int)disposition);
     if (ret != NativeMethods.SCARD_S_SUCCESS)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardUnlock"), ret);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Reconnects to the card in the smartcard reader.
 /// </summary>
 /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
 /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
 /// <param name="disposition">Type of initialization that should be performed on the card.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public void Reconnect(SmartcardShare share, SmartcardProtocols protocol, SmartcardDisposition disposition) {
     if (m_Disposed)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (m_Card == IntPtr.Zero)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardNotConnected"));
     int ret = NativeMethods.SCardReconnect(m_Card, (int)share, (int)protocol, (int)disposition, out m_ActiveProtocol);
     if (ret != NativeMethods.SCARD_S_SUCCESS)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardReconnect"), ret);
 }