예제 #1
0
        public void TestDownloadToString()
        {
            const string Target =
                @"http://maps.googleapis.com/maps/api/geocode/xml?address=" +
                @"1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false";

            var client = new HttpDownloader(Target);
            var str = client.DownloadToString();
            Assert.IsTrue(str.Length == 1756);
            Assert.IsTrue(str.Contains("1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA"));
        }
예제 #2
0
        // Вместо массива можно создать анонимный тип и применить dynamic.
        private void WorkingUnitWithArguments(object state)
        {
            var array = (object[])state;
            if (array.Length == 0)
                throw new ArgumentException(Resources.WorkingUnitWithAction_state_must_be_an_array, "state");

            var uri = array[0];
            var arg = array[1];

            var downloader = new HttpDownloader((string)uri, _options);
            downloader.DownloadProgress += (o, args) => _view.UpdateProgress(args.PercentComplete, (ProgressBar)arg);
            downloader.DownloadToFile(Path.GetTempFileName());
        }
예제 #3
0
 public void TestDownloadFile()
 {
     var downloader = new HttpDownloader(Uri);
     downloader.DownloadProgress += DownloaderProgress;
     var tempFileName = Path.GetTempFileName();
     downloader.DownloadToFile(tempFileName);
     Assert.IsTrue(File.Exists(tempFileName));
     try
     {
         File.Delete(tempFileName);
     }
     catch
     {
     }
 }
예제 #4
0
 private void WorkingUnit(object uri)
 {
     var downloader = new HttpDownloader((string)uri, _options);
     downloader.DownloadProgress += (o, args) => _view.UpdateProgress(args.PercentComplete);
     downloader.DownloadToFile(Path.GetTempFileName());
 }