Example #1
0
 /// <summary>
 /// Create a new tbl_ProdImageVerNames object.
 /// </summary>
 /// <param name="pIVNameID">Initial value of the PIVNameID property.</param>
 /// <param name="vN_Name">Initial value of the VN_Name property.</param>
 /// <param name="vN_Height">Initial value of the VN_Height property.</param>
 /// <param name="vN_Width">Initial value of the VN_Width property.</param>
 public static tbl_ProdImageVerNames Createtbl_ProdImageVerNames(global::System.Int32 pIVNameID, global::System.String vN_Name, global::System.Int16 vN_Height, global::System.Int16 vN_Width)
 {
     tbl_ProdImageVerNames tbl_ProdImageVerNames = new tbl_ProdImageVerNames();
     tbl_ProdImageVerNames.PIVNameID = pIVNameID;
     tbl_ProdImageVerNames.VN_Name = vN_Name;
     tbl_ProdImageVerNames.VN_Height = vN_Height;
     tbl_ProdImageVerNames.VN_Width = vN_Width;
     return tbl_ProdImageVerNames;
 }
Example #2
0
            private void StartAsyncTask(Object workItemState)
            {
                try
                {
                    string location = _context.Request.QueryString["image"];

                    if (location == null)
                        //throw new HttpException("Invalid request.");
                        return;

                    string extension;
                    string contentType;

                    try
                    {
                        extension = Path.GetExtension(location).ToLower();
                    }
                    catch
                    {
                        throw new HttpException("Invalid request: " + location);
                    }

                    switch (extension)
                    {
                        case ".jpg":
                            contentType = "image/jpeg";
                            break;
                        case ".jpeg":
                            contentType = "image/jpeg";
                            break;
                        case ".png":
                            contentType = "image/png";
                            break;
                        case ".gif":
                            contentType = "image/gif";
                            break;
                        case ".bmp":
                            contentType = "image/bmp";
                            break;
                        default:
                            throw new HttpException(404, "Invalid request: " + location);
                    }

                    string absoluteLocation = _context.Server.MapPath("~/" + location);
                    var ecommerceService = (IECommerce) DependencyResolver.Current.GetService(typeof (IECommerce));

                    //var config = ImageProviderWebSectionGroup.FromCurrentConfiguration().ImageProvider;
                    //if (config.Presets.Count == 0)
                    //    throw new ConfigurationErrorsException("No resize presets defined.");
                    //ImageProviderPresetElement preset;

                    var preset = new tbl_ProdImageVerNames();
                    if (_context.Request["preset"] != null)
                    {
                        preset = ecommerceService.GetProductImageVersionByName(_context.Request.QueryString["preset"]);

                        if (preset == null)
                            throw new ArgumentException("The specified preset name is not valid.", "preset");
                    }

                    _context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    _context.Response.Cache.SetExpires(DateTime.Now.AddDays(3));

                    if (preset.VN_Width == 0 && preset.VN_Width == 0 && File.Exists(absoluteLocation))
                    {
                        _context.Response.ContentType = contentType;
                        using (FileStream f = File.OpenRead(absoluteLocation))
                        {
                            f.Write(_context.Response.OutputStream, 65536);
                        }
                        return;
                    }

                    string absoluteCacheDirectoryLocation =
                        _context.Server.MapPath(String.IsNullOrWhiteSpace(preset.VN_Path)
                            ? "/Images/Versions"
                            : preset.VN_Path.TrimEnd('/'));

                    string absoluteCacheFileLocation = new StringBuilder()
                        .Append(absoluteCacheDirectoryLocation).Append(Path.DirectorySeparatorChar)
                        .Append(preset.VN_Width).Append("x").Append(preset.VN_Height)
                        .Append("_")
                        .Append(
                            (ImageResizer.ResizeMode)
                                Enum.Parse(typeof (ImageResizer.ResizeMode),
                                    preset.VN_Mode.GetValueOrDefault(
                                        (int) ImageResizer.ResizeMode.CropToDestinationAspect).ToString(CultureInfo.InvariantCulture)))
                        .Append("_").Append(Path.GetFileName(location)).ToString();

                    if (File.Exists(absoluteCacheFileLocation))
                    {
                        _context.Response.ContentType = contentType;

                        using (FileStream f = File.OpenRead(absoluteCacheFileLocation))
                        {
                            f.Write(_context.Response.OutputStream, 65536);
                        }

                        return;
                    }

                    if (File.Exists(absoluteLocation))
                    {
                        using (var resizer = new ImageResizer(absoluteLocation))
                        {
                            resizer.Background = String.IsNullOrEmpty(preset.VN_Background)
                                ? ColorTranslator.FromHtml("#FFF")
                                : ColorTranslator.FromHtml(preset.VN_Background);
                            resizer.Mode = preset.VN_Mode.HasValue
                                ? (ImageResizer.ResizeMode)
                                    Enum.Parse(typeof (ImageResizer.ResizeMode), preset.VN_Mode.Value.ToString(CultureInfo.InvariantCulture))
                                : ImageResizer.ResizeMode.CropToDestinationAspect;
                            resizer.Width = preset.VN_Width;
                            resizer.Height = preset.VN_Height;

                            resizer.Process();

                            _context.Response.ContentType = contentType;

                            if (!Directory.Exists(absoluteCacheDirectoryLocation))
                                Directory.CreateDirectory(absoluteCacheDirectoryLocation);

                            using (var output = new MemoryStream())
                            {
                                resizer.SaveAs(output);
                                output.WriteTo(_context.Response.OutputStream);
                            }

                            resizer.SaveAs(absoluteCacheFileLocation);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
                finally
                {
                    _completed = true;
                    _callback(this);
                }
            }
Example #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the tbl_ProdImageVerNames EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotbl_ProdImageVerNames(tbl_ProdImageVerNames tbl_ProdImageVerNames)
 {
     base.AddObject("tbl_ProdImageVerNames", tbl_ProdImageVerNames);
 }