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 async Task<RecipeBox> GetData() { // Use this to connect to the actual data service // Simulate by returning a DataItem //var item = new DataItem("Welcome to MVVM Light"); var item = new RecipeBox(); return item; }
public static async Task SaveRecipeBoxAsync(RecipeBox rb, bool doSaveAs = false) { var savePicker = new FileSavePicker(); string lastSavePath = rb.LastPath; string accessToken = rb.AccessToken; //__check to see if access token is valid var currentlyKnownRecipies = await ListKnownRecipeBoxes(); bool haveAccessRecord = currentlyKnownRecipies.Any(rrb => rrb.Name == rb.Name && rrb.Token == rb.AccessToken); StorageFile targetFile = null; if (haveAccessRecord && !doSaveAs) { targetFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(accessToken); } else { doSaveAs = true; } //if (targetFile != null && !doSaveAs) //{ // StorageFolder targetFolder = await StorageFolder.GetFolderFromPathAsync(lastSavePath); // targetFile = await targetFolder.CreateFileAsync(rb.Name, CreationCollisionOption.ReplaceExisting); //} //else if (targetFile == null || doSaveAs) { savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Recipe Box", new List <string>() { ".rcpbx" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = rb.Name; targetFile = await savePicker.PickSaveFileAsync(); await RecordRecentRecipeBoxAsync(rb, targetFile); //__store access to this RecipeBox for current session if (!BootStrapper.Current.SessionState.ContainsKey(rb.Name)) { BootStrapper.Current.SessionState[rb.Name] = rb; } } //__remving the ReferenceLoopHandling option as Parent is being removed in favor of event based properties //JsonSerializerSettings settings = new JsonSerializerSettings(); //settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; string rbJson = JsonConvert.SerializeObject(rb); await FileIO.WriteTextAsync(targetFile, rbJson); }
void LoadCraftbot() // Loads item_names.json into ItemBox, and craftbot.json into RecipeBox { String item_names = File.ReadAllText(CraftingPath + "item_names.json"); ItemDictionary = JsonConvert.DeserializeObject <Dictionary <String, String> >(item_names); ItemDictionaryReversed = ItemDictionary.ToDictionary(x => x.Value, x => x.Key); ItemBox.DataSource = ItemDictionary.Values.ToList(); dynamic CraftbotJson = JsonConvert.DeserializeObject <List <Recipe> >(File.ReadAllText(CraftingPath + "craftbot.json")); CraftbotDocument = CraftbotJson; foreach (Recipe r in CraftbotDocument) { RecipeBox.Items.Add(ItemDictionary[r.itemId]); } RecipeBox.SetSelected(0, true); }
//__Create a default recipe box if there is no data public static RecipeBox generateDefault() { var newBox = new RecipeBox(); for (int i = 0; i < 5; i++) { string message; var sourdough = new SourdoughRecipe(); sourdough.Name = "Sourdough " + i; var breadFlour = new Ingredient("Bread Flour", IngredientType.Dry); breadFlour.Percent = 53.9; sourdough.Preferment.AddIngredient(breadFlour, out message); Starter starter = new Starter("Standard", 166); starter.Percent = 46.1; sourdough.Preferment.AddIngredient(starter); sourdough.Preferment.Percent = 37.1; var Dry = new IngredientGroup(IngredientType.Dry, "Dry", 30.2, sourdough); var flour = new Ingredient("Bread Flour", IngredientType.Dry, Dry); flour.Percent = 67; Dry.AddIngredient(flour); var wwFlour = new Ingredient("Whole Wheat", IngredientType.Dry, Dry); Dry.AddIngredient(wwFlour); wwFlour.Percent = 33; sourdough.AddGroup(Dry, out message); var wet = new IngredientGroup(IngredientType.Wet, "Water", 31.9, sourdough); var water = new Ingredient("Water", IngredientType.Wet, wet); water.Percent = 100; wet.AddIngredient(water); sourdough.AddGroup(wet, out message); var salt = new IngredientGroup(IngredientType.Salt, "Salt", 2, sourdough); var s = new Ingredient("Pink Himalayan", IngredientType.Salt, salt); s.Percent = 100; salt.AddIngredient(s); sourdough.AddGroup(salt, out message); sourdough.Description = "This is one wicked SD, chock full of love and ready to party!!!"; sourdough.Weight = 1000; newBox.SourdoughRecipes.Add(sourdough); } return newBox; }
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); }
void LoadCraftbot(String path) // Loads item_names.json into ItemBox, and craftbot.json into RecipeBox { FullPath = path; FileName = FullPath.Split('\\').Last(); Text = "SMEMT v" + Resources.VersionString + ": Recipe Editor: " + FileName; RecipeBox.Items.Clear(); foreach (String thing in Localization.LocalizeList(DataClass.ItemDictionary.Keys.ToList())) { ItemBox.Items.Add(thing); } dynamic CraftbotJson = JsonConvert.DeserializeObject <List <Recipe> >(File.ReadAllText(path)); CraftbotDocument = CraftbotJson; foreach (Recipe r in CraftbotDocument) { RecipeBox.Items.Add(Localization.Localize(r.itemId.ToString())); } RecipeBox.SetSelected(0, true); }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState) { //Value = (suspensionState.ContainsKey(nameof(Value))) ? suspensionState[nameof(Value)]?.ToString() : parameter?.ToString(); string recipeBoxName = BootStrapper.Current.SessionState[App.ActiveRecipeBoxKey].ToString(); if (BootStrapper.Current.SessionState.Keys.Contains(recipeBoxName)) { try { activeRecipeBox = BootStrapper.Current.SessionState[recipeBoxName] as RecipeBox; CurrentRecipeGroups = activeRecipeBox?.RecipeGroups; } catch (Exception e) { throw e; } } await Task.CompletedTask; }
public static async Task <RecentRecipeBox> CreateRecentRecipeBoxAsync(RecipeBox recipeBox) { try { //_file was valid, store a copy in my storage string recipeBoxName = recipeBox.Name; // Create file; replace if exists. //await SaveRecipeBoxAsync(rb); return(new RecentRecipeBox() { Name = recipeBoxName, LastOpened = DateTime.Now, Path = recipeBox.LastPath, Description = recipeBox.Description }); } catch (Exception e) { return(null); //__show the user error notice } }
public static async Task <RecipeBox> CreateNewRecipeBoxAsync(string newName = "RecipeBox") { try { var savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Recipe Box", new List <string>() { ".rcpbx" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "MyRecipeBox"; StorageFile file = await savePicker.PickSaveFileAsync(); if (file == null) { return(null); } newName = file.DisplayName; RecipeBox rb = new RecipeBox(newName); rb.LastPath = file.Path; string recipeBoxJson = JsonConvert.SerializeObject(rb); await FileIO.WriteTextAsync(file, recipeBoxJson); await RecordRecentRecipeBoxAsync(rb, file); return(rb); } catch { //__could insert code here for case of picker cancelled return(null); } }
RecipeBoxSelectedMessage(RecipeBox rb) { SelectedRecipeBox = rb; }
//private object ReceiveMessage(RecipeBoxSelectedMessage item) //{ // activeRecipeBox = item.SelectedRecipeBox; // if (currentRecipeGroups == null) currentRecipeGroups = new ObservableCollection<RecipeGroup>(); // // if (currentRecipes == null) currentRecipes = new ObservableCollection<Recipe>(); // CurrentRecipeGroups = activeRecipeBox.RecipeGroups; // RecipeBoxOpen = true; // return null; //} #endregion Private Methods #region Public Constructors public RecipeGroupsViewModel() { //Messenger.Default.Register<RecipeBoxSelectedMessage>(this, (message) => ReceiveMessage(message)); activeRecipeBox = BootStrapper.Current.SessionState[App.ActiveRecipeBoxKey] as RecipeBox; }