Beispiel #1
0
        /*Recipe Save*/
        private async void SaveRecipe_Click(object sender, RoutedEventArgs e)
        {   //Save file, prompt for overwrite if it already exists
            try
            {
                StorageFile file;
                if (await LocalFolder.TryGetItemAsync(CurrentFilename) is StorageFile alreadyExists)
                {
                    if (!await ShowConfirmation($"Are you sure you want to overwrite \"{CurrentFilename}\"?"))
                    {
                        return;
                    }
                    file = alreadyExists;
                }
                else
                {
                    file = await LocalFolder.CreateFileAsync(CurrentFilename);

                    RecipeFiles.Add(CurrentFilename.Remove(CurrentFilename.Length - RecipeFilenameExtension.Length));
                }
                using (var stream = await file.OpenStreamForWriteAsync())
                    RecipeSerializer.Serialize(stream, Recipe);
            }
            catch (Exception x)
            {
                await ShowError(x.Message);
            }
        }
Beispiel #2
0
        private async void LoadRecipe_Click(object sender, RoutedEventArgs e)
        {   //Load currently selected recipe file
            if (RecipeSelector.SelectedIndex == -1)
            {
                return;
            }
            try
            {
                var file = await LocalFolder.GetFileAsync(CurrentFilename);

                Recipe r = RecipeSerializer.Deserialize(await file.OpenStreamForReadAsync()) as Recipe;
                if (r?.Steps?.Count >= MinSteps)
                {
                    Recipe.Steps.Clear();
                    foreach (var step in r.Steps)
                    {
                        Recipe.Steps.Add(step);
                    }
                }
                else
                {
                    await ShowError("Could not parse recipe file.");
                }
            }
            catch (Exception x)
            {
                await ShowError(x.Message);
            }
        }
 public RecipeRepo(IStorageService storageService)
 {
     Controller      = new RecipeSerializer(storageService);
     _storageService = storageService;
 }