/// <summary> /// 获取JSON格式缓存 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="cacheName">缓存名</param> /// <param name="url">服务地址</param> /// <param name="parms">服务参数</param> /// <returns></returns> public static List <T> Get <T>(String cacheName, String url, List <KeyValuePair <String, String> > parms = null) { // 1. 获取服务器缓存的版本 // 2. 查询本地是否存在对应版本的磁盘缓存文件 // 3. // a) 如果存在从本地磁盘获取数据后反序列化,返回结果,失败转入b) // b) 如果不存在或本地获取失败 1、从服务端获取数据,2、清除本地磁盘数据,3、序列化后写入本地文件, 返回结果 List <T> list = null; string remote_ver = GetRemoteVer(cacheName); // 1. 获取服务器缓存的版本 string file = EnvInfo.RunPath + "Cache\\" + cacheName + "(" + remote_ver + ").cache"; bool ok = false; if (File.Exists(file)) { try { LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "本地磁盘缓存"); string result = File.ReadAllText(file); list = JsonConvert.DeserializeObject <List <T> >(result); LogHelper.Info(typeof(CacheHelper).FullName, "成功获取" + cacheName + "本地磁盘缓存"); ok = true; } catch (Exception ex) { LogHelper.Warn(typeof(CacheHelper).FullName, "获取" + cacheName + "本地磁盘缓存失败\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } if (!ok) { try { LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "服务端数据"); CustomException ce = null; string result = HttpDataHelper.GetStringWithInfo("BASE", url, out ce, parms); if (ce != null) { throw ce; } LogHelper.Info(typeof(CacheHelper).FullName, "开始序列化" + cacheName); list = JsonConvert.DeserializeObject <List <T> >(result); LogHelper.Info(typeof(CacheHelper).FullName, "删除" + cacheName + "旧的缓存文件"); RemoveFile(cacheName); LogHelper.Info(typeof(CacheHelper).FullName, "写入" + cacheName + "新的磁盘缓存文件"); File.WriteAllText(file, result); } catch (Exception ex) { LogHelper.Error(typeof(CacheHelper).FullName, "获取" + cacheName + "服务端数据失败\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } return(list); }
/// <summary> /// 获取自定义格式缓存 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="cacheName">缓存名</param> /// <param name="url">服务地址</param> /// <param name="parms">服务参数</param> /// <returns></returns> public static List <T> GetFast <T>(String cacheName, String url, List <KeyValuePair <String, String> > parms = null) where T : IFastSerialize, new() { List <T> list = null; string remote_ver = GetRemoteVer(cacheName); // 1. 获取服务器缓存的版本 string file = EnvInfo.RunPath + "Cache\\" + cacheName + "(" + remote_ver + ").cache"; bool ok = false; if (File.Exists(file)) { try { LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "本地磁盘缓存"); byte[] cache_bytes = System.IO.File.ReadAllBytes(file); list = FastSerializeHelper.DeSerialize <T>(cache_bytes); LogHelper.Info(typeof(CacheHelper).FullName, "成功获取" + cacheName + "本地磁盘缓存"); ok = true; } catch (Exception ex) { LogHelper.Warn(typeof(CacheHelper).FullName, "获取" + cacheName + "本地磁盘缓存失败\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } if (!ok) { try { LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "服务端数据"); CustomException ce = null; string result = HttpDataHelper.GetStringWithInfo("BASE", url, out ce, parms); if (ce != null) { throw ce; } list = JsonConvert.DeserializeObject <List <T> >(result); LogHelper.Info(typeof(CacheHelper).FullName, "开始序列化" + cacheName); List <byte> list_bytes = FastSerializeHelper.Serialize(list); LogHelper.Info(typeof(CacheHelper).FullName, "删除" + cacheName + "旧的缓存文件"); RemoveFile(cacheName); LogHelper.Info(typeof(CacheHelper).FullName, "写入" + cacheName + "新的磁盘缓存文件"); File.WriteAllBytes(file, list_bytes.ToArray()); } catch (Exception ex) { LogHelper.Error(typeof(CacheHelper).FullName, "获取" + cacheName + "服务端数据失败\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } return(list); }
/// <summary> /// 获取上一次登录的系统代码 /// </summary> /// <returns></returns> public static string GetLastSystemCode() { string code = string.Empty; if (EmpInfo.Id > 0) { var parmList = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString()) }; CustomException ce = null; // 获取上一次登录的系统代码 code = HttpDataHelper.GetStringWithInfo("BASE", "/sys/systemdefault", out ce, parmList); if (ce != null) { MessageHelper.ShowError("获取默认子系统失败!\r\n" + ce.Info + " " + ce.InnerMessage); return(null); } } return(code); }
public static void SetEmpInfo(BDictEmp emp, List <string> roleList, List <CDictAction> actionList) { EmpInfo.Name = emp.Name; EmpInfo.Ceid = emp.Ceid; EmpInfo.DeptId = emp.DeptId; EmpInfo.DeptName = emp.DeptName; EmpInfo.BizDeptId = emp.BizDeptId; EmpInfo.BizDeptName = emp.BizDeptName; EmpInfo.GroupId = emp.GroupId; EmpInfo.GroupName = emp.GroupName; EmpInfo.TitlesId = emp.TitlesId; EmpInfo.TitlesName = emp.TitlesName; EmpInfo.RoleList = roleList; EmpInfo.ActionRoleList = actionList; var parmList = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString()), new KeyValuePair <string, string>("parmName", "DEF_INPUT") }; CustomException ce = null; String defInput = HttpDataHelper.GetStringWithInfo("BASE", "/sys/parameteremp", out ce, parmList); if (ce != null) { MessageHelper.ShowError("获取默认输入法失败!\r\n" + ce.Info + " " + ce.InnerMessage); } if (String.IsNullOrEmpty(defInput)) { EmpInfo.InputChoice = "1"; } else { EmpInfo.InputChoice = defInput; } }
/// <summary> /// 通过配置文件设置机构信息 /// </summary> private static void SetBranchInfo() { // 获取机构ID,默认为1. string sid = ConfigurationManager.AppSettings.Get("BranchId"); if (!sid.IsNullOrEmpty() && sid.IsInt()) { EnvInfo.BranchId = int.Parse(sid); } else { EnvInfo.BranchId = 1; } string key = ConfigurationManager.AppSettings.Get("UserSerial").Reversal(); // 获取用户名称 string rets = ConfigurationManager.AppSettings.Get("UserName"); if (!string.IsNullOrEmpty(rets)) { rets = DataCryptoHelper.Decrypting(rets, "Wonder.His" + key); EnvInfo.UserName = rets; } else { throw new Exception("配置文件中用户名称有误!"); } //try //{ // 系统时间与数据库时间同步 DateTime d = DateTime.Now; //int timezone = int.Parse(DateTime.Now.ToString("%z").Substring(1)); CustomException ex = null; String systime = HttpDataHelper.GetStringWithInfo("BASE", "/sys/date", out ex); if (ex != null) { throw ex; } char[] spp = new char[] { '-', ':', ' ', '+' }; string[] tp = systime.Split(spp, StringSplitOptions.RemoveEmptyEntries); int[] itp = new int[7]; for (int i = 0; i < 7; i++) { itp[i] = int.Parse(tp[i]); } DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(itp[0], itp[1], itp[2], itp[3], itp[4], itp[5])); long delta = GetTimeStamp(startTime) - GetTimeStamp(d) - itp[6] * 36000; //时区处理 if (Math.Abs(delta) < 60000) { SYSTEMTIME st = new SYSTEMTIME(); st.FromDateTime(DateTime.Now.AddMilliseconds(delta)); bool syn = Win32API.SetLocalTime(ref st); if (!syn) { EnvInfo.ServerTimeDelta = delta; } } // 通过BranchId 查询 名称及代码 List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >(); parms.Add(new KeyValuePair <string, string>("branchId", EnvInfo.BranchId.ToString())); CustomException ce = null; CDictBranch branch = HttpDataHelper.GetWithInfo <CDictBranch>("BASE", "/sys/branch", out ce, parms); EnvInfo.BranchCode = branch.Code; // "101"; EnvInfo.BranchName = branch.Name; // EnvInfo.UserName; #region MONGODB 测试 //ErrorLogInfo eli = new ErrorLogInfo(); //eli.BranchId = EnvInfo.BranchId; //eli.EmpId = EmpInfo.Id; //eli.ComputerIp = EnvInfo.ComputerIp; //eli.Info = "Try"; //eli.Message = "Demo message"; //String json = StringHelper.SerializeObject<ErrorLogInfo>(eli); //HttpDataHelper.HttpPostWithInfo"BASE", "/mongo/errorlog/save", json); #endregion //} //catch (Exception ex) //{ // MessageHelper.ShowError(ex.Message); //} }