/// <summary> /// 导出 /// </summary> public void Export() { var code = RouteData.Values["id"]?.ToString(); using var db = new ContextBase(); var list = db.DocSetDetail.Where(x => x.DsCode == code).OrderBy(x => x.DsdOrder).Select(x => new { x.DsdId, x.DsdPid, x.DsdTitle, x.DsdOrder, IsCatalog = string.IsNullOrEmpty(x.DsdContentMd), x.DsdContentHtml }).ToList(); var htmlbody = ListTreeEach(list, "DsdPid", "DsdId", new List <string> { Guid.Empty.ToString() }); //读取模版 var tm = FileTo.ReadText(GlobalTo.WebRootPath + "/template/", "htmltoword.html"); tm = tm.Replace("@netnrmd@", htmlbody); //文件名 var filename = db.DocSet.Where(x => x.DsCode == code).FirstOrDefault()?.DsName.Replace(" ", "") ?? "netnrdoc"; new DownTo(Response).Stream(Encoding.Default.GetBytes(tm), filename + ".doc"); }
public void ActionSetsError(string action) { FileTo fileTo = this.GetFileTo(action); Routable message = this.GetRoutable(); fileTo.Process(message); Assert.NotNull(message.Error); }
public void CanDeleteFile() { string randomFileName = $"{Guid.NewGuid().ToString("N")}.txt"; FileTo fileTo = this.Setup("Delete", randomFileName); Dictionary <string, string> routableHeaders = new Dictionary <string, string>() { { "FullSource", $"test/{randomFileName}" }, { "SourceFile", randomFileName } }; fileTo.Process(new Core.Entities.Routable(routableHeaders, System.Text.Encoding.UTF8.GetBytes("test file"))); Assert.IsFalse(System.IO.File.Exists($"test/{randomFileName}")); }
/// <summary> /// 图片文件上传 /// </summary> /// <param name="mm"></param> protected void UpFile(Song.Entities.Picture mm) { try { if (fuLoad.PostedFile.FileName == "") { return; } //新增图片对象 fuLoad.UpPath = type; fuLoad.IsMakeSmall = true; fuLoad.IsConvertJpg = true; //缩略图宽高 int tw = Business.Do <ISystemPara>()["Picture_ThumbnailWidth"].Int32 ?? 100; int th = Business.Do <ISystemPara>()["Picture_ThumbnailHeight"].Int32 ?? 100; fuLoad.SmallHeight = th; fuLoad.SmallWidth = tw; fuLoad.SaveAndDeleteOld(mm.Pic_FilePath); mm.Pic_FilePath = fuLoad.File.Server.FileName; mm.Pic_FilePathSmall = fuLoad.File.Server.SmallFileName; mm.Pic_Size = (int)fuLoad.File.Server.Size; mm.Pic_Width = fuLoad.File.Server.Width; mm.Pic_Height = fuLoad.File.Server.Height; //是否强制尺寸 bool isCompel = Business.Do <ISystemPara>()["Picture_IsCompelSize"].Boolean ?? false; int cw = Business.Do <ISystemPara>()["Picture_CompelWidth"].Int32 ?? 0; int ch = Business.Do <ISystemPara>()["Picture_CompelHeight"].Int32 ?? 0; if (isCompel) { FileTo.Zoom(fuLoad.File.Server.FileFullName, cw, ch); } //水印图片处理 bool isAddWater = Business.Do <ISystemPara>()["Picture_Watermark_IsAdd"].Boolean ?? false; if (isAddWater) { string imgFile = Business.Do <ISystemPara>()["Picture_Watermark"].String; imgFile = Upload.Get[type].Physics + imgFile; int opacity = Business.Do <ISystemPara>()["Picture_Watermark_Opacity"].Int16 ?? 60; string local = Business.Do <ISystemPara>()["Picture_Watermark_Local"].String; FileTo.OverlayImage(fuLoad.File.Server.FileFullName, imgFile, local, opacity); } // imgShow.Src = fuLoad.File.Server.VirtualPath; } catch (Exception ex) { Message.ExceptionShow(ex); } }
/// <summary> /// 上传图片文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpFile_Click(object sender, EventArgs e) { try { if (fuLoad.PostedFile.FileName == "") { return; } //新增图片对象 Song.Entities.Picture mm = new Song.Entities.Picture(); fuLoad.UpPath = type; fuLoad.IsMakeSmall = true; fuLoad.IsConvertJpg = true; //缩略图宽高 int tw = Business.Do <ISystemPara>()["Product_ThumbnailWidth"].Int32 ?? 100; int th = Business.Do <ISystemPara>()["Product_ThumbnailHeight"].Int32 ?? 100; fuLoad.SmallHeight = th; fuLoad.SmallWidth = tw; fuLoad.SaveAndDeleteOld(mm.Pic_FilePath); // mm.Pic_FilePath = fuLoad.File.Server.FileName; mm.Pic_FilePathSmall = fuLoad.File.Server.SmallFileName; mm.Pic_Size = (int)fuLoad.File.Server.Size; mm.Pic_Width = fuLoad.File.Server.Width; mm.Pic_Height = fuLoad.File.Server.Height; //是否强制尺寸 bool isCompel = Business.Do <ISystemPara>()["Product_IsCompelSize"].Boolean ?? false; int cw = Business.Do <ISystemPara>()["Product_CompelWidth"].Int32 ?? 0; int ch = Business.Do <ISystemPara>()["Product_CompelHeight"].Int32 ?? 0; if (isCompel) { FileTo.Zoom(fuLoad.File.Server.FileFullName, cw, ch); } // mm.Pic_Uid = getUID(); mm.Pic_Type = type; // Business.Do <IContents>().PictureAdd(mm); PictureBindData(null, null); } catch (Exception ex) { Message.ExceptionShow(ex); } }
public void CanDoAction(string action, string bodyType) { string randomFileName = $"{Guid.NewGuid().ToString("N")}.txt"; FileTo fileTo = this.Setup(action, randomFileName); Dictionary <string, string> routableHeaders = new Dictionary <string, string>() { { "FullSource", $"test/{randomFileName}" }, { "SourceFile", randomFileName } }; Core.Entities.Routable routable = new Core.Entities.Routable(routableHeaders, System.Text.Encoding.UTF8.GetBytes("test file")); routable.SetBody <Byte[]>(System.Text.Encoding.UTF8.GetBytes("Test")); if (bodyType == "String") { routable.SetBody <string>("Test"); } fileTo.Process(routable); Assert.IsTrue(System.IO.File.Exists($"{this.fileLocation}/target/{randomFileName}")); }
/// <summary> /// 根据控制器构建静态页面 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public SharedResultVM Html <T>() where T : Controller { var vm = new SharedResultVM(); try { //访问前缀 var urlPrefix = $"{Context.Request.Scheme}://{Context.Request.Host}/home/"; //保存目录 var savePath = GlobalTo.WebRootPath + "/"; //反射action var type = typeof(T); var methods = type.GetMethods().Where(x => x.DeclaringType == type).ToList(); vm.Log.Add($"Build Count:{methods.Count}"); var cbs = new ConcurrentBag <string>(); //并行请求 Parallel.ForEach(methods, mh => { Console.WriteLine(mh.Name); cbs.Add(mh.Name); string html = HttpTo.Get(urlPrefix + mh.Name); FileTo.WriteText(html, savePath + mh.Name.ToLower() + ".html", false); }); vm.Log.AddRange(cbs); Console.WriteLine("\nDone!\n"); vm.Set(SharedEnum.RTag.success); } catch (Exception ex) { vm.Set(ex); } return(vm); }
/// <summary> /// 验证 /// </summary> /// <returns></returns> public IActionResult Verify() { var vm = new ActionResultVM(); var id = RouteData.Values["id"]?.ToString().ToUpper(); if (!string.IsNullOrWhiteSpace(id)) { var uinfo = new UserAuthAid(HttpContext).Get(); switch (id.ToLower()) { //发送验证邮箱 case "send": { if (User.Identity.IsAuthenticated) { using var db = new ContextBase(); var usermo = db.UserInfo.Find(uinfo.UserId); if (usermo.UserMailValid == 1) { vm.msg = "邮箱已经完成验证"; } else if (string.IsNullOrWhiteSpace(usermo.UserMail)) { vm.msg = "邮箱不能为空"; } else { var cacheKey = "Global_VerifyMail_" + usermo.UserMail; var issend = CacheTo.Get(cacheKey) as bool?; if (issend == true) { vm.msg = "1分钟内只能发送一次验证信息"; } else { var tml = FileTo.ReadText(GlobalTo.WebRootPath + "/lib/mailchecker/", "list.txt"); if (tml.Contains(usermo.UserMail.Split('@').LastOrDefault())) { vm.msg = "该邮箱已被屏蔽"; } else { //发送验证 var ToMail = usermo.UserMail; var vjson = new { mail = ToMail, ts = DateTime.Now.ToTimestamp() }.ToJson(); var vcode = CalcTo.EnDES(vjson, GlobalTo.GetValue("VerifyCode:Key")).ToLower(); var VerifyLink = string.Format(GlobalTo.GetValue("VerifyCode:Url"), vcode); var txt = FileTo.ReadText(GlobalTo.WebRootPath + "/template/", "sendmailverify.html"); txt = txt.Replace("@ToMail@", ToMail).Replace("@VerifyLink@", VerifyLink); vm = MailAid.Send(ToMail, "验证你的邮箱", txt); if (vm.code == 200) { vm.msg = "已发送成功"; CacheTo.Set(cacheKey, true, 60, false); } } } } } else { vm.msg = "请登录"; } } break; //验证邮箱 default: try { var vjson = CalcTo.DeDES(id, GlobalTo.GetValue("VerifyCode:Key")).ToJObject(); if (DateTime.Now.ToTimestamp() - Convert.ToInt32(vjson["ts"]) < 60 * 5) { var mail = vjson["mail"].ToString(); if (string.IsNullOrWhiteSpace(mail)) { vm.msg = "邮件地址有误"; } else { using var db = new ContextBase(); var usermo = db.UserInfo.FirstOrDefault(x => x.UserMail == mail); if (usermo != null) { if (usermo.UserMailValid == 1) { vm.msg = "已验证,勿重复验证"; } else { usermo.UserMailValid = 1; db.UserInfo.Update(usermo); int num = db.SaveChanges(); vm.Set(num > 0); if (vm.code == 200) { vm.msg = "恭喜你,验证成功"; } } } else { vm.msg = "邮件地址无效"; } } } else { vm.msg = "链接已过期(5分钟内有效)"; } } catch (Exception) { vm.msg = "链接已失效"; } break; } } else { vm.msg = "缺失验证码信息"; } return(View(vm)); }