public OperationResult EstablishContext()
{
lock (_locker)
{
if (_contextManager.IsContextExist(Thread.CurrentThread.ManagedThreadId))
{
Logger.TraceEvent(TraceEventType.Verbose, 0, "Context is already established.");
Logger.Flush();
return new OperationResult(true, WinscardWrapper.SCARD_S_SUCCESS, null, null);
}
IntPtr resourceManagerContext;
IntPtr notUsed1 = IntPtr.Zero;
IntPtr notUsed2 = IntPtr.Zero;
int returnCode = WinscardWrapper.SCardEstablishContext(WinscardWrapper.SCARD_SCOPE_USER,
notUsed1,
notUsed2,
out resourceManagerContext);
if (returnCode == WinscardWrapper.SCARD_S_SUCCESS)
{
Logger.TraceEvent(TraceEventType.Verbose, 0, "Context established");
Logger.Flush();
_contextManager.AddContext(Thread.CurrentThread.ManagedThreadId, resourceManagerContext);
}
return ReturnCodeManager.GetErrorMessage(returnCode);
}
}