/
MainPage.xaml.cs
348 lines (273 loc) · 12.1 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
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;
using Windows.Storage;
using MR_metro.Class;
using SQLite;
using System.Net;
using System.Threading.Tasks;
using Windows.UI.Xaml.Media.Imaging;
using System.Net.Http;
using System.Text.RegularExpressions;
using Parse;
using MR_metro.Parse;
using Windows.ApplicationModel;
using System.Text;
using Windows.Storage.Streams;
using MR_metro.Temp;
using Newtonsoft.Json;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace MR_metro
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
List<lMangaAll> lstTodos = new List<lMangaAll>();
InfoManga im = new InfoManga();
public MainPage()
{
this.InitializeComponent();
if (lstTodos.Count == 0)
{
getAll();
}
//createF();
}
private async void createF()
{
StorageFolder fr = await DownloadsFolder.CreateFolderAsync("Mangas");
await fr.CreateFolderAsync("Temp");
}
private async void getAll()
{
string st = await getPage("/alphabetical");
string[] HtmlResp;
List<ResultadoHtml> RespList = new List<ResultadoHtml>();
HtmlResp = st.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (string s in HtmlResp)
{
RespList.Add(new ResultadoHtml() { resultado = s });
}
Regex filtro = new Regex("(<li><a href=\"/)(?!\")(?!privacy)(.*?)(\">)(?!<span>)(.*?)(</a>)");
RespList = RespList.Where(a => filtro.IsMatch(a.resultado)).ToList();
int i = 0;
foreach (ResultadoHtml item in RespList.ToList())
{
lstTodos.Add(new lMangaAll() {Imagem = "/Imagens/mangaReaderIco.png", EndHtml = Regex.Replace(Regex.Replace(item.resultado, "^(<)(.*?)(href=\")", ""), "(\")(.*?)*(</li>)", ""), Titulo = Regex.Replace(Regex.Replace(item.resultado, "^(<)(.*?)(href=\")(.*?)*(>)", ""), "(<)(.*?)*(</li>)", "") });
}
lstAll.ItemsSource = lstTodos;
}
private async void getManga(string url)
{
string st = await getPage(url);
string[] HtmlResp;
List<ResultadoHtml> RespList = new List<ResultadoHtml>();
List<ResultadoHtml> RespListInfo = new List<ResultadoHtml>();
HtmlResp = st.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (string s in HtmlResp)
{
RespList.Add(new ResultadoHtml() { resultado = s });
RespListInfo.Add(new ResultadoHtml() { resultado = s });
}
Regex filtro = new Regex(@"^(<div id=""mangaimg"">|<div id=""mangaproperties"">|<h1>(.*?)</h1>|<td class=""propertytitle"">|<h2 class=""aname"">|<td class=""propertytitle"">|<td>|<div id=""readmangasum"">|<h2>(.*?)</h2>|<p>(.*?)</p)");
RespListInfo = RespListInfo.Where(a => filtro.IsMatch(a.resultado)).ToList();
im = nInfoM();
string cr = "";
im.Info.EndImagem = Regex.Replace(RespListInfo[0].resultado, "(^(<d)(.*?)(c=\"))|((\" alt)(.*?)(v>))", "");
im.Info.Titulo += Regex.Replace(RespListInfo[2].resultado, "(<h1>)|(</h1>)", "");
im.Info.Nome += Regex.Replace(RespListInfo[5].resultado, "(<h2)(.*?)(e\">)|(</h2>)", "");
im.Info.ANome += Regex.Replace(RespListInfo[7].resultado, "(<td>)|(</td>)", "");
im.Info.Ano += Regex.Replace(RespListInfo[9].resultado, "(<td>)|(</td>)", "");
im.Info.Status += Regex.Replace(RespListInfo[11].resultado, "(<td>)|(</td>)", "");
im.Info.Autor += Regex.Replace(RespListInfo[13].resultado, "(<td>)|(</td>)", "");
im.Info.Artista += Regex.Replace(RespListInfo[15].resultado, "(<td>)|(</td>)", "");
im.Info.DirecaoLeitura += Regex.Replace(RespListInfo[17].resultado, "(<td>)|(</td>)", "");
im.Info.Generos += Regex.Replace(RespListInfo[19].resultado, "(</a>)|(</span>)|(<td>)|(</td>)|(<a href=)(.*?)(\">)|(<span )(.*?)(\">)", "");
im.Info.Descricao1 = Regex.Replace(RespListInfo[27].resultado, "(<h2>)|(</h2>)", "");
im.Info.Descricao2 = Regex.Replace(RespListInfo[28].resultado, "(<p>)|(</p>)", "");
List<Capitulos> ctl = new List<Capitulos>();
filtro = new Regex("^(<div class=\"chico_manga\"></div>|(<a href=\"/)|((<td>)([0-9]{2}/[0-9]{2}/[0-9]{4})(</td>)))");
RespList = RespList.Where(a => filtro.IsMatch(a.resultado)).ToList();
grdInfoManga.DataContext = im;
Regex filtroDiv, filtroHref, filtroTd;
filtroDiv = new Regex("^(<div )");
filtroHref = new Regex("^(<a href=)");
filtroTd = new Regex("^(<td>)");
int i = 0;
for (int x = 0; x < RespList.Count(); x++)
{
if (filtroDiv.IsMatch(RespList[x].resultado) && filtroHref.IsMatch(RespList[x + 1].resultado) && filtroTd.IsMatch(RespList[x + 2].resultado))
{
i++;
ctl.Add(new Capitulos()
{
Endereco = Regex.Replace(RespList[x + 1].resultado, "(<a href=\")|(\">)(.*?)*(</td>)", ""),
Numero = Convert.ToInt32(Regex.Replace(RespList[x + 1].resultado, "(^(<a )(.*?)(\">)|(</a>)(.*?)*(</td>))|(\\D+)", "")),
nome = Regex.Replace(RespList[x + 1].resultado, "^(<a )(.*?)( : )|(</td>)", ""),
Data = Regex.Replace(RespList[x + 2].resultado, "(<td>)|(</td>)", ""),
});
}
}
im.Caps = ctl.OrderByDescending(t => t.Numero).ToList();
lstCap.ItemsSource = im.Caps;
grdInfoManga.DataContext = im;
lstAll.IsEnabled = true;
}
private async Task<string> getPage(string comp)
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync("http://www.mangareader.net" + comp);
using (var streamReader = new StreamReader(await response.Content.ReadAsStreamAsync()))
{
return streamReader.ReadToEnd();
}
}
private InfoManga nInfoM()
{
Mangas mg = new Mangas()
{
Titulo = "",
Nome = "Nome: ",
ANome = "Nome Alternativo: ",
Ano = "Ano de Lançamento: ",
Status = "Status: ",
Autor = "Autor: ",
Artista = "Artista: ",
DirecaoLeitura = "Direção de Leitura: ",
Generos = "Generos: "
};
InfoManga im = new InfoManga();
im.Info = mg;
return im;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private async void Button_Click_2(object sender, RoutedEventArgs e)
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("Mangabd");
var query = conn.Table<Fontes>();
List<Fontes> result = await query.ToListAsync();
//ItemListView.DataContext = result;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("Mangabd");
await conn.CreateTableAsync<Fontes>();
Fontes fnt = new Fontes
{
Endereco = "teste",
Nome = "Teste"
};
try
{
await conn.InsertAsync(fnt);
}
catch
{
}
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
lstAll.Height = brdAll.ActualHeight - 40 - txtPesquisa.ActualHeight;
}
private void txtPesquisa_GotFocus(object sender, RoutedEventArgs e)
{
TextBox txb = (TextBox)sender;
if (txb.Text == "Pesquisar")
{
txb.Text = string.Empty;
}
}
private void txtPesquisa_LostFocus(object sender, RoutedEventArgs e)
{
TextBox txb = (TextBox)sender;
if (txb.Text == string.Empty)
{
txb.Text = "Pesquisar";
}
}
private void txtPesquisa_TextChanged(object sender, TextChangedEventArgs e)
{
if (lstTodos.Count > 0)
{
TextBox txb = (TextBox)sender;
if (!(txb.Text == string.Empty || txb.Text == "Pesquisar"))
{
lstAll.ItemsSource = lstTodos.Where(t => Regex.IsMatch(t.Titulo, "(?i).*" + txb.Text + ".*"));
}
else
{
lstAll.ItemsSource = lstTodos;
}
}
}
private void lstAll_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListView ls = (ListView)sender;
if (ls.SelectedIndex > -1)
{
lMangaAll lm = (lMangaAll)ls.SelectedItem;
lstAll.IsEnabled = false;
getManga(lm.EndHtml);
}
}
private void lstCap_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListView ls = (ListView)sender;
Capitulos cs = (Capitulos)ls.SelectedItem;
ImgPage ip = new ImgPage();
ip.endCap = cs.Endereco;
ip.NomeM = im.Info.Nome;
//ip.NumeroCap = cs.Numero;
//Visualizador vs = new Visualizador(ip);
Frame.Navigate(typeof(Visualizador), ip);
//ContainerImg.Children.Add(vs);
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
string parsedStream;
StorageFolder tempFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await tempFolder.GetFileAsync("pontos.json");
var buffer = await FileIO.ReadBufferAsync(file);
using (var dr = DataReader.FromBuffer(buffer))
{
var bytes1251 = new Byte[buffer.Length];
dr.ReadBytes(bytes1251);
parsedStream = Encoding.GetEncoding("ISO-8859-1").GetString(bytes1251, 0, bytes1251.Length);
}
JsonClass lm = JsonConvert.DeserializeObject<JsonClass>(parsedStream);
List<Pluviometro> lstUp = new List<Pluviometro>();
foreach (Placemark item in lm.Placemark)
{
Pluviometro pv = new Pluviometro();
string[] str = item.name.Split('-');
string[] strRaio = item.LookAt.range.Split('.');
pv.idEstacao = Convert.ToInt32(str[0].Substring(str[0].Length - 2));
pv.nomeLocal = str[1];
pv.raio = Convert.ToInt32(strRaio[0]);
pv.latLng = new ParseGeoPoint(Convert.ToDouble(item.LookAt.latitude), Convert.ToDouble(item.LookAt.longitude));
lstUp.Add(pv);
}
await lstUp.SaveAllAsync();
}
}
}