/// <summary> /// 根据模板Id 和 doc 获得标题和内容 /// </summary> public static bool ResolverTemplate(string channel, string templateId, Dictionary <string, object> param, out string title, out string content, out string category) { title = content = category = string.Empty; DictSchema schema = (from q in DictSchema.CreateContext(true) where q.Type == "msg" && q.Name == "template" && q.Title == templateId select q).FirstOrDefault(); if (schema == null) { LogManager.GetLogger <NoticeFactory>().ErrorFormat("指定的模板:{0} 不存在。", templateId); return(false); } category = schema.Category; ITemplateEngine te = ServiceLocator.Instance.Resolve <ITemplateEngine>(); using (StringWriter sw = new StringWriter()) { string template = schema[channel + "_title"]; if (string.IsNullOrEmpty(template)) { template = schema["default_title"]; } if (string.IsNullOrWhiteSpace(template)) { title = string.Empty; } else { te.Process(param, string.Empty, sw, template); title = sw.GetStringBuilder().ToString(); } } using (StringWriter sw = new StringWriter()) { string template = schema[channel + "_content"]; if (string.IsNullOrEmpty(template)) { template = schema["default_content"]; } if (string.IsNullOrWhiteSpace(template)) { content = string.Empty; } else { te.Process(param, string.Empty, sw, template); content = sw.GetStringBuilder().ToString(); } } return(true); }
object save(string userId, string userName, string displayName, string mobile, string email, string permission) { #region 校验数据 var site = (Site)jc["site"]; if (string.IsNullOrWhiteSpace(userName)) { return new { code = -1, msg = "用户名不能为空" } } ; if (string.IsNullOrWhiteSpace(displayName)) { return new { code = -2, msg = "显示名称不能为空" } } ; userName = userName.Trim(); displayName = displayName.Trim(); mobile = string.IsNullOrWhiteSpace(mobile) ? string.Empty : mobile.Trim(); email = string.IsNullOrWhiteSpace(email) ? string.Empty : email.Trim(); if (userName.Length > 50) { return new { code = -3, msg = "用户名字符不能超过50" } } ; if (displayName.Length > 50) { return new { code = -4, msg = "显示名字符符不能超过50" } } ; if (!Regex.IsMatch(userName, "^[a-zA-Z0-9_]+$")) { return new { code = -5, msg = "用户名只能是 英文/数字/下划线 组成" } } ; #endregion using (ILinqContext <User> cx = User.CreateContext()) using (ILinqContext <SiteUsers> cx_relation = SiteUsers.CreateContext()) { #region 构造用户信息 User user = User.Get(cx, userId); if (user == null) { if (User.Where("UserName = {0}", userName).Count() > 0) { return new { code = -6, msg = "指定的用户名已经存在,请更换其他用户名" } } ; user = new User(); user.Id = StringUtil.UniqueId(); user.OrgId = "org"; user.DateCreate = DateTime.Now; user.IsValid = true; user.DateLastVisit = DateTime.Now; user.UserName = userName; //update password user.UpdatePassword("111111"); DictSchema schema = DictSchema.GetByName("users", "config"); if (schema != null && schema["first_login_resetpwd"] != null && schema["first_login_resetpwd"].ToBoolean()) { user["needmodifyPwd"] = true.ToString(); } cx.Add(user, true); } user.DisplayName = displayName; user.Mobile = mobile; user.Email = email; #endregion #region 构造站点用户关系数据 var relation = (from q in cx_relation where q.SiteId == site.Id && q.UserId == user.Id select q).FirstOrDefault(); if (relation == null) { relation = new SiteUsers(); relation.Id = StringUtil.UniqueId(); relation.SiteId = site.Id; relation.DateCreated = DateTime.Now; relation.UserId = user.Id; cx_relation.Add(relation, true); } relation.PermissionLevel = StringEnum <PermissionLevel> .SafeParse(permission); #endregion cx.SubmitChanges(); cx_relation.SubmitChanges(); } return(new { code = 1, msg = "用户添加成功" }); }
private void Refresh() { lock (_synclock) { if (HttpContext.Current.Cache[kCACHE_KEY] == null) { qc_dict.Clear(); List <string> filenames = new List <string>(); foreach (IArea site in ServiceLocator.Instance.Resolve <IHost>().AllAreas) { string dir; string filename; List <string> files = new List <string>(); if (site.AreaKey == AreaConfig.Instance.AreaKey)// default site { dir = ServerUtil.MapPath("~/App_Data"); } else { dir = ServerUtil.MapPath(site.VirtualPath); } filename = Path.Combine(dir, "query.config"); if (!Directory.Exists(dir)) { continue; } if (File.Exists(filename)) { files.Add(filename); } // add filename like "query.post.config" files.AddRange(Directory.GetFiles(dir, "query.*.config", SearchOption.TopDirectoryOnly)); filenames.AddRange(files); // prase xml foreach (var item in files) { _logger.Debug("begin parse query file: {0}.", item); XmlDocument doc = new XmlDocument(); doc.Load(item); foreach (XmlNode node in doc.DocumentElement.SelectNodes("//query")) { string id = XmlUtil.GetStringAttribute(node, "id", string.Empty); if (string.IsNullOrEmpty(id)) { continue; } id = string.Format(FORMAT, site.AreaKey, id.ToLower()); _logger.Debug("RESULT: query id:{0}", id); Qc qc = new Qc() { Id = id, Field = XmlUtil.GetStringAttribute(node, "field", string.Empty), AllowedOrderbyColumns = XmlUtil.GetStringAttribute(node, "allowedOrderbyColumns", string.Empty), Orderby = XmlUtil.GetStringAttribute(node, "orderby", string.Empty), Where = node.InnerText.Trim(), PageSize = XmlUtil.GetIntAttribute(node, "pageSize", -1) }; if (string.IsNullOrEmpty(qc.Field)) { // 如果field是设置在单独的节点 XmlNode n = node.SelectSingleNode("field"); if (n != null) { qc.Field = n.InnerText.Trim(); n = node.SelectSingleNode("where"); if (n != null) { qc.Where = n.InnerText.Trim(); } } } qc_dict[id] = qc; foreach (XmlAttribute attr in node.Attributes) { qc_dict[id][attr.Name] = attr.Value; } } _logger.Debug("end parse query file: {0}.", item); } } // load from database foreach (var item in (from q in DictSchema.CreateContext() where q.Type == "dynamic_query" && q.IsValid == true select q).ToList()) { if (string.IsNullOrEmpty(item.Name)) { continue; } string id = string.Format(FORMAT, string.IsNullOrEmpty(item.ParentId) ? "default" : item.ParentId, item.Name.ToLowerInvariant()); var qc = qc_dict[id] = new Qc() { Id = id, Field = item.Prop1, AllowedOrderbyColumns = item.Prop2, Orderby = item.Prop3, Where = item.Prop4, PageSize = item.Prop5.ToInt(-1) }; foreach (string key in item.ExtAttrs.Keys) { qc[key] = item[key]; } } CacheDependency fileDependency = new CacheDependency(filenames.ToArray()); HttpContext.Current.Cache.Insert(kCACHE_KEY, "dummyValue", fileDependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.High, null); } } }