public override void SetAndReleaseItemExclusive (HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { if (item == null) return; EnsureGoodId (id, true); byte[] collection_data = null; byte[] sobjs_data = null; MemoryStream stream = null; BinaryWriter writer = null; Stream output = null; #if NET_4_0 GZipStream gzip = null; #endif try { SessionStateItemCollection items = item.Items as SessionStateItemCollection; if (items != null && items.Count > 0) { stream = new MemoryStream (); #if NET_4_0 if (config.CompressionEnabled) output = gzip = new GZipStream (stream, CompressionMode.Compress, true); else #endif output = stream; writer = new BinaryWriter (output); items.Serialize (writer); #if NET_4_0 if (gzip != null) gzip.Close (); #endif writer.Close (); collection_data = stream.ToArray (); } HttpStaticObjectsCollection sobjs = item.StaticObjects; if (sobjs != null && sobjs.Count > 0) sobjs_data = sobjs.ToByteArray (); } catch (Exception ex) { throw new HttpException ("Failed to store session data.", ex); } finally { #if NET_4_0 if (writer != null) writer.Dispose (); if (gzip != null) gzip.Dispose (); #else if (writer != null) ((IDisposable)writer).Dispose (); #endif if (stream != null) stream.Dispose (); } stateServer.SetAndReleaseItemExclusive (id, collection_data, sobjs_data, lockId, item.Timeout, newItem); }
string Serialize(SessionStateItemCollection items) { #if NET_4_0 GZipStream gzip = null; #endif Stream output; MemoryStream ms = null; BinaryWriter writer = null; try { ms = new MemoryStream(); #if NET_4_0 if (sessionConfig.CompressionEnabled) { output = gzip = new GZipStream(ms, CompressionMode.Compress, true); } else #endif output = ms; writer = new BinaryWriter(output); if (items != null) { items.Serialize(writer); } #if NET_4_0 if (gzip != null) { gzip.Close(); } #endif writer.Close(); return(Convert.ToBase64String(ms.ToArray())); } finally { #if NET_4_0 if (writer != null) { writer.Dispose(); } if (gzip != null) { gzip.Dispose(); } #else if (writer != null) { ((IDisposable)writer).Dispose(); } #endif if (ms != null) { ms.Dispose(); } } }
private byte[] Serialize(SessionStateItemCollection items) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); if (items != null) { items.Serialize(writer); } writer.Close(); return ms.ToArray(); }
/// <summary> /// Session 정보를 직렬화합니다. (일반적인 직렬화 방식은 안되고, SessionStateItemCollection 자체의 Serialize를 사용해서 직렬화합니다.) /// </summary> /// <param name="items"></param> /// <returns></returns> public static byte[] SerializeSessionState(SessionStateItemCollection items) { if(IsDebugEnabled) log.Debug("세션 정보를 직렬화를 수행합니다..."); if(items == null) return new byte[0]; using(var ms = new MemoryStream()) using(var writer = new BinaryWriter(ms)) { items.Serialize(writer); writer.Close(); return ms.ToArray(); } }
public void save() { Data.sName = "aa"; Data.dBaseRadius = 2; Data.dNoseRadius = .5; String x = ""; foreach (string key in HttpContext.Current.Session.Keys) { x += key + " - " + HttpContext.Current.Session[key] + ";"; } //SessionStateItemCollection items = HttpContext.Current.Session. SessionStateItemCollection items = new SessionStateItemCollection(); items["Name"] = "NN"; items["Desc"] = "DD"; try { System.IO.BinaryWriter writer = new System.IO.BinaryWriter( System.IO.File.Open(HttpContext.Current.Server.MapPath("./session_collection.bin"), System.IO.FileMode.Create)); items.Serialize(writer); writer.Close(); items["Name"] = ""; items["Desc"] = ""; System.IO.BinaryReader reader = new System.IO.BinaryReader( System.IO.File.Open(HttpContext.Current.Server.MapPath("./session_collection.bin"), System.IO.FileMode.Open)); items = SessionStateItemCollection.Deserialize(reader); String x2 = items["Name"].ToString(); String y2 = items["Desc"].ToString(); } catch (Exception e) { String err = e.StackTrace; } }
public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { EnsureGoodId(id, true); byte[] collection_data = null; byte[] sobjs_data = null; MemoryStream stream = null; BinaryWriter writer = null; try { SessionStateItemCollection items = item.Items as SessionStateItemCollection; if (items != null && items.Count > 0) { stream = new MemoryStream(); writer = new BinaryWriter(stream); items.Serialize(writer); collection_data = stream.GetBuffer(); } HttpStaticObjectsCollection sobjs = item.StaticObjects; if (sobjs != null && sobjs.Count > 0) { sobjs_data = sobjs.ToByteArray(); } } catch (Exception ex) { throw new HttpException("Failed to store session data.", ex); } finally { if (writer != null) { writer.Close(); } } stateServer.SetAndReleaseItemExclusive(id, collection_data, sobjs_data, lockId, item.Timeout, newItem); }
private string Serialize(SessionStateItemCollection items) { using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { if (items != null) items.Serialize(writer); writer.Flush(); writer.Close(); return Convert.ToBase64String(stream.ToArray()); } } }
/// <summary> /// Serialize /// (SessionStateItemCollection → Base64) /// </summary> /// <param name="items">アイテム</param> /// <returns>Base64</returns> private string Serialize(SessionStateItemCollection items) { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms)) { if (items != null) items.Serialize(writer); } return Convert.ToBase64String(ms.ToArray()); } }
/// <summary> /// Convert a SessionStateItemCollection into a Base64 string /// </summary> private static string Serialize(SessionStateItemCollection items) { if (items == null || items.Count < 1) return string.Empty; using (MemoryStream mStream = new MemoryStream()) { using (BinaryWriter bWriter = new BinaryWriter(mStream)) { items.Serialize(bWriter); bWriter.Close(); } return Convert.ToBase64String(mStream.ToArray()); } }
// // Serialize is called by the SetAndReleaseItemExclusive method to // convert the SessionStateItemCollection into a Binary. // private byte[] Serialize(SessionStateItemCollection items) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); try { if (items != null) items.Serialize(writer); } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "GetSessionStoreItem"); throw new ProviderException(e.Message, e.InnerException); } else throw e; } finally { writer.Close(); } return ms.ToArray(); }
private byte[] Serialize(SessionStateItemCollection items) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); try { if (items != null) items.Serialize(writer); } catch (Exception e) { Console.WriteLine(e.Message); } finally { writer.Close(); } return ms.ToArray(); }
private string Serialize(SessionStateItemCollection items) { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms)) { if (items != null) { items.Serialize(writer); } } var encryptedData = MachineKey.Protect(ms.ToArray(), "Session Data"); return Convert.ToBase64String(encryptedData); } }
public void Serialize(SessionStateItemCollection items) { var ms = new MemoryStream(); var writer = new BinaryWriter(ms); if (items != null) items.Serialize(writer); writer.Close(); _serializedSessionData = ms.ToArray(); }
private string Serialize(SessionStateItemCollection items) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); List<string> itemsABorrar = new List<string>(); foreach (string item in items.Keys) { if (!(items[item].GetType().IsSerializable)) itemsABorrar.Add(item); } foreach(string item in itemsABorrar) items.Remove(item); if (items != null) { items.Serialize(writer); } writer.Close(); return Convert.ToBase64String(ms.ToArray()); }
private string[] serialize(SessionStateItemCollection items) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); if (items != null) items.Serialize(writer); writer.Close(); byte[] raw = ms.ToArray(); ms.Close(); List<string> parts = new List<string>(); byte[] segment; int scount = (raw.Length / SHARD_SIZE); int tcount = raw.Length - (scount * SHARD_SIZE); for (int pos = 0; pos < scount; pos++) { segment = new byte[SHARD_SIZE]; int startIndex = pos * SHARD_SIZE; Buffer.BlockCopy(raw, pos * SHARD_SIZE, segment, 0, SHARD_SIZE); parts.Add(Convert.ToBase64String(segment)); } segment = new byte[tcount]; Buffer.BlockCopy(raw, scount * SHARD_SIZE, segment, 0, tcount); parts.Add(Convert.ToBase64String(segment)); return parts.ToArray(); }
private string serialize(SessionStateItemCollection items) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); if (items != null) items.Serialize(writer); writer.Close(); return Convert.ToBase64String(ms.ToArray()); }
private static byte[] Serialize(SessionStateItemCollection items) { using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms)) { if (items != null) items.Serialize(writer); writer.Close(); return ms.ToArray(); } } }