using System; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using xCommons.Extensions; using xExceptions.Constants; using xMessageService.Interfaces; using xMessageService.Models; namespace xMessageService.Providers { public partial class XMessageProvider : IXMessageProvider { private readonly XMessageConfiguration configuration; private readonly ILogger logger; private readonly IXSmsService smsService; private readonly IXMailService mailService; public XMessageProvider ( XMessageConfiguration configuration, ILogger logger, IXSmsService smsService, IXMailService mailService ) { this.configuration = configuration; this.logger = logger; this.smsService = smsService; this.mailService = mailService; } /// /// Send a Mail Message /// /// /// /// /// /// public async Task SendMailAsync ( XMessage message, string provider = null, bool throwException = true, Exception exception = null ) { // if (exception.IsNull ()) { exception = XException.ActionFailed.ToException (); } // try { await mailService.SendMailAsync (message, provider); } catch (Exception ex) { // logger.LogError ($"Exeption: {ex.Message}"); // if (throwException) { throw exception; } } } /// /// Send SMS Message /// /// /// public async Task SendSmsAsync ( XMessage message, string provider = null, bool throwException = true, Exception exception = null ) { // if (exception.IsNull ()) { exception = XException.ActionFailed.ToException (); } // try { await smsService.SendSmsAsync (message, provider); } catch { if (throwException) { throw exception; } } } /// /// Check Message Provider is Ready or not /// /// /// /// public bool IsReady ( bool? checkMailService = false, bool? checkSmsService = false ) { // var result = true; // // Check Mail Service ... if (checkMailService.HasValue && checkMailService.GetValueOrDefault ()) { result = result && mailService != null; } // // Check Sms Service ... if (checkSmsService.HasValue && checkSmsService.GetValueOrDefault ()) { result = result && smsService != null; } // return result; } } }