コード例 #1
0
        /// <summary>
        /// Delete an image by ImageId.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnDeleteImage(object sender, CommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Delete")
                {
                    Int32 imageId = Int32.Parse(e.CommandArgument as String);

                    if (String.IsNullOrEmpty(this.selectedValue) || this.selectedValue.Equals(BLOB))
                    {
                        ImageInBlob deletedImage = (from i in imagesDb.BlobImages
                                                    where i.ImageId == imageId
                                                    select i).FirstOrDefault();
                        if (deletedImage != null)
                        {
                            // Delete an blob by uri.
                            var blob = this.GetContainer().GetBlobReference(deletedImage.BlobUri);
                            blob.DeleteIfExists();

                            imagesDb.BlobImages.Remove(deletedImage);
                            imagesDb.SaveChanges();
                        }
                    }
                    else if (this.selectedValue.Equals(SQL))
                    {
                        ImagesTable deletedImage = (from i in imagesDb.ImagesTable
                                                    where i.ImageId == imageId
                                                    select i).FirstOrDefault();

                        if (deletedImage != null)
                        {
                            ImageInSQLAzure deletedImageInfo = deletedImage.ImageInfo;

                            imagesDb.SQLAzureImages.Remove(deletedImageInfo);
                            imagesDb.ImagesTable.Remove(deletedImage);
                            imagesDb.SaveChanges();
                        }
                    }
                }
            }
            catch (StorageClientException se)
            {
                this.status.Text = "Storage client error: " + se.Message;
            }
            catch (Exception)
            {
            }

            this.RefreshGallery();
        }
コード例 #2
0
        /// <summary>
        /// Set the uri of images.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                Image img = e.Item.FindControl("img") as Image;

                // According to the choose of location, we set the uri of image.
                if (String.IsNullOrEmpty(this.selectedValue) || this.selectedValue.Equals(BLOB))
                {
                    ImageInBlob image = e.Item.DataItem as ImageInBlob;
                    img.ImageUrl = image.BlobUri;
                }
                else if (this.selectedValue.Equals(SQL))
                {
                    ImageInSQLAzure image = e.Item.DataItem as ImageInSQLAzure;
                    img.ImageUrl = "GetImage.ashx?ImageId=" + image.ImageId;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Save the images to the location
        /// </summary>
        /// <param name="name">It's the name that user inputs.</param>
        /// <param name="description">It's the description that user inputs.</param>
        /// <param name="fileName">It's the name of the file.</param>
        /// <param name="contentType">It's the type of the file.</param>
        /// <param name="data">It's the content of the file</param>
        private void SaveImage(string name, string description, string fileName, string contentType, byte[] data)
        {
            // Store the images to the Blob and SQL Azure by the choose of the location.
            if (this.selectedValue.Equals(BLOB))
            {
                name = string.IsNullOrEmpty(name) ? "unknown" : name;

                var blob = this.GetContainer().GetBlobReference(name);

                blob.Properties.ContentType = contentType;

                ImageInBlob newImage = new ImageInBlob();
                newImage.FileName    = fileName;
                newImage.ImageName   = name;
                newImage.Description = string.IsNullOrEmpty(description) ? "unknown" : description;

                blob.UploadByteArray(data);
                newImage.BlobUri = blob.Uri.ToString();

                imagesDb.BlobImages.Add(newImage);
                imagesDb.SaveChanges();
            }
            else if (this.selectedValue.Equals(SQL))
            {
                ImageInSQLAzure newImageInfo = new ImageInSQLAzure();
                ImagesTable     newImage     = new ImagesTable();

                newImageInfo.FileName    = fileName;
                newImageInfo.ImageName   = string.IsNullOrEmpty(name) ? "unknown" : name;
                newImageInfo.Description = string.IsNullOrEmpty(description) ? "unknown" : description;

                newImage.ImageInfo = newImageInfo;
                newImage.ImageData = data;

                imagesDb.SQLAzureImages.Add(newImageInfo);
                imagesDb.ImagesTable.Add(newImage);
                imagesDb.SaveChanges();
            }
        }
コード例 #4
0
        /// <summary>
        /// Copy an image by ImageId
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnCopyImage(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Copy")
            {
                Int32 imageId = Int32.Parse(e.CommandArgument as String);
                if (String.IsNullOrEmpty(this.selectedValue) || this.selectedValue.Equals(BLOB))
                {
                    ImageInBlob copiedImage = (from i in imagesDb.BlobImages
                                               where i.ImageId == imageId
                                               select i).FirstOrDefault();
                    if (copiedImage != null)
                    {
                        var srcBlob = this.GetContainer().GetBlobReference(copiedImage.BlobUri);

                        String newImageName = "Copy of \"" + copiedImage.ImageName + "\"";
                        var    newBlob      = this.GetContainer().GetBlobReference(Guid.NewGuid().ToString());

                        // Copy content from source blob
                        newBlob.CopyFromBlob(srcBlob);

                        // Copy the info of image.
                        ImageInBlob newImage = new ImageInBlob();
                        newImage.FileName    = copiedImage.FileName;
                        newImage.ImageName   = newImageName;
                        newImage.Description = copiedImage.Description;
                        newImage.BlobUri     = newBlob.Uri.ToString();

                        imagesDb.BlobImages.Add(newImage);
                        imagesDb.SaveChanges();

                        this.RefreshGallery();
                    }
                }
                else if (this.selectedValue.Equals(SQL))
                {
                    ImagesTable copiedImage = (from i in imagesDb.ImagesTable
                                               where i.ImageId == imageId
                                               select i).FirstOrDefault();

                    if (copiedImage != null)
                    {
                        ImageInSQLAzure copiedImageInfo = copiedImage.ImageInfo;
                        ImagesTable     newImage        = new ImagesTable();
                        ImageInSQLAzure newImageInfo    = new ImageInSQLAzure();

                        // Copy the info of image.
                        newImageInfo.FileName    = copiedImageInfo.FileName;
                        newImageInfo.ImageName   = "Copy of \"" + copiedImageInfo.ImageName + "\"";
                        newImageInfo.Description = copiedImageInfo.Description;

                        newImage.ImageData = copiedImage.ImageData;
                        newImage.ImageInfo = newImageInfo;

                        imagesDb.SQLAzureImages.Add(newImageInfo);
                        imagesDb.ImagesTable.Add(newImage);
                        imagesDb.SaveChanges();

                        this.RefreshGallery();
                    }
                }
            }
        }