SerializableSession

Overview

The SerializableSession class is used as a base class for out-of-process session classes. This class provides save-to-stream and load-from-stream functionality as well as internal cache used to speed up handling of complex objects.

Unlike the in-process sessions like the MemorySessionManager that store references to objects added to session out-of-process session managers have to serialize session data before sending it to an out-of-process session state storage (f.e. Olympia state server). This implies significant restrictions on values that can be stored in the session.

Sessions based on the SerializableSession class can store data of the following types:

  • Primitive values:
    • Binary ** Boolean ** Byte ** Currency ** DateTime ** Decimal ** Double ** Guid ** Int8 ** Int16 ** Int32 ** Int64 ** String
  • Classes inherited from the ComplexType class. In this case methods ComplexType and ComplexType are used to serialize/deserialize data
  • All .NET classes marked with the Serializable attribute. In this case .NET serialization facility will be used
  • Arrays of types listed above

The SerializableSession class also provides internal cache so all non-primitive values are deserialized only when they are accessed from the user code.

Location


 

constructor  protected

Creates a new instance of the SerializableSession class and sets its IsNew and SessionID properties.

 

constructor(sessionId: Guid; isNew: Boolean)

 

SerializableSession(Guid sessionId, Boolean isNew)

 

Sub New(sessionId As Guid, isNew As Boolean)

Parameters:

  • sessionId: Session ID
  • isNew: Flag indicating whether this session instance is new (ie it was created anew, not loaded from the session storage)

Count

Gets the number of items in the session-state collection.

 

property Count: Int32 read;

 

Int32 Count { get; }

 

ReadOnly Property Count() As Int32

Created

Gets or sets UTC datetime when this session instance was created.

 

property Created: DateTime read write;

 

DateTime Created { get; set; }

 

Property Created() As DateTime

Dispose

Disposes of the current session instance.

 

method Dispose

 

void Dispose()

 

Sub Dispose()

Disposed

Gets a flag indicating whether current session instance is already disposed of.

Disposed sessions can no longer be modified and they will be discarded (rather then persisted for future calls) once they get released.

 

property Disposed: Boolean read;

 

Boolean Disposed { get; }

 

ReadOnly Property Disposed() As Boolean

Expired

Gets a flag indicating whether the current session instance is expired.

 

property Expired: Boolean read;

 

Boolean Expired { get; }

 

ReadOnly Property Expired() As Boolean

IsChanged

Gets a flag indicating that session values stored in the current session were changed.

This flag can be used by the session manager to reduce amount of data that will be sent to the session storage (ie there is no need to rewrite session values dats stream if there were no changes in them).

 

property IsChanged: Boolean read;

 

Boolean IsChanged { get; }

 

ReadOnly Property IsChanged() As Boolean

IsNew

Gets a flag indicating that the current session instance was just created and wasn't stored in the session storage yet.

 

property IsNew: Boolean read;

 

Boolean IsNew { get; }

 

ReadOnly Property IsNew() As Boolean

Item

Gets or sets individual session values.

 

property Item[name: String]: Object read write;

 

Object Item[String name] { get; set; }

 

Property Item(name As String) As Object

LastAccessed

Gets or sets a UTC datetime when this session instance was last accessed.

 

property LastAccessed: DateTime read write;

 

DateTime LastAccessed { get; set; }

 

Property LastAccessed() As DateTime

LoadFromStream

Loads session data from the provided data stream.

 

method LoadFromStream(stream: Stream)

 

void LoadFromStream(Stream stream)

 

Sub LoadFromStream(stream As Stream)

Parameters:

  • stream: Stream containing serialized session data

Names

Gets list of session value names.

 

property Names: ReadOnlyCollection<String> read;

 

ReadOnlyCollection<String> Names { get; }

 

ReadOnly Property Names() As ReadOnlyCollection<String>

Remove

Removes session value from the current session instance. If session doesn't contain value with provided name then it is ignored.

 

method Remove(name: String)

 

void Remove(String name)

 

Sub Remove(name As String)

Parameters:

  • name: Session value name

Roles

Gets or sets roles associated to this session.

Roles are checked when services or methods have their Roles property set in the Service Builder.

 

property Roles: array of String read write;

 

String[] Roles { get; set; }

 

Property Roles() As String()

SaveToStream

Loads session data to the provided data stream.

 

method SaveToStream(stream: Stream)

 

void SaveToStream(Stream stream)

 

Sub SaveToStream(stream As Stream)

Parameters:

  • stream: Stream that will contain serialized session data

SessionID

Gets session Id.

 

property SessionID: Guid read;

 

Guid SessionID { get; }

 

ReadOnly Property SessionID() As Guid

Timeout

Gets or sets the number of seconds since the last access that can elapse before the session will expire.

 

property Timeout: Int32 read write;

 

Int32 Timeout { get; set; }

 

Property Timeout() As Int32

Touch

Updates the ISession value of the session with current date and time.

 

method Touch

 

void Touch()

 

Sub Touch()

 

Count

Gets the number of items in the session-state collection.

 

property Count: Int32 read;

 

Int32 Count { get; }

 

ReadOnly Property Count() As Int32

Created

Gets or sets UTC datetime when this session instance was created.

 

property Created: DateTime read write;

 

DateTime Created { get; set; }

 

Property Created() As DateTime

Disposed

Gets a flag indicating whether current session instance is already disposed of.

Disposed sessions can no longer be modified and they will be discarded (rather then persisted for future calls) once they get released.

 

property Disposed: Boolean read;

 

Boolean Disposed { get; }

 

ReadOnly Property Disposed() As Boolean

Expired

Gets a flag indicating whether the current session instance is expired.

 

property Expired: Boolean read;

 

Boolean Expired { get; }

 

ReadOnly Property Expired() As Boolean

IsChanged

Gets a flag indicating that session values stored in the current session were changed.

This flag can be used by the session manager to reduce amount of data that will be sent to the session storage (ie there is no need to rewrite session values dats stream if there were no changes in them).

 

property IsChanged: Boolean read;

 

Boolean IsChanged { get; }

 

ReadOnly Property IsChanged() As Boolean

IsNew

Gets a flag indicating that the current session instance was just created and wasn't stored in the session storage yet.

 

property IsNew: Boolean read;

 

Boolean IsNew { get; }

 

ReadOnly Property IsNew() As Boolean

Item

Gets or sets individual session values.

 

property Item[name: String]: Object read write;

 

Object Item[String name] { get; set; }

 

Property Item(name As String) As Object

LastAccessed

Gets or sets a UTC datetime when this session instance was last accessed.

 

property LastAccessed: DateTime read write;

 

DateTime LastAccessed { get; set; }

 

Property LastAccessed() As DateTime

Names

Gets list of session value names.

 

property Names: ReadOnlyCollection<String> read;

 

ReadOnlyCollection<String> Names { get; }

 

ReadOnly Property Names() As ReadOnlyCollection<String>

Roles

Gets or sets roles associated to this session.

Roles are checked when services or methods have their Roles property set in the Service Builder.

 

property Roles: array of String read write;

 

String[] Roles { get; set; }

 

Property Roles() As String()

SessionID

Gets session Id.

 

property SessionID: Guid read;

 

Guid SessionID { get; }

 

ReadOnly Property SessionID() As Guid

Timeout

Gets or sets the number of seconds since the last access that can elapse before the session will expire.

 

property Timeout: Int32 read write;

 

Int32 Timeout { get; set; }

 

Property Timeout() As Int32

 

constructor  protected

Creates a new instance of the SerializableSession class and sets its IsNew and SessionID properties.

 

constructor(sessionId: Guid; isNew: Boolean)

 

SerializableSession(Guid sessionId, Boolean isNew)

 

Sub New(sessionId As Guid, isNew As Boolean)

Parameters:

  • sessionId: Session ID
  • isNew: Flag indicating whether this session instance is new (ie it was created anew, not loaded from the session storage)

Dispose

Disposes of the current session instance.

 

method Dispose

 

void Dispose()

 

Sub Dispose()

LoadFromStream

Loads session data from the provided data stream.

 

method LoadFromStream(stream: Stream)

 

void LoadFromStream(Stream stream)

 

Sub LoadFromStream(stream As Stream)

Parameters:

  • stream: Stream containing serialized session data

Remove

Removes session value from the current session instance. If session doesn't contain value with provided name then it is ignored.

 

method Remove(name: String)

 

void Remove(String name)

 

Sub Remove(name As String)

Parameters:

  • name: Session value name

SaveToStream

Loads session data to the provided data stream.

 

method SaveToStream(stream: Stream)

 

void SaveToStream(Stream stream)

 

Sub SaveToStream(stream As Stream)

Parameters:

  • stream: Stream that will contain serialized session data

Touch

Updates the ISession value of the session with current date and time.

 

method Touch

 

void Touch()

 

Sub Touch()