예제 #1
0
 public override string Render(string body = "")
 {
     if (!CheckSecurity("export"))
     {
         return(AccessDenied());
     }
     try
     {
         var filename = "SaberExport.zip";
         var content  = new ByteArrayContent(SaberZip.Export());
         content.Headers.ContentType                 = new MediaTypeHeaderValue("application/zip");
         content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
         content.Headers.ContentDisposition.FileName = filename;
         Context.Response.ContentLength              = content.Headers.ContentLength;
         Context.Response.ContentType                = "application/zip";
         Context.Response.StatusCode                 = 200;
         Context.Response.Headers.Add("Content-Disposition", "attachment; filename=" + filename);
         content.CopyToAsync(Context.Response.Body);
     }
     catch (Exception ex)
     {
         return(Error(ex.Message + "\n" + ex.StackTrace));
     }
     return("");
 }
예제 #2
0
        public override string Render(string body = "")
        {
            if (!CheckSecurity("import"))
            {
                return(AccessDenied());
            }
            if (Parameters.Files.Count == 0)
            {
                return(Error("Please specify a file to import"));
            }
            if (Parameters.Files.Count > 0 && Parameters.Files["zip"].ContentType != "application/x-zip-compressed")
            {
                return(Error("Import file must be a compressed zip file."));
            }
            //create backup of website
            var copyTo = App.MapPath("Content/backups/");

            if (!Directory.Exists(copyTo))
            {
                Directory.CreateDirectory(copyTo);
            }
            File.WriteAllBytes(copyTo + "latest.zip", SaberZip.Export());

            //open uploaded zip file
            SaberZip.Import(Parameters.Files["zip"]);

            return("latest.zip");
        }