Пример #1
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);
            }
        }
Пример #2
0
 public SmsPaymentServiceHost(SmsPaymentServiceInstanceProvider smsPaymentServiceInstanceProvider) : base(typeof(SmsPaymentService.SmsPaymentService))
 {
     Description.Behaviors.Add(new SmsPaymentServiceBehavior(smsPaymentServiceInstanceProvider));
 }
Пример #3
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            IConfiguration configuration;

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

                configuration = builder.Build();

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

                var bitrixSection = configuration.GetSection("Bitrix");
                baseAddress = bitrixSection["base_address"];

                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"];
            }
            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,
                    ConnectionTimeout = 30
                };

                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)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Project.HibernateMapping.TypeOfEntityMap)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Attachments.Domain.Attachment))
                });

                QS.HistoryLog.HistoryMain.Enable();

                var driverApiSection = configuration.GetSection("DriverAPI");

                var driverApiHelperConfiguration = new DriverApiHelperConfiguration
                {
                    ApiBase = new Uri(driverApiSection["ApiBase"]),
                    NotifyOfSmsPaymentStatusChangedURI = driverApiSection["NotifyOfSmsPaymentStatusChangedURI"],
                    NotifyOfFastDeliveryOrderAddedURI  = driverApiSection["NotifyOfFastDeliveryOrderAddedURI"]
                };

                ISmsPaymentStatusNotificationReciever smsPaymentStatusNotificationReciever =
                    new DriverAPIHelper(driverApiHelperConfiguration);
                var paymentSender = new BitrixPaymentController(baseAddress);

                var smsPaymentFileCache = new SmsPaymentFileCache("/tmp/VodovozSmsPaymentServiceTemp.txt");

                SmsPaymentServiceInstanceProvider smsPaymentServiceInstanceProvider = new SmsPaymentServiceInstanceProvider(
                    paymentSender,
                    smsPaymentStatusNotificationReciever,
                    new OrderParametersProvider(new ParametersProvider()),
                    smsPaymentFileCache,
                    new SmsPaymentDTOFactory(new OrderOrganizationProviderFactory().CreateOrderOrganizationProvider()),
                    new SmsPaymentValidator(new OrganizationParametersProvider(new ParametersProvider()))
                    );

                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.");

                var serviceInstance = smsPaymentServiceInstanceProvider.GetInstance(null) as ISmsPaymentService;
                serviceInstance?.SynchronizePaymentStatuses();

                var unsavedPaymentsWorker = new CachePaymentsWorker(smsPaymentFileCache, serviceInstance);
                var overduePaymentsWorker = new OverduePaymentsWorker();
                unsavedPaymentsWorker.Start();
                overduePaymentsWorker.Start();

                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    UnixSignal[] signals =
                    {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGHUP),
                        new UnixSignal(Signum.SIGTERM)
                    };
                    UnixSignal.WaitAny(signals);
                }
                else
                {
                    Console.ReadLine();
                }
            }
            catch (Exception e) {
                logger.Fatal(e);
            }
            finally {
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    Thread.CurrentThread.Abort();
                }
                Environment.Exit(0);
            }
        }
Пример #4
0
 public SmsPaymentServiceBehavior(SmsPaymentServiceInstanceProvider smsPaymentServiceInstanceProvider)
 {
     this.smsPaymentServiceInstanceProvider = smsPaymentServiceInstanceProvider ?? throw new ArgumentNullException(nameof(smsPaymentServiceInstanceProvider));
 }