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 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 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;
				}
			}
		}
Пример #5
0
        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();
        }
Пример #6
0
        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);
        }
Пример #7
0
 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;
 }
Пример #8
0
 public void DeleteFile(SprocketFile file)
 {
     ContentCache.ClearMultiple("Sprocket.Web.FileManager.CachedImage." + file.SprocketFileID + ".%");
     dataLayer.Delete(file);
 }
Пример #9
0
        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();
        }