private void SendGoSMS() { try { bool DataProcess = false; // Get unsent outgoing message from the database VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCollection unsentSMSes = VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.GetAllSendSMS(); foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE sms in unsentSMSes) { if (sms.AttemptCount == 0) { DataProcess = true; } else { if (sms.AttemptCount < 3) { if ((DateTime.Now - sms.ModificationDate).TotalSeconds > 60) { DataProcess = true; } } } if (DataProcess) { VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE smsResponse = smsGatewayController.SendSMS(sms); #region Update SMS sent status in database try { LogMessage("Trying to update sms sent status in database."); sms.AttemptCount++; smsResponse.AttemptCount = sms.AttemptCount; smsResponse.MessageSendDateTime = DateTime.Now; smsResponse.ModificationDate = DateTime.Now; VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.UpdateFirstResponse(smsResponse); LogMessage("SMS sent status updated successfully. SMS id : " + sms.EntryId + " with status : " + smsResponse.OperatorResponseCode.ToString()); } catch (Exception ex) { LogMessage("Failed tp update message sent status in database. SMS id : " + sms.EntryId + " Exception : " + ex.Message); } } #endregion } } catch (Exception ex) { LogMessage("Failed to send SMS." + ex.Message); } finally { Thread.Sleep(200); } }
private void GetGoSMSStatus() { try { // Get unsent outgoing message from the database VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCollection unsentSMSes = VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.GetAllSendSMSPendindStatus(); foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE sms in unsentSMSes) { #region Update SMS sent status in database try { if ((DateTime.Now - sms.ModificationDate).TotalSeconds > 15) { if (sms.OperatorAttemptCount <= 3) { string responseString = smsGatewayController.SMSStatus(sms); SendSMSStatus(sms, responseString); LogMessage("SMS Get SMS STATUS for SMS id : " + sms.EntryId + " with status : " + responseString); } } } catch (Exception ex) { LogMessage("Failed tp update message sent status in database. SMS id : " + sms.EntryId + " Exception : " + ex.Message); } #endregion } } catch (Exception ex) { LogMessage("Failed to send SMS." + ex.Message); } finally { Thread.Sleep(200); } }
private void SendSMS() { try { // Get unsent outgoing message from the database string query = " WHERE NVL(ATTEMPT_COUNT,0) < 3 AND SENT_STATUS = " + (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSSentStatus.Unsent + " AND MESSAGE_DIRECTION = " + (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSDirection.Outgoing; VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCollection unsentSMSes = VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.GetFilteredRecords(query); bool DataProcess = true; // Send message to customer foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE sms in unsentSMSes) { DataProcess = true; // Send message via SMS Gateway // Message will be sent if not older than 2 hours. attempt count should be less thyan equal to 5 if ((DateTime.Now - sms.CreationDate).TotalHours <= 2) { if (sms.AttemptCount < 3) { LogMessage("SMS sending attempt count is greater than 3 so will not be sent. SMS entry id: " + sms.EntryId + " Attempt: " + sms.AttemptCount + " ResponseCode :" + sms.ResponseCode); if (sms.AttemptCount > 0) { if (sms.OperatorResponseCode != 3701) { if ((DateTime.Now - sms.MessageSendDateTime).TotalSeconds < 60) { DataProcess = false; } } else { DataProcess = false; } } if (DataProcess) { VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE smsResponse = smsGatewayController.SendSMS(sms); #region Update SMS sent status in database try { LogMessage("Trying to update sms sent status in database."); sms.AttemptCount++; // Update status in database smsResponse.AttemptCount = sms.AttemptCount; smsResponse.MessageSendDateTime = DateTime.Now; smsResponse.ModificationDate = DateTime.Now; if (smsResponse.ResponseCode == 2200) { smsResponse.SentStatus = (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSSentStatus.Sent; LogMessage("2200 status received."); } VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.UpdateFirstResponse(smsResponse); LogMessage("SMS sent status updated successfully."); } catch (Exception ex) { LogMessage("Failed tp update message sent status in database." + ex.Message); } #endregion } } else { LogMessage("SMS sending attempt count is greater than 5 so will not be sent. SMS entry id: " + sms.EntryId + " Attempt: " + sms.AttemptCount); } } //else //{ // LogMessage("Message is 2 hours older so will not be sent. Message Entry Id:" + sms.EntryId); //} } } catch (Exception ex) { LogMessage("Failed to send SMS." + ex.Message); } finally { Thread.Sleep(200); } }