#Region Module Attributes
#StartAtBoot: True
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
Sub Process_Globals
Dim FTP_download As FTP
Dim JobStatus As Int
Dim STATUS_NONE, STATUS_WORKING, STATUS_DONE,STATUS_Destroy As Int
Dim message As List
STATUS_NONE = 0
STATUS_WORKING = 1
STATUS_DONE = 2
STATUS_Destroy=3
Public Rep_serveur_chat As String="/Chat/"
Public DoneSuccessfully As Boolean=False
Dim notif_mess As AdvancedNotification
Dim num As Int=0
Dim statut_main_up As Boolean=False
Dim delay_synchro As Int=5
Dim last_event As Long = DateTime.Now
Dim file_downloaded As Int =0
Dim timer_service As Timer
Dim PI As PhoneId
Dim read_data_param As String=""
Dim Bconv As ByteConverter
Dim Type_Param_init=4 As Int
Dim FTP_adress As String=""
Dim login As String=""
Dim pwd As String=""
Dim station As String=""
End Sub
Sub Service_Create
' Load init file
initfile
' Initalisation du timer
timer_service.Initialize("Timer_service",5000)
timer_service.Enabled=True
If FTP_download.IsInitialized=False Then
FTP_download.Initialize("FTP", FTP_adress, 21, login, pwd)
End If
message.Initialize
message.Clear
notif_mess.Initialize
notif_mess.Number=2
notif_mess.Sound=False
End Sub
Sub Timer_service_Tick
Try
JobStatus=STATUS_WORKING
FTP_download.List(Rep_serveur_chat)
Catch
ToastMessageShow("Erreur de lecture sur serveur FTP", True)
Log(LastException)
End Try
End Sub
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
' Relance une session FTP si déconnecté
If Success=False Then
'FTP_download.CloseNow
FTP_download.CloseNow
'StopService(Me)
Log("defaut ftp : " & FTP_adress & "/" & login & "/" & pwd)
FTP_download.Initialize("FTP", FTP_adress, 21, login, pwd)
End If
' Charge les messages où je suis destinataire
Try
file_downloaded=0
num =0
For i = 0 To Files.Length - 1
If Files(i).Name.Contains(station)=True Then
num=num+1
FTP_download.DownloadFile(Rep_serveur_chat & Files(i).Name, False,File.DirDefaultExternal, "/chat/" & "message" & num & ".log")
End If
Next
Catch
ToastMessageShow("Erreur de lecture sur serveur FTP", True)
Log(LastException)
End Try
Log(num & " messages")
End Sub