コード例 #1
0
        /// <summary>
        /// 根据配置生成对应的文件 表单生成
        /// </summary>
        /// <param name="config"></param>
        public static void generateForm(GenerateFormConfig_Model config)
        {
            //2.获取html
            //2.1根据配置拆分
            var list_afterChunk = config.columns.Chunk(config.columnsInRowNumber);
            //2.2声明行数据容器
            List <List <FormElement> > list = new List <List <FormElement> >();

            foreach (var info in list_afterChunk)
            {
                List <FormElement> row_temp = new List <FormElement>();
                //遍历当前行
                foreach (var item_info in info)
                {
                    row_temp.Add(new generateHelp().generateHtmlByType(item_info));//取列
                }
                //生成行html
                list.Add(row_temp);
            }
            //3.渲染razor模板
            string templatePath = FileSugar.MergeUrl(globalProperty.templateDic, "formElement", "form.cshtml");
            var    tempCode     = RazorEngineExtension.RazorPars(templatePath, FileSugar.FileToString(templatePath), new { FormElementTable = list });

            //4.将生成的form字符串写入html文件
            FileSugar.WriteFile($"../../html/{config.tableName}.html", tempCode);
        }
コード例 #2
0
        public string GetControlEvent(int elementId = 0, bool isSingle = false)
        {
            //获取件动作
            var eventActionTypeList = PubUiEngineGet.GetEventActionConfigList;
            var model = EventManager.GetInstance.GetEeventList.FindAll(it => it.Name.IsIn("getValue", "setValue").IsFalse());

            foreach (var it in model)
            {
                it.ActionTypeList = eventActionTypeList;
            }
            var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEditorDir, "event.cshtml");

            if (isSingle == true)
            {
                cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEditorDir, "eventSingle.cshtml");
            }
            var html = FileSugar.FileToString(cshtmlPath);

            if (elementId > 0)
            {
                var events = _db.Queryable <SysBest_ElementEvent>().Where(it => it.ElementId == elementId).ToList();
                var reval  = RazorEngineExtension.RazorPars(cshtmlPath, html, new { Key = model, Value = events });
                return(reval);
            }
            else
            {
                var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, new { Key = model, Value = new List <SysBest_ElementEvent>() });
                return(reval);
            }
        }
コード例 #3
0
        /// <summary>
        /// 获取事件HTML
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public string GetEventActionHtml(string name, List <EventActionTypeParas> pars, string id)
        {
            var path   = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEventActionDir, name + ".cshtml");
            var cshtml = FileSugar.FileToString(path);
            var reval  = RazorEngineExtension.RazorPars(path, cshtml, new { Data = pars, id = id });

            return(reval);
        }
コード例 #4
0
        public string GetTemplateCodeByName(string tempName, object model)
        {
            string dir      = FileSugar.MergeUrl(_uiEngineDir, "buildCode");
            string filePath = FileSugar.MergeUrl(dir, tempName);
            var    tempCode = RazorEngineExtension.RazorPars(filePath, FileSugar.FileToString(filePath), model);

            return(tempCode);
        }
コード例 #5
0
        /// <summary>
        /// 发送邮件通知
        /// </summary>
        /// <param name="isLogin"></param>
        /// <param name="_userInfo"></param>
        /// <param name="tid"></param>
        /// <param name="p"></param>
        /// <param name="db"></param>
        internal void SendMail(UserInfo currentUser, int tid, BBS_Posts p, SqlSugarClient db)
        {
            //未配置邮箱不发送
            if (PubGet.GetEmailUserName.IsNullOrEmpty())
            {
                return;
            }
            var topic     = db.Queryable <BBS_Topics>().Single(it => it.Tid == tid);
            var isOneUser = currentUser.Id == topic.Posterid;
            var html      = FileSugar.FileToString(FileSugar.GetMapPath("~/Template/mail/Replies.html")).Replace('\r', ' ').Replace('\n', ' ');
            var oldHtml   = html;

            //发贴和回贴不是同一个人
            if (isOneUser.IsFalse())
            {
                var toUser = db.Queryable <UserInfo>().Single(it => it.Id == topic.Posterid);
                if (toUser.Email.IsEamil())
                {
                    string   toUserName   = toUser.NickName;
                    string   fromUserName = currentUser.NickName;
                    string   toMail       = toUser.Email;
                    MailSmtp ms           = new MailSmtp(PubGet.GetEmailSmtp, PubGet.GetEmailUserName, PubGet.GetEmailPassword);
                    string   url          = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid);
                    html = html.ToFormat(toUserName, fromUserName, topic.Title, DateTime.Now, url);
                    var title = PubMethod.RemoveAllSpace(fromUserName + "回复了:" + StringSugar.ToCutString(topic.Title, 10, "..."));
                    ms.Send(PubGet.GetEmailUserName, PubConst.SiteMailUserName, toMail, title, html);
                    System.Threading.Thread.Sleep(100);
                }
            }
            html = oldHtml;
            //处理@
            if (p.Message.IsValuable() && p.Message.Contains("@"))
            {
                var adUserIds  = db.Queryable <BBS_Posts>().Where(it => it.Tid == tid && it.Parentid > 0).Select(it => it.Posterid).ToList();
                var adUsers    = db.Queryable <UserInfo>().In(adUserIds).ToList();
                var matchUsers = Regex.Matches(p.Message, @"\<span style\=""color:#4f99cf""\>@(.+?)\<\/span\>");
                if (matchUsers != null && matchUsers.Count > 0)
                {
                    var userNames = matchUsers.Cast <Match>().Select(it => it.Groups[1].Value).ToList();
                    adUsers = adUsers.Where(it => userNames.Contains(it.NickName)).ToList();
                    foreach (var item in adUsers)
                    {
                        if (item.Email.IsValuable() && item.Id != currentUser.Id)
                        {
                            string   toUserName   = item.NickName;
                            string   fromUserName = currentUser.NickName;
                            string   toMail       = item.Email;
                            MailSmtp ms           = new MailSmtp(PubGet.GetEmailSmtp, PubGet.GetEmailUserName, PubGet.GetEmailPassword);
                            string   url          = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid);
                            html = html.ToFormat(toUserName, fromUserName, p.Message, DateTime.Now, url);
                            var title = PubMethod.RemoveAllSpace(fromUserName + "在【" + topic.Title.TryToString().Trim() + "】@了你");
                            ms.Send(PubGet.GetEmailUserName, PubConst.SiteMailUserName, toMail, title, html);
                            System.Threading.Thread.Sleep(100);
                        }
                    }
                }
            }
        }
コード例 #6
0
        public JsonResult ActivateMailSend(string key, string userId, string mail)   //命名反的误导黑客
        {
            Check.Exception(mail.IsEamil().IsFalse(), "参数不合法");
            var userIdInt = EncryptSugar.GetInstance().Decrypto(key).ObjToInt();
            var date      = EncryptSugar.GetInstance().Decrypto(userId).ObjToDate();
            var model     = new ResultModel <string>();

            if (base.IsLogin == false)
            {
                model.ResultInfo = "登录超时请刷新页面重新登录";
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            var cm = CacheManager <DateTime> .GetInstance();

            string mailTimeKey = PubConst.SessionMailTime + key.ToLower();

            if (cm.ContainsKey(mailTimeKey))
            {
                var mins = (DateTime.Now - cm[mailTimeKey]).TotalSeconds;
                if (mins < 60)
                {
                    model.ResultInfo = "您刚才已经发送成功,如果还没有收到邮件,请等待{0}秒后重新发送。".ToFormat(Convert.ToUInt32(60 - mins));
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
            }
            _service.Command <HomeOutsourcing>((db, o) =>
            {
                var isAnyUser = db.Queryable <UserInfo>().Any(it => userIdInt == it.Id);
                var isOkDate  = ((DateTime.Now - date).TotalDays <= 3);
                var isAnyMail = db.Queryable <UserInfo>().Any(it => mail.ToLower() == it.Email);
                if (isAnyUser && isOkDate && isAnyMail.IsFalse())
                {
                    var html          = FileSugar.FileToString(FileSugar.GetMapPath("~/Template/mail/Validate.html")).Replace('\r', ' ').Replace('\n', ' ');
                    string userName   = _userInfo.NickName;
                    string aHtml      = "<a href=\"{0}\">{1}</a>".ToFormat(RequestInfo.HttpDomain + "" + Url.Action("ActivateMailSubmitSuccess", "UserCenter", new { key = key, userId = userId, mail }), "请点击这儿完成激活");
                    string dateString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    MailSmtp ms       = new MailSmtp(PubGet.GetEmailSmtp, PubGet.GetEmailUserName, PubGet.GetEmailPassword);
                    html = html.ToFormat(userName, aHtml, dateString);
                    ms.Send(PubGet.GetEmailUserName, PubConst.SiteMailUserName, mail, userName + "邮箱激活通知", html);
                    model.ResultInfo = "发送成功,请打开邮箱完成激活!";
                    string uniqueKey = PubGet.GetUserKey;
                    base.AddUpdateMailCache(uniqueKey);
                    model.IsSuccess = true;
                    Check.Exception(ms.Result.IsValuable(), "邮件激活失败!" + ms.Result);
                    cm.Add(mailTimeKey, DateTime.Now, cm.Minutes);
                }
                else if (isAnyMail)
                {
                    model.ResultInfo = "发送失败,该邮箱已经被激活,或已经存在。";
                }
                else
                {
                    model.ResultInfo = "发送失败";
                }
            });
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        //public void RestoreLayoutElement(string htmlId, string key, int addressId, int languageId)
        //{
        //    var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsDir, "layout", key + ".cshtml");
        //    var content = _.sysBest_PageContentService.GetSingle(it => it.LanguageId == languageId && it.AddressId == addressId);
        //    var elementList = _.sysBest_ElementService.GetElementListByHtmlIdArray(new string[] { htmlId });
        //    content.Html = GetRestoreHtml(content.Html, elementList, htmlId);
        //    _.sysBest_PageContentService.Update(content);
        //}

        /// <summary>
        /// 获取还原后的HTML
        /// </summary>
        /// <param name="html"></param>
        /// <param name="elementList"></param>
        /// <param name="htmlId"></param>
        /// <returns></returns>
        public string GetRestoreHtml(string html, List <SysBest_Element> elementList, string htmlId)
        {
            if (!elementList.Any(el => el.Html_Id == htmlId))
            {
                return(html);
            }
            //根据htmlID查对应的元素
            var ele = elementList.Single(el => el.Html_Id == htmlId);
            //正则匹配出对应的占位span标签
            var span = Regex.Match(html, @"\<span.{1,30}?data\-id\=""" + htmlId + @""".*?\<\/span\>").Value;
            //正则匹配出控件类型
            var categoryKey = Regex.Match(span, @"\<.*?data\-categorykey\=""(.+?)"".*?", RegexOptions.Singleline).Groups[1].Value;
            //正则匹配控件Key
            var key = Regex.Match(span, @"\<.*?data\-key\=""(.+?)"".*?").Groups[1].Value;
            var buildTemplatePath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsDir, categoryKey, "items", key, "build.cshtml");

            if (FileSugar.IsExistFile(buildTemplatePath))
            {
                BuildModel buildModel = new BuildModel();
                buildModel.elementId = ele.Id;
                buildModel.addressId = ele.AddressId;



                var attrs  = _db.Queryable <SysBest_ElementAttr>().Where(it => it.ElementId == ele.Id).ToList();
                var events = _db.Queryable <SysBest_ElementEvent>().Where(it => it.ElementId == ele.Id).ToList();
                buildModel.attrList = attrs.Select(attr => new KeyValuePair <string, string>(attr.Key, attr.Value)).ToDictionary(it => it.Key, it => it.Value);
                if (buildModel.attrList == null)
                {
                    buildModel.attrList = new Dictionary <string, string>();
                }
                buildModel.attrList.Add("name", ele.EleName);
                buildModel.eventList = new Dictionary <string, string>();
                foreach (var eve in events)
                {
                    List <EventActionTypeParas> pars = new List <EventActionTypeParas>();
                    if (eve.Pars.IsValuable())
                    {
                        pars = eve.Pars.JsonToModel <List <EventActionTypeParas> >();
                    }
                    string eveValue = GetEventActionHtml(eve.Value, pars, ele.EleName);
                    buildModel.eventList.Add(eve.Key, eveValue);
                }
                var cshtml = FileSugar.FileToString(buildTemplatePath);
                buildModel.api = GetApiUrlByElement(ele);
                string finallyThisIsMyParsedTemplate = "";

                finallyThisIsMyParsedTemplate = RazorEngineExtension.RazorPars(buildTemplatePath, cshtml, buildModel);

                var replaceHtml = finallyThisIsMyParsedTemplate;
                html = html.Replace(span, replaceHtml);
            }

            return(html);
        }
コード例 #8
0
        /// <summary>
        /// 开始生成表单
        /// </summary>
        public static void StartGenerateForm()
        {
            //1.解析配置
            string configPath = FileSugar.MergeUrl(System.Environment.CurrentDirectory, "generateFormConfig.json");
            //得到配置的json字符串
            string json = FileSugar.FileToString(configPath);
            List <GenerateFormConfig_Model> config = JsonConvert.DeserializeObject <List <GenerateFormConfig_Model> >(json);

            foreach (var item in config)
            {
                //根据配置生成表单
                generateForm(item);
            }
        }
コード例 #9
0
        //获取插入ueditor里面的HTML
        /// <summary>
        /// 获取插入ueditor里面的HTML
        /// </summary>
        /// <param name="key">控件的Key</param>
        /// <param name="categoryKey">控件类型的Key</param>
        /// <param name="hasSource"></param>
        /// <returns></returns>
        public string GetEditor(string key, string categoryKey, bool?hasSource)
        {
            //控件模板地址
            var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEditorDir, "template.cshtml");
            //控件图标地址
            var icon = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsWebDir, categoryKey, "items", key, "icon.png");
            //传给raozr的Model
            var model = new { categoryKey = categoryKey, key = key, icon = icon, hasSource = hasSource };
            //razor模板对应的文本
            var html = FileSugar.FileToString(cshtmlPath);
            //解析razor生成最终的文本
            var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, model);

            return(reval);
        }
コード例 #10
0
        public string GetControlAttribute(string key, string categoryKey, int elementId = 0)
        {
            var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsDir, categoryKey, "items", key, "attribute.cshtml");
            var html       = FileSugar.FileToString(cshtmlPath);

            if (elementId > 0)
            {
                var attrs = _db.Queryable <SysBest_ElementAttr>().Where(it => it.ElementId == elementId).ToList();
                var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, attrs);
                return(reval);
            }
            else
            {
                var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, new List <SysBest_ElementAttr>());
                return(reval);
            }
        }
コード例 #11
0
        /// <summary>
        /// 获取UI引擎控件信息
        /// </summary>
        /// <param name="item"></param>
        private ControlType GetControlType(string item)
        {
            ControlType   type = new ControlType();
            DirectoryInfo di   = new DirectoryInfo(item);

            type.key  = di.Name;
            type.icon = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsWebDir, type.key, "icon.png");
            string webTypeDir    = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsWebDir, type.key);
            string configPath    = FileSugar.MergeUrl(item, "config.json");
            string code          = FileSugar.FileToString(configPath);
            var    controlConfig = code.JsonToModel <ControlConfig>();

            type.controlConfig = controlConfig;
            string itemsPath = FileSugar.MergeUrl(item, "items");

            type.items = GetControlList(itemsPath, webTypeDir);
            return(type);
        }
コード例 #12
0
        private List <ControlItem> GetControlList(string itemsPath, string webTypeDir)
        {
            var reval           = new List <ControlItem>();
            var controlsDirList = FileSugar.GetDirectories(itemsPath);

            if (controlsDirList.IsValuable())
            {
                foreach (var item in controlsDirList)
                {
                    ControlItem   control = new ControlItem();
                    DirectoryInfo di      = new DirectoryInfo(item);
                    control.key  = di.Name;
                    control.icon = FileSugar.MergeUrl(webTypeDir, "items", control.key, "icon.png");
                    string configPath    = FileSugar.MergeUrl(itemsPath, control.key, "config.json");
                    string code          = FileSugar.FileToString(configPath);
                    var    controlConfig = code.JsonToModel <ControlConfig>();
                    control.controlConfig = controlConfig;
                    reval.Add(control);
                }
            }
            return(reval);
        }
コード例 #13
0
        public static string getParseString(string templatePath, object obj)
        {
            var tempCode = RazorEngineExtension.RazorPars(templatePath, FileSugar.FileToString(templatePath), obj);

            return(tempCode);
        }
コード例 #14
0
        /// <summary>
        /// 站内信
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="tid"></param>
        /// <param name="p"></param>
        /// <param name="db"></param>
        internal void SendPMS(UserInfo currentUser, int tid, BBS_Posts p, SqlSugarClient db)
        {
            var topic     = db.Queryable <BBS_Topics>().Single(it => it.Tid == tid);
            var isOneUser = currentUser.Id == topic.Posterid;
            var html      = FileSugar.FileToString(FileSugar.GetMapPath("~/Template/mail/PMS.html")).Replace('\r', ' ').Replace('\n', ' ');
            var oldHtml   = html;

            //发贴和回贴不是同一个人
            if (isOneUser.IsFalse())
            {
                var    toUser       = db.Queryable <UserInfo>().Single(it => it.Id == topic.Posterid);
                string toUserName   = toUser.NickName;
                string fromUserName = currentUser.NickName;
                string url          = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid);
                html = html.ToFormat(toUserName, fromUserName, topic.Title, url);
                var title = PubMethod.RemoveAllSpace(fromUserName + "回复了:" + StringSugar.ToCutString(topic.Title, 10, "..."));
                db.Insert <BBS_PMS>(new BBS_PMS()
                {
                    Message      = html,
                    Subject      = title,
                    Msgfrom      = fromUserName,
                    Msgfromid    = currentUser.Id,
                    Msgto        = toUserName,
                    Msgtoid      = toUser.Id,
                    New          = 1,
                    Postdatetime = DateTime.Now
                });
            }
            html = oldHtml;
            //处理@
            if (p.Message.IsValuable() && p.Message.Contains("@"))
            {
                var adUserIds  = db.Queryable <BBS_Posts>().Where(it => it.Tid == tid && it.Parentid > 0).Select(it => it.Posterid).ToList();
                var adUsers    = db.Queryable <UserInfo>().In(adUserIds).ToList();
                var matchUsers = Regex.Matches(p.Message, @"\<span style\=""color:#4f99cf""\>@(.+?)\<\/span\>");
                if (matchUsers != null && matchUsers.Count > 0)
                {
                    var userNames = matchUsers.Cast <Match>().Select(it => it.Groups[1].Value).ToList();
                    adUsers = adUsers.Where(it => userNames.Contains(it.NickName)).ToList();
                    foreach (var item in adUsers)
                    {
                        if (item.Email.IsValuable() && item.Id != currentUser.Id)
                        {
                            string toUserName   = item.NickName;
                            string fromUserName = currentUser.NickName;
                            string url          = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid);
                            html = html.ToFormat(toUserName, fromUserName, p.Message, url);
                            var title = PubMethod.RemoveAllSpace(fromUserName + "在【" + topic.Title.TryToString().Trim() + "】@了你");
                            db.Insert <BBS_PMS>(new BBS_PMS()
                            {
                                Message      = html,
                                Subject      = title,
                                Msgfrom      = fromUserName,
                                Msgfromid    = currentUser.Id,
                                Msgto        = toUserName,
                                Msgtoid      = item.Id,
                                New          = 1,
                                Postdatetime = DateTime.Now
                            });
                        }
                    }
                }
            }
        }