/// <inheritdoc /> public PlayerSessionDestructor( [NotNull] IObjectDestructorable <PlayerEntityDestructionContext> playerEntityDestructor, [NotNull] IConnectionEntityCollection connectionToEntityMap, [NotNull] ISessionCollection sessionCollection) { PlayerEntityDestructor = playerEntityDestructor ?? throw new ArgumentNullException(nameof(playerEntityDestructor)); ConnectionToEntityMap = connectionToEntityMap ?? throw new ArgumentNullException(nameof(connectionToEntityMap)); SessionCollection = sessionCollection ?? throw new ArgumentNullException(nameof(sessionCollection)); }
public NaiveSessionCache(string userId, ISessionCollection session) { UserObjectId = userId; CacheId = UserObjectId + "_TokenCache"; Session = session; this.AfterAccess = AfterAccessNotification; this.BeforeAccess = BeforeAccessNotification; Load(); }
public static string GetString(this ISessionCollection session, string key) { var data = session.Get(key); if (data == null) { return(null); } return(Encoding.UTF8.GetString(data)); }
public static int?GetInt(this ISessionCollection session, string key) { var data = session.Get(key); if (data == null || data.Length < 4) { return(null); } return(data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]); }
public static void SetInt(this ISessionCollection session, string key, int value) { var bytes = new byte[] { (byte)(value >> 24), (byte)(0xFF & (value >> 16)), (byte)(0xFF & (value >> 8)), (byte)(0xFF & value) }; session.Set(key, bytes); }
private void InitializeApplication(Host.IApplication hostApplication) { ISessionCollection hostSessions = hostApplication.Sessions; hostSessions.SessionCreated += OnHostSessionCreated; hostSessions.SessionRemoved += OnHostSessionRemoved; hostSessions.SessionStateChanged += OnHostSessionStateChanged; foreach (ISession hostSession in hostSessions) { Add(hostSession.Uid, hostSession); } }
private void DisposeApplication(Host.IApplication hostApplication) { ISessionCollection hostSessions = hostApplication.Sessions; hostSessions.SessionCreated -= OnHostSessionCreated; hostSessions.SessionRemoved -= OnHostSessionRemoved; hostSessions.SessionStateChanged -= OnHostSessionStateChanged; foreach (ISession session in this) { if (session.Application == hostApplication) { Remove(session.Uid); } } }
private HttpContext GetHttpContext(ISessionCollection session, bool sessionEnabled=true) { var httpContext = new Mock<HttpContext>(); if (session != null) { httpContext.Setup(h => h.Session).Returns(session); } else if (!sessionEnabled) { httpContext.Setup(h => h.Session).Throws<InvalidOperationException>(); } if (sessionEnabled) { httpContext.Setup(h => h.GetFeature<ISessionFeature>()).Returns(Mock.Of<ISessionFeature>()); httpContext.Setup(h => h.Session[It.IsAny<string>()]); } return httpContext.Object; }
private HttpContext GetHttpContext(ISessionCollection session, bool sessionEnabled = true) { var httpContext = new Mock <HttpContext>(); if (session != null) { httpContext.Setup(h => h.Session).Returns(session); } else if (!sessionEnabled) { httpContext.Setup(h => h.Session).Throws <InvalidOperationException>(); } if (sessionEnabled) { httpContext.Setup(h => h.GetFeature <ISessionFeature>()).Returns(Mock.Of <ISessionFeature>()); httpContext.Setup(h => h.Session[It.IsAny <string>()]); } return(httpContext.Object); }
public Core(Server server, HttpContext context, string viewstate = "", string type = "") { Server = server; Context = context; Request = context.Request; Response = context.Response; Session = context.Session; Sql = new Sql(this); Util = new Utility.Util(this); User = new User(); //load viewstate if (useViewState == true) { ViewStateId = viewstate; if(ViewStateId == "") { ViewStateId = Util.Str.CreateID(); } if (Session["viewstate-" + ViewStateId] != null) { ViewState vs = new ViewState(); vs = (ViewState)Util.Serializer.ReadObject(Util.Str.GetString(Session["viewstate-" + ViewStateId]), vs.GetType()); Page = vs.Page; Elements = new Elements(this, Page.themeFolder); }else { Page = new Page(); } }else { Page = new Page(); } if (Session["user"] != null) { User = (User)Util.Serializer.ReadObject(Util.Str.GetString(Session["user"]), User.GetType()); } //load references to Core R Sql.Load(); Page.Load(this); User.Load(this); //generate visitor id if (User.visitorId == "" || User.visitorId == null) { User.visitorId = Util.Str.CreateID(); } //detect request type & host type if (type == "service") { isWebService = true; } if (Request.Host.Value.IndexOf("localhost") >= 0 || Request.Host.Value.IndexOf("192.168.") >= 0) { isLocal = true; } }
public Core(Server server, HttpContext context, string viewstate = "", string type = "") { Server = server; Context = context; Request = context.Request; Response = context.Response; Session = context.Session; Sql = new Sql(this); Util = new Utility.Util(this); User = new User(); //load viewstate if (useViewState == true) { ViewStateId = viewstate; if (ViewStateId == "") { ViewStateId = Util.Str.CreateID(); } if (Session["viewstate-" + ViewStateId] != null) { ViewState vs = new ViewState(); vs = (ViewState)Util.Serializer.ReadObject(Util.Str.GetString(Session["viewstate-" + ViewStateId]), vs.GetType()); Page = vs.Page; Elements = new Elements(this, Page.themeFolder); } else { Page = new Page(); } } else { Page = new Page(); } if (Session["user"] != null) { User = (User)Util.Serializer.ReadObject(Util.Str.GetString(Session["user"]), User.GetType()); } //load references to Core R Sql.Load(); Page.Load(this); User.Load(this); //generate visitor id if (User.visitorId == "" || User.visitorId == null) { User.visitorId = Util.Str.CreateID(); } //detect request type & host type if (type == "service") { isWebService = true; } if (Request.Host.Value.IndexOf("localhost") >= 0 || Request.Host.Value.IndexOf("192.168.") >= 0) { isLocal = true; } }
/// <inheritdoc /> public PlayerEntityGuidEnumerable([NotNull] ISessionCollection connectedSessions, [NotNull] IReadonlyConnectionEntityCollection connectionEntities) { ConnectedSessions = connectedSessions ?? throw new ArgumentNullException(nameof(connectedSessions)); ConnectionEntities = connectionEntities ?? throw new ArgumentNullException(nameof(connectionEntities)); }
public static void Set(this ISessionCollection session, string key, byte[] value) { session.Set(key, new ArraySegment <byte>(value)); }
public static byte[] Get(this ISessionCollection session, string key) { byte[] value = null; session.TryGetValue(key, out value); return(value); }
public static void SetString(this ISessionCollection session, string key, string value) { session.Set(key, Encoding.UTF8.GetBytes(value)); }