private void InitRoleWebMenu(AfxContext db) { using (db.BeginTransaction(IsolationLevel.ReadCommitted)) { foreach (var kv in RoleWebMenuList) { foreach (var webmenuId in kv.Value) { var m = db.RoleWebMenu.Where(q => q.RoleId == kv.Key && q.WebMenuId == webmenuId).FirstOrDefault(); if (m == null) { m = new RoleWebMenu() { Id = this.GetIdentity <RoleWebMenu>(), RoleId = kv.Key, WebMenuId = webmenuId }; db.RoleWebMenu.Add(m); db.SaveChanges(); } } db.AddCommitCallback((num) => { using (var cache = IocUtils.Get <IRoleWebMenuCache>()) { cache.Remove(kv.Key); } }); } db.Commit(); } }
public virtual void OnAuthorization(AuthorizationFilterContext context) { var actionDescriptor = context.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor; if (actionDescriptor != null) { var arr = actionDescriptor.MethodInfo.GetCustomAttributes(typeof(AnonymousAttribute), true); if (arr != null && arr.Length > 0) { return; } } var user = context.HttpContext.GetUserSession(); if (user == null) { this.SetError(context, ApiStatus.NeedLogin, "未登录或登录已超时!"); } else if (!string.IsNullOrEmpty(this.ActionId)) { using (var servce = IocUtils.Get <IRoleWebMenuService>()) { if (!servce.Exist(user.RoleId, this.ActionId)) { this.SetError(context, ApiStatus.NeedAuth, "无权限访问!"); } } } }
public static UserSessionDto GetUserSession(this HttpContext httpContext) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } UserSessionDto m = httpContext.Items[USER_SESSION_KEY] as UserSessionDto; if (m == null) { var sid = GetSid(httpContext); if (!string.IsNullOrEmpty(sid)) { using (var userSessionService = IocUtils.Get <IUserSessionService>()) { m = userSessionService.Get(sid); if (m != null) { httpContext.Items[USER_SESSION_KEY] = m; } } } } return(m); }
private void listView_Server_MouseDoubleClick(object sender, MouseEventArgs e) { var item = this.listView_Server.GetItemAt(e.X, e.Y); if (item != null && item.Tag != null) { var m = item.Tag as FileInfoDto; if (m.Type == FileInfoType.Directory) { this.ServerPath = m; this.GetServerList(); } else if (m.Type == (int)FileInfoType.None) { if (this.ServerPath != null) { using (var fileclient = IocUtils.Get <IFileInfoService>(new object[] { MainForm.Current.FileClient })) { this.ServerPath = fileclient.Get(this.ServerPath.ParentId); } } this.GetServerList(); } } }
public void SetServerPath(int id) { using (var fileclient = IocUtils.Get <IFileInfoService>(new object[] { MainForm.Current.FileClient })) { this.ServerPath = fileclient.Get(id); } }
private void toolStripMenuItem_ServerPrve_Click(object sender, EventArgs e) { if (this.ServerPath != null) { using (var fileclient = IocUtils.Get <IFileInfoService>(new object[] { MainForm.Current.FileClient })) { this.ServerPath = fileclient.Get(this.ServerPath.ParentId); } this.GetServerList(); } }
public MainForm() { InitializeComponent(); Current = this; this.FileClient = IocUtils.Get <IFileClient>(); this.Login(); try { File.WriteAllText(WinAPIs.GetHandleFile(), this.Handle.ToString(), Encoding.UTF8); } catch { } }
protected virtual T GetRepository <T>(string name, object[] args) where T : IBaseRepository { var type = typeof(T); IBaseRepository repository = null; if (!repositoryDic.TryGetValue(type, out repository)) { repositoryDic[type] = repository = IocUtils.Get <T>(name, args); } return((T)repository); }
protected virtual T GetCache <T>(string name, object[] args) where T : IBaseCache { var type = typeof(T); IBaseCache cache = null; if (!cacheDic.TryGetValue(type, out cache)) { cacheDic[type] = cache = IocUtils.Get <T>(name, args); } return((T)cache); }
protected virtual T GetService <T>(string name, object[] args) where T : IBaseService { var type = typeof(T); IBaseService service = null; if (!serviceDic.TryGetValue(type, out service)) { serviceDic[type] = service = IocUtils.Get <T>(name, args); service.SetCurrentUser(this.UserSession); } return((T)service); }
public void LoadData() { this.SetEnabled(false); ThreadPool.QueueUserWorkItem((o) => { using (var client = IocUtils.Get <IRoleService>(new object[] { MainForm.Current.FileClient })) { var list = client.GetList(this.selectParam); this.Sync.Post((obj) => { this.BindListView(obj as List <RoleInfoDto>); this.SetEnabled(true); }, list); } }); }
private void btn_Save_Click(object sender, EventArgs e) { string oldpwd = this.txt_OldPwd.Text.Trim(); string newpwd = this.txt_NewPwd.Text.Trim(); string newpwd2 = this.txt_NewPwd2.Text.Trim(); if (string.IsNullOrEmpty(oldpwd)) { this.txt_OldPwd.Focus(); this.lb_msg.Text = "原密码不能为空!"; return; } if (string.IsNullOrEmpty(newpwd)) { this.txt_NewPwd.Focus(); this.lb_msg.Text = "新密码不能为空!"; return; } if (newpwd != newpwd2) { this.txt_NewPwd2.Focus(); this.lb_msg.Text = "两次输入新密码不一致!"; return; } if (newpwd == oldpwd) { this.txt_NewPwd2.Focus(); this.lb_msg.Text = "新旧密码不能相同!"; return; } using (var userService = IocUtils.Get <IUserService>(new object[] { MainForm.Current.FileClient })) { if (userService.UpdatePwd(oldpwd, newpwd)) { if (ConfigUtils.IsRememberPassword && ConfigUtils.Account.ToLower() == MainForm.Current.FileClient.UserInfo.Account.ToLower()) { ConfigUtils.Password = newpwd; } this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { this.lb_msg.Text = "修改密码失败!"; } } }
private void OnClientClosedEvent(TcpHost server, Session session) { try { UserInfo user = session[USER_INFO_KEY] as UserInfo; SessionUtils.UserInfo = user; var userService = IocUtils.Get <IUserService>(); userService.Logout(); } catch (Exception ex) { LogUtils.Error("【OnClientClosedEvent】", ex); } }
public void Start() { try { this.host.Start(ConfigUtils.Port); var fileInfoService = IocUtils.Get <IFileInfoService>(); fileInfoService.CheckFileInfo(); } catch (Exception ex) { LogUtils.Error("【Start】", ex); throw ex; } }
public static void ClearUserSession(this HttpContext httpContext) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } var sid = GetSid(httpContext); if (!string.IsNullOrEmpty(sid)) { using (var userSessionService = IocUtils.Get <IUserSessionService>()) { userSessionService.Logout(sid); httpContext.Items[USER_SESSION_KEY] = null; httpContext.Items[SET_USER_SESSION_KEY] = "0"; } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); //app.UseSid(option => //{ // option.IsCookie = true; // option.Name = SessionUtils.SidName; // option.EncryptCallback = (val) => EncryptUtils.Encrypt(val); // option.DecryptCallback = (val) => EncryptUtils.Decrypt(val); // option.BeginRequestCallback = this.OnRequest; // option.EndRequestCallback = this.OnResponse; //}); app.UseMvc(routes => { //routes.MapRoute( // name: "areas", // template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); //生成数据库 using (var service = IocUtils.Get <IService.ISystemService>()) { service.Init(); } LogDelete.Start(); }
/// <summary> /// 初始化系统 /// </summary> /// <returns></returns> public virtual void Init() { try { systemRepository.InitDb(); } catch (Exception ex) { LogUtils.Info("【InitDatabase】", ex); } if (this.IsInitSystemData()) { using (var syncLock = IocUtils.Get <ISyncLock>()) { syncLock.Init(LockType.InitSystemData, "0", null, TimeSpan.FromHours(1)); if (syncLock.Lock()) { systemRepository.InitData(); this.SetInitSystemData(); } } } }
private void InitWebMenu(AfxContext db) { using (var cache = IocUtils.Get <IWebMenuCache>()) { using (db.BeginTransaction(IsolationLevel.ReadCommitted)) { db.AddCommitCallback((num) => cache.Remove()); foreach (var m in WebMenuList) { var _m = db.WebMenu.Where(q => q.Id == m.Id).FirstOrDefault(); if (_m == null) { db.WebMenu.Add(m); db.SaveChanges(); } } db.Commit(); } } }
private void toolStripMenuItem_ServerDelete_Click(object sender, EventArgs e) { if (this.listView_Server.SelectedIndices.Count > 0) { var m = this.serverList[this.listView_Server.SelectedIndices[0]]; using (var client = IocUtils.Get <IFileInfoService>(new object[] { MainForm.Current.FileClient })) { if (client.Delete(m.Id)) { if (this.ucPageFooter_Server.PageIndex > 1) { int count = (this.ucPageFooter_Server.PageIndex - 1) * this.ucPageFooter_Server.PageSize; if (count >= this.ucPageFooter_Server.TotalCount - 1) { this.ucPageFooter_Server.SetPageIndex(this.ucPageFooter_Server.PageIndex - 1, this.ucPageFooter_Server.TotalCount - 1); } } this.GetServerList(); } } } }
public static void SetUserSession(this HttpContext httpContext, UserSessionDto m) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } var sid = GetSid(httpContext); if (!string.IsNullOrEmpty(sid)) { using (var userSessionService = IocUtils.Get <IUserSessionService>()) { if (m != null) { m.Sid = sid; } userSessionService.Set(sid, m); httpContext.Items[USER_SESSION_KEY] = m; httpContext.Items[SET_USER_SESSION_KEY] = m != null ? "1" : "0"; } } }
public static string RefreshSid(this HttpContext httpContext, string sid, TimeSpan?sidExpire, double minRefExpire) { var s = sid; string setState = httpContext.Items[SET_USER_SESSION_KEY] as string; if (setState == "0") { s = Guid.NewGuid().ToString("n"); } else if (sidExpire.HasValue) { var arr = s.Split('-'); long ticks = 0; if (arr.Length == 2) { long.TryParse(arr[1], out ticks); } var now = DateTime.Now; if (setState == "1" || (ticks > 0 && (new DateTime(ticks) - now).TotalMinutes < minRefExpire)) { var userinfo = httpContext.GetUserSession(); if (userinfo != null) { using (var sessionService = IocUtils.Get <IService.IUserSessionService>()) { sessionService.Expire(arr[0]); ticks = now.Add(sidExpire.Value).Ticks; LogUtils.Debug($"【刷新session】sid: {arr[0]}, Name: {userinfo.Name}, Account: {userinfo.Account}, LoginTime: {userinfo.LoginTime.ToString("yyyy-MM-dd HH:mm:ss")}"); s = $"{arr[0]}-{ticks}"; } } } } httpContext.Items[SessionUtils.SidName] = s; return(s); }
public override void OnAuthorization(AuthorizationContext authContext) { var user = SessionUtils.UserInfo; if (user != null && user.Id > 0) { authContext.IsAuth = true; var roleAuthService = IocUtils.Get <IRoleAuthService>(); if (this.AuthList.Count > 0 && !roleAuthService.CheckRole(user.RoleId, this.AuthList)) { authContext.IsAuth = false; authContext.Result = new ActionResult(); authContext.Result.SetMsg(MsgStatus.NeedLogin, "无权限!"); } } else { authContext.IsAuth = false; authContext.Result = new ActionResult(); authContext.Result.SetMsg(MsgStatus.NeedLogin, "未登录!"); } }
protected virtual T GetCache <T>() where T : IBaseCache => IocUtils.Get <T>();
protected virtual T GetCache <T>(string name) where T : IBaseCache => IocUtils.Get <T>(name);
protected virtual T GetCache <T>(object[] args) where T : IBaseCache => IocUtils.Get <T>(args);
protected virtual T GetCache <T>(string name, object[] args) where T : IBaseCache => IocUtils.Get <T>(name, args);
protected virtual T GetRepository <T>(string name, object[] args) where T : IBaseRepository => IocUtils.Get <T>(name, args);
protected virtual T GetRepository <T>(object[] args) where T : IBaseRepository => IocUtils.Get <T>(args);
protected virtual T GetRepository <T>(string name) where T : IBaseRepository => IocUtils.Get <T>(name);
protected virtual T GetRepository <T>() where T : IBaseRepository => IocUtils.Get <T>();