-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
159 lines (133 loc) · 6.82 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using Windows.Data.Xml.Dom;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Phone.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace AppReadDataWebBarca
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
List<ItemsData> lstItemsData = null;
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// ReadDataWeb("http://www.fcbarcelona.com/football/list/articles.rss");
// PareXmlData();
ProgressLoad.Visibility = Windows.UI.Xaml.Visibility.Visible;
lstItemsData = new List<ItemsData>();
GetPareXmlData();
HardwareButtons.BackPressed +=HardwareButtons_BackPressed;
}
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
foreach(var chilren in gridwebviewLoadlink.Children )
{
if(chilren.Visibility == Windows.UI.Xaml.Visibility.Visible)
{
gridwebviewLoadlink.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
ProgressLoad.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
}
e.Handled = true;
}
public async void ReadDataWeb(string url)
{
Uri uri = new Uri(url);
HttpClient httpclient = new HttpClient();
var data = await httpclient.GetAsync(uri, System.Threading.CancellationToken.None);
var stringdata = await data.Content.ReadAsStringAsync();
// PareXmlData(stringdata);
}
public async void GetPareXmlData()
{
XmlDocument xmldocument = await XmlDocument.LoadFromUriAsync(new Uri("http://www.fcbarcelona.com/football/list/articles.rss"));
XmlNodeList nodes = xmldocument.SelectNodes("//rss/channel/item");
foreach(var item in nodes)
{
var title = item.SelectSingleNode("title").InnerText.Replace("\n","");
var imageurl = item.SelectSingleNode("enclosure").Attributes.GetNamedItem("url").InnerText;
var link = item.SelectSingleNode("link").InnerText;
var des = item.SelectSingleNode("description").InnerText;
des = des.Remove(0, des.IndexOf("<br />")).Replace("<br />","");
des = des.Remove(des.IndexOf("<br/>")).Replace("\n","");
var date = item.SelectSingleNode("pubDate").InnerText.Trim();
lstItemsData.Add(new ItemsData() { Date = date, Description = des, ImageUrl = imageurl, Link = link, Title = title });
}
lstData.DataContext = lstItemsData;
ProgressLoad.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
public async void PareXmlData()
{
XmlDocument xmldocument = await XmlDocument.LoadFromUriAsync(new Uri("http://www.fcbarcelona.com/football/list/articles.rss"));
// var data = xmldocument.GetXml();
// XmlNamespaceManager xmlname = new XmlNamespaceManager()
// string kho = @"<widgets><widget><url>~/Portal/Widgets/ServicesList.ascx</url><castAs>ServicesWidget</castAs><urlType>ascx</urlType><parameters> <PortalCategoryId>3</PortalCategoryId></parameters> </widget><widget><url>www.omegacoder.com</url><castAs>ServicesWidget</castAs><urlType>htm</urlType><parameters><PortalCategoryId>41</PortalCategoryId></parameters></widget></widgets>";
XmlNodeList nodes = xmldocument.SelectNodes("//rss/channel/item");
foreach (var items in nodes)
{
var title = items.SelectSingleNode("title").InnerText;
// title = Regex.Replace(title,"")
var description = items.SelectSingleNode("description").InnerText;
// XDocument xdcument = XDocument.Parse(description);
// var abcdef = from a in xdcument.Descendants("description") select new { A = a.Descendants("a").First().Value, B = a.Descendants("img") };
//var widgets = from x in xdcument.Descendants("widget")
// select new
// {
// URL = x.Descendants("url").First().Value,
// Category = x.Descendants("PortalCategoryId").First().Value
// };
// var ko = from a in xdcument.Descendants("description")
//var hjh = description.GetNamedItem("a").NodeValue;
//XDocument x = new XDocument();
//x = XDocument.Parse(description);
//var data = (from a in x.Elements("description") select new DataItems { strong = (string)a.Element("strong") }).ToList();
// var khk = _link;
//foreach (var wd in widgets)
//{
// var ko = wd.URL;
//}
var image = items.SelectSingleNode("enclosure").Attributes.GetNamedItem("url").NodeValue;
}
}
private void lstData_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var link = (lstData.SelectedItem as ItemsData).Link;
webviewLoadlink.Navigate(new Uri(link));
webviewLoadlink.FrameNavigationCompleted += webviewLoadlink_FrameNavigationCompleted;
gridwebviewLoadlink.Visibility = Windows.UI.Xaml.Visibility.Visible;
ProgressLoad.Visibility = Windows.UI.Xaml.Visibility.Visible;
}
void webviewLoadlink_FrameNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
ProgressLoad.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
}
}