/// <summary> /// Backup all known routes and stops to skydrive /// </summary> /// <returns></returns> public static async Task BackupToSkydrive() { // Group by agency var knownTNS = new TransitNetworkSearch( AppSettings.KnownRoutes.Value, AppSettings.KnownStops.Value, AppSettings.AlarmThresholds.Value); Dictionary <string, TransitNetworkSearch> agencies = TransitNetworkSearch.GroupByAgency(knownTNS); //if (agencies.Count == 0) return; // Get folder List <FolderFileData> folders = await CloudStorage.GetFiles(CloudStorage.ROOT_FOLDER); string folder_id; FolderFileData ffd = folders.FirstOrDefault(f => f.Name == CloudStorage.BA_FolderName); if (ffd == null) { folder_id = await CreateFolder(CloudStorage.ROOT_FOLDER, CloudStorage.BA_FolderName); } else { folder_id = ffd.Id; } // Upload agencies foreach (var keyval in agencies) { await CloudStorage.UploadTNS(folder_id, keyval.Key, keyval.Value); } }
/// <summary> /// Download all Bus Alarm files to app /// </summary> /// <returns></returns> public static async Task RestoreFromSkydrive() { // Search for Bus Alarm folder List <FolderFileData> folders = await CloudStorage.GetFiles(CloudStorage.ROOT_FOLDER); FolderFileData baFolder = folders.FirstOrDefault(f => f.Name == CloudStorage.BA_FolderName); if (baFolder == null) { //MessageBox.Show("Cannot find 'Bus Alarm' folder in Skydrive root", "Error", MessageBoxButton.OK); throw new Exception("Cannot find 'Bus Alarm' folder in Skydrive root"); } string folder_id = baFolder.Id; // Get files List <FolderFileData> files = await CloudStorage.GetFiles(folder_id); if (files == null) { //MessageBox.Show("Could not find files in 'Bus Alarm' folder", "Error", MessageBoxButton.OK); throw new Exception("Could not find files in 'Bus Alarm' folder"); } var baFiles = files.Where(f => f.Name.EndsWith(CloudStorage.FILE_EXTENSION)); // Downloadfiles foreach (FolderFileData ffd in baFiles) { await CloudStorage.DownloadTNS(ffd.Id); } }