public static SessionStateStoreData Deserialize(byte[] buffer) { MemoryStream stream = new MemoryStream(buffer); SessionStateItemCollection itemCollection = null; HttpStaticObjectsCollection staticItemCollection = null; int timeout = 0; try { BinaryReader reader = new BinaryReader(stream); byte sessionFlag = reader.ReadByte(); if ((byte)(sessionFlag & SESSION_ITEMS) == SESSION_ITEMS) { itemCollection = SessionStateItemCollection.Deserialize(reader); } if ((byte)(sessionFlag & SESSION_STATIC_ITEMS) == SESSION_STATIC_ITEMS) { staticItemCollection = HttpStaticObjectsCollection.Deserialize(reader); } timeout = reader.ReadInt32(); } finally { if (stream != null) { stream.Close(); } } return(new SessionStateStoreData(itemCollection, staticItemCollection, timeout)); }
/// <summary> /// Deserialise the session state data. /// </summary> /// <param name="items">The bytes to deserialise.</param> /// <param name="statics">The http static object collection.</param> /// <param name="timeout">The timeout for deserialisation.</param> /// <returns>The session state object.</returns> private SessionStateStoreData DeserializeSession(byte[] items, byte[] statics, int timeout) { MemoryStream stream1 = null, stream2 = null; BinaryReader reader1 = null, reader2 = null; try { stream1 = new MemoryStream(items); stream2 = new MemoryStream(statics); reader1 = new BinaryReader(stream1); reader2 = new BinaryReader(stream2); return(new SessionStateStoreData(SessionStateItemCollection.Deserialize(reader1), HttpStaticObjectsCollection.Deserialize(reader2), timeout)); } finally { if (reader2 != null) { reader2.Close(); } if (reader1 != null) { reader1.Close(); } if (stream2 != null) { stream2.Close(); } if (stream1 != null) { stream1.Close(); } } }
private static SessionStateValue DeserializeSessionState(BinaryReader reader) { var timeout = reader.ReadInt32(); var hasSessionItems = reader.ReadBoolean(); var hasStaticObjects = reader.ReadBoolean(); return(new SessionStateValue( hasSessionItems ? SessionStateItemCollection.Deserialize(reader) : null, hasStaticObjects ? HttpStaticObjectsCollection.Deserialize(reader) : null, timeout)); }
public override void Skip(CompactBinaryReader reader) { int cookie = reader.ReadInt32(); object custom = reader.Context.GetObject(cookie); if (custom == null) { custom = HttpStaticObjectsCollection.Deserialize(reader.BaseReader); reader.Context.RememberObject(custom, false); } }
public void Serialization() { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); HttpStaticObjectsCollection hsoc = new HttpStaticObjectsCollection(); hsoc.Serialize(writer); ms.Position = 0; BinaryReader reader = new BinaryReader(ms); Assert.IsNotNull(HttpStaticObjectsCollection.Deserialize(reader)); }
/// <summary> /// Deserializes the static objects. /// </summary> private static HttpStaticObjectsCollection DeserializeStaticObjects(byte[] bytes) { if (bytes == null) { return(new HttpStaticObjectsCollection()); } using (var stream = new MemoryStream(bytes)) using (var reader = new BinaryReader(stream)) { return(HttpStaticObjectsCollection.Deserialize(reader)); } }
/// <summary> /// Uses a <see cref="BinaryFormatter"/> to read an object of /// type <see cref="ActualType"/> from the underlying stream. /// </summary> /// <param name="reader">stream reader</param> /// <returns>object read from the stream reader</returns> public override object Read(CompactBinaryReader reader) { int cookie = reader.ReadInt32(); object custom = reader.Context.GetObject(cookie); if (custom == null) { // custom = formatter.Deserialize(reader.BaseReader.BaseStream); custom = HttpStaticObjectsCollection.Deserialize(reader.BaseReader); reader.Context.RememberObject(custom, false); } return(custom); }
private static SessionStateStoreData Deserialize(HttpContextBase context, Stream stream) { int timeout; SessionStateItemCollection sessionItems; bool hasItems; bool hasStaticObjects; HttpStaticObjectsCollection staticObjects; byte eof; Debug.Assert(context != null); try { BinaryReader reader = new BinaryReader(stream); timeout = reader.ReadInt32(); hasItems = reader.ReadBoolean(); hasStaticObjects = reader.ReadBoolean(); if (hasItems) { sessionItems = SessionStateItemCollection.Deserialize(reader); } else { sessionItems = new SessionStateItemCollection(); } if (hasStaticObjects) { staticObjects = HttpStaticObjectsCollection.Deserialize(reader); } else { staticObjects = GetSessionStaticObjects(context.ApplicationInstance.Context); } eof = reader.ReadByte(); if (eof != 0xff) { throw new HttpException(String.Format(CultureInfo.CurrentCulture, Resource1.Invalid_session_state)); } } catch (EndOfStreamException) { throw new HttpException(String.Format(CultureInfo.CurrentCulture, Resource1.Invalid_session_state)); } return(new SessionStateStoreData(sessionItems, staticObjects, timeout)); }
static void Deserialize(Stream stream, out StateItemData sessionItems, out HttpStaticObjectsCollection staticObjects) { var reader = new BinaryReader(stream); var timeout = reader.ReadInt32(); var hasItems = reader.ReadBoolean(); var hasStaticObjects = reader.ReadBoolean(); sessionItems = hasItems ? new StateItemData(reader) : null; staticObjects = hasStaticObjects ? HttpStaticObjectsCollection.Deserialize(reader) : null; var eof = reader.ReadByte(); if (eof != 0xff) { throw new InvalidOperationException("Invalid session state"); } }
static protected SessionStateItem Deserialize( Stream stream, int lockCookie) { SessionStateItem item; int timeout; bool isCookieless; SessionDictionary dict; bool hasDict; bool hasStaticObjects; HttpStaticObjectsCollection col; Byte eof; BinaryReader reader = new BinaryReader(stream); timeout = reader.ReadInt32(); isCookieless = reader.ReadBoolean(); hasDict = reader.ReadBoolean(); hasStaticObjects = reader.ReadBoolean(); if (hasDict) { dict = SessionDictionary.Deserialize(reader); } else { dict = null; } if (hasStaticObjects) { col = HttpStaticObjectsCollection.Deserialize(reader); } else { col = null; } eof = reader.ReadByte(); Debug.Assert(eof == 0xff); item = new SessionStateItem( dict, col, timeout, isCookieless, (int)stream.Position, false, TimeSpan.Zero, lockCookie); return(item); }
internal static SessionStateStoreData Deserialize(HttpContext context, Stream stream) { int timeout; SessionStateItemCollection sessionItems; bool hasItems; bool hasStaticObjects; HttpStaticObjectsCollection staticObjects; Byte eof; Debug.Assert(context != null); try { BinaryReader reader = new BinaryReader(stream); timeout = reader.ReadInt32(); hasItems = reader.ReadBoolean(); hasStaticObjects = reader.ReadBoolean(); if (hasItems) { sessionItems = SessionStateItemCollection.Deserialize(reader); } else { sessionItems = new SessionStateItemCollection(); } if (hasStaticObjects) { staticObjects = HttpStaticObjectsCollection.Deserialize(reader); } else { staticObjects = SessionStateUtility.GetSessionStaticObjects(context); } eof = reader.ReadByte(); if (eof != 0xff) { throw new HttpException(SR.GetString(SR.Invalid_session_state)); } } catch (EndOfStreamException) { throw new HttpException(SR.GetString(SR.Invalid_session_state)); } return(new SessionStateStoreData(sessionItems, staticObjects, timeout)); }
private static SessionStateStoreData Deserialize(HttpContext context, Stream stream) { int timeout; bool hasItems; bool hasStaticObjects; SessionStateItemCollection sessionItems; HttpStaticObjectsCollection staticObjects; try { BinaryReader reader = new BinaryReader(stream); timeout = reader.ReadInt32(); hasItems = reader.ReadBoolean(); hasStaticObjects = reader.ReadBoolean(); if (hasItems) { sessionItems = SessionStateItemCollection.Deserialize(reader); } else { sessionItems = new SessionStateItemCollection(); } if (hasStaticObjects) { staticObjects = HttpStaticObjectsCollection.Deserialize(reader); } else { staticObjects = SessionStateUtility.GetSessionStaticObjects(context); } if (reader.ReadByte() != EndOfStream) { throw new HttpException(Resources.Invalid_session_state); } } catch (EndOfStreamException) { throw new HttpException(Resources.Invalid_session_state); } return(new SessionStateStoreData(sessionItems, staticObjects, timeout)); }
/// <summary> /// Deserializes binary data into a fully hydrated SessionStoreDataContext. /// </summary> /// <param name="bytes">serialized binary data</param> /// <returns>The object representation of the session data</returns> /// <exception cref="HttpException">Thrown if deserialization encounters a problem</exception> internal static SessionStoreDataContext Deserialize(byte[] bytes, HttpContext context) { try { using (MemoryStream stream = new MemoryStream(bytes)) { using (BinaryReader reader = new BinaryReader(stream)) { //See comments in Serialize method for description of fields int timeout = reader.ReadInt32(); bool hasItems = reader.ReadBoolean(); bool hasStaticObjects = reader.ReadBoolean(); bool isLocked = reader.ReadBoolean(); DateTime?lockDate = null; if (isLocked) { lockDate = DateTime.FromBinary(reader.ReadInt64()); } SessionStateItemCollection items = hasItems ? SessionStateItemCollection.Deserialize(reader) : new SessionStateItemCollection(); HttpStaticObjectsCollection staticObjects = hasStaticObjects ? HttpStaticObjectsCollection.Deserialize(reader) : SessionStateUtility.GetSessionStaticObjects(context); //this is a sanity byte. If it does not equal 0xFF, there is a problem if (reader.ReadByte() != 0xff) { throw new HttpException("Invalid Session State"); } SessionStoreDataContext data = new SessionStoreDataContext(new SessionStateStoreData(items, staticObjects, timeout)); data.LockDate = lockDate; return(data); } } } catch (EndOfStreamException) { throw new HttpException("Invalid Session State"); } }
internal static SessionStateStoreData Deserialize(HttpContext context, Stream stream) { int num; SessionStateItemCollection items; HttpStaticObjectsCollection sessionStaticObjects; try { BinaryReader reader = new BinaryReader(stream); num = reader.ReadInt32(); bool flag = reader.ReadBoolean(); bool flag2 = reader.ReadBoolean(); if (flag) { items = SessionStateItemCollection.Deserialize(reader); } else { items = new SessionStateItemCollection(); } if (flag2) { sessionStaticObjects = HttpStaticObjectsCollection.Deserialize(reader); } else { sessionStaticObjects = GetSessionStaticObjects(context); } if (reader.ReadByte() != 0xff) { throw new HttpException(System.Web.SR.GetString("Invalid_session_state")); } } catch (EndOfStreamException) { throw new HttpException(System.Web.SR.GetString("Invalid_session_state")); } return(new SessionStateStoreData(items, sessionStaticObjects, num)); }
public SessionItem GetSessionItem() { var result = new SessionItem(); result.Items = items; if (staticObjects != null) { using (var stream = new MemoryStream()) { stream.Write(staticObjects, 0, staticObjects.Length); stream.Seek(0, SeekOrigin.Begin); using (var reader = new BinaryReader(stream)) { result.StaticObjects = HttpStaticObjectsCollection.Deserialize(reader); } } } return(result); }
public void readExternal(java.io.ObjectInput input) { lock (this) { _needSessionPersistence = input.readBoolean(); if (!_needSessionPersistence) //nothing has been written { if (_items == null) { _items = new SessionStateItemCollection(); } if (_staticObjects == null) { _staticObjects = new HttpStaticObjectsCollection(); } return; } ObjectInputStream ms = new ObjectInputStream(input); System.IO.BinaryReader br = new System.IO.BinaryReader(ms); _items = SessionStateItemCollection.Deserialize(br); _staticObjects = HttpStaticObjectsCollection.Deserialize(br); } }
public static SessionStateStoreData Deserialize(HttpContext context, Stream stream) { int timeout; SessionStateItemCollection sessionItems; HttpStaticObjectsCollection staticObjects; BinaryReader binaryReader = new BinaryReader(stream); timeout = binaryReader.ReadInt32(); bool flag = binaryReader.ReadBoolean(); bool flag2 = binaryReader.ReadBoolean(); sessionItems = ((!flag) ? new SessionStateItemCollection() : SessionStateItemCollection.Deserialize(binaryReader)); staticObjects = ((!flag2) ? SessionStateUtility.GetSessionStaticObjects(context) : HttpStaticObjectsCollection.Deserialize(binaryReader)); byte b = binaryReader.ReadByte(); if (b != byte.MaxValue) { throw new HttpException("Invalid_session_state"); } return(new SessionStateStoreData(sessionItems, staticObjects, timeout)); }
public ActionResult Index() { const byte SESSION_ITEMS = 1; const byte SESSION_STATIC_ITEMS = 2; var sessionCache = NCache.Caches["AspNetSessionCache"]; var dataCache = NCache.Caches["AspNetDataCache"]; var ht = sessionCache.GetByTag(new Tag("NC_ASP.net_session_data")); var allSession = new Dictionary <string, Dictionary <string, object> >(); var dctNcache = ht.Cast <DictionaryEntry>().ToDictionary(c => (string)c.Key, c => (byte[])c.Value); foreach (var kvpNcache in dctNcache) { // Aggiungo la sezione var session = new Dictionary <string, object>(); allSession.Add(kvpNcache.Key, session); byte[] array = kvpNcache.Value; using (var ms = new MemoryStream(array)) { var bf = new BinaryFormatter(); var obj = bf.Deserialize(ms) as Hashtable; Debug.WriteLine($"{nameof(obj)} is {obj.GetType()}"); if (obj["SD"] is byte[] sd) { SessionStateItemCollection itemCollection = null; HttpStaticObjectsCollection staticItemCollection = null; int timeout = 0; using (var ms1 = new MemoryStream(sd)) { BinaryReader reader = new BinaryReader(ms1); byte sessionFlag = reader.ReadByte(); if ((byte)(sessionFlag & SESSION_ITEMS) == SESSION_ITEMS) { itemCollection = SessionStateItemCollection.Deserialize(reader); foreach (string key in itemCollection.Keys) { session.Add(key, itemCollection[key]); } } if ((byte)(sessionFlag & SESSION_STATIC_ITEMS) == SESSION_STATIC_ITEMS) { staticItemCollection = HttpStaticObjectsCollection.Deserialize(reader); } timeout = reader.ReadInt32(); } //var sssd = new SessionStateStoreData(itemCollection, staticItemCollection, timeout); } } } var currentSession = Session.Keys.Cast <string>().ToDictionary(c => c, c => $"{Session[c]}"); //TODO: mettere gli application event da un'altra parte (magari sempre in ncache, ma non in session) var mes = dataCache.Get(nameof(ApplicationEvent)) as List <ApplicationEvent> ?? new List <ApplicationEvent>(); //mes.AddRange(Session[nameof(ApplicationEvent)] as List<ApplicationEvent> ?? new List<ApplicationEvent>()); //mes.AddRange(MvcApplication.AppStartEvents); //mes.AddRange(MvcApplication.AppEndEvents); var viewModel = new HomeIndexViewModel { CurrentSession = currentSession, AllSession = allSession, EventSession = mes }; return(View(viewModel)); }
public SessionStateStoreData Deserialize(byte[] data) { if (data == null || data.Length == 0) { throw new InvalidSessionStateException(); } try { var reader = new BinaryReader(new MemoryStream(data)); var timeout = reader.ReadInt32(); var hasItems = reader.ReadBoolean(); var hasStaticObjects = reader.ReadBoolean(); var stateItemCollection = !hasItems ? new SessionStateItemCollection() : SessionStateItemCollection.Deserialize(reader); var staticObjects = !hasStaticObjects ? new HttpStaticObjectsCollection() : HttpStaticObjectsCollection.Deserialize(reader); if (reader.ReadByte() != byte.MaxValue) { throw new HttpException("Invalid session state"); } return(new SessionStateStoreData(stateItemCollection, staticObjects, timeout)); } catch (Exception e) { throw new InvalidSessionStateException(e); } }
private static SessionStateStoreData Deserialize( HttpContext context, Stream stream) { int timeout; SessionStateItemCollection stateItemCollection; HttpStaticObjectsCollection staticObjects; try { BinaryReader reader = new BinaryReader(stream); timeout = reader.ReadInt32(); bool flag = reader.ReadBoolean(); int num = reader.ReadBoolean() ? 1 : 0; stateItemCollection = !flag ? new SessionStateItemCollection() : SessionStateItemCollection.Deserialize(reader); staticObjects = num == 0 ? SessionStateUtility.GetSessionStaticObjects(context) : HttpStaticObjectsCollection.Deserialize(reader); if (reader.ReadByte() != byte.MaxValue) { throw new ProviderException(MsgManager.GetMsg(ErrRes.INVALID_SESSION_STATE)); } } catch (EndOfStreamException ex) { throw new ProviderException(MsgManager.GetMsg(ErrRes.INVALID_SESSION_STATE)); } return(new SessionStateStoreData((ISessionStateItemCollection)stateItemCollection, staticObjects, timeout)); }