public static bool HasChanged(RacingEvent oldData, RacingEvent newData) { StandardTileData oldTile = RacingEventDataConverter.Convert(oldData); StandardTileData newTile = RacingEventDataConverter.Convert(newData); return oldTile.BackTitle != newTile.BackTitle || oldTile.BackContent != newTile.BackContent; }
public static bool Deserialize(out RacingEvent data) { try { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("RacingEvent.xml")) { data = new RacingEvent(); return false; } using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("RacingEvent.xml", System.IO.FileMode.Open, store)) { XmlSerializer serializer = new XmlSerializer(typeof(RacingEvent)); data = (RacingEvent)serializer.Deserialize(fs); System.Diagnostics.Debug.WriteLine("Iso RacingEvent Deserialize complete"); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Iso RacingEvent Deserialize Exception: " + e.Message); data = new RacingEvent(); return false; } return true; }
public static StandardTileData Convert(RacingEvent data) { return(new StandardTileData() { BackTitle = GetTitle(data), BackContent = GetContent(data) }); }
public static bool Deserialize(out RacingEvent data) { try { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("RacingEvent.xml")) { data = new RacingEvent(); return(false); } using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("RacingEvent.xml", System.IO.FileMode.Open, store)) { XmlSerializer serializer = new XmlSerializer(typeof(RacingEvent)); data = (RacingEvent)serializer.Deserialize(fs); System.Diagnostics.Debug.WriteLine("Iso RacingEvent Deserialize complete"); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Iso RacingEvent Deserialize Exception: " + e.Message); data = new RacingEvent(); return(false); } return(true); }
public static bool HasChanged(RacingEvent oldData, RacingEvent newData) { StandardTileData oldTile = RacingEventDataConverter.Convert(oldData); StandardTileData newTile = RacingEventDataConverter.Convert(newData); return(oldTile.BackTitle != newTile.BackTitle || oldTile.BackContent != newTile.BackContent); }
void nextEvent_OnDownloadCompleted(RacingEvent data, CompletionStatus status) { if (status == CompletionStatus.Completed) { DataSerializer.Serialize(data); } DataComplete(data, status); }
void DataComplete(RacingEvent data, CompletionStatus status) { if (status == CompletionStatus.Completed || status == CompletionStatus.NoChange) { foreach (ShellTile tile in ShellTile.ActiveTiles) { StandardTileData tileData = RacingEventDataConverter.Convert(data); tile.Update(tileData); } } OnUpdateCompleted.Invoke(); }
private static string GetContent(RacingEvent data) { string content = ""; if (data.Country != "") { content += data.Country + "\n"; } if (data.Circuit != "") { content += data.Circuit + "\n"; } if (data.Session != "") { content += data.Session; } return content; }
private static string GetContent(RacingEvent data) { string content = ""; if (data.Country != "") { content += data.Country + "\n"; } if (data.Circuit != "") { content += data.Circuit + "\n"; } if (data.Session != "") { content += data.Session; } return(content); }
public static bool IsUpToDate(RacingEvent data) { DateTime now = DateTime.Now; TimeSpan span = now - data.DownloadTimestamp; data.UpdateRemainingTime(); if (span.TotalMinutes > 5) //prevent updating too often { if (!data.IsSessionStartTimeValid && data.RemainingTime == 0) { return false; } if (data.IsSessionCompleted) { return false; } } return true; }
public static bool Serialize(RacingEvent data) { try { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("RacingEvent.xml", System.IO.FileMode.Create, store)) { XmlSerializer serializer = new XmlSerializer(data.GetType()); serializer.Serialize(fs, data); System.Diagnostics.Debug.WriteLine("Iso RacingEvent Serialize complete"); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Iso RacingEvent Serialize Exception: " + e.Message); return false; } return true; }
public static bool IsUpToDate(RacingEvent data) { DateTime now = DateTime.Now; TimeSpan span = now - data.DownloadTimestamp; data.UpdateRemainingTime(); if (span.TotalMinutes > 5) //prevent updating too often { if (!data.IsSessionStartTimeValid && data.RemainingTime == 0) { return(false); } if (data.IsSessionCompleted) { return(false); } } return(true); }
public static bool Serialize(RacingEvent data) { try { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("RacingEvent.xml", System.IO.FileMode.Create, store)) { XmlSerializer serializer = new XmlSerializer(data.GetType()); serializer.Serialize(fs, data); System.Diagnostics.Debug.WriteLine("Iso RacingEvent Serialize complete"); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Iso RacingEvent Serialize Exception: " + e.Message); return(false); } return(true); }
void web_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { try { string page = ""; using (StreamReader sr = new StreamReader(e.Result)) { page = sr.ReadToEnd(); } e.Result.Close(); RacingEvent f1Event = new RacingEvent(); f1Event.Circuit = ""; f1Event.Country = "unknown"; List<SessionInfo> sessions = new List<SessionInfo>(); Match m = Regex.Match(page, "<tbody .*? class=\".*?next-event.*?\">(.*?)</tbody>", RegexOptions.Singleline); if (m.Groups.Count > 1) { string str; Match ms = Regex.Match(m.Groups[1].Value, "<tr class=\"first-practice.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo practice1 = new SessionInfo(); practice1.Type = "Practice 1"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { practice1.Start = DateTime.Parse(time.Groups[1].Value); practice1.Time = SessionTimeSpan.Practice1; sessions.Add(practice1); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"second-practice.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo practice2 = new SessionInfo(); practice2.Type = "Practice 2"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { practice2.Start = DateTime.Parse(time.Groups[1].Value); practice2.Time = SessionTimeSpan.Practice2; sessions.Add(practice2); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"third-practice.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo practice3 = new SessionInfo(); practice3.Type = "Practice 3"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { practice3.Start = DateTime.Parse(time.Groups[1].Value); practice3.Time = SessionTimeSpan.Practice3; sessions.Add(practice3); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"qualifying.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo quali = new SessionInfo(); quali.Type = "Qualifying"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { quali.Start = DateTime.Parse(time.Groups[1].Value); quali.Time = SessionTimeSpan.Qualifying; sessions.Add(quali); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"race.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo race = new SessionInfo(); race.Type = "Race"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr.*?title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { race.Start = DateTime.Parse(time.Groups[1].Value); race.Time = SessionTimeSpan.Race; sessions.Add(race); } } } ms = Regex.Match(m.Groups[1].Value, "<span class=\"location\">(.*?)</span>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { f1Event.Country = ms.Groups[1].Value.Trim(); } } SessionInfo selectedSession = null; var now = DateTime.Now; foreach (var session in sessions) { selectedSession = session; if (now < session.Start) { break; } else if (now <= session.Start + session.Time) { break; } } if (selectedSession != null) { f1Event.Session = selectedSession.Type; f1Event.SessionStartTime = selectedSession.Start; f1Event.UpdateRemainingTime(); } f1Event.DownloadTimestamp = DateTime.Now; OnDownloadCompleted.Invoke(f1Event, CompletionStatus.Completed); } catch (Exception) { OnDownloadCompleted.Invoke(new RacingEvent(), CompletionStatus.Failed); } }
private static string GetTitle(RacingEvent data) { string title = ""; if (data.IsSessionLive) { title = "Session live"; } else if (data.IsSessionCompleted) { title = "Session end"; } else if (DeviceType.IsWP7LowMemDevice && data.IsSessionStartTimeValid) { //date with time title = data.SessionStartTime.ToString("g"); } else { TimeSpan left = new TimeSpan(0, 0, (int)data.RemainingTime); if (left.Days > 0) { title = left.Days.ToString(); title += left.Days == 1 ? " Day" : " Days"; } else { if (data.IsSessionStartTimeValid) { //hour and minutes title = data.SessionStartTime.ToShortTimeString(); //day of week title += " " + data.SessionStartTime.ToString("dddd"); } else { //do it standard way if (left.Hours > 0) { title = left.Hours.ToString(); title += left.Hours == 1 ? " Hour" : " Hours"; } else if (left.Minutes > 0) { title = left.Minutes.ToString(); title += left.Minutes == 1 ? " Minute" : " Minutes"; } else if (left.Seconds > 0) { title = left.Seconds.ToString(); title += left.Seconds == 1 ? " Second" : " Seconds"; } else { title = "No data"; } } } } return(title); }
void web_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { try { string page = ""; using (StreamReader sr = new StreamReader(e.Result)) { page = sr.ReadToEnd(); } e.Result.Close(); RacingEvent f1Event = new RacingEvent(); f1Event.Circuit = ""; f1Event.Country = "unknown"; List <SessionInfo> sessions = new List <SessionInfo>(); Match m = Regex.Match(page, "<tbody .*? class=\".*?next-event.*?\">(.*?)</tbody>", RegexOptions.Singleline); if (m.Groups.Count > 1) { string str; Match ms = Regex.Match(m.Groups[1].Value, "<tr class=\"first-practice.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo practice1 = new SessionInfo(); practice1.Type = "Practice 1"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { practice1.Start = DateTime.Parse(time.Groups[1].Value); practice1.Time = SessionTimeSpan.Practice1; sessions.Add(practice1); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"second-practice.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo practice2 = new SessionInfo(); practice2.Type = "Practice 2"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { practice2.Start = DateTime.Parse(time.Groups[1].Value); practice2.Time = SessionTimeSpan.Practice2; sessions.Add(practice2); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"third-practice.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo practice3 = new SessionInfo(); practice3.Type = "Practice 3"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { practice3.Start = DateTime.Parse(time.Groups[1].Value); practice3.Time = SessionTimeSpan.Practice3; sessions.Add(practice3); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"qualifying.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo quali = new SessionInfo(); quali.Type = "Qualifying"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr .*? title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { quali.Start = DateTime.Parse(time.Groups[1].Value); quali.Time = SessionTimeSpan.Qualifying; sessions.Add(quali); } } } ms = Regex.Match(m.Groups[1].Value, "<tr class=\"race.*?>(.*?)</tr>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { SessionInfo race = new SessionInfo(); race.Type = "Race"; str = ms.Groups[1].Value; var date = Regex.Match(str, "<td class=\"date-column\">(.*?)</td>", RegexOptions.Singleline); if (date.Groups.Count > 1) { var time = Regex.Match(date.Groups[1].Value, "<abbr.*?title=\"(.*?)\".*?</abbr>", RegexOptions.Singleline); if (time.Groups.Count > 1) { race.Start = DateTime.Parse(time.Groups[1].Value); race.Time = SessionTimeSpan.Race; sessions.Add(race); } } } ms = Regex.Match(m.Groups[1].Value, "<span class=\"location\">(.*?)</span>", RegexOptions.Singleline); if (ms.Groups.Count > 1) { f1Event.Country = ms.Groups[1].Value.Trim(); } } SessionInfo selectedSession = null; var now = DateTime.Now; foreach (var session in sessions) { selectedSession = session; if (now < session.Start) { break; } else if (now <= session.Start + session.Time) { break; } } if (selectedSession != null) { f1Event.Session = selectedSession.Type; f1Event.SessionStartTime = selectedSession.Start; f1Event.UpdateRemainingTime(); } f1Event.DownloadTimestamp = DateTime.Now; OnDownloadCompleted.Invoke(f1Event, CompletionStatus.Completed); } catch (Exception) { OnDownloadCompleted.Invoke(new RacingEvent(), CompletionStatus.Failed); } }
public static StandardTileData Convert(RacingEvent data) { return new StandardTileData() { BackTitle = GetTitle(data), BackContent = GetContent(data) }; }
private static string GetTitle(RacingEvent data) { string title = ""; if (data.IsSessionLive) { title = "Session live"; } else if (data.IsSessionCompleted) { title = "Session end"; } else if (DeviceType.IsWP7LowMemDevice && data.IsSessionStartTimeValid) { //date with time title = data.SessionStartTime.ToString("g"); } else { TimeSpan left = new TimeSpan(0, 0, (int)data.RemainingTime); if (left.Days > 0) { title = left.Days.ToString(); title += left.Days == 1 ? " Day" : " Days"; } else { if (data.IsSessionStartTimeValid) { //hour and minutes title = data.SessionStartTime.ToShortTimeString(); //day of week title += " " + data.SessionStartTime.ToString("dddd"); } else { //do it standard way if (left.Hours > 0) { title = left.Hours.ToString(); title += left.Hours == 1 ? " Hour" : " Hours"; } else if (left.Minutes > 0) { title = left.Minutes.ToString(); title += left.Minutes == 1 ? " Minute" : " Minutes"; } else if (left.Seconds > 0) { title = left.Seconds.ToString(); title += left.Seconds == 1 ? " Second" : " Seconds"; } else { title = "No data"; } } } } return title; }