PHB2
Here is the Service Job Done sub. Note since I am just using the response, it a just a string. Note how the parser As JASONParser is used. I didn't invent any of this - just plaguerized from this site. Sorry, no time to cut out the non-specific parts.
Sub SvcJobDone (Job As String)
If HttpUtils.IsSuccess(PostUrl) Then
Dim response As String
Select Job
Case "Status"
'If HttpUtils.IsSuccess(PostUrl) Then
response = HttpUtils.GetString(PostUrl)
Dim strCheck As String
strCheck = response.SubString2(0,1)
listAStatus.Initialize
listAStatus.Clear
Dim HasUnAcknowledged As Boolean
HasUnAcknowledged = False
If strCheck = "x" Then 'nothing to report
'clear messages
HttpUtils.Complete = False
AlertCount = 0
Else
Dim parser As JSONParser
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray
'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
'listAStatus.Clear
For I = 0 To rows.Size - 1
'Log("Rows #" & i)
Dim m As Map
m = rows.Get(I)
Dim newAStatus As AndonStatus
newAStatus.Initialize
newAStatus.AlertId = m.Get("AlertID")
newAStatus.Location = m.Get("Location")
newAStatus.AlertLevel = m.Get("AlertLevel")
newAStatus.AlertTime = m.Get("AlertTime")
newAStatus.AcknowledgedTime = m.Get("AcknowledgedTime")
newAStatus.AcknowledgedBy = m.Get("AcknowledgedBy")
newAStatus.Comment = m.Get("Comment")
newAStatus.ClosedTime = m.Get("ClosedTime")
newAStatus.Station = m.Get("Station")
newAStatus.IsStop = m.Get("IsStop")
newAStatus.Reply = m.Get("Reply")
newAStatus.LocationID = m.Get("LocationID")
newAStatus.StationID = m.Get("StationID")
newAStatus.AckID = m.Get("AckID")
newAStatus.CallOrder = m.Get("CallOrder")
'If list item isn't call order 1 then wait 1 minute per call level based on AlertTime
If newAStatus.CallOrder = 1 Then
listAStatus.Add(newAStatus)
Else
DateTime.DateFormat = "yyyy-MM-dd" '!IMPORTANT
Dim now As Long
now = DateTime.now
Dim NowTicks As Long
NowTicks = DateTime.DateParse(DateTime.Date(now)) + DateTime.TimeParse(DateTime.Time(now))
Dim myAlertTime As Long
myAlertTime = DateTime.DateParse(newAStatus.AlertTime.SubString2(0,newAStatus.AlertTime.IndexOf(" "))) _
+ DateTime.TimeParse(newAStatus.AlertTime.SubString(newAStatus.AlertTime.IndexOf(" ") + 1))
If newAStatus.CallOrder = 2 AND myAlertTime < NowTicks - 60000 Then
listAStatus.Add(newAStatus)
End If
If newAStatus.CallOrder = 3 AND myAlertTime < NowTicks - 120000 Then
listAStatus.Add(newAStatus)
End If
End If
If newAStatus.AcknowledgedBy = "" Then
HasUnAcknowledged = True
End If
Next
If listAStatus.Size > AlertCount AND HasUnAcknowledged Then
SoundAlert = True
tmrAlert.Enabled = True
BeepCount = 0
AlertCount = listAStatus.Size
If IsPaused(Main) Then
Notification1.SetInfo("Andon Alert", "New alert found", Main)
Notification1.AutoCancel = True
Notification1.Notify(1)
End If
End If
End If
If Not(IsPaused(Main)) Then
CallSub(Main, "ShowStatus")
End If
If listAStatus.Size = 0 Then
Notification1.Cancel(1)
End If
End Select
HttpUtils.Complete = False
If Not(IsPaused(Main)) Then
CallSub(Main, "LastPollTime")
End If
End If
'StopService("")
End Sub