Пример #1
0
        static void Main(string[] args)
        {
            // get configuration
            var    rmqConfigSection = Config.GetSection("RabbitMQ");
            string rmqHost          = rmqConfigSection["Host"];
            string rmqUserName      = rmqConfigSection["UserName"];
            string rmqPassword      = rmqConfigSection["Password"];

            var    mailConfigSection = Config.GetSection("Email");
            string mailHost          = mailConfigSection["Host"];
            int    mailPort          = Convert.ToInt32(mailConfigSection["Port"]);
            string mailUserName      = mailConfigSection["User"];
            string mailPassword      = mailConfigSection["Pwd"];

            var sqlConnectionString = Config.GetConnectionString("NotificationServiceCN");

            // start notification service
            RabbitMQMessageHandler messageHandler =
                new RabbitMQMessageHandler(rmqHost, rmqUserName, rmqPassword, "Pitstop", "Notifications", "");
            INotificationRepository repo          = new SqlServerNotificationRepository(sqlConnectionString);
            IEmailNotifier          emailNotifier = new SMTPEmailNotifier(mailHost, mailPort, mailUserName, mailPassword);
            NotificationManager     manager       = new NotificationManager(messageHandler, repo, emailNotifier);

            manager.Start();

            if (_env == "Development")
            {
                Log.Information("Notification service started.");
                Console.WriteLine("Press any key to stop...");
                Console.ReadKey(true);
                manager.Stop();
            }
            else
            {
                Log.Information("Notification service started.");
                while (true)
                {
                    Thread.Sleep(10000);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            try {
                ServiceRuntime.RegisterServiceAsync("NotificationServiceType",
                                                    context => new not.NotificationService(context)).GetAwaiter().GetResult();

                not.ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(not.NotificationService).Name);

                // get configuration
                var    rmqConfigSection = Config.GetSection("RabbitMQ");
                string rmqHost          = rmqConfigSection["Host"];
                string rmqUserName      = rmqConfigSection["UserName"];
                string rmqPassword      = rmqConfigSection["Password"];

                var    mailConfigSection = Config.GetSection("Email");
                string mailHost          = mailConfigSection["Host"];
                int    mailPort          = Convert.ToInt32(mailConfigSection["Port"]);
                string mailUserName      = mailConfigSection["User"];
                string mailPassword      = mailConfigSection["Pwd"];

                var sqlConnectionString = Config.GetConnectionString("NotificationServiceCN");

                // start notification service
                RabbitMQMessageHandler messageHandler =
                    new RabbitMQMessageHandler(rmqHost, rmqUserName, rmqPassword, "Pitstop", "Notifications", "");
                INotificationRepository repo          = new SqlServerNotificationRepository(sqlConnectionString);
                IEmailNotifier          emailNotifier = new SMTPEmailNotifier(mailHost, mailPort, mailUserName, mailPassword);
                NotificationManager     manager       = new NotificationManager(messageHandler, repo, emailNotifier);
                manager.Start();

                // Prevents this host process from terminating so services keep running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                not.ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }