예제 #1
0
        //Loading data from data file
        public async void loadData() {
            Debug.WriteLine("Load Data Came");
            String[] lines;
            String[] temp;
            Route route;

            //Reading the text file
            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var file = await folder.GetFileAsync("data.txt");
            var contents =  await Windows.Storage.FileIO.ReadTextAsync(file);

            //Seperate into variables
            lines = contents.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            //Clear the buffers
            routes.Clear();
            //Read line by line to get the route number and the locations through the route
            for (int i = 0; i < lines.Length; i++)
            {
                temp = lines[i].Split('|');
                route = new Route(temp[0]);
                //Debug.WriteLine(temp[0] + "-------" + temp[1] + "------------" + temp[2]);
                route = processInput(temp[1], route);
                route = processInput(temp[2], route);
                
                //if else statements for preventing any exceptions due to duplicate key values
                if (!routes.ContainsKey(temp[0]))
                {
                    routes.Add(temp[0], route);
                }
            }

        }
예제 #2
0
        //Add the data into the data structures
        public static Route processInput(String temp, Route route) {
            Location location = null;
            String[] tempLocations = temp.Split(',');

            //fill the dictionarires for routes and locations
            foreach (String s in tempLocations) {
                if (!locations.ContainsKey(s)) {
                    location = new Location(s);
                    route.addLocationToRouteIn(location);
                    locations.Add(s, location);
                } else {
                    Location value;
                    if (locations.TryGetValue(s, out value)) {
                        route.addLocationToRouteIn(locations[s]);
                    }
                }
            }
            return route;
        }
예제 #3
0
 public void addRoute(Route route) {
     if (!routes.Contains(route)) {
         routes.AddLast(route);
     }
 }