static void Main(string[] args) { try { Loggers.AvaillableLoggers.Add(new ConsoleLogger()); string SourceDirectoryPath = @"C:\temp\DossierPrincipale"; string TargetDirectoryPath = @"C:\temp\DossierSecondaire"; string SynchronisationMethode = "TwoWaySourceWon"; //OneWay - TwoWaySourceWon - TwoWayTargetWon SynchronisationService service = new SynchronisationService(SourceDirectoryPath, TargetDirectoryPath, SynchronisationMethode); service.Start(); Loggers.WriteInformation($"Démarrage du service"); Loggers.WriteInformation($"Ecoute du répertoire {SourceDirectoryPath}"); Loggers.WriteInformation($"Ecoute du répertoire {TargetDirectoryPath}"); Console.ReadKey(); Loggers.WriteInformation($"Fin du programme."); service.Stop(); } catch (Exception ex) { Loggers.WriteError(ex.ToString()); } }
protected override void OnStart(string[] args) { try { string sourceDirectoryPath = ConfigurationManager.AppSettings["SourceDirectoryPath"]; string targetDirectoryPath = ConfigurationManager.AppSettings["TargetDirectoryPath"]; string synchronisationMethode = ConfigurationManager.AppSettings["SynchronisationMethode"]; Loggers.WriteInformation($"Démarrage du service"); Loggers.WriteInformation($"Dossier source = {sourceDirectoryPath}"); Loggers.WriteInformation($"Dossier cible = {targetDirectoryPath}"); _Service = new SynchronisationService(sourceDirectoryPath, targetDirectoryPath, synchronisationMethode); _Service.Start(); } catch (Exception ex) { Loggers.WriteError(ex.ToString()); // On relance l'exception pour que le gestionnaire de service ne finalise pas le démarrage du service. throw new Exception("Erreur au démarrage du service.", ex); } }