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 .ProgressHandle r
Dim context As HttpContext
Dim currentId As String
Public Sub Init(ByVal application As Web.HttpApplica tion)
Implements IHttpModule.Ini t
AddHandler application.Beg inRequest, AddressOf
Me.Application_ BeginRequest
AddHandler application.End Request, AddressOf
Me.Application_ EndRequest
End Sub
Public Sub Dispose() Implements IHttpModule.Dis pose
End Sub
Private Sub Application_Beg inRequest(ByVal source As Object, ByVal
e As EventArgs)
Dim application As HttpApplication = CType(source,
HttpApplication )
context = application.Con text
oHandler = Activator.GetOb ject(GetType(Pr ogressHandler.P rogressHandler) ,
"")
currentId = Guid.NewGuid.To String
Dim timer As New Timers.Timer(50 0)
AddHandler timer.Elapsed, AddressOf OnTimerTick
End Sub
Private Sub Application_End Request(ByVal source As Object, ByVal e
As EventArgs)
Dim application As HttpApplication = CType(source,
HttpApplication )
Dim context As HttpContext = application.Con text
End Sub
Private Sub OnTimerTick(ByV al source As Object, ByVal e As
Timers.ElapsedE ventArgs)
oHandler.Update Values(currentI d,
context.Request .ContentLength, context.Request .TotalBytes)
End Sub
End Class
--- The Handler (Remoted) ---
Imports System.Runtime. Remoting
Public Class ProgressHandler
Inherits MarshalByRefObj ect
Dim dtProgressValue s As DataTable
Public Sub New()
dtProgressValue s = New DataTable()
dtProgressValue s.Columns.Add(" Id", GetType(String) ,
vbNullString)
dtProgressValue s.Columns.Add(" BytesTotal", GetType(Integer ),
0)
dtProgressValue s.Columns.Add(" BytesFinished",
GetType(Integer ), 0)
dtProgressValue s.PrimaryKey(0) = dtProgressValue s.Columns(0)
End Sub
Public Sub UpdateValues(By Val Id As String, ByVal BytesTotal As
Integer, ByVal BytesFinished As Integer)
Dim dRow As DataRow
dRow = dtProgressValue s.Rows.Find(Id)
If dRow Is Nothing Then
dRow = dtProgressValue s.NewRow
dRow(0) = Id
dRow(1) = BytesTotal
dRow(2) = BytesFinished
dtProgressValue s.Rows.Add(dRow )
Else
dRow(1) = BytesTotal
dRow(2) = BytesFinished
End If
End Sub
Public Function GetBytesTotal(B yVal Id As String) As Integer
Dim dRow As DataRow
dRow = dtProgressValue s.Rows.Find(Id)
If dRow Is Nothing Then
Return 0
Else
Return dRow("BytesTota l")
End If
End Function
Public Function GetBytesFinishe d(ByVal Id As String) As Integer
Dim dRow As DataRow
dRow = dtProgressValue s.Rows.Find(Id)
If dRow Is Nothing Then
Return 0
Else
Return dRow("BytesFini shed")
End If
End Function
End Class
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 .ProgressHandle r
Dim context As HttpContext
Dim currentId As String
Public Sub Init(ByVal application As Web.HttpApplica tion)
Implements IHttpModule.Ini t
AddHandler application.Beg inRequest, AddressOf
Me.Application_ BeginRequest
AddHandler application.End Request, AddressOf
Me.Application_ EndRequest
End Sub
Public Sub Dispose() Implements IHttpModule.Dis pose
End Sub
Private Sub Application_Beg inRequest(ByVal source As Object, ByVal
e As EventArgs)
Dim application As HttpApplication = CType(source,
HttpApplication )
context = application.Con text
oHandler = Activator.GetOb ject(GetType(Pr ogressHandler.P rogressHandler) ,
"")
currentId = Guid.NewGuid.To String
Dim timer As New Timers.Timer(50 0)
AddHandler timer.Elapsed, AddressOf OnTimerTick
End Sub
Private Sub Application_End Request(ByVal source As Object, ByVal e
As EventArgs)
Dim application As HttpApplication = CType(source,
HttpApplication )
Dim context As HttpContext = application.Con text
End Sub
Private Sub OnTimerTick(ByV al source As Object, ByVal e As
Timers.ElapsedE ventArgs)
oHandler.Update Values(currentI d,
context.Request .ContentLength, context.Request .TotalBytes)
End Sub
End Class
--- The Handler (Remoted) ---
Imports System.Runtime. Remoting
Public Class ProgressHandler
Inherits MarshalByRefObj ect
Dim dtProgressValue s As DataTable
Public Sub New()
dtProgressValue s = New DataTable()
dtProgressValue s.Columns.Add(" Id", GetType(String) ,
vbNullString)
dtProgressValue s.Columns.Add(" BytesTotal", GetType(Integer ),
0)
dtProgressValue s.Columns.Add(" BytesFinished",
GetType(Integer ), 0)
dtProgressValue s.PrimaryKey(0) = dtProgressValue s.Columns(0)
End Sub
Public Sub UpdateValues(By Val Id As String, ByVal BytesTotal As
Integer, ByVal BytesFinished As Integer)
Dim dRow As DataRow
dRow = dtProgressValue s.Rows.Find(Id)
If dRow Is Nothing Then
dRow = dtProgressValue s.NewRow
dRow(0) = Id
dRow(1) = BytesTotal
dRow(2) = BytesFinished
dtProgressValue s.Rows.Add(dRow )
Else
dRow(1) = BytesTotal
dRow(2) = BytesFinished
End If
End Sub
Public Function GetBytesTotal(B yVal Id As String) As Integer
Dim dRow As DataRow
dRow = dtProgressValue s.Rows.Find(Id)
If dRow Is Nothing Then
Return 0
Else
Return dRow("BytesTota l")
End If
End Function
Public Function GetBytesFinishe d(ByVal Id As String) As Integer
Dim dRow As DataRow
dRow = dtProgressValue s.Rows.Find(Id)
If dRow Is Nothing Then
Return 0
Else
Return dRow("BytesFini shed")
End If
End Function
End Class