Example #1
0
 private void LogInBackground()
 {
     while (!_debugAPIConfigurations.LoggingExpired)
     {
         try
         {
             while (_logQueue.Count > 0)
             {
                 APILogItem apiLogItem = _logQueue.Dequeue() as APILogItem;
                 LogInternal(apiLogItem);
             }
             Thread.Sleep(_logToFileInterval);
         }
         catch (ThreadAbortException) { break; }
         catch (ThreadInterruptedException) { break; }
         catch (Exception e)
         {
             try
             {
                 APILogItem logItem = new APILogItem(null, "An error occured while logging" + e.ToString());
                 LogInternal(logItem);
             }
             catch (Exception) { }
         }
     }
 }
Example #2
0
 private void LogInBackground()
 {
     while (!_debugAPIConfigurations.LoggingExpired)
     {
         try
         {
             while (_logQueue.Count > 0)
             {
                 APILogItem apiLogItem = _logQueue.Dequeue() as APILogItem;
                 LogInternal(apiLogItem);
             }
             Thread.Sleep(_logToFileInterval);
         }
         catch (ThreadAbortException) { break; }
         catch (ThreadInterruptedException) { break; }
         catch (Exception e)
         {
             try
             {
                 APILogItem logItem = new APILogItem(null, "An error occurred while logging" + e.ToString());
                 LogInternal(logItem);
             }
             catch (Exception) { }
         }
     }
 }
Example #3
0
        public void LogInternal(APILogItem logItem)
        {
            using (StreamWriter w = File.AppendText(getFileName(logItem.LoggingTime)))
            {
                w.WriteLine(logItem.LoggingTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "\t" + logItem.Signature);
                if (logItem.NoOfKeys > 1)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Keys = {1}", "", logItem.NoOfKeys.ToString()));
                }

                if (!String.IsNullOrEmpty(logItem.Key))
                    w.WriteLine(String.Format("{0,-30}\t Key = {1}", " ", logItem.Key));
                if (logItem.AbsolueExpiration != null)
                    w.WriteLine(String.Format("{0,-30}\t Absolute Expiration = {1}", " ", logItem.AbsolueExpiration.ToString()));
                if (logItem.SlidingExpiration != null)
                    w.WriteLine(String.Format("{0,-30}\t Sliding Expiration = {1} milliseconds", " ", logItem.SlidingExpiration.Value.TotalMilliseconds));
                if (logItem.Priority != null)
                    w.WriteLine(String.Format("{0,-30}\t Priority = {1}", " ", logItem.Priority.ToString()));

                if (!string.IsNullOrEmpty(logItem.Query))
                    w.WriteLine(String.Format("{0,-30}\t Query = {1}", " ", logItem.Query.ToString()));
               
                if (logItem.QueryValues != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Values:", " "));
                    IDictionaryEnumerator ide = logItem.QueryValues.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t Key = " + ide.Key.ToString() + "\tValue = " + ide.Value.ToString(), " "));
                    }

                }

                if (logItem.LockTimeout != null)
                    w.WriteLine(String.Format("{0,-30}\t LockTimeout = {1} milliseconds", " ", logItem.LockTimeout.Value.TotalMilliseconds.ToString()));
                if (logItem.AcquireLock != null)
                    w.WriteLine(String.Format("{0,-30}\t AcquireLock = {1}", " ", logItem.AcquireLock.ToString()));

                if (logItem.RuntimeAPILogItem != null)
                {
                    RuntimeAPILogItem rtLogItem = logItem.RuntimeAPILogItem;
                    string avg = rtLogItem.IsBulk ? "Average " : "";
                    if(rtLogItem.IsBulk)
                        w.WriteLine(String.Format("{0,-30}\t Number of Objects = {1}", " ", rtLogItem.NoOfObjects.ToString()));
                    w.WriteLine(String.Format("{0,-30}\t {1}Object Size (bytes) = {2}", " ", avg, rtLogItem.SizeOfObject));
                }

                if (logItem.NoOfObjectsReturned != null)
                    w.WriteLine(String.Format("{0,-30}\t Number of Objects Returned = {1}", " ", logItem.NoOfObjectsReturned.ToString()));
                if (logItem.ExceptionMessage != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Exception = {1}", " ", logItem.ExceptionMessage));
                }
                w.WriteLine();

            }
        }
Example #4
0
 public override void Insert(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, Runtime.CacheItemPriority priority)
 {
     string exceptionMessage = null;
     try
     {
         _webCache.Insert(key, value, absoluteExpiration, slidingExpiration, priority);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem(key, exceptionMessage);
                 logItem.Signature = "GetCacheItem(string key, ref CacheItemVersion version)";
                 logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
         _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
     }
 }
Example #5
0
        public override System.Collections.IEnumerator GetEnumerator()
        {
            System.Collections.IEnumerator iEnum = null;
            string exceptionMessage = null;

            try
            {
                _webCache.GetEnumerator();
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "GetEnumerator()";
                        logItem.ExceptionMessage = exceptionMessage;
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
            return iEnum;
        }
Example #6
0
        public override int GetHashCode()
        {
            int result;
            string exceptionMessage = null;

            try
            {
                result = _webCache.GetHashCode();
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "GetHashCode()";
                        logItem.ExceptionMessage = exceptionMessage;
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
            return result;
        }
Example #7
0
 public void Log(APILogItem logItem)
 {
     logItem.LoggingTime = DateTime.Now;
     _logQueue.Enqueue(logItem);
 }
Example #8
0
        public override System.Collections.ICollection Search(string query, System.Collections.IDictionary values)
        {
            System.Collections.ICollection iCol = null;
            string exceptionMessage = null;

            try
            {
                iCol = _webCache.Search(query, values);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "Search(string query, System.Collections.IDictionary values)";
                        logItem.Query = query;
                        logItem.QueryValues = values;
                        if (iCol != null)
                            logItem.NoOfObjectsReturned = iCol.Count;
                        logItem.ExceptionMessage = exceptionMessage;
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
            return iCol;
        }
Example #9
0
        public override bool Lock(string key, TimeSpan lockTimeout, out LockHandle lockHandle)
        {
            bool result;
            string exceptionMessage = null;

            try
            {
                result = _webCache.Lock(key, lockTimeout, out lockHandle);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem(key, exceptionMessage);
                        logItem.Signature = "Lock(string key, TimeSpan lockTimeout, out LockHandle lockHandle)";
                        logItem.LockTimeout = lockTimeout;

                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
            return result;
        }
Example #10
0
        public override object Remove(string key, LockHandle lockHandle)
        {
            object obj = null;
            string exceptionMessage = null;

            try
            {
                obj = _webCache.Remove(key, lockHandle);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem(key, exceptionMessage);
                        logItem.Signature = "Remove(string key, LockHandle lockHandle)";
                        logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
                _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
            }
            return obj;
        }
Example #11
0
        public override void DeleteBulk(string[] keys)
        {
            string exceptionMessage = null;

            try
            {
                _webCache.DeleteBulk(keys);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "DeleteBulk(string[] keys)";
                        logItem.NoOfKeys = keys.Length;
                        logItem.ExceptionMessage = exceptionMessage;
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
        }
Example #12
0
 public override void Dispose()
 {
     string exceptionMessage = null;
     try
     {
         _webCache.Dispose();
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem();
                 logItem.Signature = "Dispose()";
                 logItem.ExceptionMessage = exceptionMessage;
                 _apiLogger.Log(logItem);
             }
             _apiLogger.Dispose();
         }
         catch (Exception)
         { }
     }
 }
Example #13
0
 public override bool Contains(string key)
 {
     bool result;
     string exceptionMessage = null;
     try
     {
         result = _webCache.Contains(key);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem();
                 logItem.Signature = "Contains(string key)";
                 logItem.Key = key;
                 logItem.ExceptionMessage = exceptionMessage;
                 _apiLogger.Log(logItem); ;
             }
         }
         catch (Exception)
         { }
     }
     return result;
 }
Example #14
0
        public override void Delete(string key, LockHandle lockHandle)
        {
            string exceptionMessage = null;

            try
            {
                _webCache.Delete(key, lockHandle);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem(key, exceptionMessage);
                        logItem.Signature = "Delete(string key, LockHandle lockHandle)";
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
        }
Example #15
0
 public override void Add(string key, object value)
 {
     string exceptionMessage = null;
     try
     {
         _webCache.Add(key, value);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem(key, exceptionMessage);
                 logItem.Signature = "Add(string key, object value)";
                 logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
         _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
     }
 }
Example #16
0
 internal override CacheEventDescriptor RegisterCacheNotification(CacheDataNotificationCallback cacheDataNotificationCallback, Runtime.Events.EventType eventType, Runtime.Events.EventDataFilter datafilter)
 {
     CacheEventDescriptor result = null;
     string exceptionMessage = null;
     try
     {
         result = _webCache.RegisterCacheNotification(cacheDataNotificationCallback, eventType, datafilter);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem();
                 logItem.Signature = "RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, Runtime.Events.EventType eventType, Runtime.Events.EventDataFilter datafilter)";
                 logItem.ExceptionMessage = exceptionMessage;
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
     }
     return result;
 }
Example #17
0
        public override System.Collections.IDictionary SearchEntries(string query, System.Collections.IDictionary values)
        {
            System.Collections.IDictionary iDict = null;
            string exceptionMessage = null;

            try
            {
                iDict = _webCache.SearchEntries(query, values);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "SearchEntries(string query, System.Collections.IDictionary values)";
                        logItem.Query = query;
                        logItem.QueryValues = values;
                        if (iDict != null)
                            logItem.NoOfObjectsReturned = iDict.Count;
                        logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                        logItem.ExceptionMessage = exceptionMessage;
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
                _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
            }
            return iDict;
        }
Example #18
0
        public override void Insert(string key, CacheItem item, LockHandle lockHandle, bool releaseLock)
        {
            string exceptionMessage = null;
            try
            {
                _webCache.Insert(key, item, lockHandle, releaseLock);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {

                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem(key, item, exceptionMessage);
                        logItem.Signature = "Insert(string key, CacheItem item, LockHandle lockHandle, bool releaseLock)";
                        logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
                _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
            }
        }
Example #19
0
        public override bool Equals(object obj)
        {
            bool result = false;
            string exceptionMessage = null;

            try
            {
                result = _webCache.Equals(obj);
            }
            catch (Exception e)
            {
                exceptionMessage = e.Message;
                throw;
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "Equals(object obj)";
                        logItem.ExceptionMessage = exceptionMessage;
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
            }
            return result;
        }
Example #20
0
 public override IDictionary InsertBulk(string[] keys, CacheItem[] items)
 {
     System.Collections.IDictionary iDict = null;
     string exceptionMessage = null;
     try
     {
         iDict = _webCache.InsertBulk(keys, items);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem();
                 logItem.Signature = "InsertBulk(string[] keys, CacheItem[] items)";
                 logItem.NoOfKeys = keys.Length;
                 logItem.ExceptionMessage = exceptionMessage;
                 logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
         _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
     }
     return iDict;
 }
Example #21
0
        public void LogInternal(APILogItem logItem)
        {
            using (StreamWriter w = File.AppendText(getFileName(logItem.LoggingTime)))
            {
                w.WriteLine(logItem.LoggingTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "\t" + logItem.Signature);
                if (logItem.NoOfKeys > 1)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Keys = {1}", "", logItem.NoOfKeys.ToString()));
                }

                if (!String.IsNullOrEmpty(logItem.Key))
                {
                    w.WriteLine(String.Format("{0,-30}\t Key = {1}", " ", logItem.Key));
                }
                if (logItem.AbsolueExpiration != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Absolute Expiration = {1}", " ", logItem.AbsolueExpiration.ToString()));
                }
                if (logItem.SlidingExpiration != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Sliding Expiration = {1} milliseconds", " ", logItem.SlidingExpiration.Value.TotalMilliseconds));
                }
                if (logItem.Priority != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Priority = {1}", " ", logItem.Priority.ToString()));
                }

                if (!string.IsNullOrEmpty(logItem.Query))
                {
                    w.WriteLine(String.Format("{0,-30}\t Query = {1}", " ", logItem.Query.ToString()));
                }

                if (logItem.QueryValues != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Values:", " "));
                    IDictionaryEnumerator ide = logItem.QueryValues.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t Key = " + ide.Key.ToString() + "\tValue = " + ide.Value.ToString(), " "));
                    }
                }

                if (logItem.LockTimeout != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t LockTimeout = {1} milliseconds", " ", logItem.LockTimeout.Value.TotalMilliseconds.ToString()));
                }
                if (logItem.AcquireLock != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t AcquireLock = {1}", " ", logItem.AcquireLock.ToString()));
                }

                if (logItem.RuntimeAPILogItem != null)
                {
                    RuntimeAPILogItem rtLogItem = logItem.RuntimeAPILogItem;
                    string            avg       = rtLogItem.IsBulk ? "Average " : "";
                    if (rtLogItem.IsBulk)
                    {
                        w.WriteLine(String.Format("{0,-30}\t Number of Objects = {1}", " ", rtLogItem.NoOfObjects.ToString()));
                    }
                    w.WriteLine(String.Format("{0,-30}\t {1}Object Size (bytes) = {2}", " ", avg, rtLogItem.SizeOfObject));
                }

                if (logItem.NoOfObjectsReturned != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Objects Returned = {1}", " ", logItem.NoOfObjectsReturned.ToString()));
                }
                if (logItem.ExceptionMessage != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Exception = {1}", " ", logItem.ExceptionMessage));
                }
                w.WriteLine();
            }
        }
Example #22
0
 public override void RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, Runtime.Events.EventType eventType)
 {
     string exceptionMessage = null;
     try
     {
         _webCache.RegisterCacheNotification(key, selectiveCacheDataNotificationCallback, eventType);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem();
                 logItem.Signature = "RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, Runtime.Events.EventType eventType, Runtime.Events.EventDataFilter datafilter)";
                 logItem.ExceptionMessage = exceptionMessage;
                 logItem.Key = key;
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
     }
 }
Example #23
0
        public override object Get(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)
        {
            Object obj = null;

            try
            {
                obj = _webCache.Get(key, lockTimeout, ref lockHandle, acquireLock);
            }
            finally
            {
                try
                {
                    if (_debugConfigurations.IsInLoggingInterval())
                    {
                        APILogItem logItem = new APILogItem();
                        logItem.Signature = "Get(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)";
                        logItem.Key = key;
                        logItem.LockTimeout = lockTimeout;
                        logItem.AcquireLock = acquireLock;
                        logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                        _apiLogger.Log(logItem);
                    }
                }
                catch (Exception)
                { }
                _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
            }

            return obj;
        }
Example #24
0
 public void Log(APILogItem logItem)
 {
     logItem.LoggingTime = DateTime.Now;
     _logQueue.Enqueue(logItem);
 }
Example #25
0
 public override CacheItem GetCacheItem(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)
 {
     CacheItem cItem = null;
     string exceptionMessage = null;
     try
     {
         cItem = _webCache.GetCacheItem(key, lockTimeout, ref lockHandle, acquireLock);
     }
     catch (Exception e)
     {
         exceptionMessage = e.Message;
         throw;
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem(key, exceptionMessage);
                 logItem.Signature = "GetCacheItem(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)";
                 logItem.LockTimeout = lockTimeout;
                 logItem.AcquireLock = acquireLock;
                 logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
         _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
     }
     return cItem;
 }
Example #26
0
 /// <summary>
 /// Retrieves the specified item from the Cache object.
 /// </summary>
 /// <param name="key">The identifier for the cache item to retrieve.</param>
 /// <returns>The retrieved cache item, or a null reference (Nothing 
 /// in Visual Basic) if the key is not found.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="key"/> contains a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentException"><paramref name="key"/> is not serializable.</exception>
 /// <remarks>
 /// <para><b>Note:</b> If exceptions are enabled through the <see cref="ExceptionsEnabled"/> 
 /// setting, this property throws exception incase of failure.</para>
 /// </remarks>
 /// <example>The following example demonstrates how to retrieve the value cached for an ASP.NET text 
 /// box server control.
 /// <code>
 /// Cache cache = NCache.InitializeCache("myCache");
 ///	cache.Get("MyTextBox.Value");
 /// 
 /// </code>
 /// </example>
 public override object Get(string key)
 {
     object obj = null;
     try
     {
         obj = _webCache.Get(key);
     }
     finally
     {
         try
         {
             if (_debugConfigurations.IsInLoggingInterval())
             {
                 APILogItem logItem = new APILogItem();
                 logItem.Signature = "Get(string key)";
                 logItem.Key = key;
                 logItem.RuntimeAPILogItem = (RuntimeAPILogItem)_webCache.APILogHashTable[System.Threading.Thread.CurrentThread.ManagedThreadId];
                 _apiLogger.Log(logItem);
             }
         }
         catch (Exception)
         { }
         _webCache.APILogHashTable.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
     }
     return obj;
 }
Example #27
0
        public void LogInternal(APILogItem logItem)
        {
            using (StreamWriter w = File.AppendText(getFileName(logItem.LoggingTime)))
            {
                w.WriteLine(logItem.LoggingTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "\t" + logItem.Signature);
                if (logItem.NoOfKeys > 1)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Keys = {1}", "", logItem.NoOfKeys.ToString()));
                }

                if (!String.IsNullOrEmpty(logItem.Key))
                {
                    w.WriteLine(String.Format("{0,-30}\t Key = {1}", " ", logItem.Key));
                }

                if (logItem.AbsolueExpiration != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Absolute Expiration = {1}", " ", logItem.AbsolueExpiration.ToString()));
                }
                if (logItem.SlidingExpiration != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Sliding Expiration = {1} milliseconds", " ", logItem.SlidingExpiration.Value.TotalMilliseconds));
                }

                if (!String.IsNullOrEmpty(logItem.Group))
                {
                    w.WriteLine(String.Format("{0,-30}\t Group = {1}", " ", logItem.Group));
                }
                if (!String.IsNullOrEmpty(logItem.SubGroup))
                {
                    w.WriteLine(String.Format("{0,-30}\t SubGroup = {1}", " ", logItem.SubGroup));
                }

                if (logItem.Tags != null && logItem.Tags.Length != 0)
                {
                    w.WriteLine(String.Format("{0,-30}\t Tags:", " "));
                    foreach (Tag t in logItem.Tags)
                    {
                        w.WriteLine(String.Format("{0,-30}\t\tValue = {1}", " ", t != null ? t.TagName : ""));
                    }
                }

                if (logItem.NamedTags != null && logItem.NamedTags.Count != 0)
                {
                    w.WriteLine(String.Format("{0,-30}\t NamedTags:", " "));
                    IEnumerator ie = logItem.NamedTags.GetEnumerator();
                    while (ie.MoveNext())
                    {
                        DictionaryEntry de = (DictionaryEntry)ie.Current;
                        w.WriteLine(String.Format("{0,-30}\t\t Key = " + de.Key.ToString() + "\tValue = " + de.Value.ToString(), " "));
                    }
                }

                if (logItem.Priority != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Priority = {1}", " ", logItem.Priority.ToString()));
                }

                if (logItem.Dependency != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Dependency = {1}", " ", logItem.Dependency.GetType().Name));
                    if ((logItem.Dependency as Runtime.Dependencies.KeyDependency) != null)
                    {
                        w.WriteLine(string.Format("{0,-30}\t\t KeyDependencyType = {1}", " ", (logItem.Dependency as Runtime.Dependencies.KeyDependency).KeyDependencyType));
                        w.WriteLine(String.Format("{0,-30}\t\t Keys:", " "));
                        Runtime.Dependencies.KeyDependency kd = (Runtime.Dependencies.KeyDependency)logItem.Dependency;
                        foreach (string key in kd.CacheKeys)
                        {
                            w.WriteLine(String.Format("{0,-30}\t\t\tValue = {1}", " ", key));
                        }
                    }
                    else if ((logItem.Dependency as Runtime.Dependencies.FileDependency) != null)
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t Files:", " "));
                        Runtime.Dependencies.FileDependency fd = (Runtime.Dependencies.FileDependency)logItem.Dependency;
                        foreach (string fileName in fd.fileNames)
                        {
                            w.WriteLine(String.Format("{0,-30}\t\t\tValue = {1}", " ", fileName));
                        }
                    }
                }
                if (logItem.SyncDependency != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t SyncDependency = {1}", " ", logItem.SyncDependency.ToString()));
                }
                if (logItem.IsResyncRequired != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t IsResyncRequired = {1}", " ", logItem.IsResyncRequired.ToString()));
                }


                if (!String.IsNullOrEmpty(logItem.ProviderName))
                {
                    w.WriteLine(String.Format("{0,-30}\t ProviderName = {1}", " ", logItem.ProviderName));
                }

                if (!String.IsNullOrEmpty(logItem.ResyncProviderName))
                {
                    w.WriteLine(String.Format("{0,-30}\t ResyncProviderName = {1}", " ", logItem.ResyncProviderName));
                }

                if (logItem.DSWriteOption != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t DSWriteOption = {1}", " ", logItem.DSWriteOption.ToString()));
                }

                if (logItem.DSReadOption != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t DSReadOption = {1}", " ", logItem.DSReadOption.ToString()));
                }


                if (logItem.ContinuousQuery != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t ContinuousQuery:", " "));
                    w.WriteLine(String.Format("{0,-30}\t\t Query = {1}", " ", logItem.ContinuousQuery.Query));
                    w.WriteLine(String.Format("{0,-30}\t\t Values:", " "));
                    IDictionaryEnumerator ide = logItem.ContinuousQuery.Values.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t\t Key = " + ide.Key.ToString() + "\tValue = " + ide.Value.ToString(), " "));
                    }
                }


                if (!string.IsNullOrEmpty(logItem.Query))
                {
                    w.WriteLine(String.Format("{0,-30}\t Query = {1}", " ", logItem.Query.ToString()));
                }
                if (logItem.QueryValues != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Values:", " "));
                    IDictionaryEnumerator ide = logItem.QueryValues.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        w.WriteLine(String.Format("{0,-30}\t\t Key = " + ide.Key.ToString() + "\tValue = " + ide.Value.ToString(), " "));
                    }
                }

                if (logItem.LockTimeout != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t LockTimeout = {1} milliseconds", " ", logItem.LockTimeout.Value.TotalMilliseconds.ToString()));
                }
                if (logItem.AcquireLock != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t AcquireLock = {1}", " ", logItem.AcquireLock.ToString()));
                }


                if (logItem.StreamMode != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t SreamMode = {1}", " ", logItem.StreamMode.ToString()));
                }

                if (logItem.CacheItemVersion != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t CacheItemVersion = {1}", " ", logItem.CacheItemVersion.ToString()));
                }

                if (logItem.RuntimeAPILogItem != null)
                {
                    RuntimeAPILogItem rtLogItem = logItem.RuntimeAPILogItem;
                    string            avg       = rtLogItem.IsBulk ? "Average " : "";
                    if (rtLogItem.IsBulk)
                    {
                        w.WriteLine(String.Format("{0,-30}\t Number of Objects = {1}", " ", rtLogItem.NoOfObjects.ToString()));
                    }
                    w.WriteLine(String.Format("{0,-30}\t {1}Object Size (bytes) = {2}", " ", avg, rtLogItem.SizeOfObject));
                    w.WriteLine(String.Format("{0,-30}\t Encryption Enabled = {1}", " ", rtLogItem.EncryptionEnabled.ToString()));
                    if (rtLogItem.EncryptionEnabled)
                    {
                        w.WriteLine(String.Format("{0,-30}\t {1}Encrypted Object Size (bytes) = {2}", " ", avg, logItem.RuntimeAPILogItem.SizeOfEncryptedObject));
                    }
                    w.WriteLine(String.Format("{0,-30}\t Compression Enabled = {1}", " ", rtLogItem.CompressionEnabled.ToString()));
                    if (rtLogItem.CompressionEnabled)
                    {
                        w.WriteLine(String.Format("{0,-30}\t {1}Compressed Object Size (bytes) = {2}", " ", avg, logItem.RuntimeAPILogItem.SizeOfCompressedObject));
                    }
                }

                if (logItem.NoOfObjectsReturned != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Number of Objects Returned = {1}", " ", logItem.NoOfObjectsReturned.ToString()));
                }
                if (logItem.ExceptionMessage != null)
                {
                    w.WriteLine(String.Format("{0,-30}\t Exception = {1}", " ", logItem.ExceptionMessage));
                }
                w.WriteLine();
            }
        }