private static Article Parse (string souce)
		{

			Article result = new Article ();

			Match match = Regex.Match (souce, @"<article.*news_for_copy.*?>(.+?)<\/article>", RegexOptions.Singleline);
			if (match.Success) {
				string text = match.Groups [1].Value;

				//Body
				match = Regex.Match (text, @"<div.*b-posts-1-item__text.+?>(.+?)</div>", RegexOptions.Singleline);
				if (match.Success) {
					result.Body = match.Groups [1].Value;
				}

				//Image
				match = Regex.Match (text, @"<figure.+>.*<img.+src=""(.+?)"".*/>", RegexOptions.Singleline);
				if (match.Success) {
					result.Image = match.Groups [1].Value;
				}

				//Title
				match = Regex.Match (text, @"b-posts-1-item__title.+?<span>(.+?)<\/span>", RegexOptions.Singleline);
				if (match.Success) {
					result.Title = match.Groups [1].Value;
				}

				//Date
				match = Regex.Match (text, @"<time.+?datetime=""(.+?)"".*>", RegexOptions.Singleline);
				if (match.Success) {
					string date = match.Groups [1].Value;
					result.CreatedAt = DateTime.Parse (date);
				}

				//Category
				match = Regex.Match (text, @"b-post-tags-1.+?<strong><a.+?>(.+?)<\/a>", RegexOptions.Singleline);
				if (match.Success) {
					result.Category = match.Groups [1].Value;
				}

				//Tag
				match = Regex.Match (text, @"b-post-tags-1.+?<small><a.+?>(.+?)<\/a>", RegexOptions.Singleline);
				if (match.Success) {
					result.Tag = match.Groups [1].Value;
				}
			}
			;

			result.Comments = ParseComments (souce);

			return result;
		}
		public async Task LoadData ()
		{


			try {

				IsBusy = true;

				HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create (ArticleSource);
				WebResponse response = await Task.Factory.FromAsync<WebResponse> (request.BeginGetResponse, request.EndGetResponse, null);

				using (StreamReader reader = new StreamReader (response.GetResponseStream ())) {
					string source = reader.ReadToEnd ();
					Article = Parse (source);
				}
			  
				Article.Body = string.Format (
					@"<html>
                    <head>
                       <style type='text/css'>
                         img {{border: 0 none; vertical-align: top; display: block; margin-left:auto; margin-right: auto; style: width: 100%; }}
                         p {{ font-size: 36px; margin-left: 5px; text-align: justify }}
                         h1 {{font-size: 44px; text-align: center; }}
                       </style>
                    </head>
                     <body>
					  <br />
                      <h1>{0}</h1>
					  <br /> 
                      <div><img src='{2}' /></div>
                      <section>
                       {1}
                       </section>
                    </body>
                 </html>", 
					Article.Title,
					Article.Body,
					Article.Image
				);

			} finally {
				IsBusy = false;
			}
		}
Esempio n. 3
0
        public CommentsView(Article article)
        {
            BindingContext = new ArticleViewModel();

            var stack = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Padding = new Thickness(0, 8)
            };

			Title = article.Title;

            var listView = new ListView();
            listView.ItemsSource = article.Comments;

            var cell = new DataTemplate(() => new CommentCell());

            listView.ItemTemplate = cell;

            stack.Children.Add(listView);

            Content = stack;
        }