Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AdalCache"/> class.
        /// </summary>
        /// <param name="storage">Adal cache storage</param>
        /// <param name="logger">Logger</param>
        /// <param name="lockRetryDelay">Delay in ms between retries if cache lock is contended</param>
        /// <param name="lockRetryCount">Number of retries if cache lock is contended</param>
        public AdalCache(AdalCacheStorage storage, TraceSource logger, int lockRetryDelay, int lockRetryCount)
        {
            _logger             = logger ?? s_staticLogger.Value;
            _store              = storage ?? throw new ArgumentNullException(nameof(storage));
            _lockFileRetryCount = lockRetryCount;
            _lockFileRetryDelay = lockRetryDelay;

            AfterAccess  = AfterAccessNotification;
            BeforeAccess = BeforeAccessNotification;

            _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Initializing adal cache");

            byte[] data = _store.ReadData();

            _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Read '{data?.Length}' bytes from storage");

            if (data != null && data.Length > 0)
            {
                try
                {
                    _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Deserializing data into memory");
                    DeserializeAdalV3(data);
                }
                catch (Exception e)
                {
                    _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"An exception was encountered while deserializing the data during initialization of {nameof(AdalCache)} : {e}");
                    DeserializeAdalV3(null);
                    _store.Clear();
                }
            }

            _logger.TraceEvent(TraceEventType.Information, /*id*/ 0, $"Done initializing");
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdalCache"/> class.
 /// </summary>
 /// <param name="storage">Adal cache storage</param>
 /// <param name="logger">Logger</param>
 public AdalCache(AdalCacheStorage storage, TraceSource logger) : this(storage, logger, CrossPlatLock.LockfileRetryDelayDefault, CrossPlatLock.LockfileRetryCountDefault)
 {
 }