public IHttpActionResult DeleteFile(int siteId, int formId) { try { var request = Context.AuthenticatedRequest; var fieldId = request.GetQueryInt("fieldId"); var uploadToken = request.GetQueryString("uploadToken"); var cacheKey = GetUploadTokenCacheKey(formId); var cacheList = CacheUtils.Get <List <string> >(cacheKey) ?? new List <string>(); if (!cacheList.Contains(uploadToken)) { return(Unauthorized()); } var fieldInfo = FieldManager.GetFieldInfo(formId, fieldId); if (fieldInfo.FieldType != InputType.Image.Value) { return(Unauthorized()); } return(Ok(new { Value = string.Empty, FieldId = fieldId })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static SessionalUser GetUser(this ISession sess) { string cacheKey = GetUserCacheKey(sess); SessionalUser r = CacheUtils.Get <SessionalUser>(cacheKey); if (null != r) { return(r); } string s = sess.GetString(_userIdKey); if (String.IsNullOrEmpty(s)) { return(null); } var setting = new JsonSerializerSettings(); setting.PreserveReferencesHandling = PreserveReferencesHandling.Objects; setting.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; r = JsonConvert.DeserializeObject <SessionalUser>(s, setting); if (null == r || r.Id <= 0) { return(null); } CacheUtils.Set(cacheKey, r); return(r); }
public static string GetTemplateHtml(string theme) { var htmlPath = Main.Instance.PluginApi.GetPluginPath($"themes/{theme}/template.html"); var themeUrl = Main.Instance.PluginApi.GetPluginUrl($"themes/{theme}"); var html = CacheUtils.Get <string>(htmlPath); if (html != null) { return(html); } html = Utils.ReadText(htmlPath); var startIndex = html.IndexOf("<!-- template start -->", StringComparison.Ordinal) + "<!-- template start -->".Length; var length = html.IndexOf("<!-- template end -->", StringComparison.Ordinal) - startIndex; html = html.Substring(startIndex, length); html = $@" <link rel=""stylesheet"" type=""text/css"" href=""{themeUrl}/style.css"" /> {html}"; CacheUtils.InsertHours(htmlPath, html, 3); return(html); }
public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } PageUtils.CheckRequestParameter("siteId"); if (IsPostBack) { return; } VerifySitePermissions(ConfigManager.WebSitePermissions.Template); TemplateTypeUtils.AddListItems(DdlTemplateType); ChannelManager.AddListItems(DdlChannelId.Items, SiteInfo, false, true, AuthRequest.AdminPermissionsImpl); if (AuthRequest.IsQueryExists("fromCache")) { TbTemplate.Text = TranslateUtils.DecryptStringBySecretKey(CacheUtils.Get <string>("SiteServer.BackgroundPages.Cms.PageTemplatePreview")); } if (AuthRequest.IsQueryExists("returnUrl")) { BtnReturn.Visible = true; } }
/// <summary> /// 获取计算机的硬盘序列号 /// </summary> /// <returns>计算机的硬盘序列号</returns> public static string GetColumnSerialNumber() { var columnSerialNumber = CacheUtils.Get("ComputerUtils_ColumnSerialNumber") as String; if (string.IsNullOrEmpty(columnSerialNumber)) { columnSerialNumber = string.Empty; try { var mcHD = new ManagementClass("win32_logicaldisk"); var mocHD = mcHD.GetInstances(); foreach (ManagementObject m in mocHD) { if (m["DeviceID"].ToString() == "C:") { columnSerialNumber = m["VolumeSerialNumber"].ToString(); break; } } } catch {} columnSerialNumber = columnSerialNumber.Replace(":", ""); CacheUtils.Max("ComputerUtils_ColumnSerialNumber", columnSerialNumber); } return(columnSerialNumber); }
public static object RegisterWithCode(IRequest request) { var mobile = request.GetPostString("mobile"); var password = request.GetPostString("password"); var code = request.GetPostString("code"); var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile)); var isRegister = false; string errorMessage; if (code != dbCode) { errorMessage = "短信验证码不正确"; } else { var userInfo = Main.Instance.UserApi.NewInstance(); userInfo.UserName = mobile; userInfo.Mobile = mobile; isRegister = Main.Instance.UserApi.Insert(userInfo, password, out errorMessage); } return(new { IsRegister = isRegister, ErrorMessage = errorMessage }); }
/// <summary> /// 获取计算机的网卡地址,并将网卡地址中的分隔符“:”除去 /// </summary> /// <returns>计算机的网卡地址</returns> public static string GetMacAddress() { var macAddress = CacheUtils.Get("ComputerUtils_MacAddress") as String; if (string.IsNullOrEmpty(macAddress)) { macAddress = string.Empty; try { var mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration"); var mocMAC = mcMAC.GetInstances(); foreach (ManagementObject m in mocMAC) { if ((bool)m["IPEnabled"]) { macAddress = m["MacAddress"].ToString(); break; } } } catch {} macAddress = macAddress.Replace(":", ""); CacheUtils.Max("ComputerUtils_MacAddress", macAddress); } return(macAddress); }
private void RptContents_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) { return; } var key = (string)e.Item.DataItem; var value = CacheUtils.Get(key); if (value == null) { return; } var valueType = value.GetType().FullName; var ltlKey = (Literal)e.Item.FindControl("ltlKey"); var ltlValue = (Literal)e.Item.FindControl("ltlValue"); ltlKey.Text = key; if (valueType == "System.String") { ltlValue.Text = $"string, length:{value.ToString().Length}"; } else if (valueType == "System.Int32") { ltlValue.Text = value.ToString(); } else { ltlValue.Text = valueType; } }
public static object IsCodeCorrect(IRequest request) { var mobile = request.GetPostString("mobile"); var code = request.GetPostString("code"); var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile)); var isCorrect = code == dbCode; var token = string.Empty; if (isCorrect) { var userInfo = Main.Instance.UserApi.GetUserInfoByMobile(mobile); if (userInfo != null) { token = request.GetUserTokenByUserName(userInfo.UserName); } } return(new { IsCorrect = isCorrect, Token = token }); }
public static object IsCodeCorrect(IRequest request) { var mobile = request.GetPostString("mobile"); var code = request.GetPostString("code"); var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile)); var isCorrect = code == dbCode; var token = string.Empty; if (isCorrect) { var userInfo = Context.UserApi.GetUserInfoByMobile(mobile); if (userInfo != null) { token = Context.UserApi.GetAccessToken(userInfo.Id, userInfo.UserName, DateTime.Now.AddDays(7)); } } return(new { IsCorrect = isCorrect, Token = token }); }
public IHttpActionResult IsCodeCorrect() { try { var request = Context.GetCurrentRequest(); var mobile = request.GetPostString("mobile"); var code = request.GetPostString("code"); var dbCode = CacheUtils.Get <string>(GetSendSmsCacheKey(mobile)); var isCorrect = code == dbCode; var token = string.Empty; if (isCorrect) { var userInfo = Context.UserApi.GetUserInfoByMobile(mobile); if (userInfo != null) { token = Context.UserApi.GetAccessToken(userInfo.Id, userInfo.UserName, DateTime.Now.AddDays(7)); } } return(Ok(new { Value = isCorrect, Token = token })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static List <KeyValuePair <int, SiteInfo> > GetSiteInfoKeyValuePairList() { var retval = CacheUtils.Get <List <KeyValuePair <int, SiteInfo> > >(CacheKey); if (retval != null) { return(retval); } lock (LockObject) { retval = CacheUtils.Get <List <KeyValuePair <int, SiteInfo> > >(CacheKey); if (retval == null) { var list = DataProvider.SiteDao.GetSiteInfoKeyValuePairList(); retval = new List <KeyValuePair <int, SiteInfo> >(); foreach (var pair in list) { var siteInfo = pair.Value; if (siteInfo == null) { continue; } siteInfo.SiteDir = GetSiteDir(list, siteInfo); retval.Add(pair); } CacheUtils.Insert(CacheKey, retval); } } return(retval); }
public static Dictionary <int, Tuple <string, string> > AllHtmlBlocks() { return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => { return new SpecialistWebDataContext().HtmlBlocks .Select(x => new { x.Id, x.Name, x.Description }).ToList() .ToDictionary(x => x.Id, x => Tuple.Create(x.Name, x.Description)); }, 24)); }
public List <Announce> GetAllForMainCached() { return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => { var groups = GroupVMService.GetAllForMain(); return GetAnnounces(groups.AsQueryable()).ToList(); } )); }
public List <int> AllTestSections() { return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => { var relations = TestService.GetTestSectionRelations(); return relations.Where(x => x.Object.IsActive).Select(x => x.RelationObject_ID).Distinct().ToList() .Cast <int>().ToList(); }, 24)); }
public Dictionary <string, PageMeta> GetAllPageMetas() { return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => { using (var context = new SpecialistWebDataContext()) { return context.PageMetas.ToDictionary(x => x.Url.ToLower(), x => x); } })); }
public ActionResult SiteMap() { HttpContext.Response.AddHeader("Last-modified", DateTime.Now.ToUniversalTime().ToString("r")); var siteMap = CacheUtils.Get(MethodBase.GetCurrentMethod(), () => XmlResult.ToStringWithDeclaration(new SiteMapGenerator().Get(Url))); return(new XmlResult(siteMap)); }
public List <string> TrainersWithoutGroup() { return(CacheUtils.Get(MethodBase.GetCurrentMethod(), () => { var visibleEmployees = GetAll().Where(x => x.SiteVisible).Select(x => x.Employee_TC).ToList(); var trainerWithGroup = GroupService.GetAll().Where(x => x.DateBeg > DateTime.Now.AddDays(-30) && (x.Color_TC == Colors.Pink || x.Color_TC == Colors.Yellow)).Select(x => x.Teacher_TC).Distinct() .ToList().AddFluent(Employees.TrainersAlwaysVisible); return visibleEmployees.Except(trainerWithGroup).ToList(); }, 24)); }
private static Dictionary <int, Dictionary <int, SpecialInfo> > GetCacheDictionary() { if (CacheUtils.Get(CacheKey) is Dictionary <int, Dictionary <int, SpecialInfo> > dictionary) { return(dictionary); } dictionary = new Dictionary <int, Dictionary <int, SpecialInfo> >(); CacheUtils.InsertHours(CacheKey, dictionary, 24); return(dictionary); }
public static bool IsIpAddressCached(string ipAddress) { if (ConfigManager.SystemConfigInfo.UserRegistrationMinMinutes == 0 || string.IsNullOrEmpty(ipAddress)) { return(true); } var obj = CacheUtils.Get($"SiteServer.CMS.Provider.UserDao.Insert.IpAddress.{ipAddress}"); return(obj == null); }
public IHttpActionResult UploadFile(int siteId, int formId) { try { var request = Context.AuthenticatedRequest; var fieldId = request.GetQueryInt("fieldId"); var uploadToken = request.GetQueryString("uploadToken"); var cacheKey = GetUploadTokenCacheKey(formId); var cacheList = CacheUtils.Get <List <string> >(cacheKey) ?? new List <string>(); if (!cacheList.Contains(uploadToken)) { return(Unauthorized()); } var fieldInfo = FieldManager.GetFieldInfo(formId, fieldId); if (fieldInfo.FieldType != InputType.Image.Value) { return(Unauthorized()); } var imageUrl = string.Empty; foreach (string name in HttpContext.Current.Request.Files) { var postFile = HttpContext.Current.Request.Files[name]; if (postFile == null) { return(BadRequest("Could not read image from body")); } var filePath = Context.SiteApi.GetUploadFilePath(siteId, postFile.FileName); if (!FormUtils.IsImage(Path.GetExtension(filePath))) { return(BadRequest("image file extension is not correct")); } postFile.SaveAs(filePath); imageUrl = Context.SiteApi.GetSiteUrlByFilePath(filePath); } return(Ok(new { Value = imageUrl, FieldId = fieldId })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static IList <DictsInfo> GetCacheDictsList() { IList <DictsInfo> list = (IList <DictsInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetDicts"); if (list == null) { list = BizBase.dbo.GetList <DictsInfo>(" SELECT * FROM sys_Dicts "); CacheUtils.Insert("JsonLeeCMS_CacheForGetDicts", list); } return(list); }
public static Hashtable GetHashtable() { var ht = CacheUtils.Get(CacheKey) as Hashtable; if (ht == null) { ht = new Hashtable(); CacheUtils.Insert(CacheKey, ht, null, CacheUtils.SecondFactorCalculate(15)); } return(ht); }
public static VerInfo GetVer() { VerInfo verInfo = (VerInfo)CacheUtils.Get("JsonLeeCMS_CacheForVER"); if (verInfo == null) { verInfo = Ver.GetData(); CacheUtils.Insert("JsonLeeCMS_CacheForVER", verInfo, 60, 1); } return(verInfo); }
public IActionResult Index() { /* * net core不自带httpcontext 需要在 Startup 注入 * 1、在ConfigureServices 中 services.AddStaticHttpContext(); * 2、在Configure 中 app.UseStaticHttpContext(); */ var builder = new StringBuilder("测试如下:\r\n"); //Post builder.Append($"Post值:{WebUtils.GetFormVal<string>("a")}\r\n"); //IP builder.Append($"IP:{IPUtils.GetIP()}\r\n"); //WebUtils builder.Append($"pid:{WebUtils.GetQueryVal<int>("pid")}\r\n"); //?pid=1 builder.Append($"date:{WebUtils.GetQueryVal<DateTime>("date", new DateTime(1900, 1, 1))}\r\n"); //?date=2020-12-31 //全url builder.Append($"全URL:{WebUtils.GetAbsoluteUri()}\r\n"); //CacheUtils 缓存 DateTime dateTime = DateTime.Now; var cache = new CacheUtils(); var cacheDT = DateTime.Now; if (cache.ContainKey("time")) { cacheDT = cache.Get <DateTime>("time"); } else { cache.Insert <DateTime>("time", dateTime, 3600); } builder.Append($"当前时间:{dateTime.ToFormatString()} \r\n"); builder.Append($"缓存时间:{cacheDT.ToFormatString()} \r\n"); //当前网站目录 builder.Append($"当前网站目录:{SystemUtils.GetMapPath()} \r\n"); builder.Append($"upload目录:{SystemUtils.GetMapPath("/upload")} \r\n"); //cookie CookieUtils.SetCookie("username", "jsonlee"); builder.Append($"username cookie: {CookieUtils.GetCookie("username")} \r\n"); //session SessionUtils.SetSession("username", System.Web.HttpUtility.UrlEncode("刘备")); builder.Append($"username session: {System.Web.HttpUtility.UrlDecode(SessionUtils.GetSession("username"))} \r\n"); return(Content(builder.ToString())); }
private static Dictionary <int, Dictionary <int, TemplateInfo> > GetCacheDictionary() { var dictionary = CacheUtils.Get(CacheKey) as Dictionary <int, Dictionary <int, TemplateInfo> >; if (dictionary == null) { dictionary = new Dictionary <int, Dictionary <int, TemplateInfo> >(); CacheUtils.InsertHours(CacheKey, dictionary, 24); } return(dictionary); }
public static IList <CatalogInfo> GetCacheCatalogList() { IList <CatalogInfo> list = (IList <CatalogInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetCMSCatalog"); if (list == null) { list = BizBase.dbo.GetList <CatalogInfo>(" SELECT * FROM sys_Catalog ORDER BY Sort ASC,AutoID desc "); CacheUtils.Insert("JsonLeeCMS_CacheForGetCMSCatalog", list); } return(list); }
public static IList <ContModelInfo> GetCacheModelList() { IList <ContModelInfo> list = (IList <ContModelInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetContModel"); if (list == null) { list = BizBase.dbo.GetList <ContModelInfo>(" SELECT * FROM cms_ContModel Order by Sort asc, AutoID desc "); CacheUtils.Insert("JsonLeeCMS_CacheForGetContModel", list); } return(list); }
public static IList <SettingCategoryInfo> GetCacheSettingCategoryList() { IList <SettingCategoryInfo> list = (IList <SettingCategoryInfo>)CacheUtils.Get("JsonLeeCMS_CacheForGetSettingCategory"); if (list == null) { list = BizBase.dbo.GetList <SettingCategoryInfo>(" select * from sys_SettingCategory order by sort asc "); CacheUtils.Insert("JsonLeeCMS_CacheForGetSettingCategory", list); } return(list); }
public static IList <ProductModelInfo> GetCacheModelList() { IList <ProductModelInfo> list = (IList <ProductModelInfo>)CacheUtils.Get("JsonLeeCMS_CacheForPROMODEL"); if (list == null) { list = ProductModel.GetAllList(); CacheUtils.Insert("JsonLeeCMS_CacheForPROMODEL", list); } return(list); }