Ejemplo n.º 1
0
 public void ProcessRequest(HttpContext context)
 {
     string root_abs_path = VirtualPathUtility.ToAbsolute("~/");
     string archive_file_vpath = "~/" + context.Request.RawUrl.Substring(root_abs_path.Length).Replace(".fa.aspx?", "?");
     archive_file_vpath = archive_file_vpath.Substring(0, archive_file_vpath.IndexOf("?"));
     string archive_file = context.Server.MapPath(archive_file_vpath);
     string filename = (!string.IsNullOrEmpty(context.Request.QueryString["n"]) ? context.Request.QueryString["n"] : "");
     string requesttype = (!string.IsNullOrEmpty(context.Request.QueryString["t"]) ? context.Request.QueryString["t"] : "");
     string hashcode = (!string.IsNullOrEmpty(context.Request.QueryString["u"]) ? context.Request.QueryString["u"] : "");
     string width = (!string.IsNullOrEmpty(context.Request.QueryString["w"]) ? context.Request.QueryString["w"] : "");
     string fixed_height = (!string.IsNullOrEmpty(context.Request.QueryString["fh"]) ? context.Request.QueryString["fh"] : "t");
     string watermark = (!string.IsNullOrEmpty(context.Request.QueryString["wm"]) ? context.Request.QueryString["wm"] : "0");
     try
     {
         if (Security.CheckSecurity(hashcode))
         {
             FileArchiverCore core = new FileArchiverCore(archive_file);
             if (requesttype == "thumb")
             {
                 context.Response.ContentType = "image/png";
                 Bitmap thumb = core.GetIcon(filename, width, fixed_height);
                 System.IO.MemoryStream memresult = new System.IO.MemoryStream();
                 thumb.Save(memresult, System.Drawing.Imaging.ImageFormat.Png);
                 memresult.WriteTo(context.Response.OutputStream);
                 thumb.Dispose();
                 memresult.Dispose();
                 thumb = null;
                 memresult = null;
             }
             if (requesttype == "full")
             {
                 byte[] contents = core.GetFileContents(filename);
                 AddWatermark(ref contents);
                 context.Response.BinaryWrite(contents);
                 context.Response.ContentType = MimeTypes.GetMimeType(System.IO.Path.GetExtension(filename));
             }
             if (requesttype == "down")
             {
                 byte[] contents = core.GetFileContents(filename);
                 AddWatermark(ref contents);
                 context.Response.BinaryWrite(contents);
                 context.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
             }
             if (requesttype == "up")
             {
                 if (context.Request.Files.Count > 0)
                 {
                     core.AddFile(
                         context.Request.Files[0].FileName,
                         context.Request.Files[0].InputStream);
                     context.Response.Write("{status:'success'}");
                 }
             }
             if (requesttype == "del")
             {
                 core.RemoveFile(filename);
                 context.Response.Write("{status:'success'}");
             }
             if (requesttype == "list")
             {
                 string files = "";
                 for (int i = 0; i < core.Files.Length; i++)
                     files += core.Files[i].Name + "|";
                 if (files.EndsWith("|")) files = files.Remove(files.Length - 1);
                 context.Response.Write(files);
             }
         }
         else
         {
             throw new Exception("Not logged in.");
         }
     }
     catch (Exception ex)
     {
         context.Response.Write("{status:'error',msg:'" + ex.Message.Replace("'", "\\'").Replace("\\", "\\\\") + "',detail:'" + ex.ToString().Replace("'", "\\'").Replace("\\", "\\\\") + "'}");
     }
 }
 // Methods
 protected override void OnLoad(EventArgs e)
 {
     archiver = new FileArchiverCore(Page.MapPath(ArchiveFile));
     base.ArchiveFileAddress = ResolveUrl(ArchiveFile);
     base.OnLoad(e);
 }