public void ConfigSourceEvents() { string filePath = "EventTest.ini"; IniConfigSource source = new IniConfigSource(); source.Saved += new EventHandler(this.source_saved); source.Reloaded += new EventHandler(this.source_reloaded); Assert.IsNull(eventConfig); Assert.IsNull(eventSource); IConfig config = source.AddConfig("Test"); eventSource = null; Assert.AreEqual(savedCount, 0); source.Save(filePath); Assert.AreEqual(savedCount, 1); Assert.IsTrue(source == eventSource); eventSource = null; source.Save(); Assert.AreEqual(savedCount, 2); Assert.IsTrue(source == eventSource); eventSource = null; Assert.AreEqual(reloadedCount, 0); source.Reload(); Assert.AreEqual(reloadedCount, 1); Assert.IsTrue(source == eventSource); File.Delete(filePath); }
public void Reload() { string filePath = "Reload.ini"; // Create the original source file IniConfigSource source = new IniConfigSource(); IConfig petConfig = source.AddConfig("Pets"); petConfig.Set("cat", "Muffy"); petConfig.Set("dog", "Rover"); IConfig weatherConfig = source.AddConfig("Weather"); weatherConfig.Set("skies", "cloudy"); weatherConfig.Set("precipitation", "rain"); source.Save(filePath); Assert.AreEqual(2, petConfig.GetKeys().Length); Assert.AreEqual("Muffy", petConfig.Get("cat")); Assert.AreEqual(2, source.Configs.Count); // Create another source file to set values and reload IniConfigSource newSource = new IniConfigSource(filePath); IConfig compareConfig = newSource.Configs["Pets"]; Assert.AreEqual(2, compareConfig.GetKeys().Length); Assert.AreEqual("Muffy", compareConfig.Get("cat")); Assert.IsTrue(compareConfig == newSource.Configs["Pets"], "References before are not equal"); // Set the new values to source source.Configs["Pets"].Set("cat", "Misha"); source.Configs["Pets"].Set("lizard", "Lizzy"); source.Configs["Pets"].Set("hampster", "Surly"); source.Configs["Pets"].Remove("dog"); source.Configs.Remove(weatherConfig); source.Save(); // saves new value // Reload the new source and check for changes newSource.Reload(); Assert.IsTrue(compareConfig == newSource.Configs["Pets"], "References after are not equal"); Assert.AreEqual(1, newSource.Configs.Count); Assert.AreEqual(3, newSource.Configs["Pets"].GetKeys().Length); Assert.AreEqual("Lizzy", newSource.Configs["Pets"].Get("lizard")); Assert.AreEqual("Misha", newSource.Configs["Pets"].Get("cat")); Assert.IsNull(newSource.Configs["Pets"].Get("dog")); File.Delete(filePath); }
public static void ReloadConfigFile() { if (System.IO.File.Exists(FullConfigPath)) { ConfigSource = new IniConfigSource(FullConfigPath); ConfigSource.Reload(); } else { logger.Warn("Конфигурационный фаил {0} не найден. Конфигурация не загружена."); ConfigSource = new IniConfigSource(); ConfigSource.Save(FullConfigPath); } }
public IniFileConfiguration(string iniFile) { if (string.IsNullOrWhiteSpace(iniFile)) { throw new ArgumentException("Имя ini файла должно быть указано.", nameof(iniFile)); } this.IniFile = iniFile; if (File.Exists(iniFile)) { configSource = new IniConfigSource(iniFile); configSource.Reload(); } else { logger.Warn("Конфигурационный фаил {0} не найден. Создан новый.", iniFile); configSource = new IniConfigSource(); configSource.Save(iniFile); } configSource.AutoSave = true; }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); IConfig serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); IConfig smsConfig = confFile.Configs["SmsService"]; smsServiceLogin = smsConfig.GetString("sms_service_login"); smsServicePassword = smsConfig.GetString("sms_service_password"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } try { SmsBlissSendController smsSender = new SmsBlissSendController(smsServiceLogin, smsServicePassword, SmsSendInterface.BalanceType.CurrencyBalance); InstantSmsServiceInstanceProvider instantSmsInstanceProvider = new InstantSmsServiceInstanceProvider(smsSender); ServiceHost InstantSmsServiceHost = new InstantSmsServiceHost(instantSmsInstanceProvider); var webEndPoint = InstantSmsServiceHost.AddServiceEndpoint( typeof(IInstantSmsService), new WebHttpBinding(), String.Format("http://{0}:{1}/InstantSmsInformer", serviceHostName, servicePort) ); WebHttpBehavior httpBehavior = new WebHttpBehavior(); webEndPoint.Behaviors.Add(httpBehavior); InstantSmsServiceHost.AddServiceEndpoint( typeof(IInstantSmsService), new BasicHttpBinding(), String.Format("http://{0}:{1}/InstantSmsService", serviceHostName, servicePort) ); #if DEBUG InstantSmsServiceHost.Description.Behaviors.Add(new PreFilter()); #endif InstantSmsServiceHost.Open(); logger.Info("Запущена служба отправки моментальных sms сообщений"); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception ex) { logger.Fatal(ex); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); IConfig serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); serviceWebPort = serviceConfig.GetString("service_web_port"); driverServiceHostName = serviceConfig.GetString("driver_service_host_name"); driverServicePort = serviceConfig.GetString("driver_service_port"); IConfig bitrixConfig = confFile.Configs["Bitrix"]; baseAddress = bitrixConfig.GetString("base_address"); IConfig mysqlConfig = confFile.Configs["Mysql"]; mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name"); mysqlServerPort = mysqlConfig.GetString("mysql_server_port", "3306"); mysqlUser = mysqlConfig.GetString("mysql_user"); mysqlPassword = mysqlConfig.GetString("mysql_password"); mysqlDatabase = mysqlConfig.GetString("mysql_database"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } logger.Info("Запуск службы оплаты заказов по sms"); try { var conStrBuilder = new MySqlConnectionStringBuilder { Server = mysqlServerHostName, Port = UInt32.Parse(mysqlServerPort), Database = mysqlDatabase, UserID = mysqlUser, Password = mysqlPassword, SslMode = MySqlSslMode.None }; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var dbConfig = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>() .ConnectionString(QSMain.ConnectionString); OrmConfig.ConfigureOrm(dbConfig, new[] { System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)), System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)), System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)) }); MainSupport.LoadBaseParameters(); QS.HistoryLog.HistoryMain.Enable(); ChannelFactory <IAndroidDriverService> channelFactory = new ChannelFactory <IAndroidDriverService>( new BasicHttpBinding(), string.Format("http://{0}:{1}/AndroidDriverService", driverServiceHostName, driverServicePort) ); IDriverPaymentService driverPaymentService = new DriverPaymentService(channelFactory); var paymentSender = new BitrixPaymentWorker(baseAddress); SmsPaymentServiceInstanceProvider smsPaymentServiceInstanceProvider = new SmsPaymentServiceInstanceProvider(paymentSender, driverPaymentService); ServiceHost smsPaymentServiceHost = new SmsPaymentServiceHost(smsPaymentServiceInstanceProvider); ServiceEndpoint webEndPoint = smsPaymentServiceHost.AddServiceEndpoint( typeof(ISmsPaymentService), new WebHttpBinding(), $"http://{serviceHostName}:{serviceWebPort}/SmsPaymentWebService" ); WebHttpBehavior httpBehavior = new WebHttpBehavior(); webEndPoint.Behaviors.Add(httpBehavior); smsPaymentServiceHost.AddServiceEndpoint( typeof(ISmsPaymentService), new BasicHttpBinding(), $"http://{serviceHostName}:{servicePort}/SmsPaymentService" ); smsPaymentServiceHost.Description.Behaviors.Add(new PreFilter()); smsPaymentServiceHost.Open(); logger.Info("Server started."); (smsPaymentServiceInstanceProvider.GetInstance(null) as ISmsPaymentService)?.SynchronizePaymentStatuses(); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; IConfig driverServiceConfig; IConfig firebaseConfig; try { IniConfigSource driverConfFile = new IniConfigSource(driverConfigFile); driverConfFile.Reload(); driverServiceConfig = driverConfFile.Configs["Service"]; firebaseConfig = driverConfFile.Configs["Firebase"]; IConfig mysqlConfig = driverConfFile.Configs["Mysql"]; mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name"); mysqlServerPort = mysqlConfig.GetString("mysql_server_port", "3306"); mysqlUser = mysqlConfig.GetString("mysql_user"); mysqlPassword = mysqlConfig.GetString("mysql_password"); mysqlDatabase = mysqlConfig.GetString("mysql_database"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } try { var conStrBuilder = new MySqlConnectionStringBuilder(); conStrBuilder.Server = mysqlServerHostName; conStrBuilder.Port = UInt32.Parse(mysqlServerPort); conStrBuilder.Database = mysqlDatabase; conStrBuilder.UserID = mysqlUser; conStrBuilder.Password = mysqlPassword; conStrBuilder.SslMode = MySqlSslMode.None; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>() .ConnectionString(QSMain.ConnectionString); OrmConfig.ConfigureOrm(db_config, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)), System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)), System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)) }); MainSupport.LoadBaseParameters(); QS.HistoryLog.HistoryMain.Enable(); } catch (Exception ex) { logger.Fatal(ex, "Ошибка в настройке подключения к БД."); } try { DriverServiceStarter.StartService(driverServiceConfig, firebaseConfig, new BaseParametersProvider()); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); IConfig serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); OsmService.ConfigureService(confFile); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } logger.Info(String.Format("Запуск службы OSM")); WebServiceHost OsmHost = new WebServiceHost(typeof(OsmService)); try { OsmWorker.ServiceHost = serviceHostName; OsmWorker.ServicePort = Int32.Parse(servicePort); OsmHost.AddServiceEndpoint( typeof(IOsmService), new WebHttpBinding(), OsmWorker.ServiceAddress ); #if DEBUG OsmHost.Description.Behaviors.Add(new PreFilter()); #endif OsmHost.Open(); logger.Info("Server started."); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (OsmHost.State == CommunicationState.Opened) { OsmHost.Close(); } if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); IConfig serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); IConfig osrmConfig = confFile.Configs["OsrmService"]; serverUrl = osrmConfig.GetString("server_url"); IConfig mysqlConfig = confFile.Configs["Mysql"]; mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name"); mysqlServerPort = mysqlConfig.GetString("mysql_server_port", "3306"); mysqlUser = mysqlConfig.GetString("mysql_user"); mysqlPassword = mysqlConfig.GetString("mysql_password"); mysqlDatabase = mysqlConfig.GetString("mysql_database"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } logger.Info(String.Format("Запуск службы правил доставки")); try { var conStrBuilder = new MySqlConnectionStringBuilder(); conStrBuilder.Server = mysqlServerHostName; conStrBuilder.Port = UInt32.Parse(mysqlServerPort); conStrBuilder.Database = mysqlDatabase; conStrBuilder.UserID = mysqlUser; conStrBuilder.Password = mysqlPassword; conStrBuilder.SslMode = MySqlSslMode.None; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>() .ConnectionString(QSMain.ConnectionString); OrmConfig.ConfigureOrm(db_config, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(Bank)), System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)) }); OsrmMain.ServerUrl = serverUrl; IDeliveryRepository deliveryRepository = new DeliveryRepository(); DeliveryRulesInstanceProvider deliveryRulesInstanceProvider = new DeliveryRulesInstanceProvider(deliveryRepository); ServiceHost deliveryRulesHost = new DeliveryRulesServiceHost(deliveryRulesInstanceProvider); ServiceEndpoint webEndPoint = deliveryRulesHost.AddServiceEndpoint( typeof(IDeliveryRulesService), new WebHttpBinding(), $"http://{serviceHostName}:{servicePort}/DeliveryRules" ); WebHttpBehavior httpBehavior = new WebHttpBehavior(); webEndPoint.Behaviors.Add(httpBehavior); #if DEBUG deliveryRulesHost.Description.Behaviors.Add(new PreFilter()); #endif deliveryRulesHost.Open(); logger.Info("Server started."); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; try { IniConfigSource configFile = new IniConfigSource(ConfigFile); configFile.Reload(); IConfig config = configFile.Configs ["General"]; server = config.GetString("server"); port = config.GetString("port", "3306"); user = config.GetString("user"); pass = config.GetString("password"); db = config.GetString("database"); firebaseServerApiToken = config.GetString("server_api_token"); firebaseSenderId = config.GetString("firebase_sender"); servicePort = config.GetString("service_port"); serviceHostName = config.GetString("service_host_name"); OsmService.ConfigureService(configFile); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } WebServiceHost OsmHost = new WebServiceHost(typeof(OsmService)); logger.Info(String.Format("Создаем и запускаем службы...")); try { var conStrBuilder = new MySqlConnectionStringBuilder(); conStrBuilder.Server = server; conStrBuilder.Port = UInt32.Parse(port); conStrBuilder.Database = db; conStrBuilder.UserID = user; conStrBuilder.Password = pass; conStrBuilder.SslMode = MySqlSslMode.None; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>() .ConnectionString(QSMain.ConnectionString); OrmConfig.ConfigureOrm(db_config, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(QSBanks.QSBanksMain)), System.Reflection.Assembly.GetAssembly(typeof(QSContacts.QSContactsMain)), System.Reflection.Assembly.GetAssembly(typeof(EmailService.Email)) }); MainSupport.LoadBaseParameters(); FCMHelper.Configure(firebaseServerApiToken, firebaseSenderId); ServiceHost ChatHost = new ServiceHost(typeof(ChatService)); ServiceHost AndroidDriverHost = new ServiceHost(typeof(AndroidDriverService)); ServiceHost EmailSendingHost = new ServiceHost(typeof(EmailService.EmailService)); WebServiceHost MailjetEventsHost = new WebServiceHost(typeof(EmailService.EmailService)); WebServiceHost MobileHost = new WebServiceHost(typeof(MobileService)); ChatHost.AddServiceEndpoint( typeof(IChatService), new BasicHttpBinding(), String.Format("http://{0}:{1}/ChatService", serviceHostName, servicePort) ); AndroidDriverHost.AddServiceEndpoint( typeof(IAndroidDriverService), new BasicHttpBinding(), String.Format("http://{0}:{1}/AndroidDriverService", serviceHostName, servicePort) ); EmailSendingHost.AddServiceEndpoint( typeof(IEmailService), new BasicHttpBinding(), String.Format("http://{0}:{1}/EmailService", serviceHostName, servicePort) ); MailjetEventsHost.AddServiceEndpoint( typeof(IMailjetEventService), new WebHttpBinding(), String.Format("http://{0}:{1}/Mailjet", serviceHostName, servicePort) ); MobileService.BaseUrl = String.Format("http://{0}:{1}/Mobile", serviceHostName, servicePort); MobileHost.AddServiceEndpoint( typeof(IMobileService), new WebHttpBinding(), MobileService.BaseUrl ); OsmWorker.ServiceHost = serviceHostName; OsmWorker.ServicePort = Int32.Parse(servicePort); OsmHost.AddServiceEndpoint(typeof(IOsmService), new WebHttpBinding(), OsmWorker.ServiceAddress); //FIXME Тут добавлен без дебага, потому что без него не работает отдача изображений в потоке. Метод Stream GetImage(string filename) // Просто не смог быстро разобраться. А конкретнее нужна строка reply = TraceMessage (reply.CreateBufferedCopy (int.MaxValue), Action.Send); // видимо она как то обрабатывает сообщение. MobileHost.Description.Behaviors.Add(new PreFilter()); #if DEBUG ChatHost.Description.Behaviors.Add(new PreFilter()); AndroidDriverHost.Description.Behaviors.Add(new PreFilter()); EmailSendingHost.Description.Behaviors.Add(new PreFilter()); MailjetEventsHost.Description.Behaviors.Add(new PreFilter()); OsmHost.Description.Behaviors.Add(new PreFilter()); #endif ChatHost.Open(); AndroidDriverHost.Open(); EmailSendingHost.Open(); MailjetEventsHost.Open(); MobileHost.Open(); OsmHost.Open(); //Запускаем таймеры рутины OrderRoutineTimer = new System.Timers.Timer(120000); //2 минуты OrderRoutineTimer.Elapsed += OrderRoutineTimer_Elapsed; OrderRoutineTimer.Start(); TrackRoutineTimer = new System.Timers.Timer(30000); //30 секунд TrackRoutineTimer.Elapsed += TrackRoutineTimer_Elapsed; TrackRoutineTimer.Start(); logger.Info("Server started."); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (OsmHost.State == CommunicationState.Opened) { OsmHost.Close(); } if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public void Reload() { configSource.Reload(); }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; logger.Info("Чтение конфигурационного файла..."); IConfig serviceConfig; IConfig kassaConfig; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); kassaConfig = confFile.Configs["ModulKassa"]; IConfig mysqlConfig = confFile.Configs["Mysql"]; mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name"); mysqlServerPort = mysqlConfig.GetString("mysql_server_port", "3306"); mysqlUser = mysqlConfig.GetString("mysql_user"); mysqlPassword = mysqlConfig.GetString("mysql_password"); mysqlDatabase = mysqlConfig.GetString("mysql_database"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } logger.Info("Настройка подключения к БД..."); try { var conStrBuilder = new MySqlConnectionStringBuilder { Server = mysqlServerHostName, Port = UInt32.Parse(mysqlServerPort), Database = mysqlDatabase, UserID = mysqlUser, Password = mysqlPassword, SslMode = MySqlSslMode.None }; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .ConnectionString(QSMain.ConnectionString) //.ShowSql() //.FormatSql() ; OrmConfig.ConfigureOrm( db_config, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)), System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)), System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)) } ); MainSupport.LoadBaseParameters(); QS.HistoryLog.HistoryMain.Enable(); } catch (Exception ex) { logger.Fatal(ex, "Ошибка в настройке подключения к БД."); return; } try { ReceiptServiceStarter.StartService(serviceConfig, kassaConfig); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); IConfig serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); serviceWebPort = serviceConfig.GetString("service_web_port"); IConfig mysqlConfig = confFile.Configs["Mysql"]; mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name"); mysqlServerPort = mysqlConfig.GetString("mysql_server_port", "3306"); mysqlUser = mysqlConfig.GetString("mysql_user"); mysqlPassword = mysqlConfig.GetString("mysql_password"); mysqlDatabase = mysqlConfig.GetString("mysql_database"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } logger.Info(String.Format("Запуск службы отправки электронной почты")); try { var conStrBuilder = new MySqlConnectionStringBuilder(); conStrBuilder.Server = mysqlServerHostName; conStrBuilder.Port = UInt32.Parse(mysqlServerPort); conStrBuilder.Database = mysqlDatabase; conStrBuilder.UserID = mysqlUser; conStrBuilder.Password = mysqlPassword; conStrBuilder.SslMode = MySqlSslMode.None; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>() .ConnectionString(QSMain.ConnectionString); OrmConfig.ConfigureOrm(db_config, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)), System.Reflection.Assembly.GetAssembly(typeof(EmailService.Email)), System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)), System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)) }); MainSupport.LoadBaseParameters(); QS.HistoryLog.HistoryMain.Enable(); EmailInstanceProvider emailInstanceProvider = new EmailInstanceProvider(new BaseParametersProvider()); ServiceHost EmailSendingHost = new EmailServiceHost(emailInstanceProvider); ServiceHost MailjetEventsHost = new EmailServiceHost(emailInstanceProvider); ServiceEndpoint webEndPoint = EmailSendingHost.AddServiceEndpoint( typeof(IEmailServiceWeb), new WebHttpBinding(), String.Format("http://{0}:{1}/EmailServiceWeb", serviceHostName, serviceWebPort) ); WebHttpBehavior httpBehavior = new WebHttpBehavior(); webEndPoint.Behaviors.Add(httpBehavior); EmailSendingHost.AddServiceEndpoint( typeof(IEmailService), new BasicHttpBinding(), String.Format("http://{0}:{1}/EmailService", serviceHostName, servicePort) ); var mailjetEndPoint = MailjetEventsHost.AddServiceEndpoint( typeof(IMailjetEventService), new WebHttpBinding(), String.Format("http://{0}:{1}/Mailjet", serviceHostName, servicePort) ); WebHttpBehavior mailjetHttpBehavior = new WebHttpBehavior(); mailjetEndPoint.Behaviors.Add(httpBehavior); #if DEBUG EmailSendingHost.Description.Behaviors.Add(new PreFilter()); MailjetEventsHost.Description.Behaviors.Add(new PreFilter()); #endif EmailSendingHost.Open(); MailjetEventsHost.Open(); logger.Info("Server started."); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception e) { logger.Fatal(e); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;; try { IniConfigSource confFile = new IniConfigSource(configFile); confFile.Reload(); IConfig serviceConfig = confFile.Configs["Service"]; serviceHostName = serviceConfig.GetString("service_host_name"); servicePort = serviceConfig.GetString("service_port"); IConfig mysqlConfig = confFile.Configs["Mysql"]; mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name"); mysqlServerPort = mysqlConfig.GetString("mysql_server_port", "3306"); mysqlUser = mysqlConfig.GetString("mysql_user"); mysqlPassword = mysqlConfig.GetString("mysql_password"); mysqlDatabase = mysqlConfig.GetString("mysql_database"); IConfig smsConfig = confFile.Configs["SmsService"]; smsServiceLogin = smsConfig.GetString("sms_service_login"); smsServicePassword = smsConfig.GetString("sms_service_password"); } catch (Exception ex) { logger.Fatal(ex, "Ошибка чтения конфигурационного файла."); return; } try { var conStrBuilder = new MySqlConnectionStringBuilder(); conStrBuilder.Server = mysqlServerHostName; conStrBuilder.Port = UInt32.Parse(mysqlServerPort); conStrBuilder.Database = mysqlDatabase; conStrBuilder.UserID = mysqlUser; conStrBuilder.Password = mysqlPassword; conStrBuilder.SslMode = MySqlSslMode.None; QSMain.ConnectionString = conStrBuilder.GetConnectionString(true); var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>() .ConnectionString(QSMain.ConnectionString); OrmConfig.ConfigureOrm(db_config, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)), System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)), System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)), System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)) }); MainSupport.LoadBaseParameters(); QS.HistoryLog.HistoryMain.Enable(); ISmsNotificationRepository smsNotificationRepository = new SmsNotificationRepository(); SmsBlissSendController smsSender = new SmsBlissSendController(smsServiceLogin, smsServicePassword, SmsSendInterface.BalanceType.CurrencyBalance); newClientInformer = new NewClientSmsInformer(smsSender, smsNotificationRepository); newClientInformer.Start(); BaseParametersProvider parametersProvider = new BaseParametersProvider(); LowBalanceNotifier lowBalanceNotifier = new LowBalanceNotifier(smsSender, smsSender, parametersProvider); lowBalanceNotifier.Start(); SmsInformerInstanceProvider serviceStatusInstanceProvider = new SmsInformerInstanceProvider( smsNotificationRepository, new BaseParametersProvider() ); WebServiceHost smsInformerStatus = new SmsInformerServiceHost(serviceStatusInstanceProvider); smsInformerStatus.AddServiceEndpoint( typeof(ISmsInformerService), new WebHttpBinding(), String.Format("http://{0}:{1}/SmsInformer", serviceHostName, servicePort) ); smsInformerStatus.Open(); logger.Info("Запущена служба мониторинга отправки смс уведомлений"); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGHUP), new UnixSignal(Signum.SIGTERM) }; UnixSignal.WaitAny(signals); } catch (Exception ex) { logger.Fatal(ex); } finally { if (Environment.OSVersion.Platform == PlatformID.Unix) { Thread.CurrentThread.Abort(); } Environment.Exit(0); } }