//To save the artwork if there is an artist, title and an imagepath included
        private async void SaveArtwork_Click(object sender, RoutedEventArgs e)
        {
            if ((ArtArtist.Text != "") && (ArtName.Text != "") && (_imagePath != null))
            {
                _artwork             = new Artwork(ArtArtist.Text, ArtName.Text);
                _artwork.ImagePath   = _imagePath;
                _artwork.Description = ArtDescription.Text;
                _artwork.Room        = ArtRoom.Text;
                _artwork.Signed      = CheckBoxSigned.IsChecked;
                _artwork.Place       = ArtPlace.Text;
                if (ArtPlace.Text == "")
                {
                    _artwork.Place = "Obestämd";
                }
                int height;
                int width;
                int.TryParse(ArtHeight.Text, out height);
                int.TryParse(ArtWidth.Text, out width);
                _artwork.Height = height;
                _artwork.Width  = width;

                await _artworkLogic.SaveArtworkAsync(_artwork);

                var main = new MainWindow();
                this.Close();
                main.Show();
            }
            else
            {
                MessageBox.Show("Du måste ange tavlans titel, konstnär och bifoga bild.", "Varning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        //To save the artwork if there is an artist, title and an imagepath included
        private async void SaveArtwork_Click(object sender, RoutedEventArgs e)
        {
            if ((ArtArtist.Text != "") && (ArtName.Text != "") && (_imagePath != null))
            {
                _artwork = new Artwork(ArtArtist.Text, ArtName.Text);
                _artwork.ImagePath = _imagePath;
                _artwork.Description = ArtDescription.Text;
                _artwork.Room = ArtRoom.Text;
                _artwork.Signed = CheckBoxSigned.IsChecked;
                _artwork.Place = ArtPlace.Text;
                if (ArtPlace.Text == "")
                {
                    _artwork.Place = "Obestämd";
                }
                int height;
                int width;
                int.TryParse(ArtHeight.Text, out height);
                int.TryParse(ArtWidth.Text, out width);
                _artwork.Height = height;
                _artwork.Width = width;

                await _artworkLogic.SaveArtworkAsync(_artwork);

                var main = new MainWindow();
                this.Close();
                main.Show();
            }
            else
            {
                MessageBox.Show("Du måste ange tavlans titel, konstnär och bifoga bild.", "Varning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public async Task SaveArtwork(Artwork artwork)
        {
            try
            {
                await SaveBlob(artwork);

                var cloudTable = GetCloudTable();

                var insertTableOperation = TableOperation.Insert(artwork);

                cloudTable.Execute(insertTableOperation);

                MessageBox.Show("Konstverket har nu sparats", "Statusmeddelande", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Någonting gick fel när tavlan skulle sparas /r /r" + ex, "Felmeddelande", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public async Task SaveArtwork(Artwork artwork)
        {
            try
            {
                await SaveBlob(artwork);

                var cloudTable = GetCloudTable();

                var insertTableOperation = TableOperation.Insert(artwork);

                cloudTable.Execute(insertTableOperation);

                MessageBox.Show("Konstverket har nu sparats", "Statusmeddelande", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Någonting gick fel när tavlan skulle sparas /r /r" + ex, "Felmeddelande", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async Task SaveBlob(Artwork artwork)
        {
            var cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);

            var blobClient = cloudStorageAccount.CreateCloudBlobClient();

            var container = blobClient.GetContainerReference("ogblob");

            container.CreateIfNotExists();

            container.SetPermissions(new BlobContainerPermissions {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(artwork.Title);

            using (var fileStream = System.IO.File.OpenRead(artwork.ImagePath))
            {
                await blockBlob.UploadFromStreamAsync(fileStream);

                artwork.Blob = container.GetBlockBlobReference(artwork.Title).Uri.AbsoluteUri;
            }
        }
示例#6
0
        //Saves artwork.
        public async Task SaveArtworkAsync(Artwork artwork)
        {
            await _artworkService.SaveArtwork(artwork);

            await UpdateArtworkListAsync();
        }
        //Saves artwork.
        public async Task SaveArtworkAsync(Artwork artwork)
        {
            await _artworkService.SaveArtwork(artwork);

            await UpdateArtworkListAsync();
        }
        //Replaces the existing information with new information about the artwork.
        public async Task ReplaceArtwork(string artist, string title, string imagepath, string place, string description, string oldArtworkTitle, string room, int width, int height, bool?signed)
        {
            var cloudTable = GetCloudTable();

            var art = (await GetArtworks()).SingleOrDefault(x => x.Title == oldArtworkTitle);

            if (art != null)
            {
                var retrieveOperation = TableOperation.Retrieve <Artwork>(art.Artist, art.Title);

                var retrievedResult = cloudTable.Execute(retrieveOperation);

                var artwork = (Artwork)retrievedResult.Result;

                if (artwork != null)
                {
                    //TODO: If RowKey or PartitionKey is changed, delete an entity and insert a new one with new properties.

                    if (artwork.RowKey == title && artwork.PartitionKey == artist)
                    {
                        // Update Entity
                        artwork.Description = description;
                        artwork.Place       = place;
                        artwork.Room        = room;
                        artwork.Height      = height;
                        artwork.Width       = width;
                        artwork.Signed      = signed;

                        if (artwork.ImagePath != imagepath)
                        {
                            var blob = await ReplaceBlob(title, imagepath);

                            artwork.ImagePath = imagepath;
                            artwork.Blob      = blob;
                        }

                        // Create the Replace TableOperation.
                        var updateOperation = TableOperation.Replace(artwork);

                        // Execute the operation.
                        cloudTable.Execute(updateOperation);
                    }
                    else if (artwork.RowKey != title || artwork.PartitionKey != artist)
                    {
                        await DeleteBlob(artwork.Title);

                        var deleteOperation = TableOperation.Delete(artwork);

                        cloudTable.Execute(deleteOperation);

                        Artwork replacedArtwork = new Artwork()
                        {
                            RowKey       = title,
                            PartitionKey = artist,
                            Description  = description,
                            Place        = place,
                            Room         = room,
                            Height       = height,
                            Width        = width,
                            Signed       = signed,
                            ImagePath    = imagepath
                        };

                        await SaveBlob(replacedArtwork);

                        var insertTableOperation = TableOperation.Insert(replacedArtwork);

                        cloudTable.Execute(insertTableOperation);
                    }

                    MessageBox.Show("Tavlan har uppdaterats.", "Statusmeddelande", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Kunde inte hitta tavlan.", "Felmeddelande", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        //Replaces the existing information with new information about the artwork.
        public async Task ReplaceArtwork(string artist, string title, string imagepath, string place, string description, string oldArtworkTitle, string room, int width, int height, bool? signed)
        {
            var cloudTable = GetCloudTable();

            var art = (await GetArtworks()).SingleOrDefault(x => x.Title == oldArtworkTitle);

            if (art != null)
            {
                var retrieveOperation = TableOperation.Retrieve<Artwork>(art.Artist, art.Title);

                var retrievedResult = cloudTable.Execute(retrieveOperation);

                var artwork = (Artwork)retrievedResult.Result;

                if (artwork != null)
                {
                    //TODO: If RowKey or PartitionKey is changed, delete an entity and insert a new one with new properties.

                    if (artwork.RowKey == title && artwork.PartitionKey == artist)
                    {
                        // Update Entity
                        artwork.Description = description;
                        artwork.Place = place;
                        artwork.Room = room;
                        artwork.Height = height;
                        artwork.Width = width;
                        artwork.Signed = signed;

                        if (artwork.ImagePath != imagepath)
                        {
                            var blob = await ReplaceBlob(title, imagepath);
                            artwork.ImagePath = imagepath;
                            artwork.Blob = blob;
                        }

                        // Create the Replace TableOperation.
                        var updateOperation = TableOperation.Replace(artwork);

                        // Execute the operation.
                        cloudTable.Execute(updateOperation);
                    }
                    else if (artwork.RowKey != title || artwork.PartitionKey != artist)
                    {
                        await DeleteBlob(artwork.Title);

                        var deleteOperation = TableOperation.Delete(artwork);

                        cloudTable.Execute(deleteOperation);

                        Artwork replacedArtwork = new Artwork()
                        {
                            RowKey = title,
                            PartitionKey = artist,
                            Description = description,
                            Place = place,
                            Room = room,
                            Height = height,
                            Width = width,
                            Signed = signed,
                            ImagePath = imagepath
                        };

                        await SaveBlob(replacedArtwork);

                        var insertTableOperation = TableOperation.Insert(replacedArtwork);

                        cloudTable.Execute(insertTableOperation);
                    }

                    MessageBox.Show("Tavlan har uppdaterats.", "Statusmeddelande", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else

                    MessageBox.Show("Kunde inte hitta tavlan.", "Felmeddelande", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async Task SaveBlob(Artwork artwork)
        {
            var cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);

            var blobClient = cloudStorageAccount.CreateCloudBlobClient();

            var container = blobClient.GetContainerReference("ogblob");

            container.CreateIfNotExists();

            container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(artwork.Title);

            using (var fileStream = System.IO.File.OpenRead(artwork.ImagePath))
            {
                await blockBlob.UploadFromStreamAsync(fileStream);
                artwork.Blob = container.GetBlockBlobReference(artwork.Title).Uri.AbsoluteUri;
            }
        }