public static async Task ExportRecipeBoxAsync(RecipeBox rb = null, RecentRecipeBox rrb = null) { if (rb == null && rrb == null) { return; } string fileContents = JsonConvert.SerializeObject(rb); var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Plain Text", new List <string>() { ".rcpbx" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "NewRecipeBox"; StorageFile newFile = await savePicker.PickSaveFileAsync(); await FileIO.WriteTextAsync(newFile, fileContents); }
public static async Task <List <RecentRecipeBox> > ListKnownRecipeBoxes() { List <RecentRecipeBox> recentRecipeBoxes = new List <RecentRecipeBox>(); var mru = StorageApplicationPermissions.MostRecentlyUsedList; foreach (Windows.Storage.AccessCache.AccessListEntry entry in mru.Entries) { string mruToken = entry.Token; string mruMetadata = entry.Metadata; //Windows.Storage.IStorageItem item = await mru.GetItemAsync(mruToken); RecentRecipeBox rrb = JsonConvert.DeserializeObject <RecentRecipeBox>(mruMetadata); rrb.Token = mruToken; recentRecipeBoxes.Add(rrb); } return(recentRecipeBoxes); }
public static async Task <RecentRecipeBox> OpenRecipeBoxFromFileAsync(RecentRecipeBox rrb = null, bool needToRecordAccess = false) { // TODO: this needs to be revised to utilize MRU and metadata storage string token = rrb?.Token; StorageFile file = null; RecipeBox rb; if (rrb == null || string.IsNullOrEmpty(token)) { FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".rcpbx"); file = await picker.PickSingleFileAsync(); needToRecordAccess = true; } else { file = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(token); } try { string contents = await FileIO.ReadTextAsync(file); rb = JsonConvert.DeserializeObject <RecipeBox>(contents); rb.ConnectParentsToChildren(); //__store an instance of the rb if it doesn't already exist BootStrapper.Current.SessionState[rb.Name] = rb; } catch (Exception e) { Console.WriteLine(e); return(null); //__show the user error notice } if (needToRecordAccess) { rrb = await RecordRecentRecipeBoxAsync(rb, file); } return(rrb); }
public static async Task <RecentRecipeBox> RecordRecentRecipeBoxAsync(RecipeBox rb, StorageFile file) { RecentRecipeBox rrb = await CreateRecentRecipeBoxAsync(rb); rb.LastPath = file.Path; string metaData = JsonConvert.SerializeObject(rb); if (file != null) { // Add to FA without metadata //string faToken = StorageApplicationPermissions.FutureAccessList.Add(file); string mruToken = StorageApplicationPermissions.MostRecentlyUsedList.Add(file, metaData); rrb.Token = mruToken; rb.AccessToken = mruToken; //_settings.AccessTokens.Add(faToken); } return(rrb); }