/// <summary>
        /// Delete a media on file system
        /// </summary>
        /// <param name="media">Media</param>
        private void DeleteMediaOnFileSystem(Media media)
        {
            if (media == null)
                throw new ArgumentNullException("media");

            string[] parts = media.MimeType.Split('/');
            string lastPart = parts[parts.Length - 1];
            switch (lastPart)
            {
                case "pjpeg":
                    lastPart = "jpg";
                    break;
                case "x-png":
                    lastPart = "png";
                    break;
                case "x-icon":
                    lastPart = "ico";
                    break;
            }
            string localFilename = string.Format("{0}_0.{1}", media.MediaID.ToString("0000000"), lastPart);
            string localFilepath = Path.Combine(LocalImagePath, localFilename);
            if (File.Exists(localFilepath))
            {
                File.Delete(localFilepath);
            }
        }
        /// <summary>
        /// Get a media URL
        /// </summary>
        /// <param name="media">Media instance</param>
        /// <param name="targetSize">The target media size (longest side)</param>
        /// <param name="showDefaultMedia">A value indicating whether the default media is shown</param>
        /// <returns></returns>
        public string GetMediaUrl(Media media, int targetSize,
            bool showDefaultMedia)
        {
            string url = string.Empty;
            if (media == null || media.LoadMediaBinary().Length == 0)
            {
                if (showDefaultMedia)
                {
                    url = GetDefaultMediaUrl(targetSize);
                }
                return url;
            }

            string[] parts = media.MimeType.Split('/');
            string lastPart = parts[parts.Length - 1];
            switch (lastPart)
            {
                case "pjpeg":
                    lastPart = "jpg";
                    break;
                case "x-png":
                    lastPart = "png";
                    break;
                case "x-icon":
                    lastPart = "ico";
                    break;
            }

            string localFilename = string.Empty;
            if ((bool)media.IsNew)
            {
                string filter = string.Format("{0}*.*", media.MediaID.ToString("0000000"));
                string[] currentFiles = System.IO.Directory.GetFiles(this.LocalThumbImagePath, filter);
                foreach (string currentFileName in currentFiles)
                    File.Delete(Path.Combine(this.LocalThumbImagePath, currentFileName));

                media = UpdateMedia(media.MediaID, media.LoadMediaBinary(), media.MimeType, false);
            }
            lock (s_lock)
            {
                if (targetSize == 0)
                {
                    localFilename = string.Format("{0}.{1}", media.MediaID.ToString("0000000"), lastPart);
                    if (!File.Exists(Path.Combine(this.LocalThumbImagePath, localFilename)))
                    {
                        if (!System.IO.Directory.Exists(this.LocalThumbImagePath))
                        {
                            System.IO.Directory.CreateDirectory(this.LocalThumbImagePath);
                        }
                        File.WriteAllBytes(Path.Combine(this.LocalThumbImagePath, localFilename), media.LoadMediaBinary());
                    }
                }
                else
                {
                    localFilename = string.Format("{0}_{1}.{2}", media.MediaID.ToString("0000000"), targetSize, lastPart);
                    if (!File.Exists(Path.Combine(this.LocalThumbImagePath, localFilename)))
                    {
                        if (!System.IO.Directory.Exists(this.LocalThumbImagePath))
                        {
                            System.IO.Directory.CreateDirectory(this.LocalThumbImagePath);
                        }
                        using (MemoryStream stream = new MemoryStream(media.LoadMediaBinary()))
                        {
                            var b = new Bitmap(stream);

                            var newSize = CalculateDimensions(b.Size, targetSize);

                            if (newSize.Width < 1)
                                newSize.Width = 1;
                            if (newSize.Height < 1)
                                newSize.Height = 1;

                            var newBitMap = new Bitmap(newSize.Width, newSize.Height);
                            var g = Graphics.FromImage(newBitMap);
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                            g.DrawImage(b, 0, 0, newSize.Width, newSize.Height);
                            var ep = new EncoderParameters();
                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, this.ImageQuality);
                            ImageCodecInfo ici = GetImageCodecInfoFromExtension(lastPart);
                            if (ici == null)
                                ici = GetImageCodecInfoFromMimeType("image/jpeg");
                            newBitMap.Save(Path.Combine(this.LocalThumbImagePath, localFilename), ici, ep);
                            newBitMap.Dispose();
                            b.Dispose();
                        }
                    }
                }
            }
            url = ZuluHelper.ApplicationPath + @"images\thumbs\" + localFilename;
            return url;
        }
 /// <summary>
 /// Get a media URL
 /// </summary>
 /// <param name="media">Media instance</param>
 /// <returns>Media URL</returns>
 public string GetMediaUrl(Media media)
 {
     return GetMediaUrl(media, 0);
 }
 /// <summary>
 /// Get a media URL
 /// </summary>
 /// <param name="media">Media instance</param>
 /// <param name="targetSize">The target media size (longest side)</param>
 /// <returns>Media URL</returns>
 public string GetMediaUrl(Media media, int targetSize)
 {
     return GetMediaUrl(media, targetSize, true);
 }
 /// <summary>
 /// Get a media local path
 /// </summary>
 /// <param name="media">Media instance</param>
 /// <param name="targetSize">The target media size (longest side)</param>
 /// <param name="showDefaultMedia">A value indicating whether the default media is shown</param>
 /// <returns></returns>
 public string GetMediaLocalPath(Media media, int targetSize, bool showDefaultMedia)
 {
     string url = GetMediaUrl(media, targetSize, showDefaultMedia);
     if (String.IsNullOrEmpty(url))
     {
         return String.Empty;
     }
     else
     {
         return Path.Combine(this.LocalThumbImagePath, Path.GetFileName(url));
     }
 }