Example #1
0
        static void Main(string[] args)
        {
            // get configuration
            var    configSection = Config.GetSection("RabbitMQ");
            string host          = configSection["Host"];
            string userName      = configSection["UserName"];
            string password      = configSection["Password"];

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

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

            // start invoice manager
            RabbitMQMessageHandler messageHandler    = new RabbitMQMessageHandler(host, userName, password, "Pitstop", "Invoicing", "");
            IInvoiceRepository     repo              = new SqlServerInvoiceRepository(sqlConnectionString);
            IEmailCommunicator     emailCommunicator = new SMTPEmailCommunicator(mailHost, mailPort, mailUserName, mailPassword);
            InvoiceManager         manager           = new InvoiceManager(messageHandler, repo, emailCommunicator);

            manager.Start();

            if (_env == "Development")
            {
                Log.Information("Invoice service started.");
                Console.WriteLine("Press any key to stop...");
                Console.ReadKey(true);
                manager.Stop();
            }
            else
            {
                Log.Information("Invoice service started.");
                while (true)
                {
                    Thread.Sleep(10000);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                ServiceRuntime.RegisterServiceAsync("InvoiceServiceType",
                                                    context => new inv.InvoiceService(context)).GetAwaiter().GetResult();

                inv.ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(inv.InvoiceService).Name);

                // get configuration
                var    configSection = Config.GetSection("RabbitMQ");
                string host          = configSection["Host"];
                string userName      = configSection["UserName"];
                string password      = configSection["Password"];

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

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

                // start invoice manager
                var messageHandler      = new RabbitMQMessageHandler(host, userName, password, "Pitstop", "Invoicing", "");
                IInvoiceRepository repo = new SqlServerInvoiceRepository(sqlConnectionString);
                IEmailCommunicator emailCommunicator = new SMTPEmailCommunicator(mailHost, mailPort, mailUserName, mailPassword);
                var manager = new InvoiceManager(messageHandler, repo, emailCommunicator);
                manager.Start();

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