/// <summary>
        /// Start Tasks
        /// </summary>
        public void StartTasks()
        {
            if (_running)
            {
                return;
            }

            _running = true;

            try
            {
                using (var sw = File.AppendText(Path))
                {
                    sw.WriteLine("Start Tasks ");
                }

                StartUpConfiguration startUpConfiguration = new StartUpConfiguration();
                startUpConfiguration.Startup();

                IHostedService sendInventoryManagementMessages    = startUpConfiguration.SendingHostedService();
                IHostedService receiveInventoryManagementMessages = startUpConfiguration.ReceivingHostedService();
                IHostedService processMessages = startUpConfiguration.ProcessMessagesHostedService();

                var builder = new HostBuilder().ConfigureAppConfiguration((hostingContext, config) => { })
                              .ConfigureServices((hostContext, services) =>
                {
                    services.AddTransient <IHostedService>(provider => processMessages);
                })
                              .ConfigureServices((hostContext, services) =>
                {
                    services.AddTransient <IHostedService>(provider => sendInventoryManagementMessages);
                })
                              .ConfigureServices((hostContext, services) =>
                {
                    services.AddTransient <IHostedService>(provider => receiveInventoryManagementMessages);
                })
                              .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                    logging.AddConsole();
                });

                builder.RunConsoleAsync().Wait();
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                using (var sw = File.AppendText(Path))
                {
                    if (ex.InnerException != null)
                    {
                        sw.WriteLine(errorMessage + ex.InnerException.ToString());
                    }
                    else
                    {
                        sw.WriteLine(errorMessage);
                    }
                }
            }
        }
Пример #2
0
        public static async Task Main(string[] args)
        {
            var basePath = PlatformServices.Default.Application.ApplicationBasePath;

            if (basePath.ToLower().Contains("salesordermanagementqa"))
            {
                var builderRunAsService = new HostBuilder()
                                          .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService <WindowsServiceHost>();
                });

                await builderRunAsService.RunAsServiceAsync();
            }
            else
            {
                StartUpConfiguration startUpConfiguration = new StartUpConfiguration();
                startUpConfiguration.Startup();

                IHostedService sendSalesOrderManagementMessages    = startUpConfiguration.SendingHostedService();
                IHostedService receiveSalesOrderManagementMessages = startUpConfiguration.ReceivingHostedService();
                IHostedService processMessages = startUpConfiguration.ProcessMessagesHostedService();

                var builder = new HostBuilder().ConfigureAppConfiguration((hostingContext, config) => { })
                              .ConfigureServices((hostContext, services) =>
                {
                    services.AddTransient <IHostedService>(provider => processMessages);
                })
                              .ConfigureServices((hostContext, services) =>
                {
                    services.AddTransient <IHostedService>(provider => sendSalesOrderManagementMessages);
                })
                              .ConfigureServices((hostContext, services) =>
                {
                    services.AddTransient <IHostedService>(provider => receiveSalesOrderManagementMessages);
                })
                              .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                    logging.AddConsole();
                });

                builder.RunConsoleAsync().Wait();
            }
        }