/// <summary> /// 处理TimePoint /// </summary> private static void ProcessTimePoint() { TimePointSimulationSettings settings = TimePointSimulationSettings.GetConfig(); if (settings.Enabled) { if (DeluxePrincipal.IsAuthenticated) { DateTime simulatedTime = DateTime.Now.OriginalSimulateTime(); try { if (settings.Persister != null) { simulatedTime = settings.Persister.LoadTimePoint(DeluxeIdentity.CurrentUser.ID); } } catch (System.Exception) { } TimePointContext.Current.UseCurrentTime = (simulatedTime == DateTime.MinValue); TimePointContext.Current.SimulatedTime = simulatedTime; } } }
private void signInControl_AfterSignIn(SignInContext context) { if (context.ResultType == SignInResultType.Success) { if (PassportSignInSettings.GetConfig().UseSimulateTime) { context.SignInInfo.Properties["SimulateTime"] = this.simulateDate.Value; IPersistTimePoint persister = TimePointSimulationSettings.GetConfig().Persister; if (persister != null) { OguObjectCollection <IUser> users = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.LogOnName, context.SignInInfo.UserID); if (users.Count > 0) { persister.SaveTimePoint(users[0].ID, this.simulateDate.Value); TimePointContext tpc = new TimePointContext(); tpc.UseCurrentTime = this.simulateDate.Value == DateTime.MinValue; tpc.SimulatedTime = this.simulateDate.Value; tpc.SaveToCookie(); } } } } }
//protected void bannerOrgList_ItemDataBound(object sender, RepeaterItemEventArgs e) //{ // HyperLink lnk = e.Item.FindControl("banOrgItem") as HyperLink; // if (lnk != null) // { // lnk.NavigateUrl = "~/lists/OUExplorer.aspx?ou=" + Server.UrlEncode(((SCSimpleObject)e.Item.DataItem).ID); // } //} #region Private internal static void ChangeAndSaveTimePoint(DateTime timePoint) { TimePointContext.Current.SimulatedTime = timePoint; TimePointContext.Current.UseCurrentTime = timePoint == DateTime.MinValue; IPersistTimePoint persister = TimePointSimulationSettings.GetConfig().Persister; if (persister != null) { persister.SaveTimePoint(DeluxeIdentity.CurrentUser.ID, timePoint); } else { throw new SystemSupportException("未获取IPersistTimePoint,无法保存时间点,时间穿梭失败。"); } }
/// <summary> /// 将Context保存到Cookie,Cookie的Key为TimePointSimulationSettings.GetConfig().CookieKey定义 /// </summary> public void SaveToCookie() { (EnvironmentHelper.Mode == InstanceMode.Web).FalseThrow("当前应用不能获取到HttpContext"); HttpResponse response = HttpContext.Current.Response; HttpRequest request = HttpContext.Current.Request; HttpCookie cookie = new HttpCookie(TimePointSimulationSettings.GetConfig().CookieKey); cookie.Values.Add("UseCurrentTime", this.UseCurrentTime.ToString()); cookie.Values.Add("SimulatedTime", this.SimulatedTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); cookie.Expires = DateTime.MaxValue; response.Cookies.Add(cookie); }
/// <summary> /// 从Cookie中加载Context,Cookie的Key为TimePointSimulationSettings.GetConfig().CookieKey定义 /// </summary> /// <returns></returns> public static TimePointContext LoadFromCookie() { (EnvironmentHelper.Mode == InstanceMode.Web).FalseThrow("当前应用不能获取到HttpContext"); HttpRequest request = HttpContext.Current.Request; HttpCookie cookie = request.Cookies[TimePointSimulationSettings.GetConfig().CookieKey]; if (cookie != null) { TimePointContext.Current.UseCurrentTime = cookie.Values.GetValue("UseCurrentTime", true); TimePointContext.Current.SimulatedTime = cookie.Values.GetValue("SimulatedTime", DateTime.MinValue); } return(TimePointContext.Current); }
private static void SaveSimulateTime(SignInContext context, DateTime simulateDate) { context.SignInInfo.Properties["SimulateTime"] = simulateDate; IPersistTimePoint persister = TimePointSimulationSettings.GetConfig().Persister; if (persister != null) { OguObjectCollection <IUser> users = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.LogOnName, context.SignInInfo.UserID); if (users.Count > 0) { persister.SaveTimePoint(users[0].ID, simulateDate); TimePointContext tpc = new TimePointContext(); tpc.UseCurrentTime = simulateDate == DateTime.MinValue; tpc.SimulatedTime = simulateDate; tpc.SaveToCookie(); } } }