示例#1
0
 /// <summary>
 /// Adds the given recipe image to the recipe. The image cannot
 /// be null.
 /// </summary>
 /// <param name="newImage">
 /// the new image that will be associated with this recipe
 /// </param>
 public void addImage(RecipeImage newImage)
 {
     if (newImage != null)
     {
         this.recipeImages.Add(newImage);
     }
     else
     {
         throw new ArgumentNullException("The recipe image being" +
                                         " added cannot be null", new ArgumentNullException());
     }
 }
示例#2
0
        /// <summary>
        /// Sets the associated images of this recipe to the given new
        /// set of images.
        /// </summary>
        /// <param name="newImages">
        /// The new images to associate to this recipe.
        /// </param>
        public async void setImages(ObservableCollection <RecipeImage> newImages)
        {
            // TODO: clean up this code a bit, it's messy
            if (newImages != null)
            {
                recipeImages.Clear();
                for (int i = 0; i < newImages.Count; i++)
                {
                    RecipeImage newImage = newImages[i];
                    if (newImage.RecipeID == -1)
                    {
                        StorageFolder imageFolder = await RecipeList.imageFolder.CreateFolderAsync("" + this.id, CreationCollisionOption.OpenIfExists);

                        StorageFile imageFile = await StorageFile.GetFileFromPathAsync(newImage.ImagePath);

                        if (imageFile != null)
                        {
                            BitmapImage image       = null;
                            StorageFile savingImage = await imageFile.CopyAsync(imageFolder);

                            if (imageFile.IsAvailable)
                            {
                                using (IRandomAccessStream stream = await savingImage.OpenAsync(FileAccessMode.Read))
                                {
                                    image = new BitmapImage();
                                    await image.SetSourceAsync(stream);

                                    newImage.setInternalImage(image);
                                    stream.Dispose();
                                }
                            }
                            else
                            {
                                image           = new BitmapImage();
                                image.UriSource = new Uri(savingImage.Path);
                                newImage.setInternalImage(image);
                            }
                            newImage.ImagePath = savingImage.Path;
                        }

                        newImage.setRecipeId(this.id);
                        RecipeBookDataAccessor.addImage(newImage);
                    }
                    recipeImages.Add(newImage);
                }
            }
        }