Subversion Repository Public Repository

Nextrek

Diff Revisions 48 vs 49 for //WindowsPhone/NotizieTL/NotizieTLScheduledTaskAgent/ScheduledAgent.cs

Diff revisions: vs.
  @@ -37,9 +37,9 @@
37 37
38 38 //GetString("http://tuttolavoro.indicitalia.it/RSS/app.xml");
39 39
40 - WebClient webClient1 = new WebClient();
41 - webClient1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient1_DownloadStringCompleted);
42 - webClient1.DownloadStringAsync(new System.Uri("http://tuttolavoro.indicitalia.it/RSS/app.xml"));
40 + //WebClient webClient1 = new WebClient();
41 + //webClient1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient1_DownloadStringCompleted);
42 + //webClient1.DownloadStringAsync(new System.Uri("http://tuttolavoro.indicitalia.it/RSS/app.xml"));
43 43
44 44 }
45 45 }
  @@ -74,41 +74,58 @@
74 74 /// <remarks>
75 75 /// This method is called when a periodic or resource intensive task is invoked
76 76 /// </remarks>
77 - protected override void OnInvoke(ScheduledTask task)
78 - {
79 - //ICollection<String> listaChiavi = new List<String>();
80 - //listaChiavi = title2data.Keys;
77 + // protected override void OnInvoke(ScheduledTask task)
78 + // {
79 + // //ICollection<String> listaChiavi = new List<String>();
80 + // //listaChiavi = title2data.Keys;
81 +
82 + // //TODO: Add code to perform your task in background
83 + // // some random number
84 + // Random random = new Random();
85 + // int r;
86 + // // get application tile
87 + // ShellTile tile = ShellTile.ActiveTiles.First();
88 + // if (null != tile)
89 + // {
90 + // r = random.Next(9);
91 + // // create a new data for tile
92 + // StandardTileData data = new StandardTileData();
93 + // // tile foreground data
94 + // data.Title = "";
95 + // data.BackgroundImage = new Uri("/iconaLARGE.png", UriKind.Relative); //images/iconaLARGE.png
96 + // data.Count = 0;//random.Next(99);
97 + // // to make tile flip add data to background also
98 + // data.BackTitle = articoli4tile[r].Data;
99 + // data.BackBackgroundImage = new Uri("/tileBackBlack.png", UriKind.Relative);
100 + // data.BackContent = articoli4tile[r].Titolo;
101 + // // update tile
102 + // tile.Update(data);
103 + // }
104 + //#if DEBUG_AGENT
105 + // ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(10));
106 + // System.Diagnostics.Debug.WriteLine("Periodic task is started again: " + task.Name);
107 + //#endif
81 108
82 - //TODO: Add code to perform your task in background
83 - // some random number
84 - Random random = new Random();
85 - int r;
86 - // get application tile
87 - ShellTile tile = ShellTile.ActiveTiles.First();
88 - if (null != tile)
89 - {
90 - r = random.Next(9);
91 - // create a new data for tile
92 - StandardTileData data = new StandardTileData();
93 - // tile foreground data
94 - data.Title = "";
95 - data.BackgroundImage = new Uri("/iconaLARGE.png", UriKind.Relative); //images/iconaLARGE.png
96 - data.Count = 0;//random.Next(99);
97 - // to make tile flip add data to background also
98 - data.BackTitle = articoli4tile[r].Data;
99 - data.BackBackgroundImage = new Uri("/tileBackBlack.png", UriKind.Relative);
100 - data.BackContent = articoli4tile[r].Titolo;
101 - // update tile
102 - tile.Update(data);
103 - }
104 - #if DEBUG_AGENT
105 - ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(5));
106 - System.Diagnostics.Debug.WriteLine("Periodic task is started again: " + task.Name);
107 - #endif
108 109
109 110
111 + // NotifyComplete();
112 + // }
110 113
111 - NotifyComplete();
114 +
115 + protected override void OnInvoke(ScheduledTask task)
116 + {
117 + WebClient client = new WebClient();
118 + client.DownloadStringCompleted += (s, e) =>
119 + {
120 + DownloadStringCompleted(s, e);
121 + //#if DEBUG_AGENT
122 + ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(10));
123 + System.Diagnostics.Debug.WriteLine("Periodic task is started again: " + task.Name);
124 + //#endif
125 + NotifyComplete();
126 + };
127 + client.DownloadStringAsync(new Uri("http://tuttolavoro.indicitalia.it/RSS/app.xml"));
128 + //NotifyComplete();
112 129 }
113 130
114 131
  @@ -142,23 +159,57 @@
142 159 // NotifyComplete();
143 160 // }
144 161
145 - private void webClient1_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
162 + //private void webClient1_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
163 + //{
164 + // if (e.Error != null)
165 + // {
166 + // Deployment.Current.Dispatcher.BeginInvoke(() =>
167 + // {
168 + // // Showing the exact error message is useful for debugging. In a finalized application,
169 + // // output a friendly and applicable string to the user instead.
170 + // MessageBox.Show(e.Error.Message);
171 + // });
172 + // }
173 + // else
174 + // {
175 + // // Save the feed into the State property in case the application is tombstoned.
176 + // this.risultato = e.Result;
177 +
178 + // UpdateFeedList1(e.Result);
179 + // }
180 + //}
181 +
182 + private void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
146 183 {
147 - if (e.Error != null)
184 + if (e.Error == null)
148 185 {
149 - Deployment.Current.Dispatcher.BeginInvoke(() =>
150 - {
151 - // Showing the exact error message is useful for debugging. In a finalized application,
152 - // output a friendly and applicable string to the user instead.
153 - MessageBox.Show(e.Error.Message);
154 - });
155 - }
156 - else
157 - {
158 - // Save the feed into the State property in case the application is tombstoned.
159 - this.risultato = e.Result;
160 -
161 186 UpdateFeedList1(e.Result);
187 + var tile = ShellTile.ActiveTiles.FirstOrDefault();
188 + Random random = new Random();
189 + int r;
190 + if (tile != null)
191 + {
192 + r = random.Next(9);
193 + var tileData = new StandardTileData();
194 + tileData.Title = "";
195 + tileData.BackgroundImage = new Uri("/iconaLARGE.png", UriKind.Relative); //images/iconaLARGE.png
196 + tileData.Count = random.Next(99);
197 + // to make tile flip add data to background also
198 + tileData.BackTitle = articoli4tile[r].Data;
199 + tileData.BackBackgroundImage = new Uri("/tileBackBlack.png", UriKind.Relative);
200 + tileData.BackContent = aggiustaTitolo4tile(articoli4tile[r].Titolo);
201 +
202 +
203 + //var content = latestArticle.Title.Text + " - " + latestArticle.Summary.Text;
204 + //var image = latestArticle.Links.FirstOrDefault(l => l.MediaType != null && l.MediaType.Contains("image")).Uri;
205 +
206 + //tileData.BackContent = content;
207 + //tileData.BackgroundImage = image;
208 +
209 + //tileData.WideBackContent = content;
210 + //tileData.WideBackgroundImage = image;
211 + tile.Update(tileData);
212 + }
162 213 }
163 214 }
164 215
  @@ -186,48 +237,54 @@
186 237
187 238 while (feedXML.Contains("<item>"))
188 239 {
189 - int i = feedXML.IndexOf("<item>"); //rappresenta l'indice iniziale del blocco item
190 - int j = feedXML.IndexOf("</item>"); //rappresenta l'indice finale del blocco item
191 - int k = j - i; //rappresenta la lunghezza della stringa racchiusa dal blocco item
192 - String item = feedXML.Substring(i, k);
193 -
194 - int it = item.IndexOf("<title>") + 7;
195 - int ft = item.IndexOf("</title>");
196 - String title = item.Substring(it, ft - it);
197 -
198 - //int il = item.IndexOf("<link>") + 6;
199 - //int fl = item.IndexOf("</link>");
200 - //String link = (item.Substring(il, fl - il)).Replace("amp;", "");
201 -
202 - //int id = item.IndexOf("<description>") + 13;
203 - //int fd = item.IndexOf("</description>");
204 - //String description1 = item.Substring(id, fd - id);
205 - //String descriptionComplete = HtmlToPlainText(description1);
206 - //if (descriptionComplete.Contains("\r")) //da provare
207 - // descriptionComplete = descriptionComplete.Remove(descriptionComplete.LastIndexOf("\r"));
208 -
209 - ////if (!descriptionComplete.EndsWith("."))
210 - //// descriptionComplete = descriptionComplete.Remove(descriptionComplete.LastIndexOf("\r"));
211 - //if (descriptionComplete.StartsWith("\r\n"))
212 - // descriptionComplete = descriptionComplete.Remove(0, 2);
213 - ////String description = descriptionComplete;
214 - //String description = descriptionComplete.Substring(0, 125);
215 - //description = description.Remove(description.LastIndexOf(" "));
216 - //description += "...";
217 -
218 - int idp = item.IndexOf("<pubDate>") + 9;
219 - int fdp = item.IndexOf("</pubDate>");
220 - String dataPubEng = item.Substring(idp, fdp - idp);
221 - String dataPub = convertiData(dataPubEng);
222 -
223 - art = new Articolo4tile(title, dataPub);
224 - //listArticoli1.Add(a);
225 - //titoli.Add(title);
226 - articoli4tile.Add(art);
227 -
228 - feedXML = feedXML.Substring(feedXML.IndexOf("/pubDate") + 16);
240 + if (articoli4tile.Count > 10)
241 + {
242 + break;
243 + }
244 + else
245 + {
246 + int i = feedXML.IndexOf("<item>"); //rappresenta l'indice iniziale del blocco item
247 + int j = feedXML.IndexOf("</item>"); //rappresenta l'indice finale del blocco item
248 + int k = j - i; //rappresenta la lunghezza della stringa racchiusa dal blocco item
249 + String item = feedXML.Substring(i, k);
250 +
251 + int it = item.IndexOf("<title>") + 7;
252 + int ft = item.IndexOf("</title>");
253 + String title = item.Substring(it, ft - it);
254 +
255 + //int il = item.IndexOf("<link>") + 6;
256 + //int fl = item.IndexOf("</link>");
257 + //String link = (item.Substring(il, fl - il)).Replace("amp;", "");
258 +
259 + //int id = item.IndexOf("<description>") + 13;
260 + //int fd = item.IndexOf("</description>");
261 + //String description1 = item.Substring(id, fd - id);
262 + //String descriptionComplete = HtmlToPlainText(description1);
263 + //if (descriptionComplete.Contains("\r")) //da provare
264 + // descriptionComplete = descriptionComplete.Remove(descriptionComplete.LastIndexOf("\r"));
265 +
266 + ////if (!descriptionComplete.EndsWith("."))
267 + //// descriptionComplete = descriptionComplete.Remove(descriptionComplete.LastIndexOf("\r"));
268 + //if (descriptionComplete.StartsWith("\r\n"))
269 + // descriptionComplete = descriptionComplete.Remove(0, 2);
270 + ////String description = descriptionComplete;
271 + //String description = descriptionComplete.Substring(0, 125);
272 + //description = description.Remove(description.LastIndexOf(" "));
273 + //description += "...";
274 +
275 + int idp = item.IndexOf("<pubDate>") + 9;
276 + int fdp = item.IndexOf("</pubDate>");
277 + String dataPubEng = item.Substring(idp, fdp - idp);
278 + String dataPub = convertiData(dataPubEng);
279 +
280 + art = new Articolo4tile(title, dataPub);
281 + //listArticoli1.Add(a);
282 + //titoli.Add(title);
283 + articoli4tile.Add(art);
229 284
285 + feedXML = feedXML.Substring(feedXML.IndexOf("/pubDate") + 16);
230 286
287 + }
231 288 }
232 289
233 290 //// Load the feed into a SyndicationFeed instance.
  @@ -247,6 +304,45 @@
247 304 //});
248 305 }
249 306
307 + private String aggiustaTitolo4tile(String titolo)
308 + {
309 + String[] paroleTitolo = null;
310 + //String[] paroleTitoloApp = new String[10];
311 + String titoloMod = "";
312 + char[] c = new Char[] { ' ' };
313 + int i;
314 + int j;
315 + int k;
316 +
317 + if (titolo != "")
318 + {
319 + paroleTitolo = titolo.Split(c);
320 + }
321 +
322 + //for (i = 0; i <= paroleTitolo.Length; i++)
323 + //{
324 + // if (paroleTitoloApp[i] != null && paroleTitolo[i] != null)
325 + // paroleTitoloApp[i] = paroleTitolo[i];
326 + //}
327 +
328 + for (j = 0; j < paroleTitolo.Length; j++)
329 + {
330 + if ((paroleTitolo[j].Length > 12) && (paroleTitolo[j] != null))
331 + {
332 + paroleTitolo[j] = paroleTitolo[j].Remove(12);
333 + paroleTitolo[j] += "...";
334 + }
335 + }
336 +
337 + for (k = 0; k < paroleTitolo.Length; k++)
338 + {
339 + titoloMod += paroleTitolo[k] + " ";
340 + }
341 +
342 + return titoloMod;
343 +
344 + }
345 +
250 346 private String convertiData(String data)
251 347 {
252 348 String giorno = data.Substring(0, 3);