Пример #1
0
        public void UploadMorpherCache(List <KeyValuePair <string, MorpherCacheObject> > cache)
        {
            List <KeyValuePair <string, MorpherCacheObject> > pairs =
                cache.Select(
                    pair => new KeyValuePair <string, MorpherCacheObject>(pair.Key, (MorpherCacheObject)pair.Value)).ToList();

            string serializedCache = Gzip.Zip(JsonConvert.SerializeObject(pairs));

            using (CompressedCacheDataContext context = new CompressedCacheDataContext())
            {
                var result =
                    context.CompressedCaches.FirstOrDefault(
                        compressedCache => compressedCache.Date == DateTime.Now.Date);

                if (result != null)
                {
                    result.GZipCache = serializedCache;
                }
                else
                {
                    context.CompressedCaches.InsertOnSubmit(new CompressedCache()
                    {
                        Date      = DateTime.Now.Date,
                        GZipCache = serializedCache
                    });
                }

                context.SubmitChanges();
            }
        }
Пример #2
0
        public List <KeyValuePair <string, MorpherCacheObject> > GetMorpherCache()
        {
            using (CompressedCacheDataContext context = new CompressedCacheDataContext())
            {
                var result = context.CompressedCaches.FirstOrDefault(cache => cache.Date == DateTime.Now.Date);
                if (result != null)
                {
                    return(JsonConvert.DeserializeObject <List <KeyValuePair <string, MorpherCacheObject> > >(Gzip.UnZip(result.GZipCache)));
                }

                return(null);
            }
        }