/// <summary> /// Load the collection of train trips /// </summary> private static void LoadTrips() { // Load the trips int numberOfTrips = PersistentStorage.GetIntItem(TrainTripsSizeName, 0); trips = new List <TrainTrip>(); for (int tripIndex = 0; tripIndex < numberOfTrips; ++tripIndex) { TrainTrip tripToAdd = new TrainTrip { From = PersistentStorage.GetStringItem(TrainTripFromName + tripIndex, ""), To = PersistentStorage.GetStringItem(TrainTripToName + tripIndex, ""), FromCode = PersistentStorage.GetStringItem(TrainTripFromCodeName + tripIndex, ""), ToCode = PersistentStorage.GetStringItem(TrainTripToCodeName + tripIndex, "") }; trips.Add(tripToAdd); } // Get the current trip selectedTrip = PersistentStorage.GetIntItem(TrainTripSelectedName, 0); // Make sure that the selected trip is valid if (selectedTrip >= trips.Count) { selectedTrip = trips.Count - 1; PersistentStorage.SetIntItem(TrainTripSelectedName, selectedTrip); } }
/// <summary> /// Save the entire station list to storage /// </summary> private static void SaveStations() { PersistentStorage.SetIntItem(RecentStationsSizeName, stations.Count); for (int stationIndex = 0; stationIndex < stations.Count; ++stationIndex) { PersistentStorage.SetStringItem(RecentStationName + stationIndex, stations[stationIndex]); } }
/// <summary> /// Save the entire trip list to storage /// </summary> private static void SaveTrips() { PersistentStorage.SetIntItem(TrainTripsSizeName, trips.Count); for (int tripIndex = 0; tripIndex < trips.Count; ++tripIndex) { PersistentStorage.SetStringItem(TrainTripFromName + tripIndex, trips[tripIndex].From); PersistentStorage.SetStringItem(TrainTripToName + tripIndex, trips[tripIndex].To); PersistentStorage.SetStringItem(TrainTripFromCodeName + Trips.Count, trips[tripIndex].FromCode); PersistentStorage.SetStringItem(TrainTripToCodeName + Trips.Count, trips[tripIndex].ToCode); } }
/// <summary> /// Add a new trip to the collection and store. /// </summary> /// <param name="trip"></param> public static void AddTrip(TrainTrip trip) { // Store the trip PersistentStorage.SetStringItem(TrainTripFromName + Trips.Count, trip.From); PersistentStorage.SetStringItem(TrainTripToName + Trips.Count, trip.To); PersistentStorage.SetStringItem(TrainTripFromCodeName + Trips.Count, trip.FromCode); PersistentStorage.SetStringItem(TrainTripToCodeName + Trips.Count, trip.ToCode); // Add to the list Trips.Add(trip); // Update the count PersistentStorage.SetIntItem(TrainTripsSizeName, Trips.Count); }