예제 #1
0
        private async Task saveFavorite()
        {
            int value;
            ApplicationDataContainer roamingSettings;

            try
            {
                // to get roaming settings.....
                roamingSettings =
                    ApplicationData.Current.RoamingSettings;
                value          = (int)roamingSettings.Values["FavoriteYummly"];
                favoriteNumber = value;
            }
            catch (Exception exRoaming)
            {
                // if the value key is not set, then the exception will cause
                // this code to execute, which just sets the value to 0 (default)
                string errMsg = exRoaming.Message;
                favoriteNumber = 0;
            } // end inner try for roaming settings
            Model.ResponseYummly recipe        = listRecipes[pvtRecipes.SelectedIndex];
            StorageFolder        storageFolder = ApplicationData.Current.RoamingFolder;
            StorageFile          sampleFile;
            string fileText = "";

            try
            {
                sampleFile = await storageFolder.GetFileAsync("Yummly" + favoriteNumber + ".txt");

                fileText = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);
            }
            catch (Exception myE)
            {
                string message = myE.Message;
                sampleFile = await storageFolder.CreateFileAsync(("Yummly" + favoriteNumber + ".txt"));
            }
            String objectRecipe = "";

            objectRecipe += recipe.ImageUrl + "\n";
            objectRecipe += recipe.SourceDisplayName + "\n";
            objectRecipe += recipe.Ingredients + "\n";
            objectRecipe += recipe.Id + "\n";
            objectRecipe += recipe.RecipeName + "\n";
            objectRecipe += recipe.TotalTime + "\n";
            objectRecipe += recipe.Course + "\n";
            objectRecipe += recipe.Cuisine + "\n";
            objectRecipe += recipe.Flavors + "\n";
            objectRecipe += recipe.Rating + "\n";
            // file open, now write to it using the writeTextAsync
            await Windows.Storage.FileIO.WriteTextAsync(sampleFile, objectRecipe);

            favoriteNumber++;
            roamingSettings =
                ApplicationData.Current.RoamingSettings;
            roamingSettings.Values["FavoriteYummly"] = favoriteNumber;
        }
예제 #2
0
        private async Task <int> readYummlyFiles(int yummlyFavorites)
        {
            StorageFolder storageFolder = ApplicationData.Current.RoamingFolder;
            // List<Model.ResponseYummly> listRecipe = new List<Model.ResponseYummly>();

            StorageFile sampleFile;

            for (int i = 0; i < yummlyFavorites; i++)
            {
                string fileText = "";
                try
                {
                    sampleFile = await storageFolder.GetFileAsync("Yummly" + i + ".txt");

                    fileText = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);
                }
                catch (Exception myE)
                {
                    string message = myE.Message;
                    continue;
                }
                Model.ResponseYummly recipe = new Model.ResponseYummly();
                String[]             tokens = fileText.Split('\n');
                recipe.ImageUrl          = tokens[0];
                recipe.SourceDisplayName = tokens[1];
                recipe.Ingredients       = tokens[3];
                recipe.Id         = tokens[3];
                recipe.RecipeName = tokens[4];
                recipe.TotalTime  = Double.Parse(tokens[5]);
                recipe.Course     = tokens[6];
                recipe.Cuisine    = tokens[7];
                recipe.Flavors    = tokens[8];
                recipe.Rating     = Double.Parse(tokens[9]);
                listRecipe.Add(recipe);
            }
            return(1);
        }
예제 #3
0
        private async Task<int> readYummlyFiles(int yummlyFavorites)
        {
            StorageFolder storageFolder = ApplicationData.Current.RoamingFolder;
           // List<Model.ResponseYummly> listRecipe = new List<Model.ResponseYummly>();
            
            StorageFile sampleFile;
            for (int i = 0; i < yummlyFavorites; i++)
            {
                string fileText = "";
                try
                {
                    sampleFile = await storageFolder.GetFileAsync("Yummly" + i + ".txt");
                    fileText = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);

                }
                catch (Exception myE)
                {
                    string message = myE.Message;
                    continue;
                }
                Model.ResponseYummly recipe = new Model.ResponseYummly();
                String[] tokens = fileText.Split('\n');
                recipe.ImageUrl = tokens[0];
                recipe.SourceDisplayName = tokens[1];
                recipe.Ingredients = tokens[3];
                recipe.Id = tokens[3];
                recipe.RecipeName = tokens[4];
                recipe.TotalTime = Double.Parse(tokens[5]);
                recipe.Course = tokens[6];
                recipe.Cuisine = tokens[7];
                recipe.Flavors = tokens[8];
                recipe.Rating = Double.Parse(tokens[9]);
                listRecipe.Add(recipe);
            }
            return 1;
        }