public static async void TestPhoneCall() { Console.WriteLine("Calling phone number via Twilio. It should ring out."); Utils.Logger.Info("Calling phone number via Twilio. It should ring out."); try { var call = new PhoneCall { FromNumber = Caller.Gyantal, ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal], Message = "This is a test phone call from Health Monitor.", NRepeatAll = 2 }; // skipped temporarily bool didTwilioAcceptedTheCommand = await call.MakeTheCallAsync(); if (didTwilioAcceptedTheCommand) { Utils.Logger.Debug("TestPhoneCall(): PhoneCall instruction was sent to Twilio."); } else { Utils.Logger.Error("TestPhoneCall(): PhoneCall instruction was NOT accepted by Twilio."); } } catch (Exception e) { Utils.Logger.Error(e, "TestPhoneCall(): Exception in TestPhoneCall()."); } }
private static async void SendEmailAndMakePhoneCall(string p_emailSubject, string p_emailBody, string p_phonecallText) { Utils.Logger.Info("InformSupervisors(). Sending Warning email."); try { new Email { ToAddresses = Utils.Configuration["Emails:Gyant"], Subject = p_emailSubject, Body = p_emailBody, IsBodyHtml = true // even though VBroker messages are not HTML, but text. But it works. //IsBodyHtml = false // has problems with exceptions : /bin/bash: -c: line 1: syntax error near unexpected token `(' }.Send(); } catch (Exception e) { Utils.Logger.Error(e, "InformSupervisors() email sending is crashed, but we still try to make the PhoneCall."); } if (!IsRunningAsLocalDevelopment() && !String.IsNullOrEmpty(p_phonecallText)) { Utils.Logger.Info("InformSupervisors(). Making Phonecall."); var call = new PhoneCall { FromNumber = Caller.Gyantal, ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal], Message = p_phonecallText, NRepeatAll = 2 }; bool didTwilioAcceptedTheCommand = await call.MakeTheCallAsync(); if (didTwilioAcceptedTheCommand) { Utils.Logger.Debug("PhoneCall instruction was sent to Twilio."); } else { Utils.Logger.Error("PhoneCall instruction was NOT accepted by Twilio."); } } }
private void InformSupervisors(InformSuperVisorsUrgency p_urgency, string p_emailSubject, string p_emailBody, string p_phonecallText, ref Object p_informSupervisorLock, ref DateTime p_lastEmailTime, ref DateTime p_lastPhoneCallTime) { bool doInformSupervisors = false; if (p_urgency.HasFlag(InformSuperVisorsUrgency.UrgentInfoSendEmail_OnlyUseIfCannotBeSpammedBySource) || p_urgency.HasFlag(InformSuperVisorsUrgency.UrgentInfoMakePhonecall_OnlyUseIfCannotBeSpammedBySource)) { doInformSupervisors = true; } else { lock (p_informSupervisorLock) // if InformSupervisors is called on two different threads at the same time, (if VBroker notified us twice very quickly), we still want to inform user only once { TimeSpan timeFromLastEmail = DateTime.UtcNow - p_lastEmailTime; if (timeFromLastEmail > TimeSpan.FromMinutes(10)) { doInformSupervisors = true; p_lastEmailTime = DateTime.UtcNow; } } } if (!doInformSupervisors) { return; } Utils.Logger.Info("InformSupervisors(). Sending Warning email."); try { new Email { ToAddresses = Utils.Configuration["Emails:Gyant"], Subject = p_emailSubject, Body = p_emailBody, IsBodyHtml = true //IsBodyHtml = false // has problems with exceptions : /bin/bash: -c: line 1: syntax error near unexpected token `(' }.Send(); } catch (Exception e) { Utils.Logger.Error(e, "InformSupervisors() email sending is crashed, but we still try to make the PhoneCall."); } if (!IsRunningAsLocalDevelopment() && !String.IsNullOrEmpty(p_phonecallText)) { Utils.Logger.Info("InformSupervisors(). Making Phonecall."); TimeSpan timeFromLastCall = DateTime.UtcNow - p_lastPhoneCallTime; TimeSpan minTimeFromLastCall = p_urgency.HasFlag(InformSuperVisorsUrgency.UrgentInfoMakePhonecall_OnlyUseIfCannotBeSpammedBySource) ? TimeSpan.FromSeconds(3) : TimeSpan.FromMinutes(30); if (timeFromLastCall > minTimeFromLastCall) { var call = new PhoneCall { FromNumber = Caller.Gyantal, ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal], Message = p_phonecallText, NRepeatAll = 2 }; // skipped temporarily bool didTwilioAcceptedTheCommand = call.MakeTheCallAsync().TurnAsyncToSyncTask(); if (didTwilioAcceptedTheCommand) { Utils.Logger.Debug("PhoneCall instruction was sent to Twilio."); p_lastPhoneCallTime = DateTime.UtcNow; } else { Utils.Logger.Error("PhoneCall instruction was NOT accepted by Twilio."); } } } }