1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/// <summary>
/// Permet de copier les logs du PDA sur le serveur.
/// </summary>
public void CopieLogServeur()
{
FileStream flux = null;
try
{
// Récupération des chemins des répertoires local et distant.
string repLogsLocal = MobileConfiguration.Settings["RepLogsLocal"];
string repLogsServeur = MobileConfiguration.Settings["RepLogsServeur"];
DirectoryInfo local = new DirectoryInfo(repLogsLocal);
DirectoryInfo serveur = new DirectoryInfo(repLogsServeur);
// Si les répertoires local et distant existent.
// if (Directory.Exists(repLogsLocal) == true && Directory.Exists(repLogsServeur) == true)
if (local.Exists == true && serveur.Exists == true)
{
// Liste les fichiers du dossier local.
FileInfo[] listeFichiers = local.GetFiles().OrderByDescending(f => f.LastWriteTime).ToArray();
// Pour chaque fichier listé, le copier sur le serveur distant.
foreach (FileInfo fichier in listeFichiers)
{
string fichierSource = Path.Combine(repLogsLocal, fichier.Name);
string fichierDestination = Path.Combine(repLogsServeur, fichier.Name);
FileInfo infoSource = new FileInfo(fichierSource);
FileInfo infoDestination = new FileInfo(fichierDestination);
// Si le fichier n'existe pas sur le serveur,
// Ou la date de modification entre le fichier en local et celui du serveur > 5 secondes,
// Alors le fichier est copié sur le serveur.
if (infoDestination.Exists == false || (infoDestination.Exists == true && ((infoSource.LastWriteTime - infoDestination.LastWriteTime).TotalSeconds > 5)))
{
using (flux = infoSource.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
infoSource.CopyTo(fichierDestination, true);
infoDestination.Attributes = FileAttributes.Normal;
flux.Close();
}
}
}
}
}
catch (Exception ex)
{
MasterForm.Log.ErrorFormat("Erreur copie de log {0} : {1}", ex.GetType().ToString(), ex.Message);
}
finally
{
if (flux != null)
{
flux.Close();
}
}
} |
Partager