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;
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);
}