private void ProcessarSmsNaoEnviado() { eventLog1.WriteEntry("ECJ_WS05 - Processa sms nao enviado", EventLogEntryType.Information, 2); SmsService smsService = new SmsService(); smsService.LimpaSmsEnviado(); eventLog1.WriteEntry("ECJ_WS05 - Deleta sms enviado", EventLogEntryType.Information, 200); var tww = new TWW(); var listaSmsNaoEnviado = smsService.BuscarNaoEnviados(); if (listaSmsNaoEnviado.Count == 0) { return; } foreach (var sms in listaSmsNaoEnviado) { try { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; sms.DataInicioProcesso = DateTime.Now; sms.Status = StatusSms.Processando; smsService.Salvar(sms); var response = tww.Send(sms.Id, sms.Numero, sms.Mensagem); //emailService.EnviaEmail(ParametrosAppConfig.EmailSms, sms.Mensagem + "@" + idMsg, sms.Numero); if (response != "OK") { LogarErroSms(sms.Id, StatusSms.TentarNovamente, $"créditos: {tww.Creditos()}, validade: {tww.ValidadeCreditos()}"); continue; } sms.Status = StatusSms.Enviado; smsService.Salvar(sms); } catch (Exception ex) { eventLog1.WriteEntry("ECJ_WS05 - Processa sms nao enviado" + ex.Message, EventLogEntryType.Error, 1); LogarErroSms(sms.Id, StatusSms.Erro, ex.Message); } } eventLog1.WriteEntry("ECJ_WS05 - Fim Processa sms nao enviado", EventLogEntryType.Information, 3); }
private void ProcessarSmsNaoEnviado() { SmsService smsService = new SmsService(); this._listaSmsNaoEnviado = smsService.BuscarNaoEnviados(ParametrosAppConfig.QtdeSmsEnviadosPorVez); if (_listaSmsNaoEnviado.Count == 0) { return; } foreach (var sms in _listaSmsNaoEnviado) { sms.DataInicioProcesso = DateTime.Now; sms.Status = StatusSms.Processando; smsService.Salvar(sms); } SmsGateway smsGateway = CreateSmsGateway(); smsGateway.GetDevices( success: (devices) => { foreach (var sms in _listaSmsNaoEnviado) { try { string device = devices[0]; smsGateway.SendMessage(device, sms.Numero, sms.Mensagem, success: (result) => { var smsServiceThreadSafe = new SmsService(); var smsAtualizavel = smsServiceThreadSafe.BuscarPor(sms.Id); smsAtualizavel.DataEnvio = DateTime.Now; smsAtualizavel.Erro = null; if (result[0]["status"].ToString() == "pending") { smsAtualizavel.Status = StatusSms.Pendente; } smsAtualizavel.IdMessageSmsGateway = result[0]["id"].ToString(); smsServiceThreadSafe.Salvar(smsAtualizavel); }, error: (erro) => { LogarErroSms(sms.Id, StatusSms.TentarNovamente, erro); }); var newIndex = devices.IndexOf(device) + 1; if (newIndex == devices.Count) { device = devices[0]; } else { device = devices[newIndex]; } } catch (Exception ex) { LogarErroSms(sms.Id, StatusSms.TentarNovamente, ex.Message); } } }, error: (erro) => { foreach (var sms in _listaSmsNaoEnviado) { LogarErroSms(sms.Id, StatusSms.TentarNovamente, erro); } }); }