We have 6 merge replication jobs and 4 snapshot jobs that run on our clients. I have implemented the process through a WinForms app using SMO and RMO because the process is always the same. For the merge replication jobs, I have implemented a replication monitor to monitor progress. However, I have not been able to get information about the process / progress of the snaphot other than the information behind the SnapshotGenerationAgent.Status Event and then the LastAgentJobHistory which only provides the first step. Is there a way through SMO / RMO to use the replication monitor for the Snapshot job? Here is what I use for the merge jobs but, i could not find an equivalent TransSubscriberMonitor or SnapshotSubscriberMonitor.
Private Sub MonitorReplication(ByVal voMergeSubscriberMonitor As MergeSubscriberMonitor)
Dim SessionSummary As MergeSessionSummary
Dim SessionDetail() As MergeSessionDetail
Dim bContinue As Boolean = True
Dim bFirstLoop As Boolean
Dim oListItem As ListViewItem
Dim sSavedMessage As String
Dim oSummaryListItem As ListViewItem
If (Me.Visible = False) Then
Me.Visible = True
End If
Try
While voMergeSubscriberMonitor.GetLastSessionSummary() Is Nothing
Application.DoEvents()
End While
SessionSummary = voMergeSubscriberMonitor.GetLastSessionSummary()
oSummaryListItem = Me.lvwSummary.Items.Add(SessionSummary.Status.ToString)
oSummaryListItem.SubItems.Add(SessionSummary.StartTime)
oSummaryListItem.SubItems.Add(SessionSummary.EndTime)
oSummaryListItem.SubItems.Add(Me.ConvertMSToTimeLine(SessionSummary.Duration * 1000, False))
oSummaryListItem.SubItems.Add(SessionSummary.NumberOfUploads)
oSummaryListItem.SubItems.Add(SessionSummary.NumberOfDownloads)
oSummaryListItem.SubItems.Add("")
sSavedMessage = SessionSummary.LastMessage
LogToWindow(sSavedMessage)
bFirstLoop = True
While bContinue = True
Try
Application.DoEvents()
voMergeSubscriberMonitor.RefreshSessionSummary(SessionSummary)
Catch ex As Exception
LogToWindow(ex.Message)
SessionSummary = Nothing
End Try
If (SessionSummary.LastMessage <> sSavedMessage) Then
sSavedMessage = SessionSummary.LastMessage
LogToWindow(sSavedMessage)
End If
Try
SessionDetail = voMergeSubscriberMonitor.GetSessionDetails(SessionSummary.SessionId)
Catch ex As Exception
SessionDetail = Nothing
End Try
If (SessionDetail IsNot Nothing AndAlso SessionDetail.Length > 0) Then
Me.lvwDetails.BeginUpdate()
For nIndex As Integer = 0 To SessionDetail.Length - 1
'LogToWindow(SessionSummary.CurrentPhase)
If (bFirstLoop = True) Then
oListItem = New ListViewItem
oListItem.Text = SessionDetail(nIndex).Message
oListItem.SubItems.Add(SessionDetail(nIndex).PercentOfTotalTime)
oListItem.SubItems.Add(Me.ConvertMSToTimeLine(SessionDetail(nIndex).Duration * 1000, False))
oListItem.SubItems.Add(SessionDetail(nIndex).Inserts)
oListItem.SubItems.Add(SessionDetail(nIndex).Updates)
oListItem.SubItems.Add(SessionDetail(nIndex).Deletes)
oListItem.SubItems.Add(SessionDetail(nIndex).SchemaChanges)
oListItem.SubItems.Add(SessionDetail(nIndex).RowsRetried)
oListItem.SubItems.Add(SessionDetail(nIndex).Conflicts)
Me.lvwDetails.Items.Add(oListItem)
Else
If (Me.lvwDetails.Items.Count >= (nIndex + 1)) Then
oListItem = Me.lvwDetails.Items(nIndex)
oListItem.Text = SessionDetail(nIndex).Message
oListItem.SubItems(1).Text = SessionDetail(nIndex).PercentOfTotalTime
oListItem.SubItems(2).Text = Me.ConvertMSToTimeLine(SessionDetail(nIndex).Duration * 1000, False)
oListItem.SubItems(3).Text = SessionDetail(nIndex).Inserts
oListItem.SubItems(4).Text = SessionDetail(nIndex).Updates
oListItem.SubItems(5).Text = SessionDetail(nIndex).Deletes
oListItem.SubItems(6).Text = SessionDetail(nIndex).SchemaChanges
oListItem.SubItems(7).Text = SessionDetail(nIndex).RowsRetried
oListItem.SubItems(8).Text = SessionDetail(nIndex).Conflicts
Else
oListItem = New ListViewItem
oListItem.Text = SessionDetail(nIndex).Message
oListItem.SubItems.Add(SessionDetail(nIndex).PercentOfTotalTime)
oListItem.SubItems.Add(Me.ConvertMSToTimeLine(SessionDetail(nIndex).Duration * 1000, False))
oListItem.SubItems.Add(SessionDetail(nIndex).Inserts)
oListItem.SubItems.Add(SessionDetail(nIndex).Updates)
oListItem.SubItems.Add(SessionDetail(nIndex).Deletes)
oListItem.SubItems.Add(SessionDetail(nIndex).SchemaChanges)
oListItem.SubItems.Add(SessionDetail(nIndex).RowsRetried)
oListItem.SubItems.Add(SessionDetail(nIndex).Conflicts)
Me.lvwDetails.Items.Add(oListItem)
End If
End If
Me.ProgressBar1.Value = SessionDetail(nIndex).PercentComplete
'If (SessionDetail(nIndex).PercentComplete >= 100) Then
' 'bContinue = False
'End If
'If (SessionDetail(nIndex).Errors IsNot Nothing AndAlso SessionDetail(nIndex).Errors.Length > 0) Then
' MsgBox("Would have")
' 'bContinue = False
'End If
Me.lvwDetails.EndUpdate()
Me.lvwDetails.Refresh()
Application.DoEvents()
Next
bFirstLoop = False
Else
bContinue = False
End If
oSummaryListItem.Text = SessionSummary.Status.ToString
oSummaryListItem.SubItems(1).Text = SessionSummary.StartTime
oSummaryListItem.SubItems(2).Text = SessionSummary.EndTime
oSummaryListItem.SubItems(3).Text = Me.ConvertMSToTimeLine(SessionSummary.Duration * 1000, False)
oSummaryListItem.SubItems(4).Text = SessionSummary.NumberOfUploads
oSummaryListItem.SubItems(5).Text = SessionSummary.NumberOfDownloads
If (SessionSummary.Errors IsNot Nothing AndAlso SessionSummary.Errors.Length > 0) Then
oSummaryListItem.SubItems(6).Text = (SessionSummary.Errors(0).ErrorMessage)
End If
Select Case SessionSummary.Status
Case MergeSessionStatus.Failed
bContinue = False
Case MergeSessionStatus.Idle
Case MergeSessionStatus.Interrupted
bContinue = False
Case MergeSessionStatus.NotStarted
Case MergeSessionStatus.Retry
Case MergeSessionStatus.Running
Case MergeSessionStatus.Starting
Case MergeSessionStatus.Succeeded
bContinue = False
End Select
End While
voMergeSubscriberMonitor.RefreshSessionSummary(SessionSummary)
If (SessionSummary.LastMessage <> sSavedMessage) Then
sSavedMessage = SessionSummary.LastMessage
LogToWindow(sSavedMessage)
End If
oSummaryListItem.Text = SessionSummary.Status.ToString
oSummaryListItem.SubItems(1).Text = SessionSummary.StartTime
oSummaryListItem.SubItems(2).Text = SessionSummary.EndTime
oSummaryListItem.SubItems(3).Text = Me.ConvertMSToTimeLine(SessionSummary.Duration * 1000, False)
oSummaryListItem.SubItems(4).Text = SessionSummary.NumberOfUploads
oSummaryListItem.SubItems(5).Text = SessionSummary.NumberOfDownloads
If (SessionSummary.Errors IsNot Nothing AndAlso SessionSummary.Errors.Length > 0) Then
oSummaryListItem.SubItems(6).Text = (SessionSummary.Errors(0).ErrorMessage)
End If
Me.lvwDetails.EndUpdate()
Me.lvwSummary.EndUpdate()
Catch ex As Exception
LogToWindow(ex.ToString)
End Try
End SubSteve