private void StartTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) { ((System.Timers.Timer)sender).Enabled = false; serviceEventLog.WriteEntry("Starting mirroring."); _runner = new MirrorRunner(_settings, serviceEventLog); var started = false; while (!started) { try { _runner.Start(); serviceEventLog.WriteEntry("Mirroring started."); _waitHandle.WaitOne(); started = true; } catch (Exception ex) { serviceEventLog.WriteEntry( "Starting mirroring failed with the following exception: " + ex + Environment.NewLine + "A new start will be attempted in 30s.", EventLogEntryType.Error); Thread.Sleep(30000); } } }
public static void Main() { // If true then a unique event log will be used for all copies of this executable. This helps if you want to // run the app in multiple instances from source and not let the events show up across copies. const bool useUniqueEventlog = true; var eventLogName = "Git-hg Mirror Daemon"; var eventSourceName = "GitHgMirror.Tester"; if (useUniqueEventlog) { var suffix = "-" + typeof(Program).Assembly.Location.GetHashCode(); // "Only the first eight characters of a custom log name are significant" so we need to make the name // unique withing 8 characters. eventLogName = "GHM" + suffix; eventSourceName += suffix; } if (!EventLog.Exists(eventLogName)) { EventLog.CreateEventSource(new EventSourceCreationData(eventSourceName, eventLogName)); } using var eventLog = new EventLog(eventLogName, ".", eventSourceName) { EnableRaisingEvents = true, }; eventLog.EntryWritten += (sender, e) => Console.WriteLine(e.Entry.Message); var settings = new MirroringSettings { ApiEndpointUrl = new Uri("http://githgmirror.com.127-0-0-1.org.uk/api/GitHgMirror.Common/Mirrorings"), ApiPassword = "******", RepositoriesDirectoryPath = @"C:\GitHgMirror\Repos", MaxDegreeOfParallelism = 1, BatchSize = 1, }; // Uncomment if you want to also test repo cleaning. ////new UntouchedRepositoriesCleaner(settings, eventLog).Clean(new CancellationTokenSource().Token); using var runner = new MirrorRunner(settings, eventLog); // On exit with Ctrl+C Console.CancelKeyPress += (sender, e) => runner.Stop(); runner.Start(); _waitHandle.WaitOne(); }
static void Main(string[] args) { if (!EventLog.Exists("Git-hg Mirror Daemon")) { EventLog.CreateEventSource(new EventSourceCreationData("GitHgMirror.Tester", "Git-hg Mirror Daemon")); } using (var eventLog = new EventLog("Git-hg Mirror Daemon", ".", "GitHgMirror.Tester")) { eventLog.EnableRaisingEvents = true; eventLog.EntryWritten += (sender, e) => { Console.WriteLine(e.Entry.Message); }; var settings = new MirroringSettings { ApiEndpointUrl = new Uri("http://githgmirror.com.127-0-0-1.org.uk/api/GitHgMirror.Common/Mirrorings"), ApiPassword = "******", RepositoriesDirectoryPath = @"C:\GitHgMirror\Repos", MaxDegreeOfParallelism = 1, BatchSize = 1 }; // Uncomment if you want to also test repo cleaning. //new UntouchedRepositoriesCleaner(settings, eventLog).Clean(new CancellationTokenSource().Token); var runner = new MirrorRunner(settings, eventLog); // On exit with Ctrl+C Console.CancelKeyPress += (sender, e) => { runner.Stop(); }; runner.Start(); _waitHandle.WaitOne(); } }