private void QueueReader()
        {
            isActive = true;
            while (running)
            {
                IQueueMessage msg = inputQueue.Dequeue() as IQueueMessage;
                try
                {
                    if (msg == null)
                    {
                        continue;
                    }

                    msg.Run();
                }
                catch (ThreadInterruptedException)
                {
                }
                catch (Exception e)
                {
                    instrumentationProvider.FireCacheFailed(Resources.BackgroundSchedulerProducerConsumerQueueFailure, e);
                }
            }
            isActive = false;
        }
        public void CacheFailureWithInstrumentationDisabledDoesNotWriteToEventLog()
        {
            ICachingInstrumentationProvider provider
                = new CachingInstrumentationProvider(instanceName, false, false, formatter);
            Exception exception = new Exception(exceptionMessage);

            using (var eventLog = new EventLogTracker(GetEventLog()))
            {
                provider.FireCacheFailed(errorMessage, exception);

                Assert.AreEqual(0, eventLog.NewEntries().Count());
            }
        }
        public void CacheFailureWithInstrumentationDisabledDoesNotWriteToEventLog()
        {
            ICachingInstrumentationProvider provider
                = new CachingInstrumentationProvider(instanceName, false, false, formatter);
            Exception exception = new Exception(exceptionMessage);

            using (var eventLog = new EventLogTracker(GetEventLog()))
            {
                provider.FireCacheFailed(errorMessage, exception);

                Assert.AreEqual(0, eventLog.NewEntries().Count());
            }
        }
 public static void InvokeRefreshAction(CacheItem removedCacheItem, CacheItemRemovedReason removalReason, CachingInstrumentationProvider instrumentationProvider)
 {
     if (removedCacheItem.RefreshAction == null)
     {
         return;
     }
     try
     {
         RefreshActionData refreshActionData =
             new RefreshActionData(removedCacheItem.RefreshAction, removedCacheItem.Key, removedCacheItem.Value, removalReason, instrumentationProvider);
         refreshActionData.InvokeOnThreadPoolThread();
     }
     catch (Exception e)
     {
         instrumentationProvider.FireCacheFailed(Resources.FailureToSpawnUserSpecifiedRefreshAction, e);
     }
 }
        public void CacheFailureWithInstrumentationEnabledDoesWriteToEventLog()
        {
            ICachingInstrumentationProvider provider
                = new CachingInstrumentationProvider(instanceName, false, true, formatter);
            Exception exception = new Exception(exceptionMessage);

            using (var eventLog = new EventLogTracker(GetEventLog()))
            {
                provider.FireCacheFailed(errorMessage, exception);

                var newEntries = from entry in eventLog.NewEntries()
                                 where entry.Message.IndexOf(exceptionMessage) > -1
                                 select entry;

                Assert.AreEqual(1, newEntries.Count());
            }
        }
        public void CacheFailureWithInstrumentationEnabledDoesWriteToEventLog()
        {
            ICachingInstrumentationProvider provider
                = new CachingInstrumentationProvider(instanceName, false, true, formatter);
            Exception exception = new Exception(exceptionMessage);

            using (var eventLog = new EventLogTracker(GetEventLog()))
            {
                provider.FireCacheFailed(errorMessage, exception);

                var newEntries = from entry in eventLog.NewEntries()
                                 where entry.Message.IndexOf(exceptionMessage) > -1
                                 select entry;

                Assert.AreEqual(1, newEntries.Count());
            }
        }
Exemple #7
0
 private bool RemoveItemFromCache(CacheItem itemToRemove)
 {
     lock (itemToRemove)
     {
         if (itemToRemove.EligibleForScavenging)
         {
             try
             {
                 cacheOperations.RemoveItemFromCache(itemToRemove.Key, CacheItemRemovedReason.Scavenged);
                 return(true);
             }
             catch (Exception e)
             {
                 instrumentationProvider.FireCacheFailed(Resources.FailureToRemoveCacheItemInBackground, e);
             }
         }
     }
     return(false);
 }
Exemple #8
0
        private bool RemoveItemFromCache(CacheItem itemToRemove)
        {
            bool expired = false;

            lock (itemToRemove)
            {
                if (itemToRemove.WillBeExpired)
                {
                    try
                    {
                        expired = true;
                        cacheOperations.RemoveItemFromCache(itemToRemove.Key, CacheItemRemovedReason.Expired);
                    }
                    catch (Exception e)
                    {
                        instrumentationProvider.FireCacheFailed(Resources.FailureToRemoveCacheItemInBackground, e);
                    }
                }
            }
            return(expired);
        }