async Task DecodingItem(Post item) { try { await Task.Run(async() => { WebClient web = new WebClient(); List <AttachmentsDetailModel> res1 = new List <AttachmentsDetailModel>(); HtmlDocument fdoc = new HtmlDocument(); var decodedContent = new HtmlWebViewSource(); string imageUrl = "http://shostka.info/wp-content/themes/pt-shostka/img/headpiece-red.jpg"; string image = ""; try { if (item.FeaturedMedia != 0) { AttachmentsDetails = AttachmentsDetail.LoadDetailItemData(item, ModeAttachments.FeaturedMedia).Result; imageUrl = AttachmentsDetails.SourceURL; } if (item.FeaturedMedia == 0) { if (item.Links.Attachment.Count() != 0) { string s = await web.DownloadStringTaskAsync(item.Links.Attachment.ToList()[0].Href); if (s == "[]") { } else { res1 = JsonConvert.DeserializeObject <List <AttachmentsDetailModel> >(s); imageUrl = res1[0].SourceURL; } } } fdoc.LoadHtml($"<html><body>{item.Content.Rendered}</body></html>"); if (fdoc.DocumentNode.SelectNodes("/html/body/p[*]/img").Count != 0) { foreach (HtmlNode node in fdoc.DocumentNode.SelectNodes("/html/body/p[*]/img")) { string imgsrc = node.Attributes["src"].Value; node.Attributes.RemoveAll(); node.Attributes.Add("src", imgsrc); } } } catch (Exception e) { Console.WriteLine(e); Crashes.TrackError(e); } finally { // var attachments= AttachmentsDetail.LoadDetailItemData(item,ModeAttachments.Attachments); image = $"<div class=\"fimg\"><img src=\"{imageUrl}\"</div>"; string FormatedTitle = $"<H2 style=\"color:#999999\">{item.Title.Rendered}</H2>"; decodedContent.Html = $"<html><head>" + $" <style type=\"text/css\">img {{\r\n display: block;\r\n max-width: 100% !important;\r\n margin: 0 auto;\r\n text-align: center;\r\n }} iframe{{\r\n\t width: 99%;\r\n}}</style> </head><body><p>{FormatedTitle}</p><p>{image}</p>{fdoc.DocumentNode.OuterHtml}"; DecodedContent = decodedContent; OnPropertyChanged(""); IsLoading = false; OnPropertyChanged(""); } } ); } catch (Exception e) { Console.WriteLine(e); Crashes.TrackError(e); } }
public async Task GetImageUrlCollection(IEnumerable <object> values) { // if (IsBusy) return; IsBusy = true; string s; AttachmentsDetailModel res = new AttachmentsDetailModel(); List <AttachmentsDetailModel> res1 = new List <AttachmentsDetailModel>(); var item = values as Links; WebClient web = new WebClient(); //Task.Run(Function); //async Task<Collection<string>> Function() //{ try { foreach (Post value in values) { // if (value.Links.FeaturedMedia.Count() <= 1) { if (value.Links.FeaturedMedia != null) { s = await web.DownloadStringTaskAsync(value.Links.FeaturedMedia.ToList()[0].Href); res = JsonConvert.DeserializeObject <AttachmentsDetailModel>(s); URLImageColl.Add(res.SourceURL); } //else if (false /*value.FeaturedMedia == 0*/) //{ // if (value.Links.Attachment.Count() != 0) // { // s = await web.DownloadStringTaskAsync(value.Links.Attachment.ToList()[0].Href); // if (s == "[]") // { // continue; // } // res1 = JsonConvert.DeserializeObject<List<AttachmentsDetailModel>>(s); // URLImageColl.Add(res1[0].SourceURL); // } //} else { res.SourceURL = imageUrl; URLImageColl.Add(res.SourceURL); } } } // return URLImageColl; } catch (Exception e) { Console.WriteLine(e); Crashes.TrackError(e); } finally { IsBusy = false; OnPropertyChanged(""); URLImageCollReady?.Invoke(); //.BeginInvoke(null,null); } //return URLImageColl; }