Beispiel #1
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            SmsRuConfiguration smsRuConfig;

            try {
                var builder = new ConfigurationBuilder()
                              .AddIniFile(configFile, optional: false);

                var configuration = builder.Build();

                var serviceSection = configuration.GetSection("Service");
                serviceHostName = serviceSection["service_host_name"];
                servicePort     = serviceSection["service_port"];

                var mysqlSection = configuration.GetSection("Mysql");
                mysqlServerHostName = mysqlSection["mysql_server_host_name"];
                mysqlServerPort     = mysqlSection["mysql_server_port"];
                mysqlUser           = mysqlSection["mysql_user"];
                mysqlPassword       = mysqlSection["mysql_password"];
                mysqlDatabase       = mysqlSection["mysql_database"];

                var smsRuSection = configuration.GetSection("SmsRu");

                smsRuConfig =
                    new SmsRuConfiguration(
                        smsRuSection["login"],
                        smsRuSection["password"],
                        smsRuSection["appId"],
                        smsRuSection["partnerId"],
                        smsRuSection["email"],
                        smsRuSection["smsNumberFrom"],
                        smsRuSection["smtpLogin"],
                        smsRuSection["smtpPassword"],
                        smsRuSection["smtpServer"],
                        int.Parse(smsRuSection["smtpPort"]),
                        bool.Parse(smsRuSection["smtpUseSSL"]),
                        bool.Parse(smsRuSection["translit"]),
                        bool.Parse(smsRuSection["test"])
                        );
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка чтения конфигурационного файла.");
                return;
            }

            try {
                var conStrBuilder = new MySqlConnectionStringBuilder();
                conStrBuilder.Server   = mysqlServerHostName;
                conStrBuilder.Port     = uint.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();

                SmsRuSendController smsSender = new SmsRuSendController(smsRuConfig);

                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);
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            SmsRuConfiguration smsRuConfig;

            try {
                var builder = new ConfigurationBuilder()
                              .AddIniFile(configFile, optional: false);

                var configuration = builder.Build();

                var serviceSection = configuration.GetSection("Service");
                serviceHostName = serviceSection["service_host_name"];
                servicePort     = serviceSection["service_port"];

                var smsRuSection = configuration.GetSection("SmsRu");

                smsRuConfig = new SmsRuConfiguration(
                    smsRuSection["login"],
                    smsRuSection["password"],
                    smsRuSection["appId"],
                    smsRuSection["partnerId"],
                    smsRuSection["email"],
                    smsRuSection["smsNumberFrom"],
                    smsRuSection["smtpLogin"],
                    smsRuSection["smtpPassword"],
                    smsRuSection["smtpServer"],
                    int.Parse(smsRuSection["smtpPort"]),
                    bool.Parse(smsRuSection["smtpUseSSL"]),
                    bool.Parse(smsRuSection["translit"]),
                    bool.Parse(smsRuSection["test"])
                    );
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка чтения конфигурационного файла.");
                return;
            }

            try {
                SmsRuSendController smsSender = new SmsRuSendController(smsRuConfig);

                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);
            }
        }