Progress Bars and Remoting

J

Joel Cade

I'd just like a sanity check on my thinking. I'm attempting to create
a progress bar for a file upload to an ASPX page. I'm adding an HTTP
Module, which would then call into a "Progress Handler", a remoting
object created as a singleton object, which would keep track of all
file uploads by an id. Does this make sense?

I haven't seen this implementation of a progress bar mentioned
anywhere. Am I missing something? Thanks for the input!!

Joel Cade, MCSD
Brinster, Inc.

Here's the paired down code:

-- The HTTP Module ---

Imports System.Web

Public Class progressModule
Implements IHttpModule

Dim oHandler As ProgressHandler.ProgressHandler
Dim context As HttpContext
Dim currentId As String

Public Sub Init(ByVal application As Web.HttpApplication)
Implements IHttpModule.Init
AddHandler application.BeginRequest, AddressOf
Me.Application_BeginRequest
AddHandler application.EndRequest, AddressOf
Me.Application_EndRequest
End Sub

Public Sub Dispose() Implements IHttpModule.Dispose
End Sub

Private Sub Application_BeginRequest(ByVal source As Object, ByVal
e As EventArgs)
Dim application As HttpApplication = CType(source,
HttpApplication)
context = application.Context

oHandler = Activator.GetObject(GetType(ProgressHandler.ProgressHandler),
"")
currentId = Guid.NewGuid.ToString

Dim timer As New Timers.Timer(500)
AddHandler timer.Elapsed, AddressOf OnTimerTick
End Sub

Private Sub Application_EndRequest(ByVal source As Object, ByVal e
As EventArgs)
Dim application As HttpApplication = CType(source,
HttpApplication)
Dim context As HttpContext = application.Context
End Sub

Private Sub OnTimerTick(ByVal source As Object, ByVal e As
Timers.ElapsedEventArgs)
oHandler.UpdateValues(currentId,
context.Request.ContentLength, context.Request.TotalBytes)
End Sub
End Class

--- The Handler (Remoted) ---

Imports System.Runtime.Remoting

Public Class ProgressHandler
Inherits MarshalByRefObject

Dim dtProgressValues As DataTable

Public Sub New()
dtProgressValues = New DataTable()

dtProgressValues.Columns.Add("Id", GetType(String),
vbNullString)
dtProgressValues.Columns.Add("BytesTotal", GetType(Integer),
0)
dtProgressValues.Columns.Add("BytesFinished",
GetType(Integer), 0)

dtProgressValues.PrimaryKey(0) = dtProgressValues.Columns(0)
End Sub

Public Sub UpdateValues(ByVal Id As String, ByVal BytesTotal As
Integer, ByVal BytesFinished As Integer)
Dim dRow As DataRow

dRow = dtProgressValues.Rows.Find(Id)

If dRow Is Nothing Then
dRow = dtProgressValues.NewRow

dRow(0) = Id
dRow(1) = BytesTotal
dRow(2) = BytesFinished

dtProgressValues.Rows.Add(dRow)
Else
dRow(1) = BytesTotal
dRow(2) = BytesFinished
End If
End Sub

Public Function GetBytesTotal(ByVal Id As String) As Integer
Dim dRow As DataRow

dRow = dtProgressValues.Rows.Find(Id)

If dRow Is Nothing Then
Return 0
Else
Return dRow("BytesTotal")
End If
End Function

Public Function GetBytesFinished(ByVal Id As String) As Integer
Dim dRow As DataRow

dRow = dtProgressValues.Rows.Find(Id)

If dRow Is Nothing Then
Return 0
Else
Return dRow("BytesFinished")
End If
End Function
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top