public SmsSentResult SendSmsMessage(SmsMessage smsMessage, string userId) { SmsConfiguration smsConfiguration = GetSmsConfiguration(); SmsSentResult smsSentResult = new SmsSentResult() { Success = false }; try { TwilioClient.Init(smsConfiguration.Sid, smsConfiguration.AuthToken); var message = MessageResource.Create( body: smsMessage.Body, from: new Twilio.Types.PhoneNumber(smsConfiguration.Number), to: new Twilio.Types.PhoneNumber(smsMessage.ReceiverPhoneNo) ); smsSentResult.Success = true; smsSentResult.Id = userId; _log.Info("SmsSenderManager - SendSmsMessage - Sms send successfully for user id: " + userId + " number: " + smsMessage.ReceiverPhoneNo); } catch (Exception ex) { smsSentResult.Ex = ex; _log.Error(Log4NetMessageHelper.FormateMessageForException(ex, "SendSmsMessage", smsMessage.ReceiverPhoneNo)); } return(smsSentResult); }
public SmsSenderManager(IConfiguration configuration) { _configuration = configuration; _smsConfiguration = new SmsConfiguration(); _smsConfiguration.Number = _configuration["AppSmsConfig:TwilioFromNumber"].ToString(); log.Debug("SmsSenderManager - Number: " + _smsConfiguration.Number); }
public SendSmsRequestReceivedConsumerShould() { _configuration = new SmsConfiguration { Password = "******", ServiceUrl = "http://localhost/send-sms", User = "******", }; }
public SmsClientShould() { _configuration = new SmsConfiguration { Password = "******", ServiceUrl = "http://localhost/send-sms", User = "******", }; }
public SendSmsRequestReceivedConsumerShould() { _configuration = new SmsConfiguration { Password = "******", ServiceUrl = "http://localhost/send-sms", User = "******", }; _webApiClient = Substitute.For <IWebApiClient>(); }
public void SetUp() { var container = new Container(x => { x.AddRegistry <CommonRegistry>(); x.AddRegistry <LoggingRegistry>(); x.AddRegistry <CommunicationRegistry>(); }); _smsConfiguration = container.GetInstance <IConfigurationService>() .Get <SmsConfiguration>(); }
public ReachSmsDispatcher( ILogService logger, IRestClient restClient, IConfigurationService configurationService, ISmsNumberFormatter smsNumberFormatter, IEnumerable <KeyValuePair <MessageTypes, SmsMessageFormatter> > messageFormatters ) { _logger = logger; _restClient = restClient; _reachConfiguration = configurationService.Get <SmsConfiguration>(); _smsNumberFormatter = smsNumberFormatter; _messageFormatters = messageFormatters; }
public void SetUp() { _logService = new Mock <ILogService>(); // Templates. var smsTemplateConfiguration = new SmsTemplate { Name = "MessageTypes.SendAccountUnlockCode", Message = "Your account has been locked due to suspicious activity. To unlock it please enter the following code: {0}." }; _smsTemplateConfigurations = new[] { smsTemplateConfiguration }; var configService = new Mock <IConfigurationService>(); configService.Setup(x => x.Get <SmsConfiguration>()) .Returns(new SmsConfiguration() { Templates = _smsTemplateConfigurations }); _smsMessageFormatters = new[] { new KeyValuePair <MessageTypes, SmsMessageFormatter>(MessageTypes.SendAccountUnlockCode, new SmsAccountUnlockCodeMessageFormatter(configService.Object)) }; var smsConfig = new SmsConfiguration() { Templates = _smsTemplateConfigurations, Url = "https://www.example.com" }; _configurationService = new Mock <IConfigurationService>(); _configurationService.Setup(x => x.Get <SmsConfiguration>()).Returns(smsConfig); _smsNumberFormatter = new ReachSmsNumberFormatter(); // Default request. _communicationTokens = new[] { new CommunicationToken(CommunicationTokens.AccountUnlockCode, "XYZ789") }; _smsRequest = new SmsRequestBuilder() .WithMessageType(MessageTypes.SendAccountUnlockCode) .WithTokens(_communicationTokens) .Build(); }
public SmsSenderManager(IConfiguration configuration) { _configuration = configuration; _smsConfiguration = new SmsConfiguration(); _smsConfiguration.Number = _configuration["AppSmsConfig:TwilioFromNumber"].ToString(); _smsConfiguration.Sid = _configuration["AppSmsConfig:TwilioAccountSid"].ToString(); _smsConfiguration.AuthToken = _configuration["AppSmsConfig:TwilioAuthToken"].ToString(); _log.Debug("SmsSenderManager - Number: " + _smsConfiguration.Number); _contactUsConfiguration = new ContactUsConfiguration(); _contactUsConfiguration.EmailAddress = _configuration["AppContactUsConfig:EmailAddress"].ToString(); _contactUsConfiguration.EmailAddressDisplayName = _configuration["AppContactUsConfig:EmailAddressDisplayName"].ToString(); _contactUsConfiguration.PhoneNumber = _configuration["AppContactUsConfig:PhoneNumber"].ToString(); _contactUsConfiguration.PhoneNumberDisplayName = _configuration["AppContactUsConfig:PhoneNumberDisplayName"].ToString(); _log.Debug("SmsSenderManager - ContactUsConfiguration - EmailAddress: " + _contactUsConfiguration.EmailAddress); _log.Debug("SmsSenderManager - ContactUsConfiguration - PhoneNumber: " + _contactUsConfiguration.PhoneNumber); }
public ServiceProcess(SqlDataAccess sda, IOrganizationService service) { _sda = sda; _service = service; LOG_PATH = Globals.FileLogPath; ERROR_LOG_PATH = Globals.FileLogPath; MsCrmResultObject resultSmsConf = SMSHelper.GetSmsConfigurationInfo(new Guid(Globals.SmsConfigurationDoluHayatId), sda); if (!resultSmsConf.Success) { FileLogHelper.LogFunction(this.GetType().Name, "SendSms_ServiceProcess_NOCONFIG_DEFINATION", LOG_PATH); } SMS_CONFIG = (SmsConfiguration)resultSmsConf.ReturnObject; _smsApi = new smsService.smsservice(); }
public ServiceProcess(SqlDataAccess sda, IOrganizationService service) { _sda = sda; _service = service; LOG_PATH = Globals.FileLogPath; ERROR_LOG_PATH = Globals.FileLogPath; MsCrmResultObject resultSmsConf = SMSHelper.GetSmsConfigurationInfo(new Guid(Globals.SmsConfigurationDoluHayatId), sda); if (!resultSmsConf.Success) { FileLogHelper.LogFunction(this.GetType().Name,"SendSms_ServiceProcess_NOCONFIG_DEFINATION", LOG_PATH); } SMS_CONFIG = (SmsConfiguration)resultSmsConf.ReturnObject; _smsApi = new smsService.smsservice(); }
public SmsConfiguration GetSmsConfiguration(int recipientGroupId) { var proc = "GetSmsTokens"; var paramz = new List <SqlParameter>(); paramz.Add(new SqlParameter("recipientGroupId", recipientGroupId)); Func <SqlDataReader, SmsConfiguration> readFx = (reader) => { var item = new SmsConfiguration(); item.Sid = reader.ValueOrDefault <string>("AccountSid"); item.Token = reader.ValueOrDefault <string>("AccountToken"); item.PhoneNumber = reader.ValueOrDefault <string>("PhoneNumber"); return(item); }; var list = this.executor.ExecuteSql <SmsConfiguration>(proc, CommandType.StoredProcedure, paramz, readFx); return(list.FirstOrDefault()); }
public SmsSentResult SendSmsMessage(SmsMessage smsMessage, string userId) { SmsConfiguration smsConfiguration = GetSmsConfiguration(); SmsSentResult smsSentResult = new SmsSentResult() { Success = false }; try { smsSentResult.Success = true; smsSentResult.Id = userId; log.Info("SmsSenderManager - SendSmsMessage - Sms send successfully for user id: " + userId + " number: " + smsMessage.ReceiverPhoneNo); } catch (Exception ex) { smsSentResult.Ex = ex; log.Error(Log4NetMessageHelper.FormateMessageForException(ex, "SendSmsMessage", smsMessage.ReceiverPhoneNo)); } return(smsSentResult); }
public override void Initialize() { //(0)应用运行初始配置 LoggingManager.AddLoggerAdapter(new Log4netLoggerAdapter()); //增加日志组件 EngineHelper.LoggingInfo("Quest Application - Start - "); //(1)领域相关初始配置 DomainConfiguration.Initialize(opt => { opt.Repositorys.Add(new KeyValueModel <Type, Type>(typeof(IRepository <>), typeof(SqlSugarRepository <>))); opt.Repositorys.Add(new KeyValueModel <Type, Type>(typeof(IRepository <,>), typeof(SqlSugarRepository <,>))); }); //(2)组件安装初始配置 EngineHelper.Component.List.ForEach(x => x.Install()); //(3)插件注入配置 SmsConfiguration.Initialize(); //(End)构建容器 EngineHelper.ContainerBuilder <IContainer>(); }
public static MsCrmResultObject GetSmsConfigurationInfo(Guid configurationId, SqlDataAccess sda) { MsCrmResultObject returnValue = new MsCrmResultObject(); try { #region | SQL QUERY | string sqlQuery = @"SELECT sc.new_name AS Name ,sc.new_accountnumber AS AccountNumber ,sc.new_gsmoperator AS GsmOperator ,sc.new_orginator AS Orginator ,sc.new_password AS Password ,sc.new_shortnumber AS ShortNumber ,sc.new_smsconfigurationId AS Id ,sc.new_username AS UserName ,sc.StatusCode FROM new_smsconfiguration AS sc (NOLOCK) WHERE sc.new_smsconfigurationId='{0}'"; #endregion DataTable dt = sda.getDataTable(string.Format(sqlQuery, configurationId)); if (dt.Rows.Count > 0) { SmsConfiguration smsConf = new SmsConfiguration(); smsConf.Id = (Guid)dt.Rows[0]["Id"]; smsConf.Name = dt.Rows[0]["Name"].ToString(); if (dt.Rows[0]["GsmOperator"] != DBNull.Value) { smsConf.Operator = (GsmOperators)(int)dt.Rows[0]["GsmOperator"]; } smsConf.AccountNumber = dt.Rows[0]["AccountNumber"].ToString(); smsConf.UserName = dt.Rows[0]["UserName"].ToString(); smsConf.Password = dt.Rows[0]["Password"].ToString(); smsConf.ShortNumber = dt.Rows[0]["ShortNumber"].ToString(); smsConf.Orginator = dt.Rows[0]["Orginator"].ToString(); smsConf.StatusCode = (int)dt.Rows[0]["StatusCode"]; returnValue.ReturnObject = smsConf; returnValue.Success = true; } else { returnValue.Result = "Konfigürasyon bilgisi alınamadı."; } } catch (Exception ex) { returnValue.Result = ex.Message; } return returnValue; }
SendSmsResult SendSms(string sessionId, SmsConfiguration smsConf, SendSmsRecord sendSms) { SendSmsResult returnValue = new SendSmsResult(); smsService.smsservice smsApi = new smsService.smsservice(); //string[] result = smsApi.SmsInsert_1_N("kalekulup", "cilingir123", null, null, new string[] { sendSms.PhoneNumber }, sendSms.Content); string[] result = smsApi.SmsInsert_1_N(smsConf.UserName, smsConf.Password, null, null, new string[] { sendSms.PhoneNumber }, sendSms.Content); //SendSMSRequest req = new SendSMSRequest(); //req.DeleteDate = ""; //req.GroupID = "0"; //req.SendDate = ""; //req.SessionID = sessionId; //req.Operator = (Operators)(int)smsConf.Operator; //req.Isunicode = Unicode.Yes; //req.Orginator = smsConf.Orginator; //req.ShortNumber = smsConf.ShortNumber; //MessageList mList = new MessageList(); //List<Content> cList = new List<Content>(); //List<GSM> gsmList = new List<GSM>(); //Content cnt = new Content() //{ // Value = sendSms.Content //}; //GSM gsm = new GSM() //{ // Value = sendSms.PhoneNumber //}; //cList.Add(cnt); //gsmList.Add(gsm); //mList.ContentList = cList.ToArray(); //mList.GSMList = gsmList.ToArray(); //req.MessageList = mList; //SendMessageResponse resp = mService.SendSMS(req); returnValue.SendSmsCrmId = sendSms.Id; returnValue.StatusCode = result[0]; //if (resp.Results != null) // returnValue.MessageId = resp.Results[0].MessageID; return returnValue; }
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment) { if (environment.IsEnvironment("Testing")) { // Add Persistence Infra services.AddDbContext <AppDbContext>(options => options.UseInMemoryDatabase(databaseName: "MeterData")); // Add Identity Infra services.AddDbContext <AppIdentityDbContext>(options => options.UseInMemoryDatabase(databaseName: "IdentityData")); } else { // Add Persistence Infra services.AddDbContext <AppDbContext>(options => options.UseNpgsql( configuration.GetConnectionString("DefaultConnection"))); services.AddDbContext <AppIdentityDbContext>(options => options.UseNpgsql( configuration.GetConnectionString("DefaultConnection"))); } services.AddIdentity <ApplicationUser, IdentityRole>(options => { options.SignIn.RequireConfirmedAccount = false; options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = false; options.Password.RequiredLength = 4; options.Password.RequiredUniqueChars = 2; }) .AddEntityFrameworkStores <AppIdentityDbContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(options => { // configure login path for return urls // https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-3.1&tabs=visual-studio options.LoginPath = "/Identity/Account/Login"; options.AccessDeniedPath = "/Identity/Account/AccessDenied"; options.SlidingExpiration = true; options.ExpireTimeSpan = TimeSpan.FromDays(30); }); // Add meter data fetch service services.AddSingleton <IMeterDataService, MeterDataService>(); services.AddSingleton <IScadaDataService, ScadaDataService>(); services.AddSingleton <IWbesArchiveDataService, WbesArchiveDataService>(); services.AddSingleton <IAgcFileUtilsService, AgcFileUtilsService>(); services.AddSingleton <IWbesLiveDataService, WbesLiveDataService>(); services.AddSingleton <IScadaNodesPingStatsService, ScadaNodesPingStatsService>(); // add pmu config PmuConfig pmuConfig = new PmuConfig(); configuration.Bind("PmuConfig", pmuConfig); services.AddSingleton(pmuConfig); // add reports data config ReportsConfig reportsConfig = new ReportsConfig(); configuration.Bind("ReportsData", reportsConfig); services.AddSingleton(reportsConfig); // add pmu data service services.AddSingleton <IPMUHistDataService, PMUHistDataService>(); // add reports data service services.AddSingleton <IReportsDataService, ReportsDataService>(); // add email settings from app config EmailConfiguration emailConfig = new EmailConfiguration(); configuration.Bind("EmailSettings", emailConfig); services.AddSingleton(emailConfig); // add sms settings from app config SmsConfiguration smsConfig = new SmsConfiguration(); configuration.Bind("SmsSettings", smsConfig); services.AddSingleton(smsConfig); // Add Infra services services.AddTransient <IEmailSender, EmailSender>(); services.AddTransient <ISmsSender, SmsSender>(); // Add temp monitoring realtime service services.AddSingleton <IDeviceDataService, DeviceDataService>(); return(services); }
public SmsClient(HttpClient httpClient, SmsConfiguration smsConfiguration) { _httpClient = httpClient; _smsConfiguration = smsConfiguration; }
static void Main(string[] args) { var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); _configuration = configBuilder.Build(); var logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.ColoredConsole() .CreateLogger(); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(logger); LogContext.ConfigureCurrentLogContext(loggerFactory); var smsConfiguration = new SmsConfiguration { BaseUrl = _configuration["BaseUrl"], SmsSender = _configuration["SmsSender"], RapidProPassword = _configuration["RapidProPassword"], RapidProUserName = _configuration["RapidProUserName"], RapidProSmsCode = _configuration["RapidProSmsCode"] }; var builder = new ContainerBuilder(); builder.RegisterModule(new ServiceModule(smsConfiguration)); builder.RegisterModule <ConsumersModule>(); builder.Register(context => { var busControl = Bus.Factory.CreateUsingRabbitMq(config => { config.ConfigureJsonSerializer(options => { options.DefaultValueHandling = DefaultValueHandling.Include; return(options); }); var host = config.Host(new Uri(_configuration.GetValue <string>("RabbitMQHost")), h => { h.Username(_configuration.GetValue <string>("RabbitMQUsername")); h.Password(_configuration.GetValue <string>("RabbitMQPassword")); }); config.PrefetchCount = 32; config.UseRetry(retry => retry.Interval(3, TimeSpan.FromSeconds(6))); config.ReceiveEndpoint(_configuration["SmsQueue"], e => { e.Consumer <SmsConsumer>(context); }); }); return(busControl); }) .SingleInstance() .As <IBusControl>() .As <IBus>(); LogContext.Info?.Log("Creating Service bus.."); var container = builder.Build(); var bus = container.Resolve <IBusControl>(); bus.Start(); LogContext.Info?.Log("Bus started"); LogContext.Info?.Log("Waiting for request"); Console.ReadLine(); bus.Stop(); }
public ServiceModule(SmsConfiguration smsConfiguration) { _smsConfiguration = smsConfiguration; }
public SmsService(IOptions <SmsConfiguration> smsConfiguration) { _smsConfiguration = smsConfiguration.Value; }
public SmsMessagingService(SmsConfiguration smsConfiguration) { _smsConfiguration = smsConfiguration; }
public SmsService(IOptions <Config> config, IHttpClientFactory clientFactory) { _config = config.Value.SmsConfiguration; _clientFactory = clientFactory; }
public static MsCrmResultObject GetSmsConfigurationInfo(Guid configurationId, SqlDataAccess sda) { MsCrmResultObject returnValue = new MsCrmResultObject(); try { #region | SQL QUERY | string sqlQuery = @"SELECT sc.new_name AS Name ,sc.new_accountnumber AS AccountNumber ,sc.new_gsmoperator AS GsmOperator ,sc.new_orginator AS Orginator ,sc.new_password AS Password ,sc.new_shortnumber AS ShortNumber ,sc.new_smsconfigurationId AS Id ,sc.new_username AS UserName ,sc.StatusCode FROM new_smsconfiguration AS sc (NOLOCK) WHERE sc.new_smsconfigurationId='{0}'" ; #endregion DataTable dt = sda.getDataTable(string.Format(sqlQuery, configurationId)); if (dt.Rows.Count > 0) { SmsConfiguration smsConf = new SmsConfiguration(); smsConf.Id = (Guid)dt.Rows[0]["Id"]; smsConf.Name = dt.Rows[0]["Name"].ToString(); if (dt.Rows[0]["GsmOperator"] != DBNull.Value) { smsConf.Operator = (GsmOperators)(int)dt.Rows[0]["GsmOperator"]; } smsConf.AccountNumber = dt.Rows[0]["AccountNumber"].ToString(); smsConf.UserName = dt.Rows[0]["UserName"].ToString(); smsConf.Password = dt.Rows[0]["Password"].ToString(); smsConf.ShortNumber = dt.Rows[0]["ShortNumber"].ToString(); smsConf.Orginator = dt.Rows[0]["Orginator"].ToString(); smsConf.StatusCode = (int)dt.Rows[0]["StatusCode"]; returnValue.ReturnObject = smsConf; returnValue.Success = true; } else { returnValue.Result = "Konfigürasyon bilgisi alınamadı."; } } catch (Exception ex) { returnValue.Result = ex.Message; } return(returnValue); }
string GetSession(SmsConfiguration smsConf) { string returnValue = string.Empty; Session ses = new Session(); ses.AccountNumber = smsConf.AccountNumber; ses.UserName = smsConf.UserName; ses.Password = smsConf.Password; string session = mService.Register(ses); returnValue = session; return returnValue; }