Provide Progress Update to the Client for a CSLA Command Object

Provide Progress Update to the Client for a CSLA Command Object

Old forum URL: forums.lhotka.net/forums/t/11176.aspx


tarekahf posted on Monday, February 20, 2012

I need your help how to implement this requirement.

I am planning to use this Progress Bar control:

http://demo.essentialobjects.com/Demos/Progress%20Bar/Demo.aspx

to provide progress update for a CSLA Command Object which I have developed. See soruce code below:


    Public Function RefreshDBFields(ByVal theUserCtrlInfoPack As UserCtrlInfoPack, ByVal DoGetCountOnly As Boolean) As RefreshDBFieldsCommand
        Dim result As RefreshDBFieldsCommand
        result = DataPortal.Execute(Of RefreshDBFieldsCommand)(New RefreshDBFieldsCommand(theUserCtrlInfoPack, DoGetCountOnly))
        Return result
    End Function

    
    Public Class RefreshDBFieldsCommand
        Inherits CommandBase

        Private mRecordsToBeRefreshedCnt As Integer
        Private mRecordsRefreshedCnt As Integer
        Private mDoGetCountOnly As Boolean
        Private mRecordVersion As Integer
        Private mUserCtrlInfoPack As UserCtrlInfoPack

        Public ReadOnly Property RecordsToBeRefreshedCnt() As Integer
            Get
                Return mRecordsToBeRefreshedCnt
            End Get
        End Property

        Public ReadOnly Property RecordsRefreshedCnt() As Integer
            Get
                Return mRecordsRefreshedCnt
            End Get
        End Property

        Public Sub New(ByVal theUserCtrlInfoPack As UserCtrlInfoPack, ByVal DoGetCountOnly As Boolean)
            mUserCtrlInfoPack = theUserCtrlInfoPack
            mDoGetCountOnly = DoGetCountOnly
        End Sub

        Protected Overrides Sub DataPortal_Execute()
            Using cn As New SqlConnection(Database.SPMSFormDB)
                cn.Open()
                Using cm As SqlCommand = cn.CreateCommand
                    cm.CommandType = CommandType.StoredProcedure
                    cm.CommandText = "uspSPMSFormListGetRecVer"
                    cm.Parameters.AddWithValue("@RecVer", mRecordVersion)
                    mRecordsToBeRefreshedCnt = 0
                    mRecordsRefreshedCnt = 0
                    Using da As New SqlDataAdapter(cm)
                        Using ds As New DataSet
                            da.Fill(ds)
                            mRecordsToBeRefreshedCnt = ds.Tables(0).Rows.Count
                            If Not mDoGetCountOnly Then
                                For Each theRow As DataRow In ds.Tables(0).Rows
                                    mRecordsToBeRefreshedCnt += 1
                                    Dim theSPMSForm As SPMSForm
                                    Dim theStaffID As String
                                    Dim theReviewFrom As String
                                    theStaffID = theRow.Item("StaffID")
                                    theReviewFrom = theRow.Item("ReviewFrom")
                                    mUserCtrlInfoPack.SetQueryUser(theStaffID)
                                    theSPMSForm = SPMSForm.GetSPMSForm(mUserCtrlInfoPack, theReviewFrom)
                                    theSPMSForm.SetSubmitActionRefreshDBFlds()
                                    theSPMSForm.SaveForm()
                                    mRecordsRefreshedCnt += 1
                                    theSPMSForm = Nothing
                                Next
                            End If
                        End Using
                    End Using
                End Using
            End Using

        End Sub
    End Class

 In summary, the above command will read the SPMS (Staff Performance) Forms Data Source from XML (Text) Data Files, and copy the results to SQL Server Table. The above implementaion is structured in a very similar way to the CSLA Sample Business Object "Project.vb", the ExistsCommand object impementation.

I want provide feedback to the client about the progress using the properties "RecordsToBeRefreshedCnt" and "RecordsRefreshedCnt", and update the Progress Bar.

I think I need to do the following:

1. Create a Button on a ASP.NET Web Form to call "RefreshDBFields" from a thread.

2. On Click of this Button, create a thread, which will call the function "RefreshDBFields", store the result in a session variable "RefreshDBFieldsSession".

3. After creating the thread, enable refresh of the Web Form every, say, 3 seconds. Trigger the Progress Bar. Should I use Ajax Update Panel?

4. Inside the Refresh Event, get the object from the session variable "RefreshDBFieldsSession", and read the progress, and update the progress bar.

5. When the update is completed, kill the thread, and remove the progress bar.

I need your feedback on this, any any recommendation.

Tarek.

tarekahf replied on Wednesday, March 14, 2012

Just to confirm that I managed to implement the required functinoality.

For more details, check here:

http://www.essentialobjects.com/forum/postst6503_How-to-report-exception-from-Progress-Bar-RunTask-Event.aspx

Tarek.

Copyright (c) Marimer LLC