AddToCache() public static method

public static AddToCache ( HttpWebResponse resp, string file ) : CacheMetaData
resp System.Net.HttpWebResponse
file string
return CacheMetaData
コード例 #1
0
ファイル: SyncDownloader.cs プロジェクト: Valvador/WoWFormat
        public void DownloadFile(string url, string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            //using (var client = new HttpClient())
            //{
            //    var msg = client.GetAsync(url).Result;

            //    using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
            //    {
            //        //CacheMetaData.AddToCache(resp, path);
            //        //CopyToStream(stream, fs, resp.ContentLength);

            //        msg.Content.CopyToAsync(fs).Wait();
            //    }
            //}

            HttpWebRequest request = WebRequest.CreateHttp(url);

            using (HttpWebResponse resp = (HttpWebResponse)request.GetResponseAsync().Result)
                using (Stream stream = resp.GetResponseStream())
                    using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        CacheMetaData.AddToCache(resp, path);
                        CopyToStream(stream, fs, resp.ContentLength);
                    }
        }
コード例 #2
0
        public void DownloadFile(string url, string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            HttpWebRequest request = WebRequest.CreateHttp(url);

            using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
                using (Stream stream = resp.GetResponseStream())
                    using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        CacheMetaData.AddToCache(resp, path);
                        CopyToStream(stream, fs, resp.ContentLength);
                    }
        }
コード例 #3
0
        public CacheMetaData GetMetaData(string url, string file)
        {
            try
            {
                HttpWebRequest request = WebRequest.CreateHttp(url);
                request.Method = "HEAD";

                using (HttpWebResponse resp = (HttpWebResponse)request.GetResponseAsync().Result)
                {
                    return(CacheMetaData.AddToCache(resp, file));
                }
            }
            catch
            {
                return(null);
            }
        }