示例#1
0
        public FileCacheItem Deserialize(Stream stream)
        {
            var surrogateSelector = new AnonymousTypeSurrogateSelector();

            surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate());

            BinaryFormatter formatter = new BinaryFormatter();

            formatter.SurrogateSelector = surrogateSelector;
            formatter.Binder            = _binder;

            FileCacheItem item = null;

            try
            {
                string          key     = (string)formatter.Deserialize(stream);
                CacheItemPolicy policy  = (CacheItemPolicy)formatter.Deserialize(stream);
                object          payload = formatter.Deserialize(stream);

                item = new FileCacheItem(key, policy, payload);
            }
            catch (SerializationException)
            {
            }

            return(item);
        }
示例#2
0
        public FileCacheItem Deserialize(Stream stream)
        {
            var surrogateSelector = new AnonymousTypeSurrogateSelector();
            surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate());

            BinaryFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = surrogateSelector;
            formatter.Binder = _binder;

            FileCacheItem item = null;

            try
            {
                string key = (string)formatter.Deserialize(stream);
                CacheItemPolicy policy = (CacheItemPolicy)formatter.Deserialize(stream);
                object payload = formatter.Deserialize(stream);

                item = new FileCacheItem(key, policy, payload);
            }
            catch (SerializationException)
            {

            }

            return item;
        }
示例#3
0
        public void Serialize(Stream stream, FileCacheItem cacheItem)
        {
            var surrogateSelector = new AnonymousTypeSurrogateSelector();
            surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate());

            BinaryFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = surrogateSelector;

            formatter.Serialize(stream, cacheItem.Key);
            formatter.Serialize(stream, cacheItem.Policy);
            formatter.Serialize(stream, cacheItem.Payload);
        }
示例#4
0
        public void Serialize(Stream stream, FileCacheItem cacheItem)
        {
            var surrogateSelector = new AnonymousTypeSurrogateSelector();

            surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate());

            BinaryFormatter formatter = new BinaryFormatter();

            formatter.SurrogateSelector = surrogateSelector;

            formatter.Serialize(stream, cacheItem.Key);
            formatter.Serialize(stream, cacheItem.Policy);
            formatter.Serialize(stream, cacheItem.Payload);
        }