Loading...

All project content is available for reading, but you need to be a member of the project for Subversion checkout of source code, or to create/modify any information.
Login if you are a member. Apply here to request membership (open to all).

EPiImage: SaveImagesOtherPlacesThanPageFiles.patch

File SaveImagesOtherPlacesThanPageFiles.patch, 37.8 KB (added by alexander@…, 7 years ago)
  • 6.x/EPiImage/Code/EPiImageEngine.cs

     
    377377 
    378378      UnifiedDirectory pageDirectory = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPathFromFolderId) as UnifiedDirectory; 
    379379 
     380 
     381 
    380382      return pageDirectory; 
    381383    } 
    382384 
     
    396398        xmldoc.Load(xmlFile); 
    397399 
    398400        string xmlVPPPath = GetAttribute(xmldoc, "/settings/scaledimagechache", "vpppath"); 
     401        string xmlVPPScaledPath = GetAttribute(xmldoc, "/settings/scaledimages", "vpppath"); 
    399402        string xmlDeleteFilesOlderThan = GetAttribute(xmldoc, "/settings/cleanupjob", "deletefilesolderthan"); 
    400403        string xmlPreviewWidth = GetAttribute(xmldoc, "/settings/epiimageproperty", "previewwidth"); 
    401404        string xmlPreviewHeight = GetAttribute(xmldoc, "/settings/epiimageproperty", "previewheight"); 
     
    407410        if (!String.IsNullOrEmpty(xmlVPPPath)) 
    408411          settings.ScaledImageCachePath = xmlVPPPath.ToLower(); 
    409412 
     413        if (!String.IsNullOrEmpty(xmlVPPScaledPath)) 
     414            settings.ScaledImagePath = xmlVPPScaledPath.ToLower(); 
     415 
    410416        //DeleteFilesOlderThan 
    411417        if (xmlDeleteFilesOlderThan != null) 
    412418          settings.DeleteFilesOlderThan = Int32.Parse(xmlDeleteFilesOlderThan); 
     
    455461  public class EPiImageSettings 
    456462  { 
    457463    public string ScaledImageCachePath = ""; 
     464    public string ScaledImagePath = ""; 
    458465    public int DeleteFilesOlderThan = 30; 
    459466    public int PropertyPreviewWidth = 100; 
    460467    public int PropertyPreviewHeight = 100; 
  • 6.x/EPiImage/Code/EPiImageGalleryPropertyEngine.cs

     
    11using System; 
    2 using System.Data; 
    3 using System.Configuration; 
    42using System.Linq; 
    53using System.Web; 
    6 using System.Web.Security; 
    7 using System.Web.UI; 
    8 using System.Web.UI.HtmlControls; 
    9 using System.Web.UI.WebControls; 
    10 using System.Web.UI.WebControls.WebParts; 
    11 using System.Xml.Linq; 
     4using EPiServer; 
    125using EPiServer.Web.Hosting; 
    136using EPiServer.Core; 
    147using System.Web.Hosting; 
     
    2114 
    2215namespace MakingWaves.EPiImage 
    2316{ 
    24   public static class EPiImageGalleryPropertyEngine 
    25   { 
    26     private static int SlideMaxWidth = 1200; 
    27     private static int SlideMaxHeight = 1000; 
    28     private static int SlideEditorPreviewMaxWidth = 400; 
    29     private static int SlideEditorPreviewMaxHeight = 300; 
    30     private static int SlideEditorThumbMaxWidth = 100; 
    31     private static int SlideEditorThumbMaxHeight = 100; 
     17    public static class EPiImageGalleryPropertyEngine 
     18    { 
     19        private const int SlideMaxWidth = 1200; 
     20        private const int SlideMaxHeight = 1000; 
     21        private const int SlideEditorPreviewMaxWidth = 400; 
     22        private const int SlideEditorPreviewMaxHeight = 300; 
     23        private const int SlideEditorThumbMaxWidth = 100; 
     24        private const int SlideEditorThumbMaxHeight = 100; 
    3225 
    33     private static string ImageGalleryFolder = "ImageGallery"; 
     26        public const string ImageGalleryFolder = "ImageGallery"; 
     27         
     28        #region Public Methods ---------------------------------------------------------------------- 
    3429 
     30        /// <summary> 
     31        /// Creates a slide 
     32        /// </summary> 
     33        /// <param name="pageFolderID">pageFolderID</param> 
     34        /// <param name="OriginalImagePath">Path to the original image</param> 
     35        /// <param name="page">CurrentPage</param> 
     36        /// <returns></returns> 
     37        public static string CreateImage(int pageFolderID, string OriginalImagePath) 
     38        { 
     39            //Get page folder, create it if it doesn't exist  
     40            UnifiedDirectory folder = EPiImageEngine.GetPageFolder(pageFolderID); 
    3541 
    36     #region Public Methods ---------------------------------------------------------------------- 
     42            //Get the ImageGallery folder 
     43            UnifiedDirectory imageGalleryFolder = GetImageGalleryFolder(pageFolderID, folder); 
    3744 
    38     /// <summary> 
    39     /// Creates a slide 
    40     /// </summary> 
    41     /// <param name="PageFolderID">PageFolderID</param> 
    42     /// <param name="OriginalImagePath">Path to the original image</param> 
    43     /// <returns></returns> 
    44     public static string CreateImage(int PageFolderID, string OriginalImagePath) 
    45     { 
    46       //Get page folder, create it if it doesn't exist  
    47       EPiServer.Web.Hosting.UnifiedDirectory folder = EPiImageEngine.GetPageFolder(PageFolderID); 
     45            //Get the ImageGallery/Thumbs folder 
     46            UnifiedDirectory imageGalleryThumbsFolder = GetImageGalleryThumbsFolder(imageGalleryFolder); 
    4847 
    49       //Get the ImageGallery folder 
    50       EPiServer.Web.Hosting.UnifiedDirectory imageGalleryFolder = GetImageGalleryFolder(folder); 
     48            UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(HttpUtility.UrlDecode(OriginalImagePath)) as UnifiedFile; 
     49            string fileName = string.Empty; 
     50            if (file != null) 
     51            { 
     52                string filePath = file.Name; 
     53                fileName = Path.GetFileNameWithoutExtension(filePath); 
     54            } 
    5155 
    52       //Get the ImageGallery/Thumbs folder 
    53       EPiServer.Web.Hosting.UnifiedDirectory imageGalleryThumbsFolder = GetImageGalleryThumbsFolder(imageGalleryFolder); 
     56            //Generate Slide ID 
     57            string SlideID = GenerateSlideID(fileName); 
    5458 
    55       UnifiedFile file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(HttpUtility.UrlDecode(OriginalImagePath)) as UnifiedFile; 
    56       string fileName = string.Empty; 
    57       if (file != null) 
    58       { 
    59           string filePath = file.Name; 
    60           fileName = Path.GetFileNameWithoutExtension(filePath); 
    61       } 
     59            //Create Slide 
     60            ConvertImage(SlideMaxWidth, SlideMaxHeight, OriginalImagePath, imageGalleryFolder, SlideID + ".jpg"); 
    6261 
    63       //Generate Slide ID 
    64       string SlideID = GenerateSlideID(fileName); 
     62            //Create Slide Editor Preview 
     63            ConvertImage(SlideEditorPreviewMaxWidth, SlideEditorPreviewMaxHeight, OriginalImagePath, imageGalleryThumbsFolder, SlideID + "_preview.jpg"); 
    6564 
    66       //Create Slide 
    67       ConvertImage(SlideMaxWidth, SlideMaxHeight, OriginalImagePath, imageGalleryFolder, SlideID + ".jpg"); 
     65            //Create Slide Editor Thumbnail 
     66            ConvertImage(SlideEditorThumbMaxWidth, SlideEditorThumbMaxHeight, OriginalImagePath, imageGalleryThumbsFolder, SlideID + ".jpg"); 
    6867 
    69       //Create Slide Editor Preview 
    70       ConvertImage(SlideEditorPreviewMaxWidth, SlideEditorPreviewMaxHeight, OriginalImagePath, imageGalleryThumbsFolder, SlideID + "_preview.jpg"); 
     68            return SlideID; 
     69        } 
    7170 
    72       //Create Slide Editor Thumbnail 
    73       ConvertImage(SlideEditorThumbMaxWidth, SlideEditorThumbMaxHeight, OriginalImagePath, imageGalleryThumbsFolder, SlideID + ".jpg"); 
     71        public static string GetImageGalleryFolder(int pageFolderId) 
     72        { 
     73            //Makes it possible to store images other places than in the pagefolder 
     74            string imagePath = EPiImageEngine.GetSettings().ScaledImagePath; 
     75            if (!string.IsNullOrEmpty(imagePath)) 
     76            { 
     77                return string.Format("{0}/{1}", ImageGalleryFolder, pageFolderId); 
     78            } 
     79            return ImageGalleryFolder; 
     80        } 
    7481 
    75       return SlideID; 
    76     } 
     82        public static void CleanUpUnusedImages(PageData Page, string SlideIDsInUse) 
     83        { 
     84            string[] SlideIDs = SlideIDsInUse.Split(','); 
    7785 
     86            //Get page folder, create it if it doesn't exist  
     87            UnifiedDirectory folder = Page.GetPageDirectory(true); 
    7888 
    79     public static void CleanUpUnusedImages(PageData Page, string SlideIDsInUse) 
    80     { 
    81       string[] SlideIDs = SlideIDsInUse.Split(','); 
     89            //Get the ImageGallery folder 
     90            int pageFolderId = GetPageFolderId(Page); 
     91            UnifiedDirectory imageGalleryFolder = GetImageGalleryFolder(pageFolderId, folder); 
    8292 
    83       //Get page folder, create it if it doesn't exist  
    84       EPiServer.Web.Hosting.UnifiedDirectory folder = Page.GetPageDirectory(true); 
     93            //Get the ImageGallery/Thumbs folder 
     94            UnifiedDirectory imageGalleryThumbsFolder = GetImageGalleryThumbsFolder(imageGalleryFolder); 
    8595 
    86       //Get the ImageGallery folder 
    87       EPiServer.Web.Hosting.UnifiedDirectory imageGalleryFolder = GetImageGalleryFolder(folder); 
     96            //Clean up unused slide images 
     97            foreach (UnifiedFile file in imageGalleryFolder.Files) 
     98            { 
     99                if (!SlideIDs.Contains(file.Name.Replace(file.Extension, ""))) 
     100                    file.Delete(); 
     101            } 
    88102 
    89       //Get the ImageGallery/Thumbs folder 
    90       EPiServer.Web.Hosting.UnifiedDirectory imageGalleryThumbsFolder = GetImageGalleryThumbsFolder(imageGalleryFolder); 
     103            //Clean up unused slide thumb and preview images 
     104            foreach (UnifiedFile file in imageGalleryThumbsFolder.Files) 
     105            { 
     106                if (!SlideIDs.Contains(file.Name.Replace(file.Extension, "").Replace("_preview", ""))) 
     107                    file.Delete(); 
     108            } 
     109        } 
    91110 
    92       //Clean up unused slide images 
    93       foreach (UnifiedFile file in imageGalleryFolder.Files) 
    94       { 
    95         if (!SlideIDs.Contains(file.Name.Replace(file.Extension, ""))) 
    96           file.Delete(); 
    97       } 
     111        /// <summary> 
     112        /// Returns the path to the slide image 
     113        /// </summary> 
     114        /// <param name="Page">CurrentPage</param> 
     115        /// <param name="ImageID">ImageID</param> 
     116        /// <returns></returns> 
     117        public static string GetImageUrl(PageData Page, string ImageID) 
     118        { 
     119            //Makes it possible to store images other places than in the pagefolder 
     120            string imagePath = EPiImageEngine.GetSettings().ScaledImagePath; 
     121            if (!string.IsNullOrEmpty(imagePath)) 
     122            { 
     123                int pageFolderId = GetPageFolderId(Page); 
     124                UnifiedDirectory globalFolder = HostingEnvironment.VirtualPathProvider.GetDirectory(imagePath) as UnifiedDirectory; 
     125                string filePath = string.Format("{0}{1}/{2}/{3}.jpg", globalFolder.VirtualPath, ImageGalleryFolder, pageFolderId, ImageID); 
     126                if(HostingEnvironment.VirtualPathProvider.FileExists(filePath)) 
     127                    return filePath;                 
     128            } 
    98129 
    99       //Clean up unused slide thumb and preview images 
    100       foreach (EPiServer.Web.Hosting.UnifiedFile file in imageGalleryThumbsFolder.Files) 
    101       { 
    102         if (!SlideIDs.Contains(file.Name.Replace(file.Extension, "").Replace("_preview", ""))) 
    103           file.Delete(); 
    104       } 
    105     } 
     130            UnifiedDirectory folder = Page.GetPageDirectory(true); 
     131            return string.Format("{0}{1}/{2}.jpg", folder.VirtualPath, ImageGalleryFolder, ImageID); 
     132        } 
    106133 
    107     /// <summary> 
    108     /// Returns the path to the slide image 
    109     /// </summary> 
    110     /// <param name="Page">CurrentPage</param> 
    111     /// <param name="ImageID">ImageID</param> 
    112     /// <returns></returns> 
    113     public static string GetImageUrl(PageData Page, string ImageID) 
    114     { 
    115       UnifiedDirectory folder = Page.GetPageDirectory(true); 
    116       return folder.VirtualPath + ImageGalleryFolder + "/" + ImageID + ".jpg"; 
    117     } 
    118134 
     135        /// <summary> 
     136        /// Returns the path to the thumb image 
     137        /// </summary> 
     138        /// <param name="Page">CurrentPage</param> 
     139        /// <param name="ImageID">ImageID</param> 
     140        /// <returns></returns> 
     141        public static string GetImageThumbUrl(PageData Page, string ImageID) 
     142        { 
     143            //Makes it possible to store images other places than in the pagefolder 
     144            string imagePath = EPiImageEngine.GetSettings().ScaledImagePath; 
     145            if (!string.IsNullOrEmpty(imagePath)) 
     146            { 
     147                int pageFolderId = GetPageFolderId(Page); 
     148                UnifiedDirectory globalFolder = HostingEnvironment.VirtualPathProvider.GetDirectory(imagePath) as UnifiedDirectory; 
     149                string thumbUrl = string.Format("{0}{1}/{2}/Thumbs/{3}.jpg", globalFolder.VirtualPath, ImageGalleryFolder, pageFolderId, ImageID); 
     150                if (HostingEnvironment.VirtualPathProvider.FileExists(thumbUrl)) 
     151                    return thumbUrl; 
     152            } 
     153            UnifiedDirectory folder = Page.GetPageDirectory(true); 
     154            return string.Format("{0}{1}/Thumbs/{2}.jpg", folder.VirtualPath, ImageGalleryFolder, ImageID); 
     155        } 
    119156 
    120     /// <summary> 
    121     /// Returns the path to the thumb image 
    122     /// </summary> 
    123     /// <param name="Page">CurrentPage</param> 
    124     /// <param name="ImageID">ImageID</param> 
    125     /// <returns></returns> 
    126     public static string GetImageThumbUrl(PageData Page, string ImageID) 
    127     { 
    128       EPiServer.Web.Hosting.UnifiedDirectory folder = Page.GetPageDirectory(true); 
    129       return folder.VirtualPath + ImageGalleryFolder + "/Thumbs/" + ImageID + ".jpg"; 
    130     } 
     157        public static int GetPageFolderId(PageData page) 
     158        { 
     159             if(page != null && page.Property["PageFolderID"] != null) 
     160             { 
     161                 return int.Parse(page.Property["PageFolderID"].ToString()); 
     162             } 
     163            return 0; 
     164        } 
    131165 
    132     /// <summary> 
    133     /// Returns the path to the thumb folder 
    134     /// </summary> 
    135     /// <param name="Page">CurrentPage</param> 
    136     /// <returns></returns> 
    137     public static string GetThumbFolderUrl(PageData Page) 
    138     { 
    139       EPiServer.Web.Hosting.UnifiedDirectory folder = Page.GetPageDirectory(true); 
    140       return folder.VirtualPath + ImageGalleryFolder + "/Thumbs/"; 
    141     } 
    142  
    143     /// <summary> 
    144     /// Returns EPiImageGallerySlideCollection 
    145     /// </summary> 
    146     /// <param name="Page">CurrentPage</param> 
    147     /// <param name="PropertyValue">Value of the EPiImageGallery property</param> 
    148     /// <returns></returns> 
    149     public static EPiImageGalleryImageCollection GetImages(PageData Page, string PropertyValue) 
    150     { 
    151       EPiImageGalleryImageCollection Collection = new EPiImageGalleryImageCollection(); 
    152  
    153       try 
    154       { 
    155         if (!String.IsNullOrEmpty(PropertyValue)) 
     166        /// <summary> 
     167        /// Returns the path to the thumb folder 
     168        /// </summary> 
     169        /// <param name="Page">CurrentPage</param> 
     170        /// <returns></returns> 
     171        public static string GetThumbFolderUrl(PageData Page) 
    156172        { 
    157           string[] SlideAltsArray = Regex.Split(PropertyValue, @"\|,"); 
    158           foreach (string Slide in SlideAltsArray) 
    159           { 
    160             string SlideID = Slide.Substring(0, Slide.IndexOf('|')); 
    161             string Description = Slide.Substring(Slide.IndexOf('|') + 1).Replace("|", String.Empty); 
    162             Collection.Add(new EPiImageGalleryImage(Page, SlideID, Description)); 
    163           } 
     173            UnifiedDirectory folder = Page.GetPageDirectory(true); 
     174            string pageFileThumbFolder = string.Format("{0}{1}/Thumbs/", folder.VirtualPath, ImageGalleryFolder); 
     175            if (HostingEnvironment.VirtualPathProvider.DirectoryExists(pageFileThumbFolder)) 
     176                return pageFileThumbFolder; 
     177             
     178            //Makes it possible to store images other places than in the pagefolder 
     179            string imagePath = EPiImageEngine.GetSettings().ScaledImagePath; 
     180            if (!string.IsNullOrEmpty(imagePath)) 
     181            { 
     182                int pageFolderId = GetPageFolderId(Page); 
     183                UnifiedDirectory globalFolder = HostingEnvironment.VirtualPathProvider.GetDirectory(imagePath) as UnifiedDirectory; 
     184                string thumbFolder = string.Format("{0}{1}/{2}/Thumbs/", globalFolder.VirtualPath, ImageGalleryFolder, pageFolderId); 
     185                //if (HostingEnvironment.VirtualPathProvider.DirectoryExists(thumbFolder)) 
     186                    return thumbFolder; 
     187            } 
     188             
     189            return pageFileThumbFolder; 
    164190        } 
    165       } 
    166       catch 
    167       {  
    168         //Empty property, do nothing 
    169       } 
    170191 
    171       return Collection; 
    172     } 
     192        /// <summary> 
     193        /// Returns EPiImageGallerySlideCollection 
     194        /// </summary> 
     195        /// <param name="Page">CurrentPage</param> 
     196        /// <param name="PropertyValue">Value of the EPiImageGallery property</param> 
     197        /// <returns></returns> 
     198        public static EPiImageGalleryImageCollection GetImages(PageData Page, string PropertyValue) 
     199        { 
     200            EPiImageGalleryImageCollection Collection = new EPiImageGalleryImageCollection(); 
    173201 
    174     #endregion Public Methods ------------------------------------------------------------------- 
     202            try 
     203            { 
     204                if (!String.IsNullOrEmpty(PropertyValue)) 
     205                { 
     206                    string[] SlideAltsArray = Regex.Split(PropertyValue, @"\|,"); 
     207                    foreach (string Slide in SlideAltsArray) 
     208                    { 
     209                        string SlideID = Slide.Substring(0, Slide.IndexOf('|')); 
     210                        string Description = Slide.Substring(Slide.IndexOf('|') + 1).Replace("|", String.Empty); 
     211                        Collection.Add(new EPiImageGalleryImage(Page, SlideID, Description)); 
     212                    } 
     213                } 
     214            } 
     215            catch 
     216            { 
     217                //Empty property, do nothing 
     218            } 
    175219 
     220            return Collection; 
     221        } 
    176222 
     223        #endregion Public Methods ------------------------------------------------------------------- 
    177224 
    178225 
    179226 
    180     #region Private Methods ---------------------------------------------------------------------- 
    181227 
    182     private static UnifiedDirectory GetImageGalleryFolder(UnifiedDirectory folder) 
    183     { 
    184       //Check if the folder exists 
    185       foreach (UnifiedDirectory dir in folder.Directories) 
    186       { 
    187         if (dir.Name == ImageGalleryFolder) 
    188           return dir; 
    189       } 
    190228 
    191       //It doesn't exists, so create it 
    192       folder.BypassAccessCheck = true; 
    193       return folder.CreateSubdirectory(ImageGalleryFolder); 
    194     } 
     229        #region Private Methods ---------------------------------------------------------------------- 
    195230 
    196     private static UnifiedDirectory GetImageGalleryThumbsFolder(UnifiedDirectory folder) 
    197     { 
    198       //Check if the folder exists 
    199       foreach (UnifiedDirectory dir in folder.Directories) 
    200       { 
    201         if (dir.Name == "Thumbs") 
    202           return dir; 
    203       } 
     231        private static UnifiedDirectory GetImageGalleryFolder(int pageFolderId, UnifiedDirectory folder) 
     232        { 
     233            //Check if pagefile method for storing is used already and folder exists 
     234            foreach (UnifiedDirectory dir in folder.Directories) 
     235            { 
     236                if (dir.Name == ImageGalleryFolder) 
     237                    return dir; 
     238            } 
    204239 
    205       //It doesn't exists, so create it 
    206       folder.BypassAccessCheck = true; 
    207       return folder.CreateSubdirectory("Thumbs"); 
    208     } 
     240            //Makes it possible to store images other places than in the pagefolder 
     241            string imagePath = EPiImageEngine.GetSettings().ScaledImagePath; 
     242            if (!string.IsNullOrEmpty(imagePath)) 
     243            { 
     244                folder = HostingEnvironment.VirtualPathProvider.GetDirectory(imagePath) as UnifiedDirectory; 
     245                //Check if the folder exists 
     246                foreach (UnifiedDirectory dir in folder.Directories) 
     247                { 
     248                    if (dir.Name == GetImageGalleryFolder(pageFolderId)) 
     249                        return dir; 
     250                } 
     251            } 
    209252 
    210     private static void ConvertImage(int MaxWidth, int MaxHeight, string fileFrom, UnifiedDirectory dirTo, string fileTo) 
    211     { 
    212       System.Drawing.Image image = System.Drawing.Image.FromStream(VirtualPathProvider.OpenFile(HttpUtility.UrlDecode(fileFrom))); 
    213       int srcWidth = image.Width; 
    214       int srcHeight = image.Height; 
    215       int Width = srcWidth; 
    216       int Height = srcHeight; 
     253             
     254            folder.BypassAccessCheck = true; 
     255            string path = GetImageGalleryFolder(pageFolderId); 
     256            if(path.Contains("/")) 
     257            { 
     258                if(!HostingEnvironment.VirtualPathProvider.DirectoryExists(folder.VirtualPath + ImageGalleryFolder)) 
     259                { 
     260                    folder.CreateSubdirectory(ImageGalleryFolder); 
     261                    folder = HostingEnvironment.VirtualPathProvider.GetDirectory(folder.VirtualPath + ImageGalleryFolder) as UnifiedDirectory; 
     262                    folder.BypassAccessCheck = true; 
     263                    if (HostingEnvironment.VirtualPathProvider.DirectoryExists(folder.VirtualPath + pageFolderId)) 
     264                    { 
     265                        return HostingEnvironment.VirtualPathProvider.GetDirectory(folder.VirtualPath + pageFolderId) as UnifiedDirectory; 
     266                    } 
     267                } 
     268                else 
     269                { 
     270                    folder = HostingEnvironment.VirtualPathProvider.GetDirectory(folder.VirtualPath + ImageGalleryFolder) as UnifiedDirectory; 
     271                    folder.BypassAccessCheck = true; 
     272                    if (HostingEnvironment.VirtualPathProvider.DirectoryExists(folder.VirtualPath + pageFolderId)) 
     273                    { 
     274                        return HostingEnvironment.VirtualPathProvider.GetDirectory(folder.VirtualPath + pageFolderId) as UnifiedDirectory; 
     275                    } 
     276                    return folder.CreateSubdirectory(pageFolderId.ToString()); 
     277                } 
     278            } 
    217279 
    218       //Need resize? 
    219       if (Width > MaxWidth || Height > MaxHeight) 
    220       { 
    221         decimal ratio = (decimal)Width / Height; 
     280            //It doesn't exists, so create it 
     281            return folder.CreateSubdirectory(ImageGalleryFolder); 
     282        } 
    222283 
    223         if (Width > MaxWidth) 
     284        private static UnifiedDirectory GetImageGalleryThumbsFolder(UnifiedDirectory folder) 
    224285        { 
    225           Width = MaxWidth; 
    226           Height = Convert.ToInt32(Width / ratio); 
     286            //Check if the folder exists 
     287            foreach (UnifiedDirectory dir in folder.Directories) 
     288            { 
     289                if (dir.Name == "Thumbs") 
     290                    return dir; 
     291            } 
     292 
     293            //It doesn't exists, so create it 
     294            folder.BypassAccessCheck = true; 
     295            return folder.CreateSubdirectory("Thumbs"); 
    227296        } 
    228297 
    229         if (Height > MaxHeight) 
     298        private static void ConvertImage(int MaxWidth, int MaxHeight, string fileFrom, UnifiedDirectory dirTo, string fileTo) 
    230299        { 
    231           Height = MaxHeight; 
    232           Width = Convert.ToInt32(Height * ratio); 
    233         } 
    234       } 
     300            System.Drawing.Image image = System.Drawing.Image.FromStream(VirtualPathProvider.OpenFile(HttpUtility.UrlDecode(fileFrom))); 
     301            int srcWidth = image.Width; 
     302            int srcHeight = image.Height; 
     303            int Width = srcWidth; 
     304            int Height = srcHeight; 
    235305 
    236       Bitmap bmp = new Bitmap(Width, Height); 
    237       string pathTo = dirTo.VirtualPath + "/" + fileTo; 
     306            //Need resize? 
     307            if (Width > MaxWidth || Height > MaxHeight) 
     308            { 
     309                decimal ratio = (decimal)Width / Height; 
    238310 
    239       string virtualDir = VirtualPathUtility.GetDirectory(HttpUtility.UrlDecode(pathTo)); 
    240       UnifiedDirectory destDir = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualDir) as UnifiedDirectory; 
    241       if (HostingEnvironment.VirtualPathProvider.FileExists(HttpUtility.UrlDecode(pathTo))) 
    242       { 
    243         UnifiedFile del = (UnifiedFile)HostingEnvironment.VirtualPathProvider.GetFile(HttpUtility.UrlDecode(pathTo)); 
    244         del.Delete(); 
    245       } 
    246       UnifiedFile file = destDir.CreateFile(VirtualPathUtility.GetFileName(pathTo)); 
     311                if (Width > MaxWidth) 
     312                { 
     313                    Width = MaxWidth; 
     314                    Height = Convert.ToInt32(Width / ratio); 
     315                } 
    247316 
    248       System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); 
    249       gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
    250       gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
    251       gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 
    252       System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, Width, Height); 
    253       gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel); 
     317                if (Height > MaxHeight) 
     318                { 
     319                    Height = MaxHeight; 
     320                    Width = Convert.ToInt32(Height * ratio); 
     321                } 
     322            } 
    254323 
    255       using (System.IO.Stream stream = file.Open(System.IO.FileMode.Create, System.IO.FileAccess.Write)) 
    256       { 
    257         bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); 
    258       } 
     324            Bitmap bmp = new Bitmap(Width, Height); 
     325            string pathTo = dirTo.VirtualPath + "/" + fileTo; 
    259326 
     327            string virtualDir = VirtualPathUtility.GetDirectory(HttpUtility.UrlDecode(pathTo)); 
     328            UnifiedDirectory destDir = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualDir) as UnifiedDirectory; 
     329            if (HostingEnvironment.VirtualPathProvider.FileExists(HttpUtility.UrlDecode(pathTo))) 
     330            { 
     331                UnifiedFile del = (UnifiedFile)HostingEnvironment.VirtualPathProvider.GetFile(HttpUtility.UrlDecode(pathTo)); 
     332                del.Delete(); 
     333            } 
     334            UnifiedFile file = destDir.CreateFile(VirtualPathUtility.GetFileName(pathTo)); 
    260335 
    261     } 
     336            System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); 
     337            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
     338            gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
     339            gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 
     340            System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, Width, Height); 
     341            gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel); 
    262342 
    263     private static string GenerateSlideID(string fileName) 
    264     { 
    265         //return fileName + DateTime.Now.ToString("yyMMddHHmmss"); // Removed for now due to a bug. Will be fixed in v. 2.0 
    266         return DateTime.Now.ToString("yyMMddHHmmssfff"); //Added miliseconds instead to make sure the ID is unique, will use GUID in v. 2.0 
    267     } 
     343            using (System.IO.Stream stream = file.Open(System.IO.FileMode.Create, System.IO.FileAccess.Write)) 
     344            { 
     345                bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); 
     346            } 
    268347 
    269     #endregion Private Methods ------------------------------------------------------------------- 
    270   } 
    271348 
    272   public class EPiImageGalleryImage 
    273   { 
    274     string _ImageURL; 
    275     string _Description; 
    276     string _ImageId; 
     349        } 
    277350 
    278     public string ImageURL { get { return _ImageURL; } set { _ImageURL = value; } } 
    279     public string Description { get { return _Description; } set { _Description = value; } } 
    280     public string ImageID { get { return _ImageId; } set { _ImageId = value; } } 
     351        private static string GenerateSlideID(string fileName) 
     352        { 
     353            //return fileName + DateTime.Now.ToString("yyMMddHHmmss"); // Removed for now due to a bug. Will be fixed in v. 2.0 
     354            return DateTime.Now.ToString("yyMMddHHmmssfff"); //Added miliseconds instead to make sure the ID is unique, will use GUID in v. 2.0 
     355        } 
    281356 
    282     public EPiImageGalleryImage(PageData Page, string SlideID, string Description) 
    283     { 
    284       _ImageURL = EPiImageGalleryPropertyEngine.GetImageUrl(Page, SlideID); 
    285       _Description = Description; 
    286       _ImageId = SlideID; 
     357        #endregion Private Methods ------------------------------------------------------------------- 
    287358    } 
    288359 
    289     public EPiImageGalleryImage(string ImageURL, string Description) 
     360    public class EPiImageGalleryImage 
    290361    { 
    291       _ImageURL = ImageURL; 
    292       _Description = Description; 
    293     } 
    294   } 
     362        string _ImageURL; 
     363        string _Description; 
     364        string _ImageId; 
    295365 
    296   public class EPiImageGalleryImageCollection : IEnumerator,IEnumerable 
    297   { 
    298     List<EPiImageGalleryImage> _Collection; 
    299     int position = -1; 
     366        public string ImageURL { get { return _ImageURL; } set { _ImageURL = value; } } 
     367        public string Description { get { return _Description; } set { _Description = value; } } 
     368        public string ImageID { get { return _ImageId; } set { _ImageId = value; } } 
     369        public PageData CurrentPage { get; set; } 
    300370 
    301     public EPiImageGalleryImageCollection() { _Collection = new List<EPiImageGalleryImage>();} 
     371        public EPiImageGalleryImage(PageData Page, string SlideID, string Description) 
     372        { 
     373            _ImageURL = EPiImageGalleryPropertyEngine.GetImageUrl(Page, SlideID); 
     374            _Description = Description; 
     375            _ImageId = SlideID; 
     376            CurrentPage = Page; 
     377        } 
    302378 
    303     public void Add(EPiImageGalleryImage item)  
    304     { 
    305       _Collection.Add(item); 
     379        public EPiImageGalleryImage(string ImageURL, string Description) 
     380        { 
     381            _ImageURL = ImageURL; 
     382            _Description = Description; 
     383        } 
    306384    } 
    307385 
    308     //IEnumerator and IEnumerable require these methods. 
    309     public IEnumerator GetEnumerator() 
     386    public class EPiImageGalleryImageCollection : IEnumerator, IEnumerable 
    310387    { 
    311       return (IEnumerator)this; 
    312     } 
     388        List<EPiImageGalleryImage> _Collection; 
     389        int position = -1; 
    313390 
    314     //IEnumerator 
    315     public bool MoveNext() 
    316     { 
    317       position++; 
    318       return (position < _Collection.Count); 
    319     } 
     391        public EPiImageGalleryImageCollection() { _Collection = new List<EPiImageGalleryImage>(); } 
    320392 
    321     //IEnumerable 
    322     public void Reset() 
    323     { position = 0; } 
     393        public void Add(EPiImageGalleryImage item) 
     394        { 
     395            _Collection.Add(item); 
     396        } 
    324397 
    325     //IEnumerable 
    326     public object Current 
    327     { 
    328       get { return _Collection[position]; } 
     398        //IEnumerator and IEnumerable require these methods. 
     399        public IEnumerator GetEnumerator() 
     400        { 
     401            return (IEnumerator)this; 
     402        } 
     403 
     404        //IEnumerator 
     405        public bool MoveNext() 
     406        { 
     407            position++; 
     408            return (position < _Collection.Count); 
     409        } 
     410 
     411        //IEnumerable 
     412        public void Reset() 
     413        { position = 0; } 
     414 
     415        //IEnumerable 
     416        public object Current 
     417        { 
     418            get { return _Collection[position]; } 
     419        } 
    329420    } 
    330   } 
    331421} 
  • 6.x/EPiImage/EPiImage.config

     
    1010  <!-- Where should cached scaled image be stored? (Must be a VPP folder that exists) --> 
    1111  <scaledimagechache vpppath="/Global/Scaled/" /> 
    1212 
     13  <!-- Where the scaled images should be stored if you do not want to use PageFiles (Must be a VPP folder that exists)--> 
     14  <scaledimages vpppath="/ImageGalleryScaled/" /> 
     15 
    1316  <!-- The scheduled job deletes cached scaled image files older than specified days.  
    1417       Remember to enable the job in admin mode. --> 
    1518  <cleanupjob deletefilesolderthan="7" /> 
  • 6.x/MakingWaves.EPiImage.csproj

     
    1 <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
     1<?xml version="1.0" encoding="utf-8"?> 
     2<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    23  <PropertyGroup> 
    34    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    45    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 
     
    1112    <RootNamespace>MakingWaves.EPiImage</RootNamespace> 
    1213    <AssemblyName>MakingWaves.EPiImage</AssemblyName> 
    1314    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 
     15    <FileUpgradeFlags> 
     16    </FileUpgradeFlags> 
     17    <UpgradeBackupLocation> 
     18    </UpgradeBackupLocation> 
     19    <OldToolsVersion>3.5</OldToolsVersion> 
    1420  </PropertyGroup> 
    1521  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
    1622    <DebugSymbols>true</DebugSymbols> 
     
    2026    <DefineConstants>DEBUG;TRACE</DefineConstants> 
    2127    <ErrorReport>prompt</ErrorReport> 
    2228    <WarningLevel>4</WarningLevel> 
     29    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 
    2330  </PropertyGroup> 
    2431  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 
    2532    <DebugType>none</DebugType> 
     
    2936    </DefineConstants> 
    3037    <ErrorReport>prompt</ErrorReport> 
    3138    <WarningLevel>4</WarningLevel> 
     39    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 
    3240  </PropertyGroup> 
    3341  <ItemGroup> 
    3442    <Reference Include="EPiServer, Version=5.2.375.236, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL"> 
    3543      <SpecificVersion>False</SpecificVersion> 
    3644      <HintPath>ReferencesCMS5R2\EPiServer.dll</HintPath> 
     45      <Private>False</Private> 
    3746    </Reference> 
    3847    <Reference Include="EPiServer.BaseLibrary, Version=5.2.375.236, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL"> 
    3948      <SpecificVersion>False</SpecificVersion> 
    4049      <HintPath>ReferencesCMS5R2\EPiServer.BaseLibrary.dll</HintPath> 
     50      <Private>False</Private> 
    4151    </Reference> 
    4252    <Reference Include="EPiServer.Configuration, Version=5.2.375.236, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL"> 
    4353      <SpecificVersion>False</SpecificVersion> 
    4454      <HintPath>ReferencesCMS5R2\EPiServer.Configuration.dll</HintPath> 
     55      <Private>False</Private> 
    4556    </Reference> 
    4657    <Reference Include="EPiServer.Web.WebControls, Version=5.2.375.236, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL"> 
    4758      <SpecificVersion>False</SpecificVersion> 
    4859      <HintPath>ReferencesCMS5R2\EPiServer.Web.WebControls.dll</HintPath> 
     60      <Private>False</Private> 
    4961    </Reference> 
    5062    <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL"> 
    5163      <SpecificVersion>False</SpecificVersion> 
     
    150162    <Content Include="web.config" /> 
    151163  </ItemGroup> 
    152164  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 
    153   <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" /> 
     165  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> 
    154166  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.  
    155167       Other similar extension points exist, see Microsoft.Common.targets. 
    156168  <Target Name="BeforeBuild"> 
  • 6.x/readme.txt

     
    1010(To create the .epimodule file run make-epimodule.cmd note: requires that 7-zip is installed) 
    1111(Can also be downloaded from https://www.coderesort.com/p/epicode/wiki/EPiImage) 
    1212 
     13Add this to your global.asax.cs: 
     14- In Application_Start: 
     15DataFactory.Instance.DeletingPage += new PageEventHandler(CleanUpImageGalleryFoldersAndFilesWhenPageIsDeletedHandler); 
     16 
     17and:  
     18  private void CleanUpImageGalleryFoldersAndFilesWhenPageIsDeletedHandler(object sender, PageEventArgs e) 
     19        { 
     20            PageData page = DataFactory.Instance.GetPage(e.PageLink); 
     21            string imagePath = EPiImageEngine.GetSettings().ScaledImagePath; 
     22             
     23            if(!string.IsNullOrEmpty(imagePath)) 
     24            { 
     25                const string galleryFolderPath = EPiImageGalleryPropertyEngine.ImageGalleryFolder; 
     26                string imageGalleryFolder = string.Format("{0}/{1}/{2}", imagePath, galleryFolderPath, page.Property["PageFolderID"]); 
     27                if(HostingEnvironment.VirtualPathProvider.DirectoryExists(imageGalleryFolder)) 
     28                { 
     29                    UnifiedDirectory directory = HostingEnvironment.VirtualPathProvider.GetDirectory(imageGalleryFolder) as UnifiedDirectory; 
     30                    if (directory != null) directory.Delete(); 
     31                } 
     32            } 
     33        } 
     34 
    1335You are done!  
    1436 
    1537DEMO TEMPLATES & PAGE TYPES: 
  • 6.x/web.config

     
    9393        </handlers> 
    9494    </system.webServer> 
    9595    <runtime> 
    96         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    97             <dependentAssembly> 
     96        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727"><dependentAssembly> 
    9897                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> 
    9998                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> 
    10099            </dependentAssembly> 
     
    102101                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> 
    103102                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> 
    104103            </dependentAssembly> 
    105         </assemblyBinding> 
    106     </runtime> 
     104        </assemblyBinding></runtime> 
    107105</configuration>