/// <summary> /// Checks if CAST has been enabled and remote communication has been configured for this platform. /// </summary> /// <returns>True if CAST communication should take place.</returns> public bool GetIsCastConfigured() { using (Profiler.Measure("CastService.GetIsCastConfigured")) { var isCastEnabled = false; var isRabbitMqConfigured = false; // is CAST enabled? var castConfiguration = ConfigurationSettings.GetCastConfigurationSection(); if (castConfiguration != null) { var castSettings = castConfiguration.Cast; if (castSettings != null) { isCastEnabled = castSettings.Enabled; } } // is RabbitMQ configured for communication? var mqConfiguration = ConfigurationSettings.GetRabbitMqConfigurationSection(); if (mqConfiguration != null) { var mqSettings = mqConfiguration.RabbitMq; if (mqSettings != null) { isRabbitMqConfigured = !string.IsNullOrEmpty(mqSettings.HostName); } } return(isCastEnabled && isRabbitMqConfigured); } }
/// <summary> /// Starts a timer which will send a heartbeat message every hour. /// </summary> private void StartHeartbeat() { var castConfiguration = ConfigurationSettings.GetCastConfigurationSection(); if (castConfiguration == null) { return; } var castSettings = castConfiguration.Cast; if (castSettings == null) { return; } if (castSettings.Enabled != true) { return; } var interval = castConfiguration.Cast.Heartbeat; if (interval < 0) { interval = 60; } EventLog.Application.WriteInformation("Sending heartbeat every {0} minutes.", interval); //CastService.SendHeartbeat(); _timer.Interval = interval * 1000 * 60; _timer.Elapsed += (s, a) => { try { EventLog.Application.WriteInformation("Sending heartbeat."); CastService.SendHeartbeat(); } catch (Exception ex) { EventLog.Application.WriteError("Unexpected failure starting CAST heartbeat on timer. {0}", ex); } }; _timer.Start(); }