Files
Monitor-Keymon/B4A/Starter.bas

212 lines
7.2 KiB
QBasic

B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Service
Version=9.85
@EndOfDesignText@
#Region Service Attributes
#StartAtBoot: true
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public rp As RuntimePermissions
' Dim reqManager As DBRequestManager
Dim DBReqServer As String = "http://keymon.lat:1782"
Dim skmt As SQL
' Dim Timer1 As Timer
' Dim Interval As Int = 30
Dim s As C_Subs
' Dim nid As Int = 51042
Dim monitorActivo As Boolean = True
' Dim InternetOk As Boolean = True
' Dim DBReqServerOk As Boolean = True
' Dim DBOk As Boolean = True
Dim logger As Boolean = False
Dim ping As Boolean = False
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
' Timer1.Initialize("Timer1", Interval * 1000)
' Timer1.Enabled = True
#if not(DEBUG)
logger = False
#end if
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
s.Initialize
skmt = s.inicializaBD(File.DirInternal, "kmt.db")
skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS cat_variables(nombre TEXT, valor text)")
If s.traeDBReqServerDeBD <> "N/A" Then DBReqServer = s.traeDBReqServerDeBD
' reqManager.Initialize(Me, DBReqServer)
StartService(Monitor)
End Sub
'
'Sub CreateNotification (Body As String) As Notification
' Dim notification As Notification
' notification.Initialize2(notification.IMPORTANCE_LOW)
' notification.Icon = "icon"
' notification.SetInfo("Tester", Body, Main)
' Return notification
'End Sub
'
''Genera una notificacion con importancia alta
'Sub notiHigh(title As String, body As String, id As String, activity As Object) 'ignore
' activity = Main
' Private notif As Notification
' notif.Initialize2(notif.IMPORTANCE_HIGH)
' notif.Icon = "icon"
' notif.Vibrate = False
' notif.Sound = False
' notif.AutoCancel = True
' If logger Then Log("notiHigh: "&title)
' notif.SetInfo(title, body, activity)
'' Log("notiHigh SetInfo")
' notif.Notify(id)
'End Sub
'
''Regresa el objeto de una notificacion con importancia baja
'Sub notiLowReturn(title As String, Body As String, id As Int) As Notification 'ignore
' Private notification As Notification
' notification.Initialize2(notification.IMPORTANCE_LOW)
'' Log("notiLowReturn: "&title)
' notification.Icon = "icon"
' notification.Sound = False
' notification.Vibrate = False
' notification.SetInfo(title, Body, Main)
' notification.Notify(id)
'' Log("notiLowReturn SetInfo")
' Return notification
'End Sub
'
'Sub Timer1_Tick
'' DateTime.DateFormat = "dd/MM HH:mm:ss"
'' If B4XPages.IsInitialized Then B4XPages.MainPage.l_ultimoPing.Text = $"Último ping: ${DateTime.Date(DateTime.now)}"$
'' If monitorActivo Then probamosConexion
'End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
Sub Service_Destroy
End Sub
'
'Sub probamosConexion
'' Log("probamos probamosConexion")
' If B4XPages.IsInitialized Then
' B4XPages.MainPage.cb_internet.Checked = False
' B4XPages.MainPage.cb_dbreqserver.Checked = False
' B4XPages.MainPage.cb_db.Checked = False
' End If
' If IsConnectedToInternet Then
' InternetOk = True
' If B4XPages.IsInitialized Then
' B4XPages.MainPage.cb_internet.Checked = True
' Dim cd1 As ColorDrawable
' cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
' B4XPages.MainPage.b_ping.Background = cd1
' B4XPages.MainPage.b_ping.Text = "Internet Ok"
' End If
' Dim cmd As DBCommand
' notiLowReturn("Con internet", "Hay conexion a internet", nid)
' If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "Hay conexion a internet!!"
' Dim cmd As DBCommand
' cmd.Initialize
' cmd.Name = "select_conexion"
' reqManager.ExecuteQuery(cmd, 0, "select_conexion", 1250)
' 'Reiniciamos el timer para cuando llamamos el Sub desde "seleccion"
' Timer1.Enabled = False
' Timer1.Interval = Interval * 1000
' Timer1.Enabled = True
' Else
' If logger Then Log("Sin conexión a internet!!!")
' notiLowReturn("Sin internet", "NO hay conexion a internet", nid)
' If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "NO hay conexion a internet!!"
' End If
'
'End Sub
'
'Sub reinicializaReqManager
' reqManager.Initialize(Me, DBReqServer)
' If logger Then Log("Inicializamos con: " & DBReqServer)
'End Sub
'
'Sub JobDone(Job As HttpJob)
'' Log("JOBDONE -- " & Job.Success)
'' Log(Job)
' If Job.Success = False Then
' If Job.JobName = "DBRequest" Then DBReqServerOk = False
'
' Dim cd1 As ColorDrawable
' cd1.Initialize(Colors.Red, 10dip)
' B4XPages.MainPage.b_ping.Background = cd1
' B4XPages.MainPage.b_ping.Text = "DBReqServer KO"
' notiHigh("Con internet", $"El servidor ${DBReqServer} NO responde!!"$, nid, Main)
' If Job.ErrorMessage.Contains("failed to connect") Or Job.ErrorMessage.Contains("Failed to connect") Then
' ToastMessageShow("¡Hubo un error contactando al servidor, por favor revise su conexión!", True)
' End If
' Else
' If Job.JobName = "DBRequest" Then DBReqServerOk = True
' If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211027
' If Job.JobName = "DBRequest" Then
' Dim resultado As DBResult = reqManager.HandleJob(Job)
' If resultado.Tag = "select_conexion" Then
' For Each records() As Object In resultado.Rows
' Private valor As String = records(resultado.Columns.Get("VALOR"))
' If valor = "OK" Then
' DBOk = True
' notiLowReturn("Con internet", $"El servidor esta respondiendo!!"$, nid)
' If B4XPages.IsInitialized Then
' B4XPages.MainPage.l_status.Text = "El servidor esta respondiendo!!"
' Dim cd1 As ColorDrawable
' cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
' B4XPages.MainPage.b_ping.Background = cd1
' B4XPages.MainPage.b_ping.Text = "Servidor Ok"
' End If
' Else
' notiHigh("Con internet", $"El servidor NO esta respondiendo!!"$, nid, Main)
' If B4XPages.IsInitialized Then
' B4XPages.MainPage.l_status.Text = "El servidor NO esta respondiendo!!"
' Dim cd1 As ColorDrawable
' cd1.Initialize(Colors.Red, 10dip)
' B4XPages.MainPage.b_ping.Background = cd1
' B4XPages.MainPage.b_ping.Text = "Servidor KO"
' End If
' End If
' Next
' End If
'' s.logJobDoneResultados(resultado)
' If resultado.Rows.Size = 0 Then DBOk = False
'' Log(resultado.Rows.Size)
' End If
' If B4XPages.IsInitialized Then
' B4XPages.MainPage.cb_internet.Checked = InternetOk
' B4XPages.MainPage.cb_dbreqserver.Checked = DBReqServerOk
' B4XPages.MainPage.cb_db.Checked = DBOk
' End If
' Job.Release
' End If
'
'End Sub
'
'Sub IsConnectedToInternet As Boolean 'ignore
' Dim r As Reflector
' r.Target = r.GetContext
' r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
' r.Target = r.RunMethod("getActiveNetworkInfo")
' If r.Target <> Null Then
' If logger Then LogColor("isConnectedOrConnecting", Colors.green)
' Return r.RunMethod("isConnectedOrConnecting")
' End If
' If logger Then LogColor("Not connected", Colors.red)
' Return False
'End Sub