private void OnTimer(object sender, ElapsedEventArgs e) { try { EventLog.WriteEntry("Checking for new bark", EventLogEntryType.Information); var newLatestBark = GetLatestBark().GetAwaiter().GetResult(); if (newLatestBark != null && (LatestBark == null || newLatestBark.Id != LatestBark.Id)) { EventLog.WriteEntry("Sending new bark: " + newLatestBark.Bark, EventLogEntryType.Information); if (!string.IsNullOrWhiteSpace(TwilioAccountSid) && !string.IsNullOrWhiteSpace(TwilioAuthToken)) { var twilioClient = new TwilioRestClient(TwilioAccountSid, TwilioAuthToken); twilioClient.SendMessage(TwilioSenderNumber, TwilioRecipentNumber, "🐶 " + newLatestBark.Bark); } else { EventLog.WriteEntry("Twilio account SID or AuthToken not configured", EventLogEntryType.Warning); } LatestBark = newLatestBark; } } catch (Exception exception) { EventLog.WriteEntry(exception.Message, EventLogEntryType.Error); } }
private void OnTimer(object sender, ElapsedEventArgs e) { try { EventLog.WriteEntry("Checking for new bark", EventLogEntryType.Information); var newLatestBark = GetLatestBark().GetAwaiter().GetResult(); if (newLatestBark != null && (LatestBark == null || newLatestBark.Id != LatestBark.Id)) { EventLog.WriteEntry("Sending new bark: " + newLatestBark.Bark, EventLogEntryType.Information); if (!string.IsNullOrWhiteSpace(TwilioAccountSid) && !string.IsNullOrWhiteSpace(TwilioAuthToken)) { var twilioClient = new TwilioRestClient(TwilioAccountSid, TwilioAuthToken); twilioClient.SendMessage(TwilioSenderNumber, TwilioRecipentNumber, "🐶 " + newLatestBark.Bark); } else { EventLog.WriteEntry("Twilio account SID or AuthToken not configured", EventLogEntryType.Warning); } LatestBark = newLatestBark; } } catch (Exception exception) { EventLog.WriteEntry(exception.Message, EventLogEntryType.Error); } }
protected override void OnStart(string[] args) { try { LatestBark = GetLatestBark().GetAwaiter().GetResult(); BarkCheckTimer = new Timer { Interval = BarkCheckIntervalMs }; BarkCheckTimer.Elapsed += OnTimer; BarkCheckTimer.Start(); } catch (Exception exception) { EventLog.WriteEntry(exception.Message, EventLogEntryType.Error); throw; } }
protected override void OnStart(string[] args) { try { LatestBark = GetLatestBark().GetAwaiter().GetResult(); BarkCheckTimer = new Timer { Interval = BarkCheckIntervalMs }; BarkCheckTimer.Elapsed += OnTimer; BarkCheckTimer.Start(); } catch (Exception exception) { EventLog.WriteEntry(exception.Message, EventLogEntryType.Error); throw; } }