Exemple #1
0
        /// <summary>
        /// Load store state and data from persistent medium.
        /// </summary>
        void IPersistentCacheStorage.LoadStorageState()
        {
            try
            {
                string fileName = Path.Combine(_internalStore.RootDir, STATE_FILENAME);
                lock (_itemDict)
                {
                    using (Stream state = new FileStream(fileName, FileMode.Open))
                    {
                        using (BinaryReader reader = new BinaryReader(state))
                        {
                            // Read count of total items.
                            int count = reader.ReadInt32();
                            // Clear current state; if any
                            _itemDict.Clear();
                            if (count < 1)
                            {
                                return;
                            }

                            for (int i = 0; i < count; i++)
                            {
                                int datalen = reader.ReadInt32();
                                // -1 means the item was not written correctly
                                if (datalen < 0)
                                {
                                    continue;
                                }

                                try
                                {
                                    byte[]    buffer = reader.ReadBytes(datalen);
                                    StoreItem item   = StoreItem.FromBinary(buffer, CacheContext);

                                    // key was successfuly serialized
                                    if (_internalStore.Contains(item.Value))
                                    {
                                        _itemDict.Add(item.Key, item.Value);
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.error("FileSystemStorageProvider.LoadStorageState()", e.ToString());
            }
            finally
            {
                ResetStateChanged();
            }
        }
 /// <summary>
 /// Carrega o estado.
 /// </summary>
 void IPersistentCacheStorage.LoadStorageState()
 {
     try
     {
         string path = Path.Combine(_internalStore.RootDir, "__ncfs__.state");
         lock (_itemDict)
         {
             using (Stream stream = new FileStream(path, FileMode.Open))
             {
                 using (BinaryReader reader = new BinaryReader(stream))
                 {
                     int num = reader.ReadInt32();
                     _itemDict.Clear();
                     if (num >= 1)
                     {
                         for (int i = 0; i < num; i++)
                         {
                             int count = reader.ReadInt32();
                             if (count >= 0)
                             {
                                 try
                                 {
                                     StoreItem item = StoreItem.FromBinary(reader.ReadBytes(count), base.CacheContext);
                                     if (_internalStore.Contains(item.Value))
                                     {
                                         _itemDict.Add(item.Key, item.Value);
                                     }
                                 }
                                 catch (Exception)
                                 {
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Colosoft.Logging.Trace.Error("FileSystemStorageProvider.LoadStorageState()".GetFormatter(), exception.GetFormatter());
     }
     finally
     {
         this.ResetStateChanged();
     }
 }