/// <summary> /// Gets an <see cref="ISession"/> associated with the specified session key. /// </summary> /// <param name="sessionKey">The session key</param> /// <returns>An <see cref="ISession"/> for quering the data store.</returns> public ISession GetSession(Guid sessionKey) { lock (syncRoot) { if (SessionStore.ContainsKey(sessionKey)) { // Re-initiate session if it is in an unusable state if (SessionStore[sessionKey] == null) { SessionStore[sessionKey] = SessionFactory.Instance.OpenSession(); } else if (SessionStore[sessionKey].IsOpen == false) { SessionStore[sessionKey].Dispose(); SessionStore[sessionKey] = SessionFactory.Instance.OpenSession(); } return(SessionStore[sessionKey]); } // Open new session, add it to SessionStore and return the session ISession session = SessionFactory.Instance.OpenSession(); SessionStore.Add(sessionKey, session); return(session); } }
protected void AddAuditInformation() { Int16 moduleNo = 0; Enums.ModuleConstant masterPage = Enums.ModuleConstant.HouseKeeping; if (SessionStore.ContainsKey(Params.SYS_SELECT_MODULE)) //if (Session["LoadSelectedModule"] != null) { masterPage = (Enums.ModuleConstant)SessionStore.GetValue(Params.SYS_SELECT_MODULE); //Session["LoadSelectedModule"].ToString(); } switch (masterPage) { case Enums.ModuleConstant.AccountsService: moduleNo = 1; break; case Enums.ModuleConstant.GeneralLedger: moduleNo = 2; break; case Enums.ModuleConstant.HouseKeeping: moduleNo = 2; break; case Enums.ModuleConstant.Booth: moduleNo = 3; break; //case Enums.ModuleConstant.HumanResource: // moduleNo = 3; // break; //case Enums.ModuleConstant.Inventory: // moduleNo = 4; // break; //case Enums.ModuleConstant.OffBooth: // moduleNo = 7; // break; default: moduleNo = 1; break; } var dto = new A2ZAUDITDTO(); dto.UserId = Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)); dto.EmpCode = Converter.GetSmallInteger(SessionStore.GetValue(Params.SYS_USER_EMP_CODE)); dto.UserIP = Converter.GetString(SessionStore.GetValue(Params.SYS_USER_IP)); dto.UserServerIP = Converter.GetString(SessionStore.GetValue(Params.SYS_USER_SERVER_IP)); dto.UserServerName = Converter.GetString(SessionStore.GetValue(Params.SYS_USER_SERVER_NAME)); //dto.AudRecordNo = 1; //dto.ModuleNo = moduleNo; //dto.AudRemarks = "Log In"; //dto.AudProcessDate = DateTime.Now.Date; //dto.AudOldDate = DateTime.Now.Date; //dto.AudNewDate = DateTime.Now.Date; //A2ZAUDITDTO.InsertAuditInformation(dto); }
/// <summary> /// Clears the contents of the session associated with the specified session key. /// </summary> /// <param name="sessionKey">The session key.</param> public void ClearSession(Guid sessionKey) { if (SessionStore.ContainsKey(sessionKey)) { if (SessionStore[sessionKey] != null) { SessionStore[sessionKey].Clear(); } } }
/// <summary> /// Flush the session associated with the given session key. /// </summary> public void FlushSession(Guid sessionKey) { if (SessionStore.ContainsKey(sessionKey)) { // Dispose session if it exists if (SessionStore[sessionKey] != null) { SessionStore[sessionKey].Flush(); } } }
/// <summary> /// Срабатывает при получении запроса. /// Заполняет логи, работает с куками и сессиями. /// </summary> /// <param name="request">Пришедший запрос</param> /// <param name="cancellationToken"></param> /// <returns></returns> protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var requestId = new RequestId(Guid.NewGuid()); //установка уникального номера запроса чтобы можно было идентифицировать его при обработке ответа request.Properties.Add(Constants.RequestIdKey, requestId); LogWriter.AddRequestToLog(ref request, requestId); var response = await base.SendAsync(request, cancellationToken); byte[] responseMessage = await response.Content.ReadAsByteArrayAsync(); var responseText = Encoding.UTF8.GetString(responseMessage); //обработка куки и сессий Guid sessionGuid = Guid.NewGuid(); string ipRemoteUser = request.GetOwinContext().Request.RemoteIpAddress; var cookie = CookieWorker.GetSessionGuidFromCookies(request.Headers); if (cookie != null) { try { sessionGuid = Guid.Parse(cookie[Constants.SessionIdKeyInCookies].Value); } catch { Debug.WriteLine("Не удалось распарсить Guid"); } } if (!SessionStore.ContainsKey(sessionGuid)) { //возможна ситуация - если получили guid из кук и его не оказалось в коллекции,то guid остаётся тем же и перезаписывается.Очень маловероятная ситуация если отдавать куки со сроком действия CookieWorker.AddSessionIdToCookies(sessionGuid, response); SessionStore.AddSession(sessionGuid, new Session( SessionStore.GetTimeOutdateOfSession(), ipRemoteUser)); } SessionStore.UpdateLastActivity(sessionGuid); SessionStore.AddQueryToLastQueries(sessionGuid, request.RequestUri.ToString()); if (!SessionStore.IsTheSameIp(sessionGuid, ipRemoteUser)) { throw new Exception("Сменился ip на " + ipRemoteUser); } LogWriter.AddResponseToLogs(requestId.GUID, response.IsSuccessStatusCode, response.StatusCode, responseText); //LogStore.WriteContentToOutput(); return(response); }
/// <summary> /// Disposes the session associated with the specified session key. /// </summary> /// <param name="sessionKey">The session key.</param> public void DisposeSession(Guid sessionKey) { lock (syncRoot) { if (SessionStore.ContainsKey(sessionKey)) { // Dispose session if it exists if (SessionStore[sessionKey] != null) { SessionStore[sessionKey].Dispose(); } SessionStore.Remove(sessionKey); } } }
protected void Page_PreInit(object sender, EventArgs e) { //Put default value from enum Enums.ModuleConstant masterPage = Enums.ModuleConstant.HouseKeeping; if (SessionStore.ContainsKey(Params.SYS_SELECT_MODULE)) //if (Session["LoadSelectedModule"] != null) { masterPage = (Enums.ModuleConstant)SessionStore.GetValue(Params.SYS_SELECT_MODULE); //Session["LoadSelectedModule"].ToString(); } switch (masterPage) { case Enums.ModuleConstant.AccountsService: this.Page.MasterPageFile = "~/MasterPages/CustomerServicesMenuMasterPage.Master"; break; case Enums.ModuleConstant.GeneralLedger: this.Page.MasterPageFile = "~/MasterPages/GLMenuMasterPage.Master"; break; case Enums.ModuleConstant.HouseKeeping: this.Page.MasterPageFile = "~/MasterPages/HKMenuMasterPage.Master"; break; case Enums.ModuleConstant.HumanResource: this.Page.MasterPageFile = "~/MasterPages/HRMenuMasterPage.Master"; break; case Enums.ModuleConstant.Inventory: this.Page.MasterPageFile = "~/MasterPages/INVMenuMasterPage.Master"; break; case Enums.ModuleConstant.Booth: this.Page.MasterPageFile = "~/MasterPages/BoothMenuMasterPage.Master"; break; case Enums.ModuleConstant.OffBooth: this.Page.MasterPageFile = "~/MasterPages/OffBoothMenuMasterPage.Master"; break; default: Response.Redirect("A2ZERP.aspx"); break; } }
/* © 2013 AtoZ Computer Services */ //Oni: September 22, 2013 /// <summary> /// Thsi page is Log Out page. /// </summary> protected void Page_Load(object sender, EventArgs e) { Application.Lock(); if (Application["HitCount"] != null) { Application["HitCount"] = (int)Application["HitCount"] - 1; Application.UnLock(); } else { Application["HitCount"] = 1; } Application.UnLock(); try { //Put default value from enum Enums.ModuleConstant masterPage = Enums.ModuleConstant.HouseKeeping; if (SessionStore.ContainsKey(Params.SYS_SELECT_MODULE)) //if (Session["LoadSelectedModule"] != null) { masterPage = (Enums.ModuleConstant)SessionStore.GetValue(Params.SYS_SELECT_MODULE); //Session["LoadSelectedModule"].ToString(); } switch (masterPage) { case Enums.ModuleConstant.AccountsService: //AddAuditInformation(1); A2ZSYSIDSDTO.UpdateUserCSLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); Session["LogOutFlag"] = "1"; ClearSession(); //Session.Abandon(); Response.Redirect("A2ZERP.aspx", false); break; //case Enums.ModuleConstant.GeneralLedger: // //AddAuditInformation(2); // A2ZSYSIDSDTO.UpdateUserGLLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); // Session["LogOutFlag"] = "1"; // ClearSession();//Session.Abandon(); // Response.Redirect("A2ZERP.aspx", false); // break; case Enums.ModuleConstant.HouseKeeping: //AddAuditInformation(3); A2ZSYSIDSDTO.UpdateUserHKLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); Session["LogOutFlag"] = "1"; ClearSession(); //Session.Abandon(); Response.Redirect("A2ZERP.aspx", false); break; //case Enums.ModuleConstant.Booth: // //AddAuditInformation(3); // A2ZSYSIDSDTO.UpdateUserBTLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); // Session["LogOutFlag"] = "1"; // ClearSession();//Session.Abandon(); // Response.Redirect("A2ZERP.aspx", false); // break; //case Enums.ModuleConstant.OffBooth: // AddAuditInformation(3); // A2ZSYSIDSDTO.UpdateUserOBTLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); // Session["LogOutFlag"] = "1"; // ClearSession();//Session.Abandon(); // Response.Redirect("A2ZERP.aspx", false); // break; //case Enums.ModuleConstant.HumanResource: // //AddAuditInformation(4); // A2ZSYSIDSDTO.UpdateUserHRLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); // Session["LogOutFlag"] = "1"; // ClearSession();//Session.Abandon(); // Response.Redirect("A2ZERP.aspx", false); // break; //case Enums.ModuleConstant.Inventory: // AddAuditInformation(5); // A2ZSYSIDSDTO.UpdateUserLoginFlag(Converter.GetInteger(SessionStore.GetValue(Params.SYS_USER_ID)), 0); // ClearSession();//Session.Abandon(); // Response.Redirect("A2ZERP.aspx", false); // break; } } catch (Exception ex) { //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "<script>alert('System Err.Load Problem');</script>"); ClearSession(); //throw ex; } }