Exemple #1
0
        public byte[] DownloadData(Uri address)
        {
            var localAddress = GetLocalAddressPath(address);

            if (File.Exists(localAddress)) // && ViewEngineProxy.Configuration.Instance.Offline)
            {
                using (var ms = new MemoryStream(File.ReadAllBytes(localAddress)))
                {
                    var localCacheItem = Serializer.Deserialize <LocalCacheItem>(ms);

                    _responseHeaders = new System.Net.WebHeaderCollection();
                    foreach (var header in localCacheItem.Headers)
                    {
                        _responseHeaders.Add(header.Key, header.Value);
                    }

                    return(localCacheItem.ContentResponse);
                }
            }

            var data = _client.DownloadData(address);

            using (var ms = new MemoryStream())
            {
                var localCacheItem = new LocalCacheItem();
                localCacheItem.ContentResponse = data;
                localCacheItem.Created         = DateTime.Now;
                localCacheItem.Headers         = _client.ResponseHeaders.GetHeaders();

                Serializer.Serialize <LocalCacheItem>(ms, localCacheItem);

                if (!Directory.Exists(Path.GetDirectoryName(localAddress)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(localAddress));
                }

                File.WriteAllBytes(localAddress, ms.ToArray());
            }

            return(data);
        }
        public byte[] DownloadData(Uri address)
        {
            var localAddress = GetLocalAddressPath(address);
            if (File.Exists(localAddress)) // && ViewEngineProxy.Configuration.Instance.Offline)
            {
                using (var ms = new MemoryStream(File.ReadAllBytes(localAddress)))
                {
                    var localCacheItem = Serializer.Deserialize<LocalCacheItem>(ms);

                    _responseHeaders = new System.Net.WebHeaderCollection();
                    foreach (var header in localCacheItem.Headers)
                        _responseHeaders.Add(header.Key, header.Value);

                    return localCacheItem.ContentResponse;
                }
            }

            var data = _client.DownloadData(address);

            using (var ms = new MemoryStream())
            {
                var localCacheItem = new LocalCacheItem();
                localCacheItem.ContentResponse = data;
                localCacheItem.Created = DateTime.Now;
                localCacheItem.Headers = _client.ResponseHeaders.GetHeaders();

                Serializer.Serialize<LocalCacheItem>(ms, localCacheItem);
                
                if (!Directory.Exists(Path.GetDirectoryName(localAddress)))
                    Directory.CreateDirectory(Path.GetDirectoryName(localAddress));

                File.WriteAllBytes(localAddress, ms.ToArray());
            }

            return data;
        }