/// <summary> /// Logs out the user in session. /// </summary> /// <param name="returnUrl">The return URL.</param> /// <returns></returns> public ActionResult LogOut(string returnUrl) { IUserContext userContext = SessionHandler.UserContext; if (userContext != null) { if (SessionHandler.MySettings != null) { MySettingsManager.SaveLastSettings(userContext, SessionHandler.MySettings); MySettingsManager.SaveToDisk(userContext, MySettingsManager.SettingsName, SessionHandler.MySettings); } CoreData.UserManager.Logout(userContext); SessionHandler.UserContext = null; // When logged out mySettings must be cleared SessionHandler.MySettings = new MySettings(); FormsService.SignOut(); } if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } }
public RedirectResult SaveCurrentMySettings(string returnUrl) { MySettings mySettings = SessionHandler.MySettings; if (mySettings.IsNotNull()) { MySettingsManager.SaveToDisk(SettingsName, mySettings); } return(Redirect(returnUrl)); }
private void Session_End(object sender, EventArgs e) { var userContext = Session["userContext"] as IUserContext; var mySettings = Session["mySettings"] as MySettings; if (userContext != null && mySettings != null) { LastUserSessionIdManager.UpdateLastUserSessionId(userContext.User.UserName, Session.SessionID); MySettingsManager.SaveLastSettings(userContext, mySettings); MySettingsManager.SaveToDisk(userContext, MySettingsManager.SettingsName, mySettings); } }
/// <summary> /// Saves the current settings. /// </summary> public RedirectResult SaveMySettings(string returnUrl) { IUserContext userContext = GetCurrentUser(); if (!userContext.IsAuthenticated()) { throw new Exception("User is not logged in"); } MySettings mySettings = SessionHandler.MySettings; MySettingsManager.SaveToDisk(userContext, MySettingsManager.SettingsName, mySettings); SessionHandler.UserMessages.Add(new UserMessage(Resources.Resource.MySettingsSaved)); return(Redirect(returnUrl)); }
public void SerializeAndDeserializeMySettings() { using (ShimsContext.Create()) { ShimFilePath(); AnalysisPortal.MySettings.MySettings mySettings; AnalysisPortal.MySettings.MySettings loadedSettings; const string settingsName = "test"; // Arrange mySettings = CreateMySettingsObjectWithTaxonFilter(1, 2, 5); // Act MySettingsManager.SaveToDisk(settingsName, mySettings); loadedSettings = MySettingsManager.LoadFromDisk(settingsName); // Assert CollectionAssert.AreEqual(new[] { 1, 2, 5 }, loadedSettings.Filter.Taxa.TaxonIds); } }
public void SerializeAndDeserializeProtectedSettings() { // When this test is run a file called test.dat will be saved to // c:\InetPub\wwwRoot\AnalysisPortalTestRun\temp\settings using (ShimsContext.Create()) { string fullPath = @"C:\InetPub\wwwRoot\AnalysisPortalTestRun\temp\settings\myTempFile.txt"; ShimHostingEnvironment.MapPathString = (path) => { return(fullPath); }; var mySettings = new ArtDatabanken.WebApplication.AnalysisPortal.MySettings.MySettings(); mySettings.Filter.Taxa.TaxonIds.Add(1); mySettings.Filter.Taxa.TaxonIds.Add(2); mySettings.Filter.Taxa.TaxonIds.Add(5); int wfsLayersCount = mySettings.DataProvider.MapLayers.WfsLayers.Count; var layer = mySettings.DataProvider.MapLayers.AddWfsLayer(new WfsLayerSetting() { Name = "Test", GeometryType = GeometryType.Polygon, Color = "#336699", Filter = "", ServerUrl = "http://slwgeo.artdata.slu.se:8080/geoserver/SLW/wfs", TypeName = "SLW:MapOfSwedishCounties" }); MySettingsManager.SaveToDisk("test", mySettings); var mySettings2 = MySettingsManager.LoadFromDisk("test"); Assert.IsNotNull(mySettings2); Assert.IsTrue(mySettings2.Filter.Taxa.TaxonIds.Contains(1)); Assert.IsTrue(mySettings2.Filter.Taxa.TaxonIds.Contains(2)); Assert.IsTrue(mySettings2.Filter.Taxa.TaxonIds.Contains(5)); Assert.AreEqual(wfsLayersCount + 1, mySettings.DataProvider.MapLayers.WfsLayers.Count); } }