示例#1
0
        public void GetCountryWeather(Action <CountryWeatherResult, Exception> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            var client = HttpWebRequest.Create(Resources.Greenland_CountryFeed);

            client.DownloadStringAsync(html =>
            {
                var input = HttpUtility.HtmlDecode(html);

                var pattern = @"<td class=""broedtekst"">(?<content>.*?)</td>";

                var regex   = new Regex(pattern, RegexOptions.Singleline);
                var matches = regex.Matches(input);

                var description = new StringBuilder();

                foreach (var match in matches.Cast <Match>().Skip(1))
                {
                    var content = match.Groups["content"].Value;
                    content     = content.Replace("<br>", Environment.NewLine).Trim();

                    if (string.IsNullOrEmpty(content) == false)
                    {
                        description.AppendLine(content);
                        description.AppendLine();
                    }
                }

                var result = new CountryWeatherResult()
                {
                    Image = null,
                    Items = new List <CountryWeatherItem>()
                    {
                        new CountryWeatherItem()
                        {
                            Title       = Resources.Greenland_CountryWeatherTitle,
                            Description = description.ToString()
                        }
                    }
                };

                callback(result, null);
            });
        }
示例#2
0
        public void GetCountryWeather(Action<CountryWeatherResult, Exception> callback)
        {
            if (callback == null)
                throw new ArgumentNullException("callback");

            var client = HttpWebRequest.Create(Resources.Greenland_CountryFeed);
            client.DownloadStringAsync(html =>
            {
                var input = HttpUtility.HtmlDecode(html);

                var pattern = @"<td class=""broedtekst"">(?<content>.*?)</td>";

                var regex = new Regex(pattern, RegexOptions.Singleline);
                var matches = regex.Matches(input);

                var description = new StringBuilder();

                foreach (var match in matches.Cast<Match>().Skip(1))
                {
                    var content = match.Groups["content"].Value;
                    content = content.Replace("<br>", Environment.NewLine).Trim();

                    if (string.IsNullOrEmpty(content) == false)
                    {
                        description.AppendLine(content);
                        description.AppendLine();
                    }
                }

                var result = new CountryWeatherResult()
                {
                    Image = null,
                    Items = new List<CountryWeatherItem>()
                    {
                        new CountryWeatherItem()
                        {
                            Title = Resources.Greenland_CountryWeatherTitle,
                            Description = description.ToString()
                        }
                    }
                };

                callback(result, null);
            });
        }
示例#3
0
        public void GetCountryWeather(Action<CountryWeatherResult, Exception> callback)
        {
            if (callback == null)
                throw new ArgumentNullException("callback");

            var client = HttpWebRequest.Create(Resources.Denmark_CountryFeed);
            client.DownloadStringAsync(html =>
            {
                var input = HttpUtility.HtmlDecode(html);

                var pattern = @"<td class=""mellemrubrik"">(?<title>.*?)</td>";
                pattern += @"(.*?)<td class=""broedtekst"">(?<description>.*?)</td>";

                var regex = new Regex(pattern, RegexOptions.Singleline);
                var matches = regex.Matches(input);

                var items = new List<CountryWeatherItem>();

                foreach (var match in matches.Cast<Match>())
                {
                    var title = match.Groups["title"].Value;
                    title = title.Trim();
                    title = title.Replace(":", "");

                    var description = match.Groups["description"].Value;
                    description = description.Trim();

                    if (string.IsNullOrEmpty(title) == false)
                    {
                        items.Add(new CountryWeatherItem()
                        {
                            Title = title,
                            Description = description
                        });
                    }
                }

                var countryWeatherResult = new CountryWeatherResult()
                {
                    Image = new Uri(Resources.Denmark_CountryImage),
                    Items = items
                };

                callback(countryWeatherResult, null);
            });
        }