Example #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");

                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);
            }
        }
Example #2
0
 public DeliveryRulesServiceBehavior(DeliveryRulesInstanceProvider deliveryRulesInstanceProvider)
 {
     this.deliveryRulesInstanceProvider = deliveryRulesInstanceProvider ?? throw new ArgumentNullException(nameof(deliveryRulesInstanceProvider));
 }
Example #3
0
 public DeliveryRulesServiceHost(DeliveryRulesInstanceProvider deliveryRulesInstanceProvider) : base(typeof(DeliveryRulesService))
 {
     Description.Behaviors.Add(new DeliveryRulesServiceBehavior(deliveryRulesInstanceProvider));
 }