static void Main(string[] args) { // 如果 压缩文件已存在,先删除. if (File.Exists(ZIP_FILE_NAME)) { File.Delete(ZIP_FILE_NAME); } // 如果解压缩目录不存在,那么创建. if (!Directory.Exists(UPZIP_PATH_NAME)) { Directory.CreateDirectory(UPZIP_PATH_NAME); } Console.WriteLine("测试调用 7z.exe 来 压缩 / 解压缩."); Zip7 ziper = new Zip7(); Console.WriteLine("测试压缩."); ziper.Zip("cjyw.xml", ZIP_FILE_NAME); Console.WriteLine("压缩完毕."); Console.WriteLine("测试解压."); ziper.UnZip(ZIP_FILE_NAME, UPZIP_PATH_NAME); Console.WriteLine("解压完毕."); Console.ReadLine(); }
byte[] readImageAndCompress(Stream stream) { var image = Image.FromStream(stream); image = resizeImage(image, new Size(140, 60)); MemoryStream imgStream = new MemoryStream(); image.Save(imgStream, ImageFormat.Png); var comppressedImg = Zip7.Compress(imgStream.ToArray()); return(comppressedImg); }
public OrganizationModule() { this.RequiresClaims(new string[1] { Account.OWNER }); Post["/setuporganization"] = p => { try { string name = (string)this.Request.Form.name; string timezone = (string)this.Request.Form.timezone; string curr = (string)this.Request.Form.curr; int starts = (int)this.Request.Form.starts; Account acc = this.CurrentAccount(); this.OrganizationRepository().Save(new Organization() { _id = acc.OwnerId, OwnerId = acc.OwnerId, Name = name, Currency = curr, FiscalYearPeriod = starts }); Image img = Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Content\images\default-logo-organization.png")); MemoryStream imgStream = new MemoryStream(); img.Save(imgStream, ImageFormat.Png); byte[] logoData = readImageAndCompress(imgStream); LogoOrganization logoOrganization = new LogoOrganization { _id = this.CurrentAccount().OwnerId, ImageData = logoData, OwnerId = this.CurrentAccount().OwnerId }; this.LogoOrganizationCommand().Save(logoOrganization); } catch (Exception ex) { return(Response.AsRedirect("/?error=true&message=" + ex.Message)); } return(Response.AsRedirect("/")); }; Post["/settingorganization"] = p => { try { var test = this.Request.Form.Organization; Organization org = JsonConvert.DeserializeObject <Organization>(this.Request.Form.Organization); org._id = this.CurrentAccount().OwnerId; this.OrganizationRepository().Save(org); } catch (Exception ex) { return(Response.AsJson(new { error = false, message = ex.Message })); } return(Response.AsJson("success")); }; Post["/uploadlogoorg"] = p => { Stream stream = this.Request.Files.FirstOrDefault().Value; byte[] logoData = readImageAndCompress(stream); LogoOrganization logoOrganization = new LogoOrganization { _id = this.CurrentAccount().OwnerId, ImageData = logoData, OwnerId = this.CurrentAccount().OwnerId }; this.LogoOrganizationCommand().Save(logoOrganization); return(Response.AsRedirect("/uploadlogo")); }; Get["/logoOrganization"] = p => { LogoOrganization logo = this.LogoOrganizationQuery().GetLogo(this.CurrentAccount().OwnerId); if (logo == null) { return(null); } MemoryStream stream = new MemoryStream(Zip7.Decompress(logo.ImageData)); return(Response.FromStream(stream, "image/png")); }; }