Example #1
0
        private async void InitContent()
        {
           
            
            try{

            var client = new WebClient();
            string content="";
            
            content = await client.DownloadStringTask(new Uri("http://www.9gag.com/random"));
            string replaceWith = "";
            content = content.Replace("\r\n", replaceWith).Replace("\n", replaceWith).Replace("\r", replaceWith).Replace(" ", replaceWith);
            var s1 = content.Substring(content.IndexOf("img-wrap"));
            s1 = s1.Remove(0, 19);
            var  s2 = s1.Split('\"');

            ImageField.Source = new BitmapImage(new Uri("http:" + s2[0]));
            


          
                
                //titleBox.Text = jsonObject["title"].GetString();
                //string imgSource = "http:" + jsonObject["gag"].GetString();
                //var uri = new Uri(imgSource, UriKind.Absolute);
                //ImageField.Source = new BitmapImage(uri);
            }
            catch (Exception)
            {
                InitContent();
            }
            

        }
Example #2
0
        async Test()
        {
            // download the google home page
            WebClient client = new WebClient();
            var google = client.DownloadStringTask("http://www.google.com");
            yield return google;
            // find and download the first link on the google home page
            Regex regex = new Regex("href=\"(?<href>http://.*?)\"");
            var match = regex.Match(google.Result);
            var firstHref = match.Groups["href"].Value;
            var firstHrefTask = client.DownloadStringTask(firstHref);
            yield return firstHrefTask;

            yield return new UIThreadTask(this);
            button.Text = firstHrefTask.Result.Substring(0, 10);
        }
        public async void LoadData()
        {
            IsLoading = true;

            var client = new WebClient();

            try
            {
                string webcontent = await client.DownloadStringTask(new Uri("http://meteo.search.ch/" + Plz));


                string uriString = "http://meteo.search.ch/images/chart/" + GetImageUrl(webcontent);
                var source = new BitmapImage(new Uri(uriString));
                
                ImageSource = source;
                ExtractDescription(webcontent);

            }
            catch (Exception e) { }
            finally { IsLoading = false; }
        }
        /// <summary>
        /// 실제 작업을 정의합니다.
        /// </summary>
        /// <param name="context">Quartz <see cref="JobExecutionContext"/></param>
        /// <param name="token">작업중 중단를 할 수 있도록 하는 Token</param>
        public override void DoExecute(JobExecutionContext context, CancellationToken token) {
            var jobName = context.JobDetail.FullName;

            if(IsDebugEnabled)
                log.Debug(@"Job[{0}]을 시작합니다...", jobName);

            var targetUri = context.GetJobData("TargetUri") as Uri;

            using(var client = new WebClient()) {
                var task = client.DownloadStringTask(targetUri ?? new Uri(@"http://debop.egloos.com"));

                Task.WaitAll(new[] { task }, token);

                if(IsDebugEnabled) {
                    log.Debug("다운로드를 받았습니다.");
                    log.Debug(task.Result);
                }
            }

            if(IsDebugEnabled)
                log.Debug(@"Job[{0}]을 완료했습니다.", jobName);
        }
Example #5
0
        async DispatcherTest()
        {
            // download the google home page
            WebClient client = new WebClient();
            var google = client.DownloadStringTask("http://www.google.com");
            yield return google;
            // find and download the first link on the google home page
            Regex regex = new Regex("href=\"(?<href>http://.*?)\"");
            var match = regex.Match(google.Result);
            var firstHref = match.Groups["href"].Value;
            var firstHrefTask = TaskHelper.Create(client.DownloadString, firstHref);
            yield return firstHrefTask;

            // let's yield back onto the Dispatcher to get onto the UI thread
            yield return this.Dispatcher();

            textBox1.Text = firstHrefTask.Result;
        }
 public void Ping() {
     using(var client = new WebClient()) {
         client.DownloadStringTask(GetScriptUrl()).Result.Should().Not.Be.Null();
     }
 }
 /// <summary>Downloads the resource with the specified URI as a string, asynchronously.</summary>
 /// <param name="webClient">The WebClient.</param>
 /// <param name="address">The URI from which to download data.</param>
 /// <returns>A Task that contains the downloaded string.</returns>
 public static Task <string> DownloadStringTask(this WebClient webClient, string address)
 {
     return(webClient.DownloadStringTask(new Uri(address)));
 }