/// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS)
     {
         lastError = PCSC.SCardEndTransaction(cardHandle, (UInt32)Disposition);
         ThrowSmartcardException("SCardEndTransaction", lastError);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (m_hCard != IntPtr.Zero)
     {
         m_nLastError = SCardEndTransaction(m_hCard, (UInt32)Disposition);
         if (m_nLastError != 0)
         {
             string msg = "SCardEndTransaction error: " + m_nLastError;
             throw new Exception(msg);
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (SCardIsValidContext(m_hContext) == SCARD_S_SUCCESS)
     {
         m_nLastError = SCardEndTransaction(m_hCard, (UInt32)Disposition);
         if (m_nLastError != 0)
         {
             string msg = "SCardEndTransaction error: " + m_nLastError;
             throw new Exception(msg);
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (m_hCard != 0)
     {
         m_nLastError = SCardEndTransaction(m_hCard, (UInt32)Disposition);
         if (m_nLastError != 0)
         {
             string msg = "SCardEndTransaction error: " + new Win32Exception(m_nLastError).Message;
             throw new Exception(msg);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Wraps the PCSC function
        ///	LONG SCardDisconnect(
        ///		IN SCARDHANDLE hCard,
        ///		IN DWORD dwDisposition
        ///	);
        /// </summary>
        /// <param name="Disposition"></param>
        public override void Disconnect(DISCONNECT Disposition)
        {
            if (m_hCard != IntPtr.Zero)
            {
                m_nLastError = SCardDisconnect(m_hCard, (uint)Disposition);
                m_hCard      = IntPtr.Zero;

                if (m_nLastError != 0)
                {
                    string msg = "SCardDisconnect error: " + m_nLastError;
                    throw new Exception(msg);
                }

                ReleaseContext();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Wraps the PCSC function
        ///	LONG SCardDisconnect(
        ///		IN SCARDHANDLE hCard,
        ///		IN DWORD dwDisposition
        ///	);
        /// </summary>
        /// <param name="Disposition"></param>
        public override void Disconnect(DISCONNECT Disposition)
        {
            if (m_hCard != 0)
            {
                m_nLastError = SCardDisconnect(m_hCard, (uint)Disposition);
                m_hCard      = 0;

                if (m_nLastError != 0)
                {
                    string msg = "SCardDisconnect error: " + new Win32Exception(m_nLastError).Message;
                    throw new Exception(msg);
                }

                ReleaseContext();
            }
        }
        /// <summary>
        /// Wraps the PCSC function
        ///	LONG SCardDisconnect(
        ///		IN SCARDHANDLE hCard,
        ///		IN DWORD dwDisposition
        ///	);
        /// </summary>
        /// <param name="Disposition"></param>
        public override void Disconnect(DISCONNECT Disposition)
        {
            if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS)
            {
                lastError  = PCSC.SCardDisconnect(cardHandle, (uint)Disposition);
                cardHandle = IntPtr.Zero;

                try
                {
                    ThrowSmartcardException("SCardDisconnect", lastError);
                }
                finally
                {
                    ReleaseContext();
                }
            }
        }
Esempio n. 8
0
 public void Disconnect(DISCONNECT disposition)
 {
     try
     {
         card.Disconnect(disposition);
     }
     catch (SmartCardException scEx)
     {
         SmartcardFault scFault = new SmartcardFault(scEx);
         throw new FaultException <SmartcardFault>(scFault);
     }
     catch (Exception ex)
     {
         GeneralFault genFault = new GeneralFault(ex);
         throw new FaultException <GeneralFault>(genFault);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (m_hCard != IntPtr.Zero)
     {
         m_nLastError = SCardEndTransaction(m_hCard, (UInt32)Disposition);
         if (m_nLastError != 0)
         {
             string msg = "SCardEndTransaction error: " + m_nLastError;
             throw new Exception(msg);
         }
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Wraps the PCSC function
        ///	LONG SCardDisconnect(
        ///		IN SCARDHANDLE hCard,
        ///		IN DWORD dwDisposition
        ///	);
        /// </summary>
        /// <param name="Disposition"></param>
        public override void Disconnect(DISCONNECT Disposition)
        {
            if (m_hCard != IntPtr.Zero)
            {
                m_nLastError = SCardDisconnect(m_hCard, (uint) Disposition);
                m_hCard = IntPtr.Zero;

                if (m_nLastError != 0)
                {
                    string msg = "SCardDisconnect error: " + m_nLastError;
                    throw new Exception(msg);
                }

                ReleaseContext();
            }
        }
Esempio n. 11
0
 public void Disconnect(DISCONNECT disposition)
 {
     try
     {
         card.Disconnect(disposition);
     }
     catch (SmartCardException scEx)
     {
         SmartcardFault scFault = new SmartcardFault(scEx);
         throw new FaultException<SmartcardFault>(scFault);
     }
     catch (Exception ex)
     {
         GeneralFault genFault = new GeneralFault(ex);
         throw new FaultException<GeneralFault>(genFault);
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Disconnect the current session
 /// </summary>
 /// <param name="Disposition">Action when disconnecting from the card</param>
 void Disconnect(DISCONNECT disposition)
 {
     cardClient.DisconnectAsync((SCardService.DISCONNECT)disposition).Wait(TIMEOUT);
 }
Esempio n. 13
0
 /// <summary>
 /// Ends a card transaction
 /// </summary>
 void EndTransaction(DISCONNECT disposition)
 {
     cardClient.EndTransactionAsync((SCardService.DISCONNECT)disposition).Wait(TIMEOUT);
 }
Esempio n. 14
0
 /// <summary>
 /// Wraps the PCSC function
 ///	LONG SCardDisconnect(
 ///		IN SCARDHANDLE hCard,
 ///		IN DWORD dwDisposition
 ///	);
 /// </summary>
 /// <param name="Disposition"></param>
 public override void Disconnect(DISCONNECT Disposition)
 {
     // Off the connection with the card
     m_itfCard.Detach((SCARD_DISPOSITIONS)Disposition);
 }
Esempio n. 15
0
 abstract public void Disconnect(DISCONNECT Disposition);
Esempio n. 16
0
        public void Close()
        {
            if (!this.closed.Value && !transportFailed.Value)
            {
                this.Stop();
            }

            lock (connectedLock)
            {
                if (this.closed.Value)
                {
                    return;
                }

                try
                {
                    Tracer.InfoFormat("Connection[{0}]: Closing Connection Now.", this.ClientId);
                    this.closing.Value = true;

                    Scheduler scheduler = this.scheduler;
                    if (scheduler != null)
                    {
                        try
                        {
                            scheduler.Stop();
                        }
                        catch (Exception e)
                        {
                            throw NMSExceptionSupport.Create(e);
                        }
                    }

                    lock (sessions.SyncRoot)
                    {
                        foreach (Session session in sessions)
                        {
                            session.Shutdown();
                        }
                    }
                    sessions.Clear();

                    // Connected is true only when we've successfully sent our CONNECT
                    // to the broker, so if we haven't announced ourselves there's no need to
                    // inform the broker of a remove, and if the transport is failed, why bother.
                    if (connected.Value && !transportFailed.Value)
                    {
                        DISCONNECT disconnect = new DISCONNECT();
                        transport.Oneway(disconnect);
                    }

                    executor.Shutdown();
                    if (!executor.AwaitTermination(TimeSpan.FromMinutes(1)))
                    {
                        Tracer.DebugFormat("Connection[{0}]: Failed to properly shutdown its executor", this.ClientId);
                    }

                    Tracer.DebugFormat("Connection[{0}]: Disposing of the Transport.", this.ClientId);
                    transport.Stop();
                    transport.Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Connection[{0}]: Error during connection close: {1}", ClientId, ex);
                }
                finally
                {
                    if (executor != null)
                    {
                        executor.Shutdown();
                    }

                    this.transport       = null;
                    this.closed.Value    = true;
                    this.connected.Value = false;
                    this.closing.Value   = false;
                }
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (SCardIsValidContext(m_hContext) == SCARD_S_SUCCESS)
     {
         m_nLastError = SCardEndTransaction(m_hCard, (UInt32)Disposition);
         ThrowSmartcardException("SCardEndTransaction", m_nLastError);
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Wraps the PCSC function
        ///	LONG SCardDisconnect(
        ///		IN SCARDHANDLE hCard,
        ///		IN DWORD dwDisposition
        ///	);
        /// </summary>
        /// <param name="Disposition"></param>
        public override void Disconnect(DISCONNECT Disposition)
        {
            if (SCardIsValidContext(m_hContext) == SCARD_S_SUCCESS)
            {
                m_nLastError = SCardDisconnect(m_hCard, (uint) Disposition);
                m_hCard = IntPtr.Zero;

                try
                {
                    ThrowSmartcardException("SCardDisconnect", m_nLastError);
                }
                finally
                {
                    ReleaseContext();
                }
            }
        }
 /// <summary>
 /// Ends a card transaction
 /// </summary>
 public void EndTransaction(DISCONNECT disposition)
 {
     try
     {
         cardClient.EndTransactionAsync((SCardService.DISCONNECT)disposition).Wait(TIMEOUT);
     }
     catch (AggregateException ax)
     {
         throw new Exception(ProcessAggregateException(ax));
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Wraps the PCSC function
 ///	LONG SCardDisconnect(
 ///		IN SCARDHANDLE hCard,
 ///		IN DWORD dwDisposition
 ///	);
 /// </summary>
 /// <param name="Disposition"></param>
 public override void Disconnect(DISCONNECT Disposition)
 {
     // Off the connection with the card
     m_itfCard.Detach((SCARD_DISPOSITIONS) Disposition);
 }
Esempio n. 21
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// This function is not supported in the COM implementation
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     throw new NotImplementedException("EndTransaction is not supported in the COM implementation");
 }
Esempio n. 22
0
        /// <summary>
        /// Wraps the PCSC function
        ///	LONG SCardDisconnect(
        ///		IN SCARDHANDLE hCard,
        ///		IN DWORD dwDisposition
        ///	);
        /// </summary>
        /// <param name="Disposition"></param>
        public override void Disconnect(DISCONNECT Disposition)
        {
            if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS)
            {
                lastError = PCSC.SCardDisconnect(cardHandle, (uint)Disposition);
                cardHandle = IntPtr.Zero;

                try
                {
                    ThrowSmartcardException("SCardDisconnect", lastError);
                }
                finally
                {
                    ReleaseContext();
                }
            }
        }
Esempio n. 23
0
 abstract public void EndTransaction(DISCONNECT Disposition);
Esempio n. 24
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// This function is not supported in the COM implementation
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     throw new NotImplementedException("EndTransaction is not supported in the COM implementation");
 }
Esempio n. 25
0
        public static Command CreateCommand(byte fixedHeader)
        {
            Header header = new Header(fixedHeader);

            Command result = null;

            switch (header.Type)
            {
            case 1:
                result = new CONNECT(header);
                break;

            case 2:
                result = new CONNACK(header);
                break;

            case 3:
                result = new PUBLISH(header);
                break;

            case 4:
                result = new PUBACK(header);
                break;

            case 5:
                result = new PUBREC(header);
                break;

            case 6:
                result = new PUBREL(header);
                break;

            case 7:
                result = new PUBCOMP(header);
                break;

            case 8:
                result = new SUBSCRIBE(header);
                break;

            case 9:
                result = new SUBACK(header);
                break;

            case 10:
                result = new UNSUBSCRIBE(header);
                break;

            case 11:
                result = new UNSUBACK(header);
                break;

            case 12:
                result = new PINGREQ(header);
                break;

            case 13:
                result = new PINGRESP(header);
                break;

            case 14:
                result = new DISCONNECT(header);
                break;

            default:
                throw new NMSException("Unknown Command received");
            }

            return(result);
        }
Esempio n. 26
0
 /// <summary>
 /// Ends a card transaction
 /// </summary>
 void EndTransaction(DISCONNECT disposition)
 {
     cardClient.EndTransactionAsync((SCardService.DISCONNECT)disposition).Wait(TIMEOUT);
 }
Esempio n. 27
0
 /// <summary>
 /// Wraps the PCSC function
 /// LONG SCardEndTransaction(
 ///     SCARDHANDLE hCard,
 ///     DWORD dwDisposition
 /// );
 /// </summary>
 /// <param name="Disposition">A value from DISCONNECT enum</param>
 public override void EndTransaction(DISCONNECT Disposition)
 {
     if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS)
     {
         lastError = PCSC.SCardEndTransaction(cardHandle, (UInt32)Disposition);
         ThrowSmartcardException("SCardEndTransaction", lastError);
     }
 }
Esempio n. 28
0
 /// <summary> 
 /// Disconnect the current session
 /// </summary>
 /// <param name="Disposition">Action when disconnecting from the card</param>
 void Disconnect(DISCONNECT disposition)
 {
     cardClient.DisconnectAsync((SCardService.DISCONNECT)disposition).Wait(TIMEOUT);
 }