Files
Kelloggs_v4/B4A/errorManager.bas
Jose Alberto Guerra Ugalde 626a4eb59c 29/10/23 - Corrección de ErrorManager
- Se corrigio el código de errorManager para que guarde y envie correctamente los errores a la tabla PushInfo
2023-10-29 19:53:12 -06:00

170 lines
5.4 KiB
QBasic

B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=10.2
@EndOfDesignText@
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'******************************************************************************
'Este modulo intercepta los errores de la aplicación mediante "Starter.Application_Error" y muestra una pantalla
'con el log del error y lo manda al servidor con un query de DBRequestManager, se necesita que exista el query
'en el "config.properties" llamado "guardaErrores" y que tenga el siguiente texto:
'
'sql.guardaErrores=INSERT INTO KELLOGGS.PUSH_INFO (ID, RUTA, FECHA, DATOS) VALUES((?),(?),(?),(?))
'
'Agregar estas lineas a "Starter.Process_Globals"
' 'Para los Logs
' Dim logs As StringBuilder
' Private logcat As LogCat
'
'Agregar estas lineas a "Starter.Service_Create"
' 'Para los Logs
' #if RELEASE
' logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
' #end if
' logs.Initialize
'
'Agregar este Sub a "Starter"
'
'Return true to allow the OS default exceptions handler to handle the uncaught exception. 'Para los Logs
'Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
' 'wait for 500ms to allow the logs to be updated.
' Dim jo As JavaObject
' Dim l As Long = 500: jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l)) 'Sleep 500ms
' logcat.LogCatStop
' logs.Append(StackTrace)
' Subs.revisaBD
' Subs.errorLog.ExecNonQuery2("INSERT INTO errores(fecha, error) VALUES (?,?)", Array As Object (Subs.fechaKMT(DateTime.now), logs))
' StartActivity(errorManager)
' Return True
'End Sub
'******************************************************************************
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
' Dim errorLog As SQL
Dim c As Cursor
Private p_principal As Panel
Private l_titulo As Label
Private svScroll As ScrollView
Private etText As EditText
Private c_continuar As Button
Private p_botones As Panel
Private b_salir As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("errorManager")
End Sub
Sub Activity_Resume
Dim elError As String = ""
Dim laFecha As String = ""
' svScroll.Initialize(500dip)
' Activity.AddView(svScroll, 0, 300, 100%x, 80%y)
p_principal.Height = Activity.Height
p_principal.Width = Activity.Width
svScroll.Width = Round(p_principal.Width * 0.9)
svScroll.Left = Round(p_principal.Width/2)-Round(svScroll.Width/2)
p_botones.Left = Round(p_principal.Width/2)-Round(p_botones.Width/2)
p_botones.Top = Activity.Height - (p_botones.Height + 80)
etText.Initialize("")
etText.TextSize = 13
' etText.Wrap = True
' Activity.RemoveViewAt(1)
svScroll.Panel.AddView(etText, 0, 0, 90%x, 80%y)
' etText.Width = svScroll.Width - 100
etText.InputType = etText.INPUT_TYPE_NONE
etText.Gravity = Gravity.TOP
etText.SingleLine = False
etText.Wrap = True
' Dim lblText, edtText As StringBuilder
Dim lbl As Label
lbl.Initialize("")
Activity.AddView(lbl, 0, 300, 100%x, 100%y) 'ignore
etText.Text = ""
' Subs.revisaBD
c = Starter.errorLog.ExecQuery("select * from errores order by fecha desc limit 1")
If c.RowCount > 0 Then
c.Position = 0
elError = c.GetString("error")
laFecha = c.GetString("fecha")
etText.Text = elError
End If
c.Close
Dim usuario As String = ""
c = Starter.skmt.ExecQuery("select usuario from usuarioa")
If c.RowCount > 0 Then
c.Position = 0
usuario = c.GetString("USUARIO")
End If
' Log("++++++" & Starter.logsStr)
' etText.Text = etText.Text & Starter.logsStr
' lbl.TextSize = etText.TextSize
' lbl.Text = etText.Text
' Dim su As StringUtils
' Dim edheight As Int = su.MeasureMultilineTextHeight(lbl, lbl.Text)
' lbl.RemoveView
' etText.Height = edheight
' svScroll.Panel.Height = edheight
svScroll.Height = Round(Activity.Height * 0.9)
' Log(edheight)
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "guardaErrores"
cmd.Parameters = Array As Object(laFecha, usuario&"|"&Starter.rutaV, laFecha, elError)
Log($"Mandamos: ${Subs.fechaKMT(DateTime.Now)}, |${usuario}|, ${Subs.fechaKMT(DateTime.Now)}"$)
Starter.reqManager.ExecuteCommand(cmd,"guardaErrores")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success = False Then
ToastMessageShow("Error: " & Job.ErrorMessage, True)
Else
LogColor("JobDone: '" & Starter.reqManager.HandleJob(Job).tag & "' - Registros: " & Starter.reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
If Job.JobName = "DBRequest" Then
Dim result As DBResult = Starter.reqManager.HandleJob(Job)
If result.Tag = "guardaErrores" Then 'query tag
For Each records() As Object In result.Rows
For Each k As String In result.Columns.Keys
Log("GuardaErrores: " & k & ": " & records(result.Columns.Get(k)))
Next
Next
End If
End If
End If
Job.Release
End Sub
Private Sub c_continuar_Click
Subs.iniciaActividad("Principal")
' B4XPages.ShowPage("Principal")
End Sub
Private Sub b_salir_Click
cierraActividades
End Sub
Sub cierraActividades
Log("closing activities")
Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("finishAffinity", Null)
End Sub