public async Task GetDataBlogZaSeriozniHora(string pageToken, Action<PageModel, Exception> callback) { string uri = "http://blogzaserioznihora.blogspot.com/"; Exception err = null; var result = new PageModel(); try { BloggerService _service = new BloggerService(new BaseClientService.Initializer() { ApiKey = "AIzaSyCkyf5p4x_2tW-Bwmqt7Bbj-HhFIC_kXvw", }); SiteModel site = Sites.FirstOrDefault(x => x.Title == "Блог за сериозни хора"); if (site == null) { var blog = await _service.Blogs.GetByUrl(uri).ExecuteAsync(); site = new SiteModel() { Title = "Блог за сериозни хора", Id = blog.Id }; //group.ImagePath = blog. Sites.Add(site); } PageModel page = site.Pages.FirstOrDefault(x => x.CurrentPageToken == pageToken); if (page != null) { result = page; } else { var getPosts = _service.Posts.List(site.Id); getPosts.MaxResults = 8; if (!string.IsNullOrEmpty(pageToken)) { getPosts.PageToken = pageToken; result.CurrentPageToken = pageToken; } var response = await getPosts.ExecuteAsync(); result.NextPageToken = response.NextPageToken; result.PrevPageToken = response.PrevPageToken; result.PageIndex = site.Pages.Count; foreach (var item in response.Items) { var itemModel = new ItemModel() { Id = item.Id, Title = item.Title, OriginalItem = item, //Parent = result, OriginalUrl = item.Url, CommentUrl = "http://www.blogger.com/comment.g?blogID=" + site.Id + "&postID="+ item.Id +"&isPopup=true" }; var document = new HtmlDocument(); document.LoadHtml(WebContentHelper.WrapHtml(item.Content, 0, 0)); itemModel.Content = RefactorContent(document); var img = document.DocumentNode.Descendants().FirstOrDefault(doc => doc.Name == "img" && (doc.Attributes["src"].Value.EndsWith(".jpg") || doc.Attributes["src"].Value.EndsWith(".gif") || doc.Attributes["src"].Value.EndsWith(".png"))); if (img != null) { itemModel.ImagePath = img.Attributes["src"].Value; } AddItemToTiles(itemModel); result.Items.Add(itemModel); if (string.IsNullOrEmpty(pageToken)) { site.Items.Add(itemModel); } } site.Pages.Add(result); } } catch (Exception ex) { err = ex; } callback(result, err); }
private static void AddItemToTiles(ItemModel itemModel) { if (!string.IsNullOrEmpty(itemModel.ImagePath)) { TileModels.AddSafe(EscapingText(itemModel.Title), EscapingText(itemModel.ImagePath)); } }
public async Task GetDataAlterInformation(int? pageToken, Action<PageModel, Exception> callback) { if (pageToken == null) { pageToken = 1; } HttpClient client = new HttpClient(); string uri = "http://alterinformation.wordpress.com/feed/?paged=" + pageToken; Exception err = null; var result = new PageModel(); try { var blog = await client.GetStringAsync("http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=8&q=" + uri); var responseRootObject = JsonConvert.DeserializeObject<RootObject>(blog); SiteModel site = Sites.FirstOrDefault(x => x.Title == "Alter Information"); if (site == null) { site = new SiteModel() { Title = "Alter Information", //Id = blog.Id }; //group.ImagePath = blog. Sites.Add(site); } PageModel page = site.Pages.FirstOrDefault(x => x.CurrentPageToken == pageToken.ToString()); if (page != null) { result = page; } else { result.PageIndex = site.Pages.Count; result.CurrentPageToken = pageToken.ToString(); result.NextPageToken = (pageToken + 1).ToString(); foreach (var item in responseRootObject.ResponseData.Feed.Entries) { var itemModel = new ItemModel() { Title = item.Title, OriginalItem = item, //Parent = result, OriginalUrl = item.Link, CommentUrl = item.Link +"/feed/" }; var document = new HtmlDocument(); document.LoadHtml(WebContentHelper.WrapHtml(item.Content, 0, 0)); itemModel.Content = RefactorContent(document); var img = document.DocumentNode.Descendants().FirstOrDefault(doc => doc.Name == "img"); if (img != null) { itemModel.ImagePath = img.Attributes["src"].Value; } result.Items.Add(itemModel); if (pageToken < 2) { site.Items.Add(itemModel); } } site.Pages.Add(result); } } catch (Exception ex) { err = ex; } callback(result, err); }
private void BtnSahreWebPage_OnClick(object sender, RoutedEventArgs e) { var btnAction = sender as AppBarButton; if (btnAction != null && btnAction.Tag != null) { var item = btnAction.Tag as ItemModel; if (item != null) { ShareItem = item; DataTransferManager.ShowShareUI(); } } }