public SprocketFile SelectSprocketFile(long id, bool getFileData) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { using (SqlConnection conn = new SqlConnection(DatabaseManager.DatabaseEngine.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("SprocketFile_Select", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@SprocketFileID", id)); cmd.Parameters.Add(new SqlParameter("@GetFileData", getFileData)); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); SprocketFile entity; if (!reader.Read()) { entity = null; } else { entity = new SprocketFile(reader); } reader.Close(); return(entity); } } }
public Result Delete(SprocketFile sprocketFile) { Result result = new Result(); if (OnBeforeDeleteSprocketFile != null) OnBeforeDeleteSprocketFile(sprocketFile, result); SqlConnection conn = null; if (result.Succeeded) { try { using (TransactionScope scope = new TransactionScope()) { conn = (SqlConnection)DatabaseManager.DatabaseEngine.GetConnection(); SqlCommand cmd = new SqlCommand("SprocketFile_Delete", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@SprocketFileID", sprocketFile.SprocketFileID)); cmd.ExecuteNonQuery(); scope.Complete(); } } catch (Exception ex) { return new Result(ex.Message); } finally { DatabaseManager.DatabaseEngine.ReleaseConnection(conn); } if (OnSprocketFileDeleted != null) OnSprocketFileDeleted(sprocketFile); } return result; }
public SprocketFile SpawnThumbnail(SprocketFile imageFile) { if (!Utility.Utilities.MatchesAny(imageFile.FileTypeExtension.ToLower(), "gif", "jpg", "png")) { throw new SprocketException("The specified file is not an image. No thumbnail can be created."); } return(null); }
public static SprocketFile[] Load(DataTable sprocketfileDataTable) { SprocketFile[] arr = new SprocketFile[sprocketfileDataTable.Rows.Count]; for (int i = 0; i < sprocketfileDataTable.Rows.Count; i++) { arr[i] = new SprocketFile(sprocketfileDataTable.Rows[i]); } return(arr); }
public void DeleteFile(SprocketFile file) { long f1 = file.SprocketFileID % 200 + 1; long f2 = ((file.SprocketFileID - f1) / 200) % 200 + 1; string path = WebUtility.MapPath(string.Format("datastore/filecache/{0}/{1}", f1, f2)); DirectoryInfo dir = new DirectoryInfo(path); if (dir.Exists) { foreach (FileInfo f in dir.GetFiles("*.jpg", SearchOption.TopDirectoryOnly)) try { f.Delete(); } catch { } } dataLayer.Delete(file); }
public static SprocketFile[] LoadByOwner(Guid ownerID) { Database.Main.RememberOpenState(); IDbCommand cmd = Database.Main.CreateCommand("SelectSprocketFilesByOwner", CommandType.StoredProcedure); Database.Main.AddParameter(cmd, "@OwnerID", ownerID); DataSet ds = Database.Main.GetDataSet(cmd); Database.Main.CloseIfWasntOpen(); SprocketFile[] arr = new SprocketFile[ds.Tables[0].Rows.Count]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { arr[i] = new SprocketFile(ds.Tables[0].Rows[i]); } return(arr); }
public void DeleteFile(SprocketFile file) { long f1 = file.SprocketFileID % 200 + 1; long f2 = ((file.SprocketFileID - f1) / 200) % 200 + 1; string path = WebUtility.MapPath(string.Format("datastore/filecache/{0}/{1}", f1, f2)); DirectoryInfo dir = new DirectoryInfo(path); if (dir.Exists) { foreach (FileInfo f in dir.GetFiles("*.jpg", SearchOption.TopDirectoryOnly)) { try { f.Delete(); } catch { } } } dataLayer.Delete(file); }
public static SprocketFile Upload(HttpPostedFile upload, Guid?clientID, Guid?ownerID, Guid?parentFileID, string sprocketPath, string categoryCode, string moduleRegCode, string description) { if (upload.ContentLength > int.Parse(SprocketSettings.GetValue("FileManagerMaxUploadSizeBytes"))) { return(null); } SprocketFile file = new SprocketFile(); file.sprocketFileID = Guid.NewGuid(); file.clientID = clientID; file.ownerID = ownerID; file.parentFileID = parentFileID; file.sprocketPath = (sprocketPath.Trim('/') + "/" + Path.GetFileName(upload.FileName)).Trim('/'); file.categoryCode = categoryCode; file.moduleRegCode = moduleRegCode; file.description = description; file.contentType = upload.ContentType; file.uploadDate = DateTime.Now; file.FileTypeExtension = Path.GetExtension(upload.FileName); upload.SaveAs(file.PhysicalPath); if (Database.Main.IsTransactionActive) { file.Save(); } else { Database.Main.BeginTransaction(); try { file.Save(); } catch (Exception ex) { Database.Main.RollbackTransaction(); file.EnsureFileDeleted(); throw ex; } Database.Main.CommitTransaction(); } return(file); }
internal void NotifyFileDeleted(SprocketFile file) { object obj = HttpContext.Current.Application["SprocketFileManager"]; if (obj == null) { return; } Dictionary <string, SprocketFile> cache = (Dictionary <string, SprocketFile>)obj; if (cache.ContainsKey(file.SprocketPath)) { cache.Remove(file.SprocketPath); } if (OnSprocketFileDeleted != null) { OnSprocketFileDeleted(file); } }
private SprocketFile LoadCacheSprocketFile(string sprocketPath) { if (HttpContext.Current.Application["SprocketFileManager"] == null) { HttpContext.Current.Application["SprocketFileManager"] = new Dictionary <string, SprocketFile>(); } Dictionary <string, SprocketFile> files = (Dictionary <string, SprocketFile>)HttpContext.Current.Application["SprocketFileManager"]; SprocketFile file; if (!files.ContainsKey(sprocketPath)) { file = SprocketFile.Load(sprocketPath); files[sprocketPath] = file; } else { file = files[sprocketPath]; } return(file); }
void OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled) { if (handled.Handled) { return; } if (sprocketPath.StartsWith("datastore/filemanager/")) { // deny access if the directory is accessed directly handled.Set(); return; } SprocketFile file = LoadCacheSprocketFile(sprocketPath); if (file == null) { return; } if (!File.Exists(file.PhysicalPath)) { throw new SprocketException("A file has been requested that is handled by the FileManager. " + "The file has a record in the database but the accompanying file is missing. The ID for " + "the file is " + file.SprocketFileID + " and the Sprocket path is " + file.SprocketPath + "."); } handled.Set(); if (OnBeforeSprocketFileServed != null) { Result result = new Result(); OnBeforeSprocketFileServed(file, result); // allow other modules to deny access to the file if (!result.Succeeded) { return; } } if (OnSprocketFileServed != null) { OnSprocketFileServed(file); } HttpContext.Current.Response.TransmitFile(file.PhysicalPath); HttpContext.Current.Response.ContentType = file.ContentType; }
public Result Delete(SprocketFile sprocketFile) { Result result = new Result(); if (OnBeforeDeleteSprocketFile != null) { OnBeforeDeleteSprocketFile(sprocketFile, result); } SqlConnection conn = null; if (result.Succeeded) { try { using (TransactionScope scope = new TransactionScope()) { conn = (SqlConnection)DatabaseManager.DatabaseEngine.GetConnection(); SqlCommand cmd = new SqlCommand("SprocketFile_Delete", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@SprocketFileID", sprocketFile.SprocketFileID)); cmd.ExecuteNonQuery(); scope.Complete(); } } catch (Exception ex) { return(new Result(ex.Message)); } finally { DatabaseManager.DatabaseEngine.ReleaseConnection(conn); } if (OnSprocketFileDeleted != null) { OnSprocketFileDeleted(sprocketFile); } } return(result); }
public Result Store(SprocketFile sprocketFile) { SqlConnection conn = null; try { using (TransactionScope scope = new TransactionScope()) { conn = (SqlConnection)DatabaseManager.DatabaseEngine.GetConnection(); SqlCommand cmd = new SqlCommand("SprocketFile_Store", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter prm = new SqlParameter("@SprocketFileID", sprocketFile.SprocketFileID); prm.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(prm); cmd.Parameters.Add(NewSqlParameter("@ClientSpaceID", sprocketFile.ClientSpaceID, SqlDbType.BigInt)); cmd.Parameters.Add(NewSqlParameter("@FileData", sprocketFile.FileData, SqlDbType.VarBinary)); cmd.Parameters.Add(NewSqlParameter("@FileTypeExtension", sprocketFile.FileTypeExtension, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@OriginalFileName", sprocketFile.OriginalFileName, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@ContentType", sprocketFile.ContentType, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@Title", sprocketFile.Title, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@Description", sprocketFile.Description, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@UploadDate", sprocketFile.UploadDate, SqlDbType.DateTime)); cmd.ExecuteNonQuery(); sprocketFile.SprocketFileID = (long)prm.Value; scope.Complete(); } } catch (Exception ex) { return(new Result(ex.Message)); } finally { DatabaseManager.DatabaseEngine.ReleaseConnection(conn); } return(new Result()); }
public Result Store(SprocketFile sprocketFile) { SqlConnection conn = null; try { using (TransactionScope scope = new TransactionScope()) { conn = (SqlConnection)DatabaseManager.DatabaseEngine.GetConnection(); SqlCommand cmd = new SqlCommand("SprocketFile_Store", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter prm = new SqlParameter("@SprocketFileID", sprocketFile.SprocketFileID); prm.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(prm); cmd.Parameters.Add(NewSqlParameter("@ClientSpaceID", sprocketFile.ClientSpaceID, SqlDbType.BigInt)); cmd.Parameters.Add(NewSqlParameter("@FileData", sprocketFile.FileData, SqlDbType.VarBinary)); cmd.Parameters.Add(NewSqlParameter("@FileTypeExtension", sprocketFile.FileTypeExtension, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@OriginalFileName", sprocketFile.OriginalFileName, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@ContentType", sprocketFile.ContentType, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@Title", sprocketFile.Title, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@Description", sprocketFile.Description, SqlDbType.NVarChar)); cmd.Parameters.Add(NewSqlParameter("@UploadDate", sprocketFile.UploadDate, SqlDbType.DateTime)); cmd.ExecuteNonQuery(); sprocketFile.SprocketFileID = (long)prm.Value; scope.Complete(); } } catch (Exception ex) { return new Result(ex.Message); } finally { DatabaseManager.DatabaseEngine.ReleaseConnection(conn); } return new Result(); }
public SprocketFile SelectSprocketFile(long id, bool getFileData) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { using (SqlConnection conn = new SqlConnection(DatabaseManager.DatabaseEngine.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("SprocketFile_Select", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@SprocketFileID", id)); cmd.Parameters.Add(new SqlParameter("@GetFileData", getFileData)); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); SprocketFile entity; if (!reader.Read()) entity = null; else entity = new SprocketFile(reader); reader.Close(); return entity; } } }
public Result ReadAdminField(out IEditFieldData efdata) { ImageEditFieldData data = new ImageEditFieldData(); SprocketFile file = null; if (HttpContext.Current.Request.Files[fieldName] != null) if (HttpContext.Current.Request.Files[fieldName].ContentLength > 0) { file = new SprocketFile(SecurityProvider.ClientSpaceID, HttpContext.Current.Request.Files[fieldName], "", ""); Image img; Result r = file.ValidateImageData(out img); if (!r.Succeeded) { efdata = new ImageEditFieldData(); return new Result("The image selected could not be loaded. The system reported back the following error: " + r.Message); } if (maxwidth > 0 || maxheight > 0) { SizingOptions options = new SizingOptions(maxwidth, maxheight, SizingOptions.Display.Constrain, 0); options.Image = img; MemoryStream stream = new MemoryStream(); FileManager.FileManager.Instance.ResizeImage(options, stream); file.FileData = stream.ToArray(); } } bool deleted = HttpContext.Current.Request.Form["deleteimage_" + fieldName] != null; long existing; if (!long.TryParse(HttpContext.Current.Request.Form["existingimage_" + fieldName], out existing)) existing = 0; if (deleted) data.SprocketFileID = 0; else if (file != null) data.SprocketFile = file; else data.SprocketFileID = existing; efdata = data; return new Result(); }
public void ResizeImage(SizingOptions options, Stream outStream) { SprocketFile file = dataLayer.SelectSprocketFile(options.SprocketFileID, true); Image sourceImage = options.Image == null?Image.FromStream(new MemoryStream(file.FileData)) : options.Image; Size imageSize; if (options.DisplayType == SizingOptions.Display.Constrain) { int maxWidth = 0, maxHeight = 0; if (options.Width > 0) { maxWidth = options.Width - options.Padding * 2 - options.BorderSize * 2; } if (options.Height > 0) { maxHeight = options.Height - options.Padding * 2 - options.BorderSize * 2; } if (maxWidth == 0 && maxHeight == 0) { throw new Exception("Can't resize image. No dimensions were specified."); } float srcRatio = (float)sourceImage.Width / (float)sourceImage.Height; if (maxWidth == 0) { imageSize = new Size((int)((float)maxHeight * srcRatio) + options.BorderSize * 2 + options.Padding * 2, maxHeight + options.BorderSize * 2 + options.Padding * 2); } else if (maxHeight == 0) { imageSize = new Size(maxWidth + options.BorderSize * 2 + options.Padding * 2, (int)((float)maxWidth / srcRatio) + options.BorderSize * 2 + options.Padding * 2); } else { float destRatio = (float)maxWidth / (float)maxHeight; if (destRatio < srcRatio) // landscape; keep width, set height { imageSize = new Size(maxWidth + options.BorderSize * 2 + options.Padding * 2, (int)((float)maxWidth / srcRatio) + options.BorderSize * 2 + options.Padding * 2); } else // portrait; keep height, set width { imageSize = new Size((int)((float)maxHeight * srcRatio) + options.BorderSize * 2 + options.Padding * 2, maxHeight + options.BorderSize * 2 + options.Padding * 2); } } } else { imageSize = new Size(options.Width, options.Height); } if (options.PreventEnlargement) { if (imageSize.Width - options.Padding * 2 - options.BorderSize * 2 > sourceImage.Width) { imageSize.Width = sourceImage.Width + options.Padding * 2 + options.BorderSize * 2; } if (imageSize.Height - options.Padding * 2 - options.BorderSize * 2 > sourceImage.Height) { imageSize.Height = sourceImage.Height + options.Padding * 2 + options.BorderSize * 2; } } using (Image finalImage = new Bitmap(imageSize.Width, imageSize.Height)) { using (Graphics gfx = Graphics.FromImage(finalImage)) { // set the rendering defaults gfx.CompositingQuality = CompositingQuality.HighQuality; gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // set colours and pens Brush fill = new SolidBrush(options.BackgroundColor); Pen pen = new Pen(options.BorderColor, options.BorderSize); pen.Alignment = PenAlignment.Inset; // fill the background gfx.FillRectangle(fill, 0, 0, finalImage.Width, finalImage.Height); // calculate the area in which we can paint the image Rectangle clientRect = new Rectangle( options.BorderSize + options.Padding, options.BorderSize + options.Padding, finalImage.Width - options.BorderSize * 2 - options.Padding * 2, finalImage.Height - options.BorderSize * 2 - options.Padding * 2); // work out the letterboxing ratios (if the inner ratio is greater, the photo is // proportionally wider than the container, i.e. standard widescreen letterbox) float containerRatio = (float)clientRect.Width / (float)clientRect.Height; float imgRatio = (float)sourceImage.Width / (float)sourceImage.Height; bool landscape = imgRatio > containerRatio; Rectangle destRect = new Rectangle(clientRect.X, clientRect.Y, clientRect.Width, clientRect.Height); switch (options.DisplayType) { case SizingOptions.Display.Letterbox: if (landscape) { int h = (int)((float)destRect.Width / imgRatio); destRect.Y += (destRect.Height - h) / 2; destRect.Height = h; } else { int w = (int)((float)destRect.Height * imgRatio); destRect.X += (destRect.Width - w) / 2; destRect.Width = w; } gfx.DrawImage(sourceImage, destRect); break; case SizingOptions.Display.Constrain: case SizingOptions.Display.Stretch: gfx.DrawImage(sourceImage, destRect); break; case SizingOptions.Display.Center: gfx.DrawImage(sourceImage, destRect, new Rectangle( (sourceImage.Width - destRect.Width) / 2, (sourceImage.Height - destRect.Height) / 2, destRect.Width, destRect.Height), GraphicsUnit.Pixel); break; case SizingOptions.Display.Tile: int tileX, tileY = clientRect.Y; do { tileX = clientRect.X; do { destRect = new Rectangle(tileX, tileY, tileX + sourceImage.Width > clientRect.Right ? clientRect.Right - tileX : sourceImage.Width, tileY + sourceImage.Height > clientRect.Bottom ? clientRect.Bottom - tileY : sourceImage.Height); gfx.DrawImageUnscaledAndClipped(sourceImage, destRect); tileX += sourceImage.Width + options.TileSpacing; } while (tileX < clientRect.Right); tileY += sourceImage.Height + options.TileSpacing; } while (tileY < clientRect.Bottom); break; case SizingOptions.Display.Crop: switch (options.Anchor) { case SizingOptions.CropAnchor.Top: using (Bitmap bmp = new Bitmap(destRect.Width, (int)((float)destRect.Width / imgRatio))) { using (Graphics gfx2 = Graphics.FromImage(bmp)) { gfx2.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx2.DrawImage(sourceImage, 0, 0, bmp.Width, bmp.Height); } gfx.DrawImage(bmp, destRect, new Rectangle(0, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } break; case SizingOptions.CropAnchor.Bottom: using (Bitmap bmp = new Bitmap(destRect.Width, (int)((float)destRect.Width / imgRatio))) { using (Graphics gfx2 = Graphics.FromImage(bmp)) { gfx2.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx2.DrawImage(sourceImage, 0, 0, bmp.Width, bmp.Height); } gfx.DrawImage(bmp, destRect, new Rectangle(0, bmp.Height - destRect.Height, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } break; case SizingOptions.CropAnchor.Left: using (Bitmap bmp = new Bitmap((int)((float)destRect.Height * imgRatio), destRect.Height)) { using (Graphics gfx2 = Graphics.FromImage(bmp)) { gfx2.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx2.DrawImage(sourceImage, 0, 0, bmp.Width, bmp.Height); } gfx.DrawImage(bmp, destRect, new Rectangle(0, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } break; case SizingOptions.CropAnchor.Right: using (Bitmap bmp = new Bitmap((int)((float)destRect.Height * imgRatio), destRect.Height)) { using (Graphics gfx2 = Graphics.FromImage(bmp)) { gfx2.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx2.DrawImage(sourceImage, 0, 0, bmp.Width, bmp.Height); } gfx.DrawImage(bmp, destRect, new Rectangle(bmp.Width - destRect.Width, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } break; case SizingOptions.CropAnchor.Center: int midW, midH; if (landscape) { midH = destRect.Height; midW = (int)((float)destRect.Height * imgRatio); } else { midW = destRect.Width; midH = (int)((float)destRect.Width / imgRatio); } using (Bitmap bmp = new Bitmap(midW, midH)) { using (Graphics gfx2 = Graphics.FromImage(bmp)) { gfx2.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx2.DrawImage(sourceImage, 0, 0, bmp.Width, bmp.Height); } if (landscape) { gfx.DrawImage(bmp, destRect, new Rectangle((bmp.Width - destRect.Width) / 2, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } else { gfx.DrawImage(bmp, destRect, new Rectangle(0, (bmp.Height - destRect.Height) / 2, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } } break; default: break; } break; default: break; } // draw the border last to ensure it doesn't get obscured; if (options.BorderSize > 0) { gfx.DrawRectangle(pen, 0, 0, finalImage.Width - 1, finalImage.Height - 1); } // find the jpeg encoder ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo encoder = null; for (int i = 0; i < encoders.Length; i++) { if (encoders[i].MimeType == "image/jpeg") { encoder = encoders[i]; break; } } if (encoder == null) { throw new SprocketException("Can't create a thumbnail because no JPEG encoder exists."); } EncoderParameters prms = new EncoderParameters(1); // set the jpeg quality prms.Param[0] = new EncoderParameter(Encoder.Quality, options.JpegQuality); if (outStream != null) { finalImage.Save(outStream, encoder, prms); if (outStream is MemoryStream) { outStream.Seek(0, SeekOrigin.Begin); } } else { // make sure the cache directory exists DirectoryInfo info = new FileInfo(options.PhysicalPath).Directory; if (!info.Exists) { info.Create(); } // save the image finalImage.Save(options.PhysicalPath, encoder, prms); } } } if (options.Image == null) { sourceImage.Dispose(); } }
public void DeleteFile(SprocketFile file) { ContentCache.ClearMultiple("Sprocket.Web.FileManager.CachedImage." + file.SprocketFileID + ".%"); dataLayer.Delete(file); }
void OnLoadRequestedPath(HandleFlag handled) { switch (SprocketPath.Value) { case "test": Response.Write("<form method=\"post\" action=\"" + WebUtility.BasePath + "test/upload/\" enctype=\"multipart/form-data\">" + "<input type=\"file\" size=\"40\" name=\"thefile\" /> <input type=\"submit\" value=\"upload\" />" + "</form>" ); break; case "test/upload": HttpPostedFile posted = HttpContext.Current.Request.Files[0]; SprocketFile file = new SprocketFile(Security.SecurityProvider.ClientSpaceID, posted, "Test Image", "A test image."); FileManager.DataLayer.Store(file); WebUtility.Redirect("test/show/?" + file.SprocketFileID); break; case "test/show": long id = long.Parse(WebUtility.RawQueryString); SizingOptions options = new SizingOptions(320, 180, 10, Color.Black, Color.CadetBlue, 2, SizingOptions.Display.Letterbox, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(200, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Letterbox, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(200, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Stretch, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Letterbox, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 10, Color.White, Color.FromArgb(240, 240, 240), 1, SizingOptions.Display.Letterbox, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Top, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Top, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Bottom, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Bottom, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Center, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Center, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Left, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Left, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Right, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Right, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Center, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.Display.Center, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> "); options = new SizingOptions(400, 300, 10, Color.Black, Color.CadetBlue, 0, 10, id); Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" align=\"top\" /> "); break; default: if (SprocketPath.Value.EndsWith(".jpg") && SprocketPath.Value.StartsWith("test/image/")) { FileManager.Instance.TransmitRequestedImage(); break; } return; } handled.Set(); }
internal void NotifyFileDeleted(SprocketFile file) { object obj = HttpContext.Current.Application["SprocketFileManager"]; if (obj == null) return; Dictionary<string, SprocketFile> cache = (Dictionary<string, SprocketFile>)obj; if(cache.ContainsKey(file.SprocketPath)) cache.Remove(file.SprocketPath); if (OnSprocketFileDeleted != null) OnSprocketFileDeleted(file); }
public SprocketFile SpawnThumbnail(SprocketFile imageFile) { if (!Utility.Utilities.MatchesAny(imageFile.FileTypeExtension.ToLower(), "gif", "jpg", "png")) throw new SprocketException("The specified file is not an image. No thumbnail can be created."); return null; }