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