Beispiel #1
0
        /// <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);
                    }
                }
            }
        }
Beispiel #2
0
        public static async Task Main(string[] args)
        {
            var basePath = PlatformServices.Default.Application.ApplicationBasePath;

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

                await builderRunAsService.RunAsServiceAsync();
            }
            else
            {
                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();
            }
        }