Type=Service
Version=2.71
@EndOfDesignText@
'Module Service : SMB
#Region Module Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'Src signifie Serveur et Dest = Tablette
Dim usismb As SMB
'Activity is expected to set URL
Dim Src,Dest,Fil,Fil2,Jour, Heure As String
Dim Listfil As List
Dim Action As Int
Dim DoneSuccessfully As Boolean
Dim Notification1 As Notification
Dim Abandon As Boolean
End Sub
Sub Service_Create
'Initialisation du Module SMBservrice
usismb.Initialize("usismb")
Notification1.Initialize
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = True
Log ("SMB : Début du service")
End Sub
'Récapitulatif des actions possibles
'Action = 100 : Copie d'un fichier du serveur à la tablette
'Action = 200 : Copie d'un fichier de la tablette au serveur
'Action = 300 : Comparaison de la date de modification
'Action = 400 : Recherche liste fichiers
'Action = 500 : Supression d'un fichier ou dossier
'______________________________________________________________________
Sub Service_Start
'Initialisation de la connexion au serveur
usismb.SetCredentials(bibli.UtilisateurServeur,bibli.MotDePasseServeur,bibli.DomaineServeur)
DoneSuccessfully= False
Abandon = False
If Action = 4000 Then 'copie du fichier texte nommé jeton vers le repertoire
Log("copie du jeton")
Log(Dest)
Log(Fil)
Log(Src)
usismb.UploadFile(Dest,Fil,Src,Fil2)'Copie du fichier
End If
If Action = 202 Then' sauvegarde Qualité-Fabrication
usismb.uploadFile(Dest,Fil,Src,Fil)'Copie du fichier
'bibli.valeur=4011
ToastMessageShow("Plan Qualité-Fabrication sauvegardé sur le serveur",False)
End If
If Action = 201 Then ' sauvegarde page notation
usismb.uploadFile(Dest,Fil,Src,Fil)'Copie du fichier
ToastMessageShow("page sauvegardé sur le serveur",False)
End If
If Action = 203 Then ' sauvegarde photo
usismb.uploadFile(Dest,Fil,Src,Fil)'Copie du fichier
End If
If Action = 100 Then
usismb.DownloadFile(Src,Fil,Dest,Fil)'Copie du fichier
'Copier un fichier de la tablette au serveur
Else If Action = 200 Then
'If bibli.TesteVerrouDT()=False Then
' usismb.uploadFile(Dest,Fil,Src,Fil)'Copie du fichier
' bibli.valeur=4001
' CallSub(Main,"VerrouilleDT")
' CallSub(Main,"AfficheProtege")
' Else
'bibli.Msgbox1("Dossier technique verrouillé en écriture."&CRLF&"Aucune modification n'a été prise en compte.","Information")
' CallSub(Main,"MainMsgBox1")
' Abandon = True
'End If
'Liste des fichiers
Else If(Action = 300 OR Action = 400) Then
Log("ttt")
usismb.ListFiles(Src,Fil)'Recherche les fichiers
Else If Action = 500 Then
usismb.DeleteFile(Src,Fil)'Suppresion d'un dossier ou fichier
End If
If Abandon = False Then
'Affichage d une notification dans la barre des tâches
Notification1.SetInfo("SMB service en cours", "En cours: " & Fil, Main)
Notification1.Sound = False'Pas du son
Service.StartForeground(1, Notification1)
Else
Fin
End If
End Sub
'Signale la fin de la copie du serveur à la tablette
Sub usismb_DownloadCompleted (Url As String, RemoteFile As String, Success As Boolean)
If Not(Success) Then
Log(LastException)
DoneSuccessfully = False
Fin
Else
'ToastMessageShow( "Download Completed", True)
Log("SMB : Copie terminée")
DoneSuccessfully = Success
Fin
End If
End Sub
'Signale la fin de la copie de la tablette au serveur
Sub usismb_UploadCompleted (Url As String, RemoteFile As String, Success As Boolean)
If Not(Success) Then
Log(LastException)
Else
'ToastMessageShow( "Download Completed", True)
Log("SMB : Copie terminée")
DoneSuccessfully = Success
End If
Fin
End Sub
'Récupère la date de modification
Sub usismb_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
If Not(Success) Then
Log(LastException)
Else
Listfil.Initialize
Log("SMB : Listage fichiers")
For i = 0 To Entries.Length - 1
If Action= 300 Then
Jour = DateTime.Date(Entries(i).LastModified)
Heure = DateTime.Time(Entries(i).LastModified)
Log(Heure)
Log(Jour)
taille = Entries(i).Size
Else If Action = 400 Then
Delay(200)
Listfil.Add(Entries(i).Name)
Delay(200)
End If
Next
DoneSuccessfully = Success
End If
Fin
End Sub
'Signale la fin de la supression du fichier
Sub usismb_DeleteCompleted (Url As String, RemoteFile As String, Success As Boolean)
If Not(Success) Then
Log(LastException)
Else
DoneSuccessfully = Success
Log("SMB : Suppression terminée")
End If
Fin
End Sub
Sub Fin
Log("SMB : Fin du service")
Service.StopForeground(1) 'Retourne le service en 'background' (supprime aussi la notification)
'Si l'activité est en pause, une notification est envoyée
If IsPaused(Main) Then
Notification1.Sound = False
Notification1.SetInfo("Service SMB", "Action terminée", Main)
Notification1.AutoCancel = True
Notification1.Notify(1)
End If
End Sub
Sub Service_Destroy
End Sub
'fonction delay
Sub Delay(nMilliSecond As Long)As Boolean
Dim nBeginTime As Long
Dim nEndTime As Long
nEndTime = DateTime.Now + nMilliSecond
nBeginTime = DateTime.Now
Do While nBeginTime < nEndTime
nBeginTime = DateTime.Now
'Log(nBeginTime)
If nEndTime < nBeginTime Then
Return True
End If
DoEvents
Loop
End Sub