/// <summary> /// 切换系统语言 /// </summary> /// <returns></returns> public JsonResult SwitchLanguage(string currentLanguage) { var retModel = new JsonReturnModel(); try { if (currentLanguage == "English") { Userinfo.language = "Chinese"; } else { Userinfo.language = "English"; } MemoryCacheUtils.Clear(Userinfo.LoginName); CacheItemPolicy policy = new CacheItemPolicy(); policy.Priority = CacheItemPriority.NotRemovable; MemoryCacheUtils.Set(Userinfo.LoginName, Userinfo, policy); } catch (Exception ex) { retModel.AddError("errorMessage", ex.Message); } return(Json(retModel, JsonRequestBehavior.AllowGet)); }
public static List <AuthEntity> GetAllAuth() { var allAuth = MemoryCacheUtils.Get("GetAllAuth") as List <AuthEntity>; if (allAuth == null) { allAuth = AuthDA.GetAllAuth(); MemoryCacheUtils.Set("GetAllAuth", allAuth); } return(allAuth); }
/// <summary> /// 保存用户信息 /// </summary> public static void SaveUserInfoToCache(UserInfo user) { UserInfo accountEntities = MemoryCacheUtils.Get(user.LoginName) as UserInfo; if (accountEntities == null) { CacheItemPolicy policy = new CacheItemPolicy(); policy.Priority = CacheItemPriority.NotRemovable; MemoryCacheUtils.Set(user.LoginName, user, policy); } }
public static List <DepartmentEntity> GetAllDepartment() { var key = "GetAllDepartmentEntity"; var all = MemoryCacheUtils.Get(key) as List <DepartmentEntity>; if (all == null) { all = DepartmentDA.GetAllDepartment(); MemoryCacheUtils.Set(key, all); } return(all); }
public static List <AccountAuthEntity> GetAccountAuthByAccountId(int accountId) { var key = "GetAccountAuthByAccountId_" + accountId; var allAccountAuth = MemoryCacheUtils.Get(key) as List <AccountAuthEntity>; if (allAccountAuth == null) { allAccountAuth = AccountAuthDA.GetAccountAuthByAccountId(accountId); MemoryCacheUtils.Set(key, allAccountAuth); } return(allAccountAuth); }
/// <summary> /// 退出系统 /// </summary> /// <returns></returns> public ActionResult LogOut() { HttpCookie cookie = HttpContext.Request.Cookies["Passport.Token"]; if (cookie != null && !string.IsNullOrEmpty(cookie.Value)) { MemoryCacheUtils.Clear(cookie.Value); cookie.Expires = DateTime.Today.AddDays(-2); Response.Cookies.Add(cookie); Request.Cookies.Remove("Passport.Token"); } return(RedirectToAction("Index", "Login", new { errorStr = "", isAdLogin = false })); }
/// <summary> /// 根据用户名称获取用户信息 /// </summary> /// <param name="userName"></param> public static UserInfo GetUserInfoByUserName(string userName) { UserInfo accountEntities = MemoryCacheUtils.Get(userName) as UserInfo; if (accountEntities == null) { USER userObJ = UserDA.GetUserByLoginName(userName); accountEntities = new UserInfo(); if (userObJ != null) { accountEntities.UserId = userObJ.ID; accountEntities.UserName = userObJ.KEYED_NAME; accountEntities.LoginName = userObJ.LOGIN_NAME; accountEntities.Password = userObJ.PASSWORD; accountEntities.Email = userObJ.EMAIL; accountEntities.b_JobNumber = userObJ.B_JOBNUMBER; accountEntities.b_AffiliatedCompany = userObJ.B_AFFILIATEDCOMPANY; accountEntities.language = "Chinese"; } } return(accountEntities); }
/// <summary> /// 根据中文字符获取对应的英文字符 /// </summary> /// <param name="chineseValue"></param> /// <param name="languageCategory"></param> /// <returns></returns> public string GetLanguageValueByParam(string chineseValue, string languageCategory, string fileName) { string languageType = Userinfo.language; //string languageType = System.Threading.Thread.CurrentThread.CurrentCulture.Name; if (languageType.IndexOf("zh") > 0) { return(chineseValue); } else { string value = MemoryCacheUtils.Get(chineseValue) as string; if (string.IsNullOrEmpty(value)) { //获取语言数据 string filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + fileName + ".json"; String jsonStr = Common.GetFileJson(filePath); value = Common.GetKeyValue(jsonStr, languageCategory, chineseValue); } return(value); } }
public void OnLoadingStarted(string imageUri, View view) { try { IList <string> memCache = MemoryCacheUtils.FindCacheKeysForImageUri(imageUri, ImageLoader.Instance.MemoryCache); if (memCache?.Count != 0) { cacheFound = true; } if (!cacheFound) { File discCache = DiskCacheUtils.FindInCache(imageUri, ImageLoader.Instance.DiskCache); if (discCache != null) { cacheFound = discCache.Exists(); } } } catch (Exception e) { Console.WriteLine(e); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { HttpCookie cookie = HttpContext.Request.Cookies["Passport.Token"]; if (cookie == null) // 站内凭证不存在 { Response.Redirect("/Login/Index"); } else { if (Userinfo == null || Userinfo.LoginName != cookie.Value) { //string language = Request.Headers["Accept-Language"].ToString(); //language = language.Split(',')[0].ToString(); Userinfo = UserBll.GetUserInfoByUserName(cookie.Value); if (Userinfo == null) { Response.Redirect("/Login/Index"); } else { if (string.IsNullOrEmpty(Userinfo.department)) { CommonMethod.GetAdInfoByUser(Userinfo, "bordrin.com"); } ViewBag.userName = Userinfo.UserName; ViewBag.language = Userinfo.language; } bool isaddCache = false; inn = Userinfo.inn; if (inn == null || inn.getUserID() != Userinfo.UserId) { using (ArasInnovator arasConn = new ArasInnovator()) { inn = arasConn.ArasConnection(Userinfo.LoginName, Userinfo.Password); Userinfo.inn = inn; isaddCache = true; } } //如果角色为空,获取角色权限 if (Userinfo.Roles == null) { Userinfo.Roles = IdentityDA.getIdentityListByUserID(inn, Userinfo.UserId); isaddCache = true; } //如果菜单权限为空,获取菜单权限 if (Userinfo.MemuAuth == null) { Userinfo.MemuAuth = new List <string>(); for (int j = 0; j < Userinfo.Roles.Count; j++) { string id = Userinfo.Roles[j]; //根据Id获取权限列表 Item ItemTypes = ItemTypeDA.GetMenuAuthByIdentity(inn, id); if (ItemTypes.getItemCount() > 0) { for (int i = 0; i < ItemTypes.getItemCount(); i++) { Item itemobj = ItemTypes.getItemByIndex(i); string itemName = itemobj.getProperty("name"); if (Userinfo.MemuAuth.IndexOf(itemName) < 0) { Userinfo.MemuAuth.Add(itemName); } } } } isaddCache = true; } //获取委托的权限数据 DateTime currentTime = DateTime.Now.AddMinutes(-10); if ((Userinfo.AgentAuth == null && Userinfo.AgentCreateTime == null) || (Userinfo.AgentCreateTime != null && currentTime > Userinfo.AgentCreateTime)) { List <AgentSetEntity> AgentSetList = AgentSetBll.GetAgentSetByUserName(Userinfo.UserName); if (AgentSetList.Count > 0) { AgentSetBll.GetAgentRoles(inn, Userinfo, AgentSetList); isaddCache = true; } } //重新添加缓存 if (isaddCache) { CacheItemPolicy policy = new CacheItemPolicy(); policy.Priority = CacheItemPriority.NotRemovable; MemoryCacheUtils.Set(Userinfo.LoginName, Userinfo, policy); } } else { ViewBag.userName = Userinfo.UserName; ViewBag.language = Userinfo.language; } ViewData["MemuAuth"] = Userinfo.MemuAuth; string strController = filterContext.RouteData.Values["controller"].ToString(); switch (strController) { case "MenuAuthManage": string menuAuthManage = Userinfo.MemuAuth.Where(x => x == "b_MenuAuthManage").FirstOrDefault(); if (string.IsNullOrEmpty(menuAuthManage)) { Response.Redirect("/Home/AuthWarn"); } break; case "RoleManage": string roleManage = Userinfo.MemuAuth.Where(x => x == "b_RoleManage").FirstOrDefault(); if (string.IsNullOrEmpty(roleManage)) { Response.Redirect("/Home/AuthWarn"); } break; case "ProjectManage": string projectManage = Userinfo.MemuAuth.Where(x => x == "b_ProjectManage").FirstOrDefault(); if (string.IsNullOrEmpty(projectManage)) { Response.Redirect("/Home/AuthWarn"); } break; case "OrganizationalStructure": string organizationalStructure = Userinfo.MemuAuth.Where(x => x == "b_OrganizationalStructure").FirstOrDefault(); if (string.IsNullOrEmpty(organizationalStructure)) { Response.Redirect("/Home/AuthWarn"); } break; case "User": string user = Userinfo.MemuAuth.Where(x => x == "b_User").FirstOrDefault(); if (string.IsNullOrEmpty(user)) { Response.Redirect("/Home/AuthWarn"); } break; case "ExpenseCategory": string expenseCategory = Userinfo.MemuAuth.Where(x => x == "b_ExpenseCategory").FirstOrDefault(); if (string.IsNullOrEmpty(expenseCategory)) { Response.Redirect("/Home/AuthWarn"); } break; case "ExpenseAuditConfiguration": string expenseAuditConfiguration = Userinfo.MemuAuth.Where(x => x == "b_ExpenseAuditConfiguration").FirstOrDefault(); if (string.IsNullOrEmpty(expenseAuditConfiguration)) { Response.Redirect("/Home/AuthWarn"); } break; case "AgentSet": string agentSet = Userinfo.MemuAuth.Where(x => x == "b_AgentSet").FirstOrDefault(); if (string.IsNullOrEmpty(agentSet)) { Response.Redirect("/Home/AuthWarn"); } break; default: break; } } base.OnActionExecuting(filterContext); }