Exemple #1
0
        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 += 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);
            }
        }