Пример #1
0
 public void Format(CompactFormatWriter formatter)
 {
     for (int i = 0; i < DaySchedules.Count; i++)
     {
         formatter.WriteInt((int)Days[i]);
         formatter.WriteInt((int)TechnicalDays[i]);
         formatter.OpenParens();
         DaySchedules[i].Format(formatter);
         formatter.CloseParens();
         formatter.NextItem();
     }
 }
Пример #2
0
        public static async Task SavePendingDownloads()
        {
            CompactFormatWriter writer = new CompactFormatWriter();

            foreach (var route in PendingDownloadsCache)
            {
                foreach (var item in route)
                {
                    writer.WriteString(item);
                }
                writer.NextItem();
            }
            var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("PendingDownloadsCache.txt");

            await FileIO.WriteTextAsync(file, writer.ToString());
        }
Пример #3
0
 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);
 }
Пример #4
0
 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);
 }
Пример #5
0
 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);
     }
 }
Пример #6
0
        public static async Task OverwriteScheduleAsync(WeekSchedule schedule, BusStop stop)
        {
            int hash = HashLocation(stop.Position);
            var file = await(await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).CreateFileAsync(stop.ID.ToString() + ".txt", CreationCollisionOption.ReplaceExisting);
            CompactFormatWriter encoder = new CompactFormatWriter();

            schedule.Format(encoder);
            encoder.TrimDelimiter();
            await FileIO.WriteTextAsync(file, encoder.ToString());

            await AccessStopCache(hash, delegate(List <BusStop> cache)
            {
                if (!cache.Any(item => item == stop))
                {
                    cache.Add(stop);
                    return(true);
                }
                return(false);
            }
                                  );
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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 void FormatStops(List <BusStop> stops, CompactFormatWriter writer)
 {
     for (int i = 0; i < stops.Count; i++)
     {
         var stop = stops[i];
         writer.WriteString(stop.ID);
         writer.WriteInt((int)stop.Direction);
         writer.WriteString(stop.Position.Latitude.ToString());
         writer.WriteString(stop.Position.Longitude.ToString());
         writer.WriteQuotedString(stop.Name);
         writer.WriteString(stop.Code);
         writer.WriteInt(stop.LocationType);
         writer.OpenParens();
         foreach (var route in stop.Routes)
         {
             writer.WriteString(route);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
     }
 }
Пример #10
0
        public void Format(CompactFormatWriter formatter)
        {
            string curRoute = "";

            foreach (var item in Data)
            {
                if (curRoute == "")
                {
                    curRoute = item.Item1;
                    formatter.WriteString(curRoute);
                    formatter.OpenParens();
                }
                else if (item.Item1 != curRoute)
                {
                    curRoute = item.Item1;
                    formatter.CloseParens();
                    formatter.NextItem();
                    formatter.WriteString(curRoute);
                    formatter.OpenParens();
                }
                formatter.WriteQuotedString(item.Item2);
                formatter.OpenParens();
                foreach (var subItem in item.Item3)
                {
                    formatter.WriteInt(subItem.Item1);
                    formatter.WriteString(subItem.Item2);
                    if (subItem.Item3 != null)
                    {
                        formatter.WriteInt(subItem.Item3.Value);
                    }
                    formatter.NextItem();
                }
                formatter.CloseParens();
                formatter.NextItem();
            }
            formatter.CloseParens();
        }
Пример #11
0
 public static async Task SaveScheduleAsync(WeekSchedule schedule, BusStop stop)
 {
     await EnsureFolders();
     var file = await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).CreateFileAsync(stop.ID.ToString() + ".txt", CreationCollisionOption.ReplaceExisting);
     CompactFormatWriter encoder = new CompactFormatWriter();
     schedule.Format(encoder);
     encoder.TrimDelimiter();
     await FileIO.WriteTextAsync(file, encoder.ToString());
     await ModifyStopCache(delegate (List<BusStop> cache)
     {
             if (!cache.Any(item => item == stop))
                 cache.Add(stop);
     }
         );
 }
Пример #12
0
 public static void FormatRoutes(List <Tuple <BusRoute, string[], string[]> > routes, CompactFormatWriter writer)
 {
     for (int i = 0; i < routes.Count; i++)
     {
         var route = routes[i];
         writer.WriteString(route.Item1.ID);
         writer.WriteQuotedString(route.Item1.Name);
         writer.WriteQuotedString(route.Item1.Description);
         writer.WriteString(route.Item1.Agency);
         writer.OpenParens();
         foreach (var stop in route.Item2)
         {
             writer.WriteString(stop);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.OpenParens();
         foreach (var shape in route.Item3)
         {
             writer.WriteQuotedString(shape);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
     }
 }
Пример #13
0
 public static void FormatAgencies(List<Tuple<TransitAgency, string[]>> agencies, CompactFormatWriter writer)
 {
     while (agencies.Count > 0)
     {
         var agency = agencies[0];
         writer.WriteString(agency.Item1.ID);
         writer.WriteQuotedString(agency.Item1.Name);
         writer.WriteQuotedString(agency.Item1.Url);
         writer.OpenParens();
         foreach (var route in agency.Item2)
         {
             writer.WriteString(route);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
         agencies.RemoveAt(0);
     }
 }
Пример #14
0
 public static void FormatRoutes(List<Tuple<BusRoute, string[], string[]>> routes, CompactFormatWriter writer)
 {
     while (routes.Count > 0)
     {
         var route = routes[0];
         writer.WriteString(route.Item1.ID);
         writer.WriteQuotedString(route.Item1.Name);
         writer.WriteString(route.Item1.ID);
         writer.WriteString(route.Item1.Agency);
         writer.OpenParens();
         foreach (var stop in route.Item2)
         {
             writer.WriteString(stop);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.OpenParens();
         foreach (var shape in route.Item3)
         {
             writer.WriteQuotedString(shape);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
         routes.RemoveAt(0);
     }
 }
Пример #15
0
 public static void FormatStops(List<BusStop> stops, CompactFormatWriter writer)
 {
     for (int i = 0; i < stops.Count; i++)
     {
         var stop = stops[i];
         writer.WriteString(stop.ID);
         writer.WriteInt((int)stop.Direction);
         writer.WriteString(stop.Position.Latitude.ToString());
         writer.WriteString(stop.Position.Longitude.ToString());
         writer.WriteQuotedString(stop.Name);
         writer.WriteString(stop.Code);
         writer.WriteInt(stop.LocationType);
         writer.OpenParens();
         foreach (var route in stop.Routes)
         {
             writer.WriteString(route);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
     }
 }
Пример #16
0
 public static void FormatAgencies(List <Tuple <TransitAgency, string[]> > agencies, CompactFormatWriter writer)
 {
     for (int i = 0; i < agencies.Count; i++)
     {
         var agency = agencies[i];
         writer.WriteString(agency.Item1.ID);
         writer.WriteQuotedString(agency.Item1.Name);
         writer.WriteQuotedString(agency.Item1.Url);
         writer.OpenParens();
         foreach (var route in agency.Item2)
         {
             writer.WriteString(route);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
     }
 }
Пример #17
0
 public static void FormatRoutes(List<Tuple<BusRoute, string[], string[]>> routes, CompactFormatWriter writer)
 {
     for (int i = 0; i < routes.Count; i++)
     {
         var route = routes[i];
         writer.WriteString(route.Item1.ID);
         writer.WriteQuotedString(route.Item1.Name);
         writer.WriteQuotedString(route.Item1.Description);
         writer.WriteString(route.Item1.Agency);
         writer.OpenParens();
         foreach (var stop in route.Item2)
         {
             writer.WriteString(stop);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.OpenParens();
         foreach (var shape in route.Item3)
         {
             writer.WriteQuotedString(shape);
             writer.NextItem();
         }
         writer.CloseParens();
         writer.NextItem();
     }
 }
Пример #18
0
 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);
     }
 }
Пример #19
0
 public static async Task OverwriteScheduleAsync(WeekSchedule schedule, BusStop stop)
 {
     int hash = HashLocation(stop.Position);
     var file = await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).CreateFileAsync(stop.ID.ToString() + ".txt", CreationCollisionOption.ReplaceExisting);
     CompactFormatWriter encoder = new CompactFormatWriter();
     schedule.Format(encoder);
     encoder.TrimDelimiter();
     await FileIO.WriteTextAsync(file, encoder.ToString());
     await AccessStopCache(hash, delegate (List<BusStop> cache)
     {
         if (!cache.Any(item => item == stop))
         {
             cache.Add(stop);
             return true;
         }
         return false;
     }
         );
 }
Пример #20
0
 public static async Task SavePendingDownloads()
 {
     CompactFormatWriter writer = new CompactFormatWriter();
     foreach (var route in PendingDownloadsCache)
     {
         foreach (var item in route)
         {
             writer.WriteString(item);
         }
         writer.NextItem();
     }
     var file = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("PendingDownloadsCache.txt");
     await FileIO.WriteTextAsync(file, writer.ToString());
 }