예제 #1
0
파일: SmsManager.cs 프로젝트: evkap/DVS
		public void SendSMS(string userPhone, int appraiserOrderId, SMSTemplateType smsType, Dictionary<string, string> replaceDictionary = null)
		{
			if (!_config.IsSMSEnabled)
				throw new SystemException("SMS sending is disabled");
			if (string.IsNullOrWhiteSpace(userPhone))
				throw new ArgumentNullException("User phone cannot be blank for SMS notification");

			string clearedPhoneType = string.Empty;
			var phoneValidationResult = Messaging.MessageController.PhoneNumberIsValid(userPhone, out clearedPhoneType);
			if (phoneValidationResult == PhoneNumberValidity.Invalid)
				throw new ArgumentOutOfRangeException("Incorrect mobile phone format: " + userPhone);

			SetupAccount();
			CheckAccount();
			var template = _smsRepository.GetBySMSTemplateType(smsType);
			var smsBody = new StringBuilder(template.Body);
			if (replaceDictionary != null)
			{
				foreach (var replacePair in replaceDictionary)
					smsBody.Replace(replacePair.Key, replacePair.Value);
			}

			var smsMessage = new SMSMessage();
			smsMessage.PhoneNumber = clearedPhoneType;
			smsMessage.MessageText = smsBody.ToString();
			smsMessage.MessageID = appraiserOrderId;

			MessageQueue batch = new MessageQueue();
			batch.Add(smsMessage);
			string smsTypeString = smsType.ToString();
			Logger.WriteInfo(string.Format("Sending {0} sms to {1} ", smsTypeString, userPhone));
			var result = Messaging.MessageController.SendMessageBatchSynchronous(batch);

			if (result.Success)
				Logger.WriteInfo(string.Format("Sending {0} sms to {1} success", smsTypeString, userPhone));
			else
			{
				Logger.WriteInfo(string.Format("Sending {0} sms to {1} failed", smsTypeString, userPhone));
				if (result.Exception != null)
					throw new Exception(string.Format("Error occured during ending {0} sms to {1}.", smsTypeString, userPhone), result.Exception);
			}
		}
예제 #2
0
파일: TaskManager.cs 프로젝트: evkap/DVS
		public void SendAppraiserOrderNotificationSMS(SMSTemplateType SMStype, int appraiserOrderId)
		{
			var parameters = new Dictionary<TaskParamsKey, string>();
			parameters.Add(TaskParamsKey.SMSTemplate, SMStype.ToString());
			parameters.Add(TaskParamsKey.AppraiserOrderId, appraiserOrderId.ToString());
			_backgroundService.AddTask(TaskTypeEnum.SendAppraiserOrderInvitationSMS, parameters);
		}