/// <summary> /// 通知接口 /// </summary> /// <param name="pid"></param> /// <param name="mid"></param> /// <param name="Request"></param> /// <returns></returns> public async Task <NotifyReturn> Notify(int pid, int mid, Microsoft.AspNetCore.Http.HttpRequest Request) { Pay_plat p = OnlinePay.GetPlat(pid); Pay_mch m = OnlinePay.GetMch(mid); OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m); NotifyReturn r = await onlinepay.Notify(Request); if (r.IsCheck) { if (r.IsPay) { Pay_order order = DB.Context.From <Pay_order>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault(); if (order != null && !string.IsNullOrEmpty(order.Order_id)) { if (order.Status == 0) { order.Status = 1; order.Finish_time = DateTime.Now.ToTimeStamp(); order.Pay_amount = r.Totalfee; order.Notify_status = 0; order.Notify_times = 0; order.Notify_lasttime = DateTime.Now.ToTimeStamp(); DB.Context.Save(order); } } } return(r); } else { return(r); } }
/// <summary> /// 回调接口 /// </summary> /// <param name="pid"></param> /// <param name="mid"></param> /// <param name="Request"></param> /// <param name="Response"></param> /// <returns></returns> public async Task <NotifyReturn> CallBack(int pid, int mid, Microsoft.AspNetCore.Http.HttpRequest Request, Microsoft.AspNetCore.Http.HttpResponse Response) { Settle_plat p = OnlineSettle.GetPlat(pid); Settle_mch m = OnlineSettle.GetMch(mid); OnlineSettle onlinepay = (OnlineSettle)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m); NotifyReturn r = await onlinepay.CallBack(Request); if (r.IsCheck) { if (r.IsPay) { Settle_order order = DB.Context.From <Settle_order>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault(); if (order != null && string.IsNullOrEmpty(order.Order_id)) { if (order.Status == 0) { order.Status = 1; order.Finish_time = DateTime.Now.ToTimeStamp(); order.Pay_amount = r.Totalfee; order.Notify_status = 0; order.Notify_times = 0; order.Notify_lasttime = DateTime.Now.ToTimeStamp(); order.Returnmsg = r.ReturnMsg; DB.Context.Save(order); } } } } if (string.IsNullOrEmpty(r.OrderNumber)) { Settle_order order = DB.Context.From <Settle_order>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault(); if (order != null && !string.IsNullOrEmpty(order.Order_id) && !string.IsNullOrEmpty(order.Callback_url)) { SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", DB.MchId); para.Add("orderid", order.Order_id); para.Add("serialid", order.Plat_order_id); para.Add("amount", order.Pay_amount.ToString()); para.Add("attach", order.Attach); para.Add("status", order.Status.ToString()); string sign = string.Format("{0}&key={1}", OnlineSettle.GetParamSrc(para), DB.MchKey); sign = Dos.Common.EncryptHelper.MD5EncryptWeChat(sign, "utf-8"); para.Add("sign", sign); Response.Redirect(string.Format("{0}?{1}", order.Callback_url, OnlineSettle.GetParamSrc(para))); } } return(r); }
public async Task <string> Notify(int pid, int mid) { NotifyReturn n = await Settle_OrderBll.Instance.CallBack(pid, mid, Request, Response); if (n.IsCheck && n.IsPay) { Settle_OrderBll.Instance.Publish(DB.MchId, n.OrderNumber); } return(n.ReturnMsg); }
public async Task <string> CallBack(int pid, int mid) { NotifyReturn n = await Settle_OrderBll.Instance.CallBack(pid, mid, Request, Response); if (n.IsCheck && n.IsPay) { //_bus.PublishAsync(new PayOrderNotify { mchid = DB.MchId, orderid = n.OrderNumber }); } return(n.ReturnMsg); }
/// <summary> /// Dials the number. /// </summary> public long DialNumber(INotifyObject _notifyObject) { long QueueID = -1; string sensorInfo = _notifyObject.NotificationData.ToString(); string phoneNumber = _notifyObject.NotifierSettings["PhoneNo"].ToString(); string storePhoneNumber = _notifyObject.NotifierSettings["StorePhoneNo"].ToString(); string voiceMode = _notifyObject.NotifierSettings["CDYNE_VOICEID"].ToString(); string voiceVolume = _notifyObject.NotifierSettings["CDYNE_VOLUME"].ToString(); string voiceLicense = _notifyObject.NotifierSettings["CDYNE_ID"].ToString(); string voiceRetries = _notifyObject.NotifierSettings["CDYNE_RETRIES"].ToString(); LogBook.Write("PhoneNo.: " + _notifyObject.NotifierSettings["PhoneNumber"] + ", Voice Prompt: " + sensorInfo); PhoneNotify notify = new PhoneNotify(); AdvancedNotifyRequest anr = new AdvancedNotifyRequest(); PhoneNotify pn = new PhoneNotify(); anr.CallerIDName = "TempTrak"; anr.CallerIDNumber = storePhoneNumber; //TT registration #, if blank shows as private anr.PhoneNumberToDial = phoneNumber; anr.TextToSay = /*"~\\ActOnFeature(false)~*/ "~\\SetVar(Attempt|1)~ ~\\ActOnDigitPress(false)~ ~\\Label(Menu)~ ~\\AssignDTMF(*|Ack)~ ~\\ActOnDigitPress(true)~ ~\\Beep()~ ~\\PlaySilence(0.1)~" + sensorInfo + " ~\\WaitForDTMF(1)~" + "Press the star key to acknowledge receipt of this alert. Press 1 to repeat this message. ~\\PlaySilence(0.1)~ ~\\WaitForDTMF(10)~ ~\\IncreaseVariable(Attempt|1)~ ~\\GotoIf(Attempt|1|Menu)~ ~\\GotoIf(Attempt|2|Menu)~ ~\\GotoIf(Attempt|3|AttemptEnd)~ ~\\Label(AttemptEnd)~ Good Bye ~\\EndCall()~ ~\\Label(Ack)~ ~\\PlaySilence(0.1)~ Thank you for acknowledging receipt of this alert. ~\\PlaySilence(0.1)~ Log into TempTrak to take corrective action and officially clear alert. ~\\PlaySilence(0.1)~ Good Bye. ~\\EndCall()~"; anr.VoiceID = voiceMode.ToInt(); //store this in config if customer does not like voice anr.UTCScheduledDateTime = DateTime.UtcNow; anr.LicenseKey = voiceLicense; //"54B1B99F-7E7E-40AC-88EB-A91DBE859B82"; //stored in config file for now anr.TryCount = 0; //voiceRetries.ToInt(); //controlled by TT not CDyne anr.NextTryInSeconds = 0; //controlled by TT anr.TTSvolume = Convert.ToByte(voiceVolume); //also store this in config NotifyReturn nr = pn.NotifyPhoneAdvanced(anr); LogBook.Write("Info Passed to Notify Phone Advanced: "); LogBook.Write("CallerIDName: " + anr.CallerIDName); LogBook.Write("CallerIDNumber: " + anr.CallerIDNumber); LogBook.Write("PhoneNumberToDial: " + anr.PhoneNumberToDial); LogBook.Write("TextToSay: " + anr.TextToSay); LogBook.Write("VoiceID: " + anr.VoiceID); LogBook.Write("UTCScheduledDateTime: " + anr.UTCScheduledDateTime); LogBook.Write("LicenseKey: " + anr.LicenseKey); LogBook.Write("NextTryInSeconds: " + anr.NextTryInSeconds); LogBook.Write("TTSVolume: " + anr.TTSvolume); LogBook.Write("Dialed: " + phoneNumber + " ......... "); //final released version will have script uploaded to CDyne so we can say goodbye if user presses key QueueID = nr.QueueID; LogBook.Write("QueueID: " + nr.QueueID + " ......... "); return(QueueID); }
/// <summary> /// Dials the number. /// </summary> public long DialNumber() { LogBook.Write("Dialing the number"); InitCall(); LogBook.Write("InitCall() completed"); LogBook.Write("PhoneNo. : " + phoneNumber + ", Voice Prompt: " + sensorInfo); /* reset previous flags */ isCallConnected = false; IsDone = false; stopVoicePrompt = false; digitReceived = false; Action["CallConnected"] = 0; Action["SilenceDetected"] = 0; notifyComResponse = new NotifyComResponse(); LogBook.Write("Starting to dial " + phoneNumber); PhoneNotify notify = new PhoneNotify(); AdvancedNotifyRequest anr = new AdvancedNotifyRequest(); PhoneNotify pn = new PhoneNotify(); anr.CallerIDName = "TempTrak"; anr.CallerIDNumber = fromNumber; //TT registration # anr.PhoneNumberToDial = phoneNumber; // anr.TextToSay = "This is an important message from your "+_alarmObject.StoreName TempTrak Monitoring System, to alert,,"+personName+",,at <say-as type=\"number:digits\">"+phoneNumber+"</say-as>"+",,that device name,"+deviceName+",probe number,"+probe+", is in violation,,, measuring a value of "+value+" for an elapsed time of "+timeOutOfRange+",,,Press any key to acknowlege this call,, Thank You,,,"; // string promptMessage = @"This is the " + alarmObject.StoreName + " Temp Track voice notification system, , , , There is an alarm with " // + alarmObject.IVR_SensorName + ", , Last Reading was " + SensorValueToTTS(alarmObject.UTID, alarmObject.Probe, alarmObject.SensorType, (decimal)alarmObject.Value, alarmObject.IsCelsius) // + ", , , , press any key to acknowledge. "; anr.TextToSay = "This is the Temp Track voice notification system, , , , There is an alarm with " + deviceName + ", , Last Reading was " + value + ", , , , press any key to acknowledge. "; anr.VoiceID = 6; anr.UTCScheduledDateTime = DateTime.UtcNow; anr.LicenseKey = "54B1B99F-7E7E-40AC-88EB-A91DBE859B82"; //stored in config file for now anr.TryCount = 5; anr.NextTryInSeconds = 30; anr.TTSvolume = 5; NotifyReturn nr = pn.NotifyPhoneAdvanced(anr); //store TransactionID into table where QueueID = -1; QueueID = nr.QueueID; Thread.Sleep(30000); //now query the webservice and update records MachineDetection = nr.MachineDetection; DigitsPressed = nr.DigitsPressed; CallAnswered = nr.CallAnswered; CallComplete = nr.CallComplete; IVRServiceResponseText = nr.ResponseText; Duration = nr.Duration; StartTime = nr.StartTime; EndTime = nr.EndTime; if (DigitsPressed.Length > 0) { notifyComResponse.IsSucceeded = true; notifyComResponse.IsError = false; notifyComResponse.ResponseContent += "\r\n Acknowledgement received, " + DigitsPressed + " pressed."; notifyComResponse.IsSucceeded = true; LogBook.Write("Digit Received"); LogBook.Write("\t" + "Digit: " + DigitsPressed); } else { notifyComResponse.IsSucceeded = false; notifyComResponse.IsError = true; if (MachineDetection == "MACHINE") { notifyComResponse.ResponseContent += "\r\n Answering Machine Detected"; } else if (CallAnswered == false) { notifyComResponse.ResponseContent += "\r\n No Answer"; } else if ((CallAnswered == true) && (DigitsPressed.Length == 0)) { notifyComResponse.ResponseContent += "\r\n Call Answerd, No Digits Pressed"; } } return(QueueID); }
/// <summary> /// Returns true if the current operation succeeded. /// </summary> /// <param name="data"></param> /// <param name="settings"></param> /// <param name="notificationID"></param> /// <returns></returns> /// public static bool Send(string data, Hashtable settings, int notificationID, int ivrID, int alarmID, AlarmObject alarmObject) { bool retValue = false; bool callConnected = false; string response = string.Empty; string succeeded = string.Empty; string error = string.Empty; Int16 dailAttempts = 1; string DigitsPressed = string.Empty; long QueueID = -1; int TryCount = -1; bool CallAnswered = false; bool Answered = false; bool CallComplete = false; string MachineDetection = string.Empty; int Duration = -1; string IVRServiceResponseText = string.Empty; int TTIVRNotifications_RecID = -1; NotifyObject notifyObject = new NotifyObject(); NotifyComResponse notifyResponse = new NotifyComResponse(); NotifyComResponse notifyComResponse = new NotifyComResponse(); notifyObject.NotificationType = "Voice"; notifyObject.NotificationData = data; //voice message to be played notifyObject.NotifierSettings = settings; //hash table of keys and values NotificationEndPointElement element; string vcElement1; string vcElement2; string vcElement3; string vcElement4; /* get end point for voice composer*/ string method = NotificationClient.GetInstance().WhoAmI("Voice", out element); string arguments = null; LogBook.Write("Sending voice alert...."); switch (method.ToLower()) { case "cooperatkins.notificationclient.notifyengine.ivrnotificationcom": System.Diagnostics.Process process = new System.Diagnostics.Process(); if (element == null) { arguments = @"-m ""<notification ack='true'><notificationData><![CDATA[" + data + @"]]></notificationData><notificationType><![CDATA[Voice]]></notificationType><notificationSettings><PhoneNo><![CDATA[" + settings["PhoneNo"].ToStr() + @"]]></PhoneNo></notificationSettings></notification>"" "; } else { arguments = @"-c " + element.EndpointAddress + @" -m ""<notification ack='true'><notificationData><![CDATA[" + data + @"]]></notificationData><notificationType><![CDATA[Voice]]></notificationType><notificationSettings><PhoneNo><![CDATA[" + settings["PhoneNo"].ToStr() + @"]]></PhoneNo></notificationSettings></notification>"" "; } while (!callConnected) { IvrAlarmStatus ivrAlarmStatus = new IvrAlarmStatus(); try { LogBook.Write("Checking whether alarm is cleared or not"); ivrAlarmStatus.AlarmID = alarmID; ivrAlarmStatus.NotificationID = notificationID; ivrAlarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID; ivrAlarmStatus.Execute(); } catch (Exception ex) { LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.IvrClientHelper", ErrorSeverity.High); } finally { ivrAlarmStatus.Dispose(); } if (ivrAlarmStatus.IsAlarmClearedOrBackInRange) { break; } /* analog modem use */ process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; //process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Utility.exe"; //process.StartInfo.FileName = @"F:\DEV\CooperAtkins\CooperAtkins.NotificationEngine.Utility\bin\Debug\Utility.exe"; process.StartInfo.Arguments = arguments; // process.StartInfo.WorkingDirectory = ; process.Start(); process.WaitForExit(); response = process.StandardOutput.ReadToEnd(); callConnected = true; if (response.ToLower().Contains("device initialization failed") || response.ToLower().Contains("invalid_device_id") || response.ToLower().Contains("dll_not_found") || response.ToLower().Contains("exception from hresult")) { callConnected = false; } /* end analog modem use */ } break; case "cooperatkins.notificationclient.notificationcomposer.cdyneivrnotificationcomposer": long TransactionID = -1; DateTime StartTime; DateTime EndTime; long AlarmID = -1; string CDYNE_ID = GenStoreInfo.GetInstance().CDYNE_ACCOUNT;//NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneID", out vcElement1); string CDYNE_RETRIES = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneRetries", out vcElement2); string CDYNE_VOICEID = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneVoiceID", out vcElement3); string CDYNE_VOLUME = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneVolume", out vcElement4); notifyObject.NotifierSettings["CDYNE_ID"] = CDYNE_ID; notifyObject.NotifierSettings["CDYNE_RETRIES"] = CDYNE_RETRIES; notifyObject.NotifierSettings["CDYNE_VOICEID"] = CDYNE_VOICEID; notifyObject.NotifierSettings["CDYNE_VOLUME"] = CDYNE_VOLUME; NotificationStyle notificationStyle = new NotificationStyle(); TTIvrNotifications tTIvrNotificationsObject = new TTIvrNotifications(); callConnected = false; while (!callConnected) { notifyComResponse.IsInProcess = true; int QueryCall = 0; int UnivError = 0; //if (!alarmObject.IsFailsafeEscalationNotification) //{ //IvrAlarmStatus ivrAlarmStatus = new IvrAlarmStatus(); //try //{ // LogBook.Write("Checking whether alarm is cleared or not"); // ivrAlarmStatus.AlarmID = alarmID; // ivrAlarmStatus.NotificationID = notificationID; // ivrAlarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID; // ivrAlarmStatus.Execute(); //} //catch (Exception ex) //{ // LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.CDYNEIvrClientHelper", ErrorSeverity.High); //} //finally //{ // ivrAlarmStatus.Dispose(); //} //12/9/15 comment start //AlarmStatus alarmStatus = new AlarmStatus(); //try //{ // LogBook.Write("IVR Checking whether alarm [" + alarmObject.NotificationID + "] is cleared or not"); // alarmStatus.NotificationID = alarmObject.NotificationID; // alarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID; // alarmStatus.Execute(); //} //catch (Exception ex) //{ // LogBook.Write(ex, "CooperAtkins.NotificationClient.Alarm.AlarmInitializer", ErrorSeverity.High); //} //finally //{ // alarmStatus.Dispose(); //12/9/15 comment end } int threadID = notifyObject.NotifierSettings["ThreadID"].ToInt(); //12/9/15 comment start //if (alarmStatus.IsAlarmClearedOrBackInRange) //{ // Answered = false; // callConnected = false; // notifyComResponse.IsSucceeded = false; // notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " SUSPENDED (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")"; // notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nALARM WAS CLEARED OR BACK IN RANGE"; // LogBook.Write("CALL SUSPENDED To " + notifyObject.NotifierSettings["PhoneNo"] + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "] ALARM WAS CLEARED OR SENSOR IS BACK IN RANGE"); // notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.FAIL, NotifyTypes.VOICE); // UpdateIVRNotification(ivrID, false, false, dailAttempts, TransactionID, threadID); // break; //12/9/15 comment end } int totalCallAttempts = notifyObject.NotifierSettings["Attempts"].ToInt(); if ((totalCallAttempts + dailAttempts) > (CDYNE_RETRIES.ToInt() + 1)) //also if a notficicationId is in an alert progress state from another thread, //fall into this code to break out OR if cleared or inprogress check to be sure //we made contatc through our maximum attempts value { notifyComResponse.IsInProcess = false; UpdateIVRNotification(ivrID, false, notifyComResponse.IsInProcess, dailAttempts, TransactionID, threadID); break; } //} UpdateIVRNotification(ivrID, false, true, (totalCallAttempts + dailAttempts), TransactionID, threadID); try{ IVRProcessor maketheIVRCall = new IVRProcessor(); notifyResponse = maketheIVRCall.Invoke(notifyObject); // notifyComResponse = new NotifyComResponse(); TransactionID = notifyResponse.TransactionIDReturned; //query for call result Answered = false; PhoneNotify pn2 = new PhoneNotify(); while (!Answered) { if (QueryCall == 0) //on first call, wait 1 minute for call to complete before getting call results { System.Threading.Thread.Sleep(1 * 60 * 1000); } else { System.Threading.Thread.Sleep(5 * 1000); } NotifyReturn nr2 = pn2.GetQueueIDStatus(TransactionID); MachineDetection = nr2.MachineDetection; DigitsPressed = nr2.DigitsPressed; CallAnswered = nr2.CallAnswered; CallComplete = nr2.CallComplete; IVRServiceResponseText = nr2.ResponseText; Duration = nr2.Duration; StartTime = nr2.StartTime; EndTime = nr2.EndTime; if (CallAnswered == true && DigitsPressed.Contains("*")) { Answered = true; callConnected = true; notifyComResponse.IsSucceeded = true; //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")"; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected. "; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nAcknowledgement received, " + "'" + DigitsPressed + "' pressed."; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nCall Complete >"; LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered and Digits: " + DigitsPressed + " were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); break; } else if (CallAnswered == true && !DigitsPressed.Contains("*") && MachineDetection == "HUMAN" && CallComplete) { Answered = true; notifyComResponse.IsSucceeded = false; //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")"; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected. "; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nNo Acknowledgement received, Digits Pressed: " + DigitsPressed + ">"; LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered but no digits were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); break; } else if (CallAnswered == true && DigitsPressed == "" && MachineDetection == "HUMAN" && !CallComplete) { notifyComResponse.IsSucceeded = false; //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")"; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected. "; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nNo Acknowledgement received >"; LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered but no digits were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); QueryCall += 1; } else if (CallAnswered == true && DigitsPressed == "" && MachineDetection == "MACHINE") { Answered = false; notifyComResponse.IsSucceeded = false; //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] +"["+ notifyObject.NotifierSettings["CallerName"]+"]"+ " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")"; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected. "; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nAnswering Machine Detected >"; LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered by MACHINE: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); break; } else if (IVRServiceResponseText == "In Call/Ringing" || IVRServiceResponseText == "Queued" || IVRServiceResponseText == "Universal Error") { notifyComResponse.IsSucceeded = false; notifyComResponse.IsError = true; //if (notifyComResponse.ResponseContent != null) //{ // if ((!notifyComResponse.ResponseContent.ToString().Contains("Call/Ringing (Attempt # " + dailAttempts)) && // (!notifyComResponse.ResponseContent.ToString().Contains("Queued (Attempt # " + dailAttempts)) && // (!notifyComResponse.ResponseContent.ToString().Contains("Universal Error (Attempt # " + dailAttempts))) //only add line if it has not already been logged for this dial attempt // { // notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "] " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >"; // } //} //else //{ // notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "] " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >"; //} // notifyComResponse.ResponseContent = ""; LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Current Status: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); if (IVRServiceResponseText == "Universal Error") { UnivError += 1; //if it continues to return Universl Error allow a way to get out } QueryCall += 1; } else { notifyComResponse.IsSucceeded = false; if (notifyComResponse.ResponseContent != null) { if (!notifyComResponse.ResponseContent.ToString().Contains("ERROR")) //only add line if it has not already been logged { //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >"; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " >"; } } else { //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >"; notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " >"; } LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Current Status: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); QueryCall += 1; } if (QueryCall > 2 || Answered || (UnivError > 10)) { break; } } }catch (Exception ex) { LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.CDYNEIvrClientHelper MAkeTheCall", ErrorSeverity.High); } if (!callConnected || !Answered) { //write to TTNotificationLog if (notifyComResponse.ResponseContent != null) { if (notifyComResponse.ResponseContent.ToString() != "") { notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.FAIL, NotifyTypes.VOICE); } } notifyComResponse.ResponseContent = ""; //write to TTIVRNotifications UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID); // System.Threading.Thread.Sleep(30 * 1000); //wait and try that number 1 more time before trying next person dailAttempts += 1; retValue = false; if (((totalCallAttempts + dailAttempts.ToInt())) > CDYNE_RETRIES.ToInt16() + 1) { //try each person X times from config LogBook.Write("Exhausted " + (CDYNE_RETRIES.ToInt()) + " Re-Try Attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); notifyComResponse.IsInProcess = false; if (UnivError >= 10) //reset call counter, so it will re-attempt to call person has CDyne never truly made a call { //4th param in below function UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, 0, TransactionID, threadID); } else { UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID); } retValue = false; alarmObject.IVRSuccess = false; break; } else { LogBook.Write("Trying Retry Call Attempt " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " Attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID); } } else { LogBook.Write("Call Complete. Alert Success during call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]"); notifyComResponse.IsInProcess = false; notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.PASS, NotifyTypes.VOICE); notifyComResponse.ResponseContent = ""; UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID); retValue = true; alarmObject.IVRSuccess = true; } } break; //end call attempts default: break; } if (method.ToLower() == "cooperatkins.notificationserver.notifyengine.ivrnotificationcom") { NotificationStyle notificationStyle = new NotificationStyle(); foreach (string responseLine in response.Split(new string[] { "\n" }, StringSplitOptions.None)) { if (responseLine.ToLower().Contains("succeeded")) { succeeded = responseLine.ToLower().Replace("succeeded :", string.Empty); } else if (responseLine.ToLower().Contains("error")) { error = responseLine.ToLower().Replace("error :", string.Empty); } } LogBook.Write("ResponseContent:" + response + ", IsSucceeded:" + succeeded + ", IsError:" + error); /* record the notification information to the database. */ if (succeeded == "no") { notificationStyle.RecordNotification(response.Remove(0, 60).Replace("\n", "\r\n"), notificationID, 0, NotifyStatus.FAIL, NotifyTypes.VOICE); } else { notificationStyle.RecordNotification(response.Remove(0, 60).Replace("\n", "\r\n"), notificationID, 0, NotifyStatus.PASS, NotifyTypes.VOICE); } retValue = succeeded == "yes"; } return(retValue); }
static void Main(string[] args) { if (CommandLineExec(args)) { return; } string userInput; Console.Title = "Cooper Atkins Notification Utility"; WriteLine("Notification Engine Utility Program\n"); WriteLine("(C) Cooper Atkins 2015\n"); bool exitFlag = false; while (true) { Console.Write("\nNotification>"); string[] commandArray = new string[1]; if (args.Length > 0) { commandArray = args; WriteLine("\r\nNotification>" + args[0], false); args = null; } else { userInput = Console.ReadLine(); commandArray = userInput.Split(' '); WriteLine("\r\nNotification>" + userInput, false); } IniHelp iniHelp = new IniHelp(); string settingsXml = string.Empty; string inputYN = ""; switch (commandArray[0].ToLower()) { case "help": DisplayHelp(commandArray[0].ToLower()); break; case "removeprocessall": WriteLine("Are you sure you want to stop all the notification process?(Y/N):"); inputYN = Console.ReadLine(); WriteLine(inputYN, false); if (inputYN.ToUpper() != "Y") { break; } foreach (Process pro in Process.GetProcessesByName("CooperAtkins.NotificationClient.Service")) { try { pro.Kill(); } catch { } } break; case "removeprocess": //if (commandArray.Length <= 2) { // WriteLine("Invalid arguments. Syntax: process [-r] [-s][-a] <processid>\n -r remove \n -s single process or -a all processes"); //} //if (commandArray[1].ToLower() == "-r") WriteLine("Are you sure you want to stop notification process?(Y/N):"); inputYN = Console.ReadLine(); WriteLine(inputYN, false); if (inputYN.ToUpper() != "Y") { break; } int result; if (!int.TryParse(commandArray[1], out result)) { WriteLine("Invalid argument. Enter valid process id."); break; } int pid = Convert.ToInt32(result); foreach (Process pro in Process.GetProcessesByName("CooperAtkins.NotificationClient.Service")) { if (pro.Id == pid) { try { pro.Kill(); } catch { } } } break; case "ping": Send("command ping"); break; case "exit": case "quit": exitFlag = true; break; case "testivr": PhoneNotify notify = new PhoneNotify(); string phoneNumber = ""; if (commandArray.Length == 2) { if (commandArray[1].Length != 10) { WriteLine("Please provide valid phone number.\n"); DisplayHelp(commandArray[0].ToLower()); break; } phoneNumber = commandArray[1].Trim(); } else { WriteLine("Invalid notification command.\n"); DisplayHelp(commandArray[0].ToLower()); } AdvancedNotifyRequest anr = new AdvancedNotifyRequest(); PhoneNotify pn = new PhoneNotify(); anr.CallerIDName = "TempTrak Alert System"; anr.CallerIDNumber = "888-533-6900"; //TT registration # anr.PhoneNumberToDial = phoneNumber; //anr.TextToSay = "This is a test call from TempTrak for,, <say-as type=\"number:digits\">" + phoneNumber + "</say-as>" + ",,,Press the star key to acknowlege this call,, Thank You,,,This is a test call from TempTrak for,, <say-as type=\"number:digits\">" + phoneNumber + "</say-as>" + ",,,Press the star key to acknowlege this call,, Thank You,,,This is a test call from TempTrak for,, <say-as type=\"number:digits\">" + phoneNumber + "</say-as>" + ",,,Press the star key to acknowlege this call,, Thank You,,,"; //anr.TextToSay = /*"~\\ActOnFeature(false)~*/ "~\\SetVar(Attempt|1)~ ~\\ActOnDigitPress(false)~ ~\\Label(Menu)~ ~\\AssignDTMF(*|Ack)~ ~\\ActOnDigitPress(true)~ ~\\Beep()~ ~\\PlaySilence(0.1)~" + sensorInfo + " ~\\WaitForDTMF(1)~" + "Press the star key to acknowledge receipt of this alert. Press 1 to repeat this message. ~\\PlaySilence(0.1)~ ~\\WaitForDTMF(10)~ ~\\IncreaseVariable(Attempt|1)~ ~\\GotoIf(Attempt|1|Menu)~ ~\\GotoIf(Attempt|2|Menu)~ ~\\GotoIf(Attempt|3|AttemptEnd)~ ~\\Label(AttemptEnd)~ Good Bye ~\\EndCall()~ ~\\Label(Ack)~ ~\\PlaySilence(0.1)~ Thank you for acknowledging receipt of this alert. ~\\PlaySilence(0.1)~ Log into TempTrak to take corrective action and officially clear alert. ~\\PlaySilence(0.1)~ Good Bye. ~\\EndCall()~"; string promptMessage = @"This is the Temp Track voice notification system ~\\PlaySilence(0.2)~ There is an alarm with a sensor named " + "Research Specimen Freezer 696" + " ~\\PlaySilence(0.2)~ The Last Reading was " + "-5 degrees C" + " ~\\PlaySilence(0.2)~ Sensor has been operating out of range for ~\\PlaySilence(0.1)~ " + "30 minutes"; anr.TextToSay = /*"~\\ActOnFeature(false)~*/ "~\\SetVar(Attempt|1)~ ~\\ActOnDigitPress(false)~ ~\\Label(Menu)~ ~\\AssignDTMF(*|Ack)~ ~\\ActOnDigitPress(true)~ ~\\Beep()~ ~\\PlaySilence(0.1)~" + promptMessage + " ~\\WaitForDTMF(1)~" + "Press the star key to acknowledge receipt of this alert. Press 1 to repeat this message. ~\\PlaySilence(0.1)~ ~\\WaitForDTMF(10)~ ~\\IncreaseVariable(Attempt|1)~ ~\\GotoIf(Attempt|1|Menu)~ ~\\GotoIf(Attempt|2|Menu)~ ~\\GotoIf(Attempt|3|AttemptEnd)~ ~\\Label(AttemptEnd)~ Good Bye ~\\EndCall()~ ~\\Label(Ack)~ ~\\PlaySilence(0.1)~ Thank you for acknowledging receipt of this alert. ~\\PlaySilence(0.1)~ Log into TempTrak to take corrective action and officially clear alert. ~\\PlaySilence(0.1)~ Good Bye. ~\\EndCall()~"; anr.VoiceID = 6; anr.UTCScheduledDateTime = DateTime.UtcNow; anr.LicenseKey = "b9eec503-0308-46f0-b5f2-01d3ae1182ea"; //stored in config file for now anr.TryCount = 1; anr.NextTryInSeconds = 0; anr.TTSvolume = 5; NotifyReturn nr = pn.NotifyPhoneAdvanced(anr); Console.WriteLine("Call Server Response Text: " + nr.ResponseText); // Console.WriteLine("Call Server Response Code: " + nr.ResponseCode); Console.WriteLine("Call QueueID: " + nr.QueueID); Console.WriteLine("After Call is Complete: type 'getivrstatus " + nr.QueueID + "' to see call results"); for (int f = 0; f < 40; f++) { System.Threading.Thread.Sleep(2000); if (f == 0) { Console.WriteLine(""); } else { Console.Write("- "); } } break; case "getivrstatus": string commandlineInput = commandArray[1].ToString(); long TransactionID = Convert.ToInt64(commandlineInput); PhoneNotify notify2 = new PhoneNotify(); NotifyReturn notifyResult2 = notify2.GetQueueIDStatus(TransactionID); Console.WriteLine(notifyResult2.ResponseText); Console.WriteLine("Ans Machine Detection: " + notifyResult2.MachineDetection); Console.WriteLine("Demo: " + notifyResult2.Demo); Console.WriteLine("Digits Pressed: " + notifyResult2.DigitsPressed); Console.WriteLine("Call Duration: " + notifyResult2.Duration); Console.WriteLine("Call Start Time: " + notifyResult2.StartTime); Console.WriteLine("Call End Time: " + notifyResult2.EndTime); Console.WriteLine("Call QueueID: " + notifyResult2.QueueID); Console.WriteLine("Try Count: " + notifyResult2.TryCount); Console.WriteLine("Text To Say: " + notifyResult2.TextToSay); Console.WriteLine("Call Answered: " + notifyResult2.CallAnswered); Console.WriteLine("Call Complete: " + notifyResult2.CallComplete); if ((notifyResult2.MachineDetection == "MACHINE") || (notifyResult2.DigitsPressed == "")) { string[] commandArray2 = new string[] { "testivr" }; Main(commandArray2); } break; case "report": FileStream logFileStream = File.Create(AppDomain.CurrentDomain.BaseDirectory + "Log.txt"); logFileStream.Write(Encoding.ASCII.GetBytes(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\r\n"), 0, (DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\r\n").Length); logFileStream.Write(Encoding.ASCII.GetBytes(logBuilder.ToString().Replace("\\n", " ")), 0, logBuilder.ToString().Length); logFileStream.Flush(); logFileStream.Close(); logFileStream.Dispose(); logFileStream = null; Process process1 = new Process(); process1.StartInfo = new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "Log.txt"); process1.Start(); break; case "connect": if (commandArray.Length > 2) { bool flag = ValidateIpPort(commandArray[1].Trim(), commandArray[2].Trim()); if (!flag) { WriteLine("Please provide valid IP Address and port.\n"); break; } _server = commandArray[1].Trim(); _port = Convert.ToInt32(commandArray[2].Trim()); Send("command ping"); localNEObj = null; } else { if (localNEObj == null) { //string notificationInstallationPath = Environment.GetEnvironmentVariable("NotifyServerPath", EnvironmentVariableTarget.Machine); ; LoadLocalNotifyEngine(); } else { WriteLine("Invalid notification command.\n"); DisplayHelp(commandArray[0].ToLower()); } } break; case "clear": case "cls": Console.Clear(); break; case "open": Process process = new Process(); process.StartInfo = new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "Commands.ini"); process.Start(); break; default: string[] keys = null; if (commandArray[0].ToLower() != "utilitymessageformats") { keys = iniHelp.IniReadKeys(commandArray[0].ToLower()); } if (keys != null) { StringBuilder sb = new StringBuilder(); if (commandArray.Length == 1) { string[] format = GetMessageFormat(commandArray[0].ToLower()); if (!string.IsNullOrEmpty(format[0]) && !string.IsNullOrEmpty(format[1])) { string[] arrayVars = format[1].Split(','); string message = format[0]; for (int i = 0; i < arrayVars.Length; i++) { Console.Write("Enter " + arrayVars[i].Trim() + ":"); message = message.Replace("{" + i.ToString() + "}", Console.ReadLine()); } if (commandArray[0].ToLower() == "remotepopup" || commandArray[0].ToLower() == "serverpopup") { string temp = "00000000"; int strLength = temp.Length - message.Length.ToString().Length; message = temp.Substring(0, strLength) + message.Length + message; sb = new StringBuilder(message); } } else { Console.WriteLine("\nPlease enter message to send (Press ctrl+z to end the message):\n"); string line = string.Empty; do { line = Console.ReadLine(); sb.Append(line); } while (line != null); } } else { sb = new StringBuilder(string.Join(" ", commandArray, 1, commandArray.Length - 1)); } settingsXml = WriteKeyValue(commandArray[0].ToLower(), sb.ToString()); if (settingsXml != null) { if (localNEObj == null) { Send(settingsXml); } else { LocalExecution(settingsXml); } } } else { WriteLine("Invalid notification command. \nPlease use open command to check available commands.\nSyntax: open\n\n"); } break; } if (exitFlag) { break; } } }