/// <summary> /// using Microsoft.Extensions.DependencyInjection; /// </summary> /// <returns></returns> public IActionResult GeteServicesInFunction() { StringBuilder stringBuilder = new StringBuilder(); //sms ISms smsService = HttpContext.RequestServices.GetService <ISms>(); stringBuilder.Append(smsService.SmsSend() + " \n"); //mails IEnumerable <IMail> mailServices = HttpContext.RequestServices.GetServices <IMail>(); foreach (var mail in mailServices) { stringBuilder.Append(mail.Send() + "\n"); } //file Converter IFileConverter fileConverterService = HttpContext.RequestServices.GetService <IFileConverter>(); //v1 Func <string, IFileConverter> fileConverterServiceDelg = HttpContext.RequestServices.GetService <Func <string, IFileConverter> >(); //v2 stringBuilder.Append(fileConverterService.Convert()); //v1 ///stringBuilder.Append(fileConverterServiceDelg("XmlConverter").Convert());//v2 return(Content(stringBuilder.ToString())); }
public override void Enqueue(ISms sms) { using (var db = new SmsLogDataContext()) { db.SmsQueue_Enqueue(sms); } }
protected override ISmsStatusCollection OnSend(ISms sms) { ASPSMSNET aspsms; SmsStatusCollection status; SmsStatus smsStatus; aspsms = new ASPSMSNET { UserKey = Provider.Configuration.Settings["userKey"], Password = Provider.Configuration.Settings["password"], Originator = sms.Sender, MessageData = sms.Message, }; foreach (string recipient in sms.Recipients) aspsms.Recipients.Add(recipient, ToInt(sms.ReferenceId)); if (Provider.TestMode == false) aspsms.SendTextSMS(); status = new SmsStatusCollection(sms); if ((aspsms.ErrorCode != 1) && (Provider.TestMode == false)) status.SetError(aspsms.ErrorCode, aspsms.ErrorDescription); foreach (string recipient in sms.Recipients) { smsStatus = new SmsStatus(recipient) {TestMode = Provider.TestMode}; if (status.Successful == false) smsStatus.SetError(EnMtStatus.Failure, status.ErrorCode, status.ErrorMessage); status.Add(smsStatus); } return status; }
protected override ISmsStatusCollection OnSend(ISms sms) { SmsStatusCollection status; SmsStatus smsStatus; int? failCode = null; if (sms.CustomProperties.ContainsKey("FailCode")) failCode = int.Parse(sms.CustomProperties["FailCode"].ToString() ); status = new SmsStatusCollection(sms); for (int count = 0; count < sms.Recipients.Count; ++count) { smsStatus = new SmsStatus(sms.Recipients[count]); smsStatus.ProviderReference = sms.ReferenceId.ToString(); if (failCode != null) smsStatus.SetError(EnMtStatus.Failure, (int) failCode, "Error forced for testing purposes"); else { if (sms.CustomProperties.ContainsKey(count.ToString())) smsStatus.SetError(EnMtStatus.Failure, -1, "Error forced using sms custom properties"); } status.Add(smsStatus); } return status; }
/// <inheritdoc/> public ISmsSendResult SendSms(ISms sms) { try { if (!sms?.IsValid(_smsServiceConfig) ?? true) { throw new Exception("Invalid SMS request."); } var paramDict = new Dictionary <string, string>(); paramDict.Add(_smsServiceConfig.MessageMask, sms.Message); paramDict.Add(_smsServiceConfig.RecepientMask, sms.Recepient); _smsServiceConfig?.RequestParameters?.ToList()?.ForEach(x => paramDict?.Add(x.Key, x.Value)); HttpWebRequest request = null; string postData = null; byte[] postBytes = null; switch (_smsServiceConfig.RequestContentType) { case RequestContentType.FormData: NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(string.Empty); paramDict?.ToList()?.ForEach(x => outgoingQueryString.Add(x.Key, x.Value)); postData = outgoingQueryString?.ToString(); postBytes = _smsServiceConfig.Encoding.GetBytes(postData); request = (HttpWebRequest)WebRequest.Create(_smsServiceConfig.BaseUrl); request.ContentType = "application/form-data"; break; case RequestContentType.JSON: postData = JsonConvert.SerializeObject(paramDict); postBytes = _smsServiceConfig.Encoding.GetBytes(postData); request = (HttpWebRequest)WebRequest.Create(_smsServiceConfig.BaseUrl); request.ContentType = "application/json"; break; default: //Handles Enums.RequestContentType.URL too string @params = String.Join("&&", paramDict?.Select(x => $"{x.Key}={x.Value}")?.ToArray()); string url = _smsServiceConfig.BaseUrl + '?' + @params; request = (HttpWebRequest)WebRequest.Create(url); break; } request.Method = _smsServiceConfig.RequestMethod.Method; if (postBytes != null) { using (var stream = request.GetRequestStream()) { stream.Write(postBytes, 0, postBytes.Length); } } HttpWebResponse response = request.GetResponse() as HttpWebResponse; return(new SmsSendResult(sms.Recepient, response.StatusCode, response.GetResponseStream())); } catch (Exception e) { return(new SmsSendResult(sms.Recepient, e.Message)); } }
public void SmsQueue_Enqueue(ISms sms) { ISingleResult<SmsQueue_EnqueueResult> ret; SmsQueue_EnqueueResult res; ret = SmsQueue_Enqueue(sms.ReferenceId, sms.ApplicationId, sms.Sender, sms.Recipients.Count, sms.Message, DateTime.Now, ConvertRecipients(sms.Recipients)); res = ret.ReturnValue as SmsQueue_EnqueueResult; }
public override void OnAcceptance(ISms sms, DateTime timeStamp) { using (var db = new SmsLogDataContext()) { db.SmsLog_Insert(sms, timeStamp); db.SubmitChanges(); } }
public SmsBase(string apiId, bool isTest) { m_apiId = apiId; SmsError = new SmsError(); Sms = new Sms(this); SmsAccount = new SmsAccount(this); m_isTest = isTest; }
public SmsRecipientFormatException(ISms sms, RecipientFormatError[] recipientFormatErrors) : base(sms, EnSmsFormat.InvalidRecipient, recipientFormatErrors.Length == 1 ? string.Format("Invalid SMS: 1 empty or invalid recipient") : string.Format("Invalid SMS: {0} empty or invalid recipients", recipientFormatErrors.Length)) { _recipientFormatErrors = recipientFormatErrors; }
public PedidoService(ICarrinho carrinho, IPagamento pagamento, IEstoque estoqueService, IMail mailService, ISms smsService) { _carrinhoService = carrinho; _pagamentoService = pagamento; _estoqueService = estoqueService; _mailService = mailService; _smsService = smsService; }
public static void SmsLog_Submitted(ISms sms, ISmsStatusCollection status, DateTime timeStamp) { using (var db = new SmsLogDataContext()) { for (int count = 0; count < status.Count; ++count) db.SmsLog_Forwarded(sms.ReferenceId, status[count].ProviderReference, timeStamp, sms.Recipients[count], status[count].Status < 0, status[count].ErrorCode, status[count].ErrorMessage); db.SubmitChanges(); } }
private readonly Func <string, IFileConverter> _fileConverterDelg; //v2 public HomeController(ISms sms, IEnumerable <IMail> mails, IFileConverter fileConverter, //v1 Func <string, IFileConverter> fileConverterDelg //v2 ) { _sms = sms; _mails = mails; _fileConverter = fileConverter; //v1 _fileConverterDelg = fileConverterDelg; //v2 }
public bool Enviar(Cliente cliente, ISms iSms) { //using (var sms = new SMSConnection()) //{ // sms.to = "193232339223"; // sms.sender; //} iSms.Enviar(); Console.WriteLine("Salvando o objeto no banco de dados"); return(true); }
public override void OnSubmissionFailure(ISms sms, ISmsStatusCollection status, DateTime timeStamp) { int failures = 0; WriteLine(string.Format("**Failure: {0}", sms)); foreach (ISmsStatus st in status) { WriteIndented(st.ToString()); if (st.Status < 0) failures++; } WriteIndented(string.Format("Number of failures: {0}", failures)); }
public static void SetSmsInterface(SmsInterfaceType interfaceType, string account, string password) { switch (interfaceType) { case SmsInterfaceType.IHUYI: sms = IHUYISms.Initialize(account, password); break; case SmsInterfaceType.C123: sms = C123Sms.Initialize(account, password); break; default: throw new NotImplementedException(); } }
/// <summary> /// Send an immediate sms message to multiple recipients /// </summary> /// <remarks> /// To be used when the number of recipients is greater than 1 /// </remarks> /// <exception cref="InvalidSmsOperationException"> /// <see cref="EnSmsOperation.AlreadyProcessed"/>: /// If the SMS has been already processed /// </exception> /// <param name="message">The message to be sent</param> /// <returns> /// A collection of <see cref="ISmsStatus" /> containing /// the status for each recipient /// </returns> public ISmsStatusCollection SendMultipleImmediate(ISms message) { ISmsStatusCollection status; ISmsProvider smsProvider; ISmsGateway smsGateway; Sms sms; sms = (Sms) message; PreProcessSms(sms); smsProvider = sms.Provider ?? _defaultSmsProvider; if (smsProvider == null) throw new ProviderNotFoundException(); sms.Provider = smsProvider; NotifyAcceptance(sms); smsGateway = _smsGateways[smsProvider.Name]; status = smsGateway.Send(sms); if (status.Successful) NotifySubmission(sms, status); else NotifySubmissionFailure(sms, status); sms.SetProcessed(); return status; }
protected SmsFormatException(ISms sms, EnSmsFormat enSmsFormat, string message) : base(message) { _enSmsFormat = enSmsFormat; _sms = sms; }
public ProfileController(ISms sms) { _sms = sms; _repoProfile = new RepoProfile(); db = new ApplicationDbContext(); }
public override void OnSubmissionFailure(ISms sms, ISmsStatusCollection status, DateTime timeStamp) { SmsLogDataContext.SmsLog_Submitted(sms, status, timeStamp); }
public override void OnEnqueuement(ISms sms, DateTime timeStamp) { }
/// <summary> /// Initializes a new instance of the <see cref="LawsController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public LawsController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
/// <summary> /// Forward a SMS Send request to the gateway /// Made a private method to allow refreshing of the /// session id - if session is expired, it attempts /// 1 time only, then if the error persists /// does not retry anymore /// </summary> /// <param name="sms">The sms to be sent</param> /// <param name="refresingSession"> /// true if the session id is expired and a new send attempt is /// being done after reconnecting with a new session id /// </param> /// <returns></returns> private ISmsStatusCollection Send(ISms sms, bool refresingSession) { ISmsStatusCollection status; SmsStatus smsStatus; string[] errorMessages; bool retry = false; if (Provider.TestMode == false) { string[] recipients; recipients = new string[sms.Recipients.Count]; for (int count = 0; count < sms.Recipients.Count; ++count) recipients[count] = sms.Recipients[count]; lock (_server) { errorMessages = _server.sendmsg(_sessionId, _apiId, null, null, recipients, sms.Sender, sms.Message, 0, 1, 0, 0, 3, 0, 3, 1, 0, sms.ReferenceId.ToString(), 0, "SMS_TEXT", string.Empty, string.Empty, 1440); if ((errorMessages.Length == 1) && (IsSessionError(errorMessages[0]) && (refresingSession == false))) { Connect(); retry = true; } } } else errorMessages = new string[sms.Recipients.Count]; if (retry) status = Send(sms, true); else { status = new SmsStatusCollection(sms); for (int count = 0; count < sms.Recipients.Count; ++count) { smsStatus = new SmsStatus(sms.Recipients[count]); smsStatus.TestMode = Provider.TestMode; CheckResponse(smsStatus, errorMessages[count]); status.Add(smsStatus); } } return status; }
/// <summary> /// Privat24 SMS API /// </summary> /// <param name="login"></param> /// <param name="password"></param> /// <param name="apikey"></param> public SmsSender(string login, string password, string apikey) { Sender = new AlphaSmsManager(login, password, apikey); }
public SmsSenderFormatException(ISms sms, EnSmsSenderFormat senderFormatError) : base(sms, EnSmsFormat.InvalidSender, string.Format("Invalid sender")) { _smsSenderFormat = senderFormatError; }
public SmsBodyFormatException(ISms sms, EnSmsBodyFormat bodyFormatError) : base(sms, EnSmsFormat.InvalidBody, string.Format("Invalid body")) { _smsBodyFormat = bodyFormatError; }
/// <summary> /// Send an immediate sms message to a single recipient /// </summary> /// <remarks> /// This method must be used for a single recipient only.<br/> /// For multiple recipients use <see cref="SendMultipleImmediate"/> /// </remarks> /// <exception cref="InvalidSmsOperationException"> /// <see cref="EnSmsOperation.AlreadyProcessed" />: /// If the SMS has already been processed /// </exception> /// <exception cref="InvalidSmsOperationException"> /// <see cref="EnSmsOperation.MultipleRecipients" />: /// If more than 1 recipient has been added /// </exception> /// <param name="message">The message to be sent</param> /// <returns> /// <see cref="ISmsStatus"/> instance containing status information /// </returns> public ISmsStatus SendImmediate(ISms message) { if (message.Recipients.Count > 1) throw new InvalidSmsOperationException(EnSmsOperation.MultipleRecipients, message); return SendMultipleImmediate(message)[0]; }
public void Enqueue(ISms message) { Sms sms; sms = (Sms) message; PreProcessSms(sms); //NotifyAcceptance(sms); _defaultQueueHandler.Enqueue(sms); NotifyEnqueuement(sms); }
/// <summary> /// Initializes a new instance of the <see cref="ArticlesController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public ArticlesController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
public override void OnAcceptance(ISms sms, DateTime timeStamp) { WriteLine(string.Format("Accepted: {0}", sms)); }
/// <summary> /// Privat24 SMS API /// </summary> /// <param name="merchantId"></param> /// <param name="merchantPassword"></param> public SmsSender(int merchantId, string merchantPassword) { Sender = new Privat24Manager(merchantId, merchantPassword); }
public override void OnEnqueuement(ISms sms, DateTime timeStamp) { WriteLine(string.Format("Enqueued: {0}", sms)); }
/// <summary> /// Initializes a new instance of the <see cref="BaseController"/> class. /// </summary> /// <param name="serviceFactory">The service factory.</param> /// <param name="sms">The SMS.</param> public BaseController(IServiceFactory serviceFactory, ISms sms) { Guard.NotNull(serviceFactory, nameof(serviceFactory)); _serviceFactory = serviceFactory; _sms = sms; }
public override void OnSubmission(ISms sms, ISmsStatusCollection status, DateTime timeStamp) { WriteLine(string.Format("Submitted: {0}", sms)); foreach (ISmsStatus st in status) WriteIndented(st.ToString()); }
protected override ISmsStatusCollection OnSend(ISms sms) { return Send(sms, false); }
#pragma warning disable CS3001 // Argument type is not CLS-compliant /// <summary> /// Constructor which accepts the sms as a parameter which is a dependency. /// This dependency is configured in the UnityConfig file inside RegisterTypes function /// This is inside ServiceLocation folder /// </summary> /// <param name="sms"></param> public SmsBL(Sms sms) { _sms = sms; }
/// <summary> /// Initializes a new instance of the <see cref="UtilityController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public UtilityController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
public Notification(IMail mail, ISms sms) { _mail = mail; _sms = sms; }
public void SmsLog_Insert(ISms sms, DateTime timeStamp) { SmsLog_Insert(sms.ReferenceId, sms.ApplicationId, sms.Sender, sms.Recipients.Count, sms.Message, timeStamp, ConvertRecipients(sms.Recipients), false); }
public AlertController(ISms sms, IOptions <SmsAlertConfig> config) { _sms = sms; _config = config; }
public SmsFormatException(ISms sms, EnSmsFormat enSmsFormat) : base(string.Format("Invalid SMS format - Reason: {0}", enSmsFormat)) { _enSmsFormat = enSmsFormat; _sms = sms; }
/// <summary> /// Initializes a new instance of the <see cref="EmiratesController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public EmiratesController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
public Teacher2Controller( ) { ob = new Sms(); // dbContext = new AppDbContext(); DbService = new TeacherDbService(); }
public void RunDequeuingThreads() { IDequeueService dequeuers; Mock<SqlServerLogProvider> mockLogProvider; ISmsc smsc; ISms[] messages; mockLogProvider = MockManager.Mock<SqlServerLogProvider>(Constructor.NotMocked); mockLogProvider.ExpectCall("OnEnqueuement", 20); smsc = SmsFactory.GetSmsc(); // Create and enqueue 20 messages messages = new ISms[20]; for (int count = 0; count < 20; ++count) { messages[count] = SmsFactory.NewSms(TestConstants.Default_ApplicationId); messages[count].Sender = TestConstants.Default_Sender; messages[count].AddRecipient(TestConstants.Default_Recipient); messages[count].Message = string.Format("Message {0}", count + 1); smsc.Enqueue(messages[count]); } mockLogProvider = MockManager.Mock<SqlServerLogProvider>(Constructor.NotMocked); mockLogProvider.ExpectCall("OnSubmission", 20); // Instantiate a dequeuer with 5 instances dequeuers = SmsFactory.CreateDequeueService(5); Assert.IsFalse(dequeuers.IsQueueEmpty()); // Run the 5 dequeuer threads dequeuers.Start(); Thread.Sleep(2000); // Wait until all dequeuer threads are idle dequeuers.Suspend(); Assert.IsTrue(dequeuers.IsQueueEmpty()); dequeuers.Terminate(); }
/// <summary> /// Initializes a new instance of the <see cref="CampaignController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public CampaignController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
protected void NotifySubmission(ISms sms, ISmsStatusCollection status) { if (OnSubmission != null) OnSubmission(sms, status, DateTime.Now); }
public SmsRecipientFormatException(ISms sms) : base(sms, EnSmsFormat.InvalidRecipient, "Invalid SMS: no recipient") { _recipientFormatErrors = new RecipientFormatError[0]; }
/// <summary> /// 通过短信发送验证码 /// </summary> /// <param name="formatter">验证码内容模板</param> /// <param name="sms">短信发送接口</param> public SmsSender(IContentFormatter formatter, ISms sms) { this.Formatter = formatter ?? throw new ArgumentNullException(nameof(formatter)); this.Sms = sms ?? throw new ArgumentNullException(nameof(sms)); }
/// <summary> /// Initializes a new instance of the <see cref="ContactTypeController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public ContactTypeController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
public SmsNotificationArgs(ISms sms, ISmsStatus smsStatus) { _sms = sms; _smsStatus = smsStatus; }
public void EnqueueAndDequeueMultipleMessages() { ISmsc smsc; ISms[] messages; messages = new ISms[5]; smsc = SmsFactory.GetSmsc(); // Verify the queue is empty Assert.IsTrue(smsc.IsQueueEmpty()); for (int count = 0; count < 5; ++count) { messages[count] = SmsFactory.NewSms(TestConstants.Default_ApplicationId); messages[count].Sender = TestConstants.Default_Sender; messages[count].AddRecipient(TestConstants.Default_Recipient); messages[count].Message = string.Format("Message {0}", count + 1); smsc.Enqueue(messages[count]); } // Verify the queue is not empty Assert.IsFalse(smsc.IsQueueEmpty()); for (int count = 0; count < 5; ++count) { using (var dequeuer = smsc.GetDequeuer()) { var enqueuedSms = dequeuer.Dequeue(); dequeuer.DequeueCommit(true); Helpers.CompareSms(messages[count], enqueuedSms); } } // Verify the queue is empty Assert.IsTrue(smsc.IsQueueEmpty()); }
/// <summary> /// Initializes a new instance of the <see cref="DecisionController"/> class. /// </summary> /// <param name="_serviceFactory">The service factory.</param> /// <param name="_sms">The SMS.</param> public DecisionController(IServiceFactory _serviceFactory, ISms _sms) : base(_serviceFactory, _sms) { }
public Helper(ISms sms) { _sms = sms; }
public CommonController(ISms smsRepository) { _smsRepository = smsRepository; }