コード例 #1
0
ファイル: Images.cs プロジェクト: ChrisPelatari/SubText
        /// <summary>
        /// Saves two images. A normal image for the web site and then a thumbnail.
        /// </summary>
        /// <param name="image">Original image to process.</param>
        public static void MakeAlbumImages(Image image)
        {
            if(image == null)
            {
                throw new ArgumentNullException("image");
            }

            // Indexed GIFs can cause issues.
            using(System.Drawing.Image originalImage = GraphicsHelper.FromFilePathAsUnindexedImage(image.OriginalFilePath))
            {
                var originalSize = new Size(originalImage.Width, originalImage.Height);

                /// TODO: make new sizes configurations.
                // New Display Size
                Size displaySize = originalSize.ScaleToFit(Config.Settings.GalleryImageMaxWidth, Config.Settings.GalleryImageMaxHeight);
                image.Height = displaySize.Height;
                image.Width = displaySize.Width;
                using(System.Drawing.Image displayImage = originalImage.GetResizedImage(displaySize))
                {
                    displayImage.Save(image.ResizedFilePath, ImageFormat.Jpeg);
                }

                // smaller thumbnail
                Size thumbSize = originalSize.ScaleToFit(Config.Settings.GalleryImageThumbnailWidth, Config.Settings.GalleryImageThumbnailHeight);
                using(System.Drawing.Image thumbnailImage = originalImage.GetResizedImage(thumbSize))
                {
                    thumbnailImage.Save(image.ThumbNailFilePath, ImageFormat.Jpeg);
                }
            }
        }
コード例 #2
0
        private void ReplaceImage()
        {
            if (Page.IsValid)
            {
                _image            = Repository.GetImage(ImageId, false /* activeOnly */);
                _image.CategoryID = Convert.ToInt32(ddlGalleries.SelectedItem.Value);
                _image.Title      = txbTitle.Text;
                _image.IsActive   = ckbPublished.Checked;

                try
                {
                    _image.FileName           = Path.GetFileName(ImageFile.PostedFile.FileName);
                    _image.Url                = Url.ImageGalleryDirectoryUrl(Blog, _image.CategoryID);
                    _image.LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, _image.CategoryID);
                    Images.Update(_image, ImageFile.PostedFile.GetFileStream());

                    Messages.ShowMessage(Resources.EditGalleries_ImageUpdated);
                    BindImage();
                }
                catch (Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }
        }
コード例 #3
0
ファイル: ImageTests.cs プロジェクト: rhoadsce/Subtext
 public void CanGetFilePath()
 {
     var image = new Image();
     image.LocalDirectoryPath = @"c:\";
     image.FileName = @"Test.jpg";
     Assert.AreEqual(@"c:\Test.jpg", image.FilePath);
 }
コード例 #4
0
ファイル: ImageTests.cs プロジェクト: rhoadsce/Subtext
        public void CanGetRecentImages()
        {
            //arrange
            UnitTestHelper.SetupBlog();
            var repository = new DatabaseObjectProvider();
            var category = new LinkCategory
            {
                BlogId = Config.CurrentBlog.Id,
                Description = "Whatever",
                IsActive = true,
                Title = "Whatever"
            };
            int categoryId = repository.CreateLinkCategory(category);

            var image = new Image
            {
                Title = "Title",
                CategoryID = categoryId,
                BlogId = Config.CurrentBlog.Id,
                FileName = "Foo",
                Height = 10,
                Width = 10,
                IsActive = true,
            };
            int imageId = repository.InsertImage(image);

            //act
            ICollection<Image> images = repository.GetImages(Config.CurrentBlog.Host, null, 10);

            //assert
            Assert.AreEqual(1, images.Count);
            Assert.AreEqual(imageId, images.First().ImageID);
        }
コード例 #5
0
        private void UpdateImage()
        {
            if (Page.IsValid)
            {
                _image            = Repository.GetImage(ImageId, false /* activeOnly */);
                _image.CategoryID = Convert.ToInt32(ddlGalleries.SelectedItem.Value);
                _image.Title      = txbTitle.Text;
                _image.IsActive   = ckbPublished.Checked;

                try
                {
                    Images.UpdateImage(_image);

                    // would need to also move files for this to work here. should happen
                    // in the provider though.

                    Messages.ShowMessage(Resources.EditGalleries_ImageUpdated);
                    BindImage();
                }
                catch (Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }
        }
コード例 #6
0
ファイル: Images.cs プロジェクト: ayende/Subtext
        public static void DeleteImage(Image image)
        {
            if (image == null)
                throw new ArgumentNullException("image", Resources.ArgumentNull_Generic);

            ObjectProvider.Instance().DeleteImage(image.ImageID);
        }
コード例 #7
0
        /// <summary>
        /// Saves two images. A normal image for the web site and then a thumbnail.
        /// </summary>
        /// <param name="image">Original image to process.</param>
        public static void MakeAlbumImages(Image image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            // Indexed GIFs can cause issues.
            using (System.Drawing.Image originalImage = GraphicsHelper.FromFilePathAsUnindexedImage(image.OriginalFilePath))
            {
                var originalSize = new Size(originalImage.Width, originalImage.Height);

                /// TODO: make new sizes configurations.
                // New Display Size
                Size displaySize = originalSize.ScaleToFit(Config.Settings.GalleryImageMaxWidth, Config.Settings.GalleryImageMaxHeight);
                image.Height = displaySize.Height;
                image.Width  = displaySize.Width;
                using (System.Drawing.Image displayImage = originalImage.GetResizedImage(displaySize))
                {
                    displayImage.Save(image.ResizedFilePath, ImageFormat.Jpeg);
                }

                // smaller thumbnail
                Size thumbSize = originalSize.ScaleToFit(Config.Settings.GalleryImageThumbnailWidth, Config.Settings.GalleryImageThumbnailHeight);
                using (System.Drawing.Image thumbnailImage = originalImage.GetResizedImage(thumbSize))
                {
                    thumbnailImage.Save(image.ThumbNailFilePath, ImageFormat.Jpeg);
                }
            }
        }
コード例 #8
0
ファイル: ImageTests.cs プロジェクト: rhoadsce/Subtext
        public void CanGetAndSetSimpleProperties()
        {
            var image = new Image();

            image.BlogId = 123;
            Assert.AreEqual(123, image.BlogId);

            image.CategoryID = 321;
            Assert.AreEqual(321, image.CategoryID);

            image.FileName = "Test.jpg";
            Assert.AreEqual("Test.jpg", image.FileName);

            image.Height = 300;
            Assert.AreEqual(300, image.Height);

            image.ImageID = 999;
            Assert.AreEqual(999, image.ImageID);

            image.IsActive = true;
            Assert.IsTrue(image.IsActive);

            image.LocalDirectoryPath = @"d:\";
            Assert.AreEqual(@"d:\", image.LocalDirectoryPath);

            image.Title = "Testing";
            Assert.AreEqual("Testing", image.Title);

            image.Width = 312;
            Assert.AreEqual(312, image.Width);
        }
コード例 #9
0
 /// <summary>
 /// Updates the image.
 /// </summary>
 /// <param name="image">The image.</param>
 public static void UpdateImage(Image image)
 {
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     ObjectProvider.Instance().UpdateImage(image);
 }
コード例 #10
0
 /// <summary>
 /// Updates the image.
 /// </summary>
 /// <param name="image">The image.</param>
 public static void Update(this ObjectRepository repository, Image image)
 {
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     repository.UpdateImage(image);
 }
コード例 #11
0
ファイル: Images.cs プロジェクト: ChrisPelatari/SubText
        public static void DeleteImage(Image image)
        {
            if(image == null)
            {
                throw new ArgumentNullException("image");
            }

            ObjectProvider.Instance().DeleteImage(image.ImageID);
        }
コード例 #12
0
        /// <summary>
        /// A fancy term for saving the image to disk :-). We'll take the image and try to save
        /// it. This currently puts all images in the same directory which can cause a conflict
        /// if the file already exists. So we'll add in a way to take a new file name.
        /// </summary>
        private void PersistImage(string fileName)
        {
            if (Page.IsValid)
            {
                var image = new Image
                {
                    Blog               = Blog,
                    CategoryID         = CategoryId,
                    Title              = txbImageTitle.Text,
                    IsActive           = ckbIsActiveImage.Checked,
                    FileName           = Path.GetFileName(fileName),
                    Url                = Url.ImageGalleryDirectoryUrl(Blog, CategoryId),
                    LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, CategoryId)
                };

                try
                {
                    if (File.Exists(image.OriginalFilePath))
                    {
                        // tell the user we can't accept this file.
                        Messages.ShowError(Resources.EditGalleries_FileAlreadyExists);

                        // switch around our GUI.
                        PanelSuggestNewName.Visible = true;
                        PanelDefaultName.Visible    = false;

                        AddImages.Collapsed = false;
                        // Unfortunately you can't set ImageFile.PostedFile.FileName. At least suggest
                        // a name for the new file.
                        TextBoxImageFileName.Text = image.FileName;
                        return;
                    }

                    int imageId = Images.InsertImage(image, ImageFile.PostedFile.GetFileStream());
                    if (imageId > 0)
                    {
                        Messages.ShowMessage(Resources.EditGalleries_ImageAdded);
                        txbImageTitle.Text = String.Empty;
                    }
                    else
                    {
                        Messages.ShowError(Constants.RES_FAILUREEDIT + " " + Resources.EditGalleries_ProblemPosting);
                    }
                }
                catch (Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }

            // if we're successful we need to revert back to our standard view
            PanelSuggestNewName.Visible = false;
            PanelDefaultName.Visible    = true;

            // re-bind the gallery; note we'll skip this step if a correctable error occurs.
            BindGallery();
        }
コード例 #13
0
        private void DeleteImage(int imageId)
        {
            Image image   = Repository.GetImage(imageId, false /* activeOnly */);
            var   command = new DeleteImageCommand(image, Url.ImageGalleryDirectoryUrl(Blog, image.CategoryID))
            {
                ExecuteSuccessMessage = string.Format(CultureInfo.CurrentCulture, "Image '{0}' deleted",
                                                      image.OriginalFile)
            };

            Messages.ShowMessage(command.Execute());
            BindGallery();
        }
コード例 #14
0
ファイル: Images.cs プロジェクト: ChrisPelatari/SubText
        /// <summary>
        /// Inserts the image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="buffer">The buffer.</param>
        /// <returns></returns>
        public static int InsertImage(Image image, byte[] buffer)
        {
            if(image == null)
            {
                throw new ArgumentNullException("image");
            }

            if(!File.Exists(image.OriginalFilePath) && SaveImage(buffer, image.OriginalFilePath))
            {
                MakeAlbumImages(image);
                return ObjectProvider.Instance().InsertImage(image);
            }
            return NullValue.NullInt32;
        }
コード例 #15
0
        /// <summary>
        /// Inserts the image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="buffer">The buffer.</param>
        /// <returns></returns>
        public static int Insert(this ObjectRepository repository, Image image, byte[] buffer)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (!File.Exists(image.OriginalFilePath) && SaveImage(buffer, image.OriginalFilePath))
            {
                MakeAlbumImages(image);
                return(repository.InsertImage(image));
            }
            return(NullValue.NullInt32);
        }
コード例 #16
0
        /// <summary>
        /// Inserts the image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="buffer">The buffer.</param>
        /// <returns></returns>
        public static int InsertImage(Image image, byte[] buffer)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (!File.Exists(image.OriginalFilePath) && SaveImage(buffer, image.OriginalFilePath))
            {
                MakeAlbumImages(image);
                return(ObjectProvider.Instance().InsertImage(image));
            }
            return(NullValue.NullInt32);
        }
コード例 #17
0
        // added
        public static void Update(this ObjectRepository repository, Image image, byte[] buffer)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (SaveImage(buffer, image.OriginalFilePath))
            {
                MakeAlbumImages(image);
                repository.Update(image);
            }
        }
コード例 #18
0
ファイル: ImageTests.cs プロジェクト: ayende/Subtext
        public void CanMakeAlbumImages()
        {
            Image image = new Image();
            image.Title = "Test Image";
            image.Height = 1;
            image.Width = 1;
            image.IsActive = true;
            image.LocalDirectoryPath = Path.GetFullPath(TestDirectory);
            image.FileName = "test.gif";

            //Write original image.
            Images.SaveImage(singlePixelBytes, image.OriginalFilePath);
            FileAssert.Exists(image.OriginalFilePath);

            Images.MakeAlbumImages(image);
            FileAssert.Exists(image.ResizedFilePath);
            FileAssert.Exists(image.ThumbNailFilePath);
        }
コード例 #19
0
ファイル: Images.cs プロジェクト: ayende/Subtext
        /// <summary>
        /// Saves two images. A normal image for the web site and then a thumbnail.
        /// </summary>
        /// <param name="image">Original image to process.</param>
        public static void MakeAlbumImages(Image image)
        {
            if (image == null)
                throw new ArgumentNullException("image", Resources.ArgumentNull_Generic);

            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(image.OriginalFilePath);

            // Need to load the original image to manipulate. But indexed GIFs can cause issues.
            if ((originalImage.PixelFormat & PixelFormat.Indexed) != 0)
            {
                // Draw the index image to a new bitmap.  It will then be unindexed.
                System.Drawing.Image unindexedImage = new Bitmap(originalImage.Width, originalImage.Height);
                Graphics g = Graphics.FromImage(unindexedImage);
                g.DrawImageUnscaled(originalImage, 0, 0);

                originalImage.Dispose();
                originalImage = unindexedImage;
            }

            // Dispose the original graphic (be kind; clean up)
            using (originalImage)
            {
                /// TODO: make both sizes configurations.
                // Calculate the new sizes we want (properly scaled)
                Size displaySize = ResizeImage(originalImage.Width, originalImage.Height, 640, 480);
                Size thumbSize = ResizeImage(originalImage.Width, originalImage.Height, 120, 120);

                // Tell the object what its new display size will be
                image.Height = displaySize.Height;
                image.Width = displaySize.Width;

                // Create a mid-size display image by drawing the original image into a smaller area.
                using (System.Drawing.Image displayImage = new Bitmap(displaySize.Width, displaySize.Height, originalImage.PixelFormat))
                {
                    using (Graphics displayGraphic = Graphics.FromImage(displayImage))
                    {
                        displayGraphic.CompositingQuality = CompositingQuality.HighQuality;
                        displayGraphic.SmoothingMode = SmoothingMode.HighQuality;
                        displayGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        Rectangle displayRectangle = new Rectangle(0, 0, displaySize.Width, displaySize.Height);
                        displayGraphic.DrawImage(originalImage, displayRectangle);
                        // Save our file
                        displayImage.Save(image.ResizedFilePath, ImageFormat.Jpeg);
                    }
                }

                // Create a small thumbnail
                using (System.Drawing.Image thumbImage = new Bitmap(thumbSize.Width, thumbSize.Height, originalImage.PixelFormat))
                {
                    using (Graphics thumbGraphic = Graphics.FromImage(thumbImage))
                    {
                        thumbGraphic.CompositingQuality = CompositingQuality.HighQuality;
                        thumbGraphic.SmoothingMode = SmoothingMode.HighQuality;
                        thumbGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        Rectangle thumbRectangle = new Rectangle(0, 0, thumbSize.Width, thumbSize.Height);
                        thumbGraphic.DrawImage(originalImage, thumbRectangle);
                        // Save our file
                        thumbImage.Save(image.ThumbNailFilePath, ImageFormat.Jpeg);
                    }
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// A fancy term for saving the image to disk :-). We'll take the image and try to save
        /// it. This currently puts all images in the same directory which can cause a conflict
        /// if the file already exists. So we'll add in a way to take a new file name. 
        /// </summary>
        private void PersistImage(string fileName)
        {
            if(Page.IsValid)
            {
                var image = new Image
                {
                    Blog = Blog,
                    CategoryID = CategoryId,
                    Title = txbImageTitle.Text,
                    IsActive = ckbIsActiveImage.Checked,
                    FileName = Path.GetFileName(fileName),
                    Url = Url.ImageGalleryDirectoryUrl(Blog, CategoryId),
                    LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, CategoryId)
                };

                try
                {
                    if(File.Exists(image.OriginalFilePath))
                    {
                        // tell the user we can't accept this file.
                        Messages.ShowError(Resources.EditGalleries_FileAlreadyExists);

                        // switch around our GUI.
                        PanelSuggestNewName.Visible = true;
                        PanelDefaultName.Visible = false;

                        AddImages.Collapsed = false;
                        // Unfortunately you can't set ImageFile.PostedFile.FileName. At least suggest
                        // a name for the new file.
                        TextBoxImageFileName.Text = image.FileName;
                        return;
                    }

                    int imageId = Images.InsertImage(image, ImageFile.PostedFile.GetFileStream());
                    if(imageId > 0)
                    {
                        Messages.ShowMessage(Resources.EditGalleries_ImageAdded);
                        txbImageTitle.Text = String.Empty;
                    }
                    else
                    {
                        Messages.ShowError(Constants.RES_FAILUREEDIT + " " + Resources.EditGalleries_ProblemPosting);
                    }
                }
                catch(Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }

            // if we're successful we need to revert back to our standard view
            PanelSuggestNewName.Visible = false;
            PanelDefaultName.Visible = true;

            // re-bind the gallery; note we'll skip this step if a correctable error occurs.
            BindGallery();
        }
コード例 #21
0
        private void PersistImageArchive()
        {
            List<string> goodFiles = new List<string>(),
                         badFiles = new List<string>(),
                         updatedFiles = new List<string>();

            byte[] archiveData = ImageFile.PostedFile.GetFileStream();

            using(var memoryStream = new MemoryStream(archiveData))
            {
                using(var zip = new ZipInputStream(memoryStream))
                {
                    ZipEntry theEntry;
                    while((theEntry = zip.GetNextEntry()) != null)
                    {
                        string fileName = Path.GetFileName(theEntry.Name);

                        // TODO: Filter for image types?
                        if(!String.IsNullOrEmpty(fileName))
                        {
                            byte[] fileData;

                            var image = new Image
                            {
                                Blog = Blog,
                                CategoryID = CategoryId,
                                Title = fileName,
                                IsActive = ckbIsActiveImage.Checked,
                                FileName = Path.GetFileName(fileName),
                                Url = Url.ImageGalleryDirectoryUrl(Blog, CategoryId),
                                LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, CategoryId)
                            };

                            // Read the next file from the Zip stream
                            using(var currentFileData = new MemoryStream((int)theEntry.Size))
                            {
                                int size = 2048;
                                var data = new byte[size];
                                while(true)
                                {
                                    size = zip.Read(data, 0, data.Length);
                                    if(size > 0)
                                    {
                                        currentFileData.Write(data, 0, size);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                fileData = currentFileData.ToArray();
                            }

                            try
                            {
                                // If it exists, update it
                                if(File.Exists(image.OriginalFilePath))
                                {
                                    Images.Update(image, fileData);
                                    updatedFiles.Add(theEntry.Name);
                                }
                                else
                                {
                                    // Attempt insertion as a new image
                                    int imageId = Images.InsertImage(image, fileData);
                                    if(imageId > 0)
                                    {
                                        goodFiles.Add(theEntry.Name);
                                    }
                                    else
                                    {
                                        // Wrong format, perhaps?
                                        badFiles.Add(theEntry.Name);
                                    }
                                }
                            }
                            catch(Exception ex)
                            {
                                badFiles.Add(theEntry.Name + " (" + ex.Message + ")");
                            }
                        }
                    }
                }
            }

            // Construct and display the status message of added/updated/deleted images
            string status = string.Format(CultureInfo.InvariantCulture,
                                          Resources.EditGalleries_ArchiveProcessed +
                                          @"<br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportAddDetails'))"">" +
                                          Resources.Label_Adds +
                                          @" ({0})</a></b><span id=""ImportAddDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{1}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportUpdateDetails'))"">" +
                                          Resources.Label_Updates +
                                          @"  ({2})</a></b><span id=""ImportUpdateDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{3}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportErrorDetails'))"">" +
                                          Resources.Label_Errors +
                                          @" ({4})</a></b><span id=""ImportErrorDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{5}</span>",
                                          goodFiles.Count,
                                          (goodFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", goodFiles.ToArray())
                                               : "none"),
                                          updatedFiles.Count,
                                          (updatedFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", updatedFiles.ToArray())
                                               : "none"),
                                          badFiles.Count,
                                          (badFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", badFiles.ToArray())
                                               : "none"));

            Messages.ShowMessage(status);
            txbImageTitle.Text = String.Empty;

            // if we're successful we need to revert back to our standard view
            PanelSuggestNewName.Visible = false;
            PanelDefaultName.Visible = true;

            // re-bind the gallery; note we'll skip this step if a correctable error occurs.
            BindGallery();
        }
コード例 #22
0
 protected void SetGalleryInfo(Image image)
 {
     GalleryTitle = SubtextContext.Repository.GetLinkCategory(image.CategoryID, false).Title;
 }
コード例 #23
0
ファイル: ImageTests.cs プロジェクト: rhoadsce/Subtext
 public void GetOriginalFileNamePrependsLetterOWithUnderscore()
 {
     var image = new Image();
     image.LocalDirectoryPath = @"c:\";
     image.FileName = @"Test.jpg";
     Assert.AreEqual(@"o_Test.jpg", image.OriginalFile);
     Assert.AreEqual(@"c:\o_Test.jpg", image.OriginalFilePath);
 }
コード例 #24
0
ファイル: Images.cs プロジェクト: ChrisPelatari/SubText
        // added
        public static void Update(Image image, byte[] buffer)
        {
            if(image == null)
            {
                throw new ArgumentNullException("image");
            }

            if(buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if(SaveImage(buffer, image.OriginalFilePath))
            {
                MakeAlbumImages(image);
                UpdateImage(image);
            }
        }
コード例 #25
0
        private void PersistImageArchive()
        {
            List<string> goodFiles = new List<string>(),
                         badFiles = new List<string>(),
                         updatedFiles = new List<string>();

            byte[] archiveData = ImageFile.PostedFile.GetFileStream();

            using (var zipArchive = ZipFile.Read(new MemoryStream(archiveData)))
            {
                foreach (var entry in zipArchive.Entries)
                {
                    var image = new Image
                    {
                        Blog = Blog,
                        CategoryID = CategoryId,
                        Title = entry.FileName,
                        IsActive = ckbIsActiveImage.Checked,
                        FileName = Path.GetFileName(entry.FileName),
                        Url = Url.ImageGalleryDirectoryUrl(Blog, CategoryId),
                        LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, CategoryId)
                    };

                    var memoryStream = new MemoryStream();

                    entry.Extract(memoryStream);
                    var fileData = memoryStream.ToArray();
                    try
                    {
                        // If it exists, update it
                        if (File.Exists(image.OriginalFilePath))
                        {
                            Repository.Update(image, fileData);
                            updatedFiles.Add(entry.FileName);
                        }
                        else
                        {
                            // Attempt insertion as a new image
                            int imageId = Repository.Insert(image, fileData);
                            if (imageId > 0)
                            {
                                goodFiles.Add(entry.FileName);
                            }
                            else
                            {
                                // Wrong format, perhaps?
                                badFiles.Add(entry.FileName);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        badFiles.Add(entry.FileName + " (" + ex.Message + ")");
                    }
                }
            }

            // Construct and display the status message of added/updated/deleted images
            string status = string.Format(CultureInfo.InvariantCulture,
                                          Resources.EditGalleries_ArchiveProcessed +
                                          @"<br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportAddDetails'))"">" +
                                          Resources.Label_Adds +
                                          @" ({0})</a></b><span id=""ImportAddDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{1}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportUpdateDetails'))"">" +
                                          Resources.Label_Updates +
                                          @"  ({2})</a></b><span id=""ImportUpdateDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{3}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportErrorDetails'))"">" +
                                          Resources.Label_Errors +
                                          @" ({4})</a></b><span id=""ImportErrorDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{5}</span>",
                                          goodFiles.Count,
                                          (goodFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", goodFiles.ToArray())
                                               : "none"),
                                          updatedFiles.Count,
                                          (updatedFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", updatedFiles.ToArray())
                                               : "none"),
                                          badFiles.Count,
                                          (badFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", badFiles.ToArray())
                                               : "none"));

            Messages.ShowMessage(status);
            txbImageTitle.Text = String.Empty;

            // if we're successful we need to revert back to our standard view
            PanelSuggestNewName.Visible = false;
            PanelDefaultName.Visible = true;

            // re-bind the gallery; note we'll skip this step if a correctable error occurs.
            BindGallery();
        }
コード例 #26
0
ファイル: EditImage.aspx.cs プロジェクト: rsaladrigas/Subtext
        private void ReplaceImage()
        {
            if (Page.IsValid)
            {
                _image = Repository.GetImage(ImageId, false /* activeOnly */);
                _image.CategoryID = Convert.ToInt32(ddlGalleries.SelectedItem.Value);
                _image.Title = txbTitle.Text;
                _image.IsActive = ckbPublished.Checked;

                try
                {
                    _image.FileName = Path.GetFileName(ImageFile.PostedFile.FileName);
                    _image.Url = Url.ImageGalleryDirectoryUrl(Blog, _image.CategoryID);
                    _image.LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, _image.CategoryID);
                    Repository.Update(_image, ImageFile.PostedFile.GetFileStream());

                    Messages.ShowMessage(Resources.EditGalleries_ImageUpdated);
                    BindImage();
                }
                catch (Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }
        }
コード例 #27
0
ファイル: ImageTests.cs プロジェクト: ayende/Subtext
 private static Image CreateStandaloneImageInstance()
 {
     Image image = new Image();
     image.Title = "Test Image";
     image.Height = 1;
     image.Width = 1;
     image.IsActive = true;
     image.LocalDirectoryPath = Path.GetFullPath(TestDirectory);
     image.FileName = "test.gif";
     return image;
 }
コード例 #28
0
        private void PersistImageArchive()
        {
            List <string> goodFiles    = new List <string>(),
                          badFiles     = new List <string>(),
                          updatedFiles = new List <string>();

            byte[] archiveData = ImageFile.PostedFile.GetFileStream();

            using (var memoryStream = new MemoryStream(archiveData))
            {
                using (var zip = new ZipInputStream(memoryStream))
                {
                    ZipEntry theEntry;
                    while ((theEntry = zip.GetNextEntry()) != null)
                    {
                        string fileName = Path.GetFileName(theEntry.Name);

                        // TODO: Filter for image types?
                        if (!String.IsNullOrEmpty(fileName))
                        {
                            byte[] fileData;

                            var image = new Image
                            {
                                Blog               = Blog,
                                CategoryID         = CategoryId,
                                Title              = fileName,
                                IsActive           = ckbIsActiveImage.Checked,
                                FileName           = Path.GetFileName(fileName),
                                Url                = Url.ImageGalleryDirectoryUrl(Blog, CategoryId),
                                LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, CategoryId)
                            };

                            // Read the next file from the Zip stream
                            using (var currentFileData = new MemoryStream((int)theEntry.Size))
                            {
                                int size = 2048;
                                var data = new byte[size];
                                while (true)
                                {
                                    size = zip.Read(data, 0, data.Length);
                                    if (size > 0)
                                    {
                                        currentFileData.Write(data, 0, size);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                fileData = currentFileData.ToArray();
                            }

                            try
                            {
                                // If it exists, update it
                                if (File.Exists(image.OriginalFilePath))
                                {
                                    Images.Update(image, fileData);
                                    updatedFiles.Add(theEntry.Name);
                                }
                                else
                                {
                                    // Attempt insertion as a new image
                                    int imageId = Images.InsertImage(image, fileData);
                                    if (imageId > 0)
                                    {
                                        goodFiles.Add(theEntry.Name);
                                    }
                                    else
                                    {
                                        // Wrong format, perhaps?
                                        badFiles.Add(theEntry.Name);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                badFiles.Add(theEntry.Name + " (" + ex.Message + ")");
                            }
                        }
                    }
                }
            }

            // Construct and display the status message of added/updated/deleted images
            string status = string.Format(CultureInfo.InvariantCulture,
                                          Resources.EditGalleries_ArchiveProcessed +
                                          @"<br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportAddDetails'))"">" +
                                          Resources.Label_Adds +
                                          @" ({0})</a></b><span id=""ImportAddDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{1}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportUpdateDetails'))"">" +
                                          Resources.Label_Updates +
                                          @"  ({2})</a></b><span id=""ImportUpdateDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{3}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportErrorDetails'))"">" +
                                          Resources.Label_Errors +
                                          @" ({4})</a></b><span id=""ImportErrorDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{5}</span>",
                                          goodFiles.Count,
                                          (goodFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", goodFiles.ToArray())
                                               : "none"),
                                          updatedFiles.Count,
                                          (updatedFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", updatedFiles.ToArray())
                                               : "none"),
                                          badFiles.Count,
                                          (badFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", badFiles.ToArray())
                                               : "none"));

            Messages.ShowMessage(status);
            txbImageTitle.Text = String.Empty;

            // if we're successful we need to revert back to our standard view
            PanelSuggestNewName.Visible = false;
            PanelDefaultName.Visible    = true;

            // re-bind the gallery; note we'll skip this step if a correctable error occurs.
            BindGallery();
        }
コード例 #29
0
ファイル: EditImage.aspx.cs プロジェクト: rsaladrigas/Subtext
 protected void SetGalleryInfo(Image image)
 {
     GalleryTitle = SubtextContext.Repository.GetLinkCategory(image.CategoryID, false).Title;
 }
コード例 #30
0
ファイル: ImageTests.cs プロジェクト: rhoadsce/Subtext
 public void GetResizedFileNamePrependsLetterTWithUnderscore()
 {
     var image = new Image();
     image.FileName = @"Test.jpg";
     image.LocalDirectoryPath = @"c:\";
     Assert.AreEqual(@"r_Test.jpg", image.ResizedFile);
     Assert.AreEqual(@"c:\r_Test.jpg", image.ResizedFilePath);
 }
コード例 #31
0
ファイル: EditImage.aspx.cs プロジェクト: rsaladrigas/Subtext
        private void UpdateImage()
        {
            if (Page.IsValid)
            {
                _image = Repository.GetImage(ImageId, false /* activeOnly */);
                _image.CategoryID = Convert.ToInt32(ddlGalleries.SelectedItem.Value);
                _image.Title = txbTitle.Text;
                _image.IsActive = ckbPublished.Checked;

                try
                {
                    Repository.Update(_image);

                    // would need to also move files for this to work here. should happen
                    // in the provider though.

                    Messages.ShowMessage(Resources.EditGalleries_ImageUpdated);
                    BindImage();
                }
                catch (Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
                }
            }
        }
コード例 #32
0
        private void PersistImageArchive()
        {
            List <string> goodFiles    = new List <string>(),
                          badFiles     = new List <string>(),
                          updatedFiles = new List <string>();

            byte[] archiveData = ImageFile.PostedFile.GetFileStream();

            using (var zipArchive = ZipFile.Read(new MemoryStream(archiveData)))
            {
                foreach (var entry in zipArchive.Entries)
                {
                    var image = new Image
                    {
                        Blog               = Blog,
                        CategoryID         = CategoryId,
                        Title              = entry.FileName,
                        IsActive           = ckbIsActiveImage.Checked,
                        FileName           = Path.GetFileName(entry.FileName),
                        Url                = Url.ImageGalleryDirectoryUrl(Blog, CategoryId),
                        LocalDirectoryPath = Url.GalleryDirectoryPath(Blog, CategoryId)
                    };

                    var memoryStream = new MemoryStream();

                    entry.Extract(memoryStream);
                    var fileData = memoryStream.ToArray();
                    try
                    {
                        // If it exists, update it
                        if (File.Exists(image.OriginalFilePath))
                        {
                            Repository.Update(image, fileData);
                            updatedFiles.Add(entry.FileName);
                        }
                        else
                        {
                            // Attempt insertion as a new image
                            int imageId = Repository.Insert(image, fileData);
                            if (imageId > 0)
                            {
                                goodFiles.Add(entry.FileName);
                            }
                            else
                            {
                                // Wrong format, perhaps?
                                badFiles.Add(entry.FileName);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        badFiles.Add(entry.FileName + " (" + ex.Message + ")");
                    }
                }
            }

            // Construct and display the status message of added/updated/deleted images
            string status = string.Format(CultureInfo.InvariantCulture,
                                          Resources.EditGalleries_ArchiveProcessed +
                                          @"<br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportAddDetails'))"">" +
                                          Resources.Label_Adds +
                                          @" ({0})</a></b><span id=""ImportAddDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{1}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportUpdateDetails'))"">" +
                                          Resources.Label_Updates +
                                          @"  ({2})</a></b><span id=""ImportUpdateDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{3}</span><br />
                <b><a onclick=""javascript:ToggleVisibility(document.getElementById('ImportErrorDetails'))"">" +
                                          Resources.Label_Errors +
                                          @" ({4})</a></b><span id=""ImportErrorDetails"" style=""display:none""> : <br />&nbsp;&nbsp;{5}</span>",
                                          goodFiles.Count,
                                          (goodFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", goodFiles.ToArray())
                                               : "none"),
                                          updatedFiles.Count,
                                          (updatedFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", updatedFiles.ToArray())
                                               : "none"),
                                          badFiles.Count,
                                          (badFiles.Count > 0
                                               ? string.Join("<br />&nbsp;&nbsp;", badFiles.ToArray())
                                               : "none"));

            Messages.ShowMessage(status);
            txbImageTitle.Text = String.Empty;

            // if we're successful we need to revert back to our standard view
            PanelSuggestNewName.Visible = false;
            PanelDefaultName.Visible    = true;

            // re-bind the gallery; note we'll skip this step if a correctable error occurs.
            BindGallery();
        }