Session State

Posts   
 
    
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 28-Nov-2006 17:58:00   

Hi All,

This has nothing to do with llblgen, but your all are quite knowledgable and friendly that I thought I would pass this by you. I'm trying to encapsulate the session variables like so:

#Region " Imports "
Imports Microsoft.VisualBasic
Imports MedfordSchoolDistrict.Elementary.GradeBook.LLBL.EntityClasses
Imports MedfordSchoolDistrict.Elementary.GradeBook.LLBL.DatabaseSpecific
Imports MedfordSchoolDistrict.Elementary.GradeBook.LLBL.FactoryClasses
Imports MedfordSchoolDistrict.Elementary.GradeBook.LLBL.RelationClasses
Imports MedfordSchoolDistrict.Elementary.GradeBook.LLBL.HelperClasses
Imports MedfordSchoolDistrict.Elementary.GradeBook.LLBL
Imports MedfordSchoolDistrict.ElementaryGradeBookBLL
Imports MedfordSchoolDistrict.ElementaryCommon
Imports MedfordSchoolDistrict

Imports Infragistics.WebUI

Imports System.Collections.Generic
Imports System.Web.SessionState.HttpSessionState
Imports System.data

Imports SD.LLBLGen.Pro.ORMSupportClasses
#End Region

Public Class UserData
    Public Shared SessionName As String = "UserData"

    Public UserName As String

    Private _StudentAssignmentTable As DataTable

    Public Property StudentAssignmentTable() As DataTable
        Get
            If _StudentAssignmentTable Is Nothing Then
                _StudentAssignmentTable = DirectCast(HttpContext.Current.Session.Item("StudentAssignmentTable"), DataTable)
            End If
            Return _StudentAssignmentTable
        End Get
        Set(ByVal value As DataTable)
            _StudentAssignmentTable = value
            HttpContext.Current.Session.Add("StudentAssignmentTable", value)
        End Set
    End Property

Then the Page_Load is:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            _UserData = New UserData
            RetrieveUserInformation()
            Session(UserData.SessionName) = _UserData
            drpTerm.Text = "1"
            ElementaryCommon.SchoolCalendar.CurrentDate = Now
            'TODO: I first need the SchoolEntity before I can calculate term.  Not sure if I'm going to do this.
            'drpTerm.Text = ElementaryWebGradeBookBll.SchoolCalendar.CurrentTerm
        Else
            If Session(UserData.SessionName) IsNot Nothing Then
                _UserData = DirectCast(Session(UserData.SessionName), UserData)
            Else
                'TODO: Send to time out
            End If
        End If

    End Sub

Then I'll access an item like:

    Protected Sub ScoreChange(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim ScoreValue As TextBox = CType(sender, TextBox)

        Dim Index As Integer = CType(ScoreValue.Parent.Parent, GridViewRow).DataItemIndex
        Dim dvr As DataRowView = _UserData.StudentAssignmentTable.DefaultView(Index)

    End Sub

It seems to work. I just would like to know if this is a good way to do this or if a better way exists.

Thanks,

Fishy

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 28-Nov-2006 19:16:20   

I would personally recommend against storing the datatable in the session? (This is user/page specific data right?) Doing this doesn't really scale very well. How much data is in that table?

What type of session are you using? InProc?

BOb

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 28-Nov-2006 19:19:20   

PilotBob wrote:

I would personally recommend against storing the datatable in the session? (This is user/page specific data right?) Doing this doesn't really scale very well. How much data is in that table?

What type of session are you using? InProc?

BOb

The table will most likely average 30 rows with 10 columns.

Yes, I'm using InProc.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 29-Nov-2006 17:04:29   

I'm also storing some llblgen entities this way.

But I guess my real question is doing it this way:

    Public Property SelectedSchool() As SchoolEntity
        Get
            If _SelectedSchool Is Nothing Then
                _SelectedSchool = DirectCast(HttpContext.Current.Session.Item("SelectedSchool"), SchoolEntity)
            End If
            Return _SelectedSchool
        End Get
        Set(ByVal value As SchoolEntity)
            _SelectedSchool = value
            HttpContext.Current.Session.Add("SelectedSchool", value)
        End Set
    End Property

Are there better ways?

Thanks again,

Fishy

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 30-Nov-2006 05:39:27   

Fishy wrote:

I'm also storing some llblgen entities this way.

But I guess my real question is doing it this way:

    Public Property SelectedSchool() As SchoolEntity
        Get
            If _SelectedSchool Is Nothing Then
                _SelectedSchool = DirectCast(HttpContext.Current.Session.Item("SelectedSchool"), SchoolEntity)
            End If
            Return _SelectedSchool
        End Get
        Set(ByVal value As SchoolEntity)
            _SelectedSchool = value
            HttpContext.Current.Session.Add("SelectedSchool", value)
        End Set
    End Property

Are there better ways?

Thanks again,

Fishy

The code is correct, if you want to store the data in the session. You have to determine if the memory usage of the InProc session, based on your server load is adequate to store this data in the session for each user. If you only have a couple of dozen active sessions at a time, it shouldn't be a problem. If you have hundreds or thousands of sessions at the same time, I would recommend against doing this.

BOb