public static List <Tuple <BusRoute, string[], string[]> > DeformatRoutes(CompactFormatReader reader) { List <Tuple <BusRoute, string[], string[]> > result = new List <Tuple <BusRoute, string[], string[]> >(); CompactFormatReader[] routeReader; List <string> stops; List <string> shapes; while ((routeReader = reader.Next()) != null) { BusRoute route = new BusRoute(); route.ID = routeReader[0].ReadString(); route.Name = routeReader[1].ReadString(); route.Description = routeReader[2].ReadString(); route.Agency = routeReader[3].ReadString(); stops = new List <string>(); shapes = new List <string>(); CompactFormatReader[] subReader; while ((subReader = routeReader[4].Next()) != null) { stops.Add(subReader[0].ReadString()); } while ((subReader = routeReader[5].Next()) != null) { shapes.Add(subReader[0].ReadString()); } result.Add(new Tuple <BusRoute, string[], string[]>(route, stops.ToArray(), shapes.ToArray())); } return(result); }
public static List <BusStop> DeformatStops(CompactFormatReader reader) { List <BusStop> result = new List <BusStop>(); CompactFormatReader[] stopReader; List <string> routes; while ((stopReader = reader.Next()) != null) { BusStop stop = new BusStop(); stop.ID = stopReader[0].ReadString(); stop.Direction = (StopDirection)stopReader[1].ReadInt(); stop.Position = new BasicGeoposition() { Latitude = double.Parse(stopReader[2].ReadString()), Longitude = double.Parse(stopReader[3].ReadString()) }; stop.Name = stopReader[4].ReadString(); stop.Code = stopReader[5].ReadString(); stop.LocationType = stopReader[6].ReadInt(); routes = new List <string>(); CompactFormatReader[] routeReader; while ((routeReader = stopReader[7].Next()) != null) { routes.Add(routeReader[0].ReadString()); } stop.Routes = routes.ToArray(); result.Add(stop); } return(result); }
private static async Task ModifyAgencyCache(Action<List<Tuple<TransitAgency, string[]>>> action) { List<Tuple<TransitAgency, string[]>> agencies; var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("AgencyCache.txt"); if (!SavedAgencyCache.TryGetTarget(out agencies)) { string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); agencies = DeformatAgencies(reader); } action(agencies); CompactFormatWriter writer = new CompactFormatWriter(); FormatAgencies(agencies, writer); await FileIO.WriteTextAsync(file, writer.ToString()); SavedAgencyCache.SetTarget(agencies); }
private static async Task ModifyStopCache(Action<List<BusStop>> action) { List<BusStop> stops; var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("StopCache.txt"); if (!SavedStopCache.TryGetTarget(out stops)) { string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); stops = DeformatStops(reader); } int oldCount = count; action(stops); count = stops.Count; CompactFormatWriter writer = new CompactFormatWriter(); FormatStops(stops, writer); await FileIO.WriteTextAsync(file, writer.ToString()); SavedStopCache.SetTarget(stops); }
internal static async Task AccessStopCache(int hash, Func<List<BusStop>, bool> action) { List<BusStop> stops; var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("StopCache" + hash.ToString() + ".txt"); if (!SavedStopCache[hash].TryGetTarget(out stops)) { string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); stops = DeformatStops(reader); } if (action(stops)) { CompactFormatWriter writer = new CompactFormatWriter(); FormatStops(stops, writer); await FileIO.WriteTextAsync(file, writer.ToString()); SavedStopCache[hash].SetTarget(stops); } }
public static async Task <WeekSchedule> LoadSchedule(string stopId) { WeekSchedule result = new WeekSchedule(); //var file = (await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).GetFilesAsync()).FirstOrDefault(item => item.Name == stopId + ".txt"); var file = await(await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).TryGetItemAsync(stopId + ".txt") as StorageFile; if (file != null) { string text = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(text); result.Deformat(reader, stopId); return(result); } else { return(null); } }
public static async Task LoadPendingDownloads() { var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("PendingDownloadsCache.txt"); string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); PendingDownloadsCache.Clear(); CompactFormatReader[] routeReader; while ((routeReader = reader.Next()) != null) { List <string> item = new List <string>(); foreach (var subReader in routeReader) { item.Add(subReader.ReadString()); } PendingDownloadsCache.Add(item); } }
public void Deformat(CompactFormatReader reader, string stopId) { Stop = stopId; Days.Clear(); TechnicalDays.Clear(); DaySchedules.Clear(); CompactFormatReader[] items; while ((items = reader.Next()) != null) { ServiceDay nextDay = (ServiceDay)items[0].ReadInt(); ServiceDay nextTechnicalDay = (ServiceDay)items[1].ReadInt(); DaySchedule schedule = new DaySchedule() { Stop = stopId }; schedule.Deformat(items[2]); Days.Add(nextDay); TechnicalDays.Add(nextTechnicalDay); DaySchedules.Add(schedule); } }
internal static async Task AccessRouteCache(Func <List <Tuple <BusRoute, string[], string[]> >, bool> action) { List <Tuple <BusRoute, string[], string[]> > routes; var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("RouteCache.txt"); if (!SavedRouteCache.TryGetTarget(out routes)) { string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); routes = DeformatRoutes(reader); } if (action(routes)) { CompactFormatWriter writer = new CompactFormatWriter(); FormatRoutes(routes, writer); await FileIO.WriteTextAsync(file, writer.ToString()); SavedRouteCache.SetTarget(routes); } }
internal static async Task AccessStopCache(int hash, Func <List <BusStop>, bool> action) { List <BusStop> stops; var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("StopCache" + hash.ToString() + ".txt"); if (!SavedStopCache[hash].TryGetTarget(out stops)) { string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); stops = DeformatStops(reader); } if (action(stops)) { CompactFormatWriter writer = new CompactFormatWriter(); FormatStops(stops, writer); await FileIO.WriteTextAsync(file, writer.ToString()); SavedStopCache[hash].SetTarget(stops); } }
public static List <Tuple <TransitAgency, string[]> > DeformatAgencies(CompactFormatReader reader) { List <Tuple <TransitAgency, string[]> > result = new List <Tuple <TransitAgency, string[]> >(); CompactFormatReader[] agencyReader; List <string> routes; while ((agencyReader = reader.Next()) != null) { TransitAgency agency = new TransitAgency(); agency.ID = agencyReader[0].ReadString(); agency.Name = agencyReader[1].ReadString(); agency.Url = agencyReader[2].ReadString(); routes = new List <string>(); CompactFormatReader[] routeReader; while ((routeReader = agencyReader[3].Next()) != null) { routes.Add(routeReader[0].ReadString()); } result.Add(new Tuple <TransitAgency, string[]>(agency, routes.ToArray())); } return(result); }
public void Deformat(CompactFormatReader reader) { List <Tuple <string, string, Tuple <short, string, short?>[]> > data = new List <Tuple <string, string, Tuple <short, string, short?>[]> >(); CompactFormatReader[] curRouteReader; while ((curRouteReader = reader.Next()) != null) { string curRoute = curRouteReader[0].ReadString(); CompactFormatReader[] curDirectionReader; while ((curDirectionReader = curRouteReader[1].Next()) != null) { string sign = curDirectionReader[0].ReadString(); List <Tuple <short, string, short?> > trips = new List <Tuple <short, string, short?> >(); CompactFormatReader[] curTripReader; while ((curTripReader = curDirectionReader[1].Next()) != null) { trips.Add(new Tuple <short, string, short?>((short)curTripReader[0].ReadInt(), curTripReader[1].ReadString(), (curTripReader.Length > 2) ? new short?((short)curTripReader[2].ReadInt()) : null)); } data.Add(new Tuple <string, string, Tuple <short, string, short?>[]>(curRoute, sign, trips.ToArray())); } } Data = data.ToArray(); }
public static List<Tuple<TransitAgency, string[]>> DeformatAgencies(CompactFormatReader reader) { List<Tuple<TransitAgency, string[]>> result = new List<Tuple<TransitAgency, string[]>>(); CompactFormatReader[] agencyReader; List<string> routes; while ((agencyReader = reader.Next()) != null) { TransitAgency agency = new TransitAgency(); agency.ID = agencyReader[0].ReadString(); agency.Name = agencyReader[1].ReadString(); agency.Url = agencyReader[2].ReadString(); routes = new List<string>(); CompactFormatReader[] routeReader; while ((routeReader = agencyReader[3].Next()) != null) { routes.Add(routeReader[0].ReadString()); } result.Add(new Tuple<TransitAgency, string[]>(agency, routes.ToArray())); } return result; }
public static List<Tuple<BusRoute, string[], string[]>> DeformatRoutes(CompactFormatReader reader) { List<Tuple<BusRoute, string[], string[]>> result = new List<Tuple<BusRoute, string[], string[]>>(); CompactFormatReader[] routeReader; List<string> stops; List<string> shapes; while ((routeReader = reader.Next()) != null) { BusRoute route = new BusRoute(); route.ID = routeReader[0].ReadString(); route.Name = routeReader[1].ReadString(); route.Description = routeReader[2].ReadString(); route.Agency = routeReader[3].ReadString(); stops = new List<string>(); shapes = new List<string>(); CompactFormatReader[] subReader; while ((subReader = routeReader[4].Next()) != null) { stops.Add(subReader[0].ReadString()); } while ((subReader = routeReader[5].Next()) != null) { shapes.Add(subReader[0].ReadString()); } result.Add(new Tuple<BusRoute, string[], string[]>(route, stops.ToArray(), shapes.ToArray())); } return result; }
public static List<BusStop> DeformatStops(CompactFormatReader reader) { List<BusStop> result = new List<BusStop>(); CompactFormatReader[] stopReader; List<string> routes; while ((stopReader = reader.Next()) != null) { BusStop stop = new BusStop(); stop.ID = stopReader[0].ReadString(); stop.Direction = (StopDirection)stopReader[1].ReadInt(); stop.Position = new BasicGeoposition() { Latitude = double.Parse(stopReader[2].ReadString()), Longitude = double.Parse(stopReader[3].ReadString()) }; stop.Name = stopReader[4].ReadString(); stop.Code = stopReader[5].ReadString(); stop.LocationType = stopReader[6].ReadInt(); routes = new List<string>(); CompactFormatReader[] routeReader; while ((routeReader = stopReader[7].Next()) != null) { routes.Add(routeReader[0].ReadString()); } stop.Routes = routes.ToArray(); result.Add(stop); } return result; }
internal static async Task AccessRouteCache(Func<List<Tuple<BusRoute, string[], string[]>>, bool> action) { List<Tuple<BusRoute, string[], string[]>> routes; var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("RouteCache.txt"); if (!SavedRouteCache.TryGetTarget(out routes)) { string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); routes = DeformatRoutes(reader); } if (action(routes)) { CompactFormatWriter writer = new CompactFormatWriter(); FormatRoutes(routes, writer); await FileIO.WriteTextAsync(file, writer.ToString()); SavedRouteCache.SetTarget(routes); } }
public static async Task<WeekSchedule> LoadSchedule(string stopId) { WeekSchedule result = new WeekSchedule(); //var file = (await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).GetFilesAsync()).FirstOrDefault(item => item.Name == stopId + ".txt"); var file = await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).TryGetItemAsync(stopId + ".txt") as StorageFile; if (file != null) { string text = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(text); result.Deformat(reader, stopId); return result; } else return null; }
public static async Task LoadPendingDownloads() { var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("PendingDownloadsCache.txt"); string encodedText = await FileIO.ReadTextAsync(file); CompactFormatReader reader = new CompactFormatReader(encodedText); PendingDownloadsCache.Clear(); CompactFormatReader[] routeReader; while ((routeReader = reader.Next()) != null) { List<string> item = new List<string>(); foreach (var subReader in routeReader) { item.Add(subReader.ReadString()); } PendingDownloadsCache.Add(item); } }