protected override Task RunAsync(CancellationToken cancellationToken) { return(Task.Run(() => { var builder = new ConfigurationBuilder() .AddServiceFabricConfiguration(); var configuration = builder.Build(); var appConfiguration = configuration.GetSection("Config"); var rmqPublisher = new RmqPublisherBuilder() .UsingConfigConnectionSettings(configuration.GetSection("Config:RmqConnectionSettings")) .Build(); var rmqConsumer = new RmqConsumerBuilder() .UsingConfigConnectionSettings(configuration.GetSection("Config:RmqConnectionSettings")) .Build(); var serviceProvider = new ServiceCollection() .AddSingleton <IConfigurationSection>(appConfiguration) .AddSingleton <IRmqConsumer>(rmqConsumer) .AddSingleton <IRmqPublisher>(rmqPublisher) .AddSingleton <ICsvConverter, CsvConverter>() .AddSingleton <ICsvToJsonConverterEngine, CsvToJsonConverterEngine>() .BuildServiceProvider(); var engine = serviceProvider.GetService <ICsvToJsonConverterEngine>(); engine.Start(); })); }
public void ConfigureServices(IServiceCollection services) { services.Configure <IISServerOptions>(options => { options.AutomaticAuthentication = false; }); services.AddControllers(); services.AddHostedService <DeploymentHostedService>(); var deploymentServiceConfigSection = this.Configuration.GetSection("DeploymentService"); var rmqPublisher = new RmqPublisherBuilder() .UsingDefaultConnectionSetting() .Build(); var rmqConsumer = new RmqConsumerBuilder() .UsingDefaultConnectionSetting() .Build(); services.AddSingleton <IRmqConsumer>(rmqConsumer); services.AddSingleton <IRmqPublisher>(rmqPublisher); services.AddScoped <IRmqBindingService, RmqBindingService>(); services.AddScoped <IRmqManagementService, RmqManagementService>(); services.AddSingleton <IDeploymentServiceProvider, DeploymentServiceProvider>(); services.AddSingleton <IConfigurationSection>(deploymentServiceConfigSection); //dependency for DeploymentServiceChirushin services.AddSingleton <IDeploymentService, DeploymentServiceChirushin>(); services.AddSingleton <IDeploymentManagerWrapper, DeploymentManagerWrapper>(); services.AddSingleton <IComponentDetailsReader, ComponentDetailsReader>(); services.AddSingleton <IInfoLogger, Logger>(); services.AddScoped(typeof(HttpClient)); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Component Configurator", Description = "Component Configurator" }); }); }
protected override Task RunAsync(CancellationToken cancellationToken) { return(Task.Run(() => { var builder = new ConfigurationBuilder() .AddServiceFabricConfiguration(); var configuration = builder.Build(); var configurationSection = configuration.GetSection("Config"); var applicationName = configurationSection.GetValue <string>("Application:Name"); ConfigureLogging(applicationName); var loggerService = new LoggerService(Log.Logger, applicationName); loggerService.RunWithExceptionLogging(() => { var rmqPublisher = new RmqPublisherBuilder() .UsingConfigConnectionSettings(configuration.GetSection("Config:RmqConnectionSettings")) .Build(); var rmqConsumer = new RmqConsumerBuilder() .UsingConfigConnectionSettings(configuration.GetSection("Config:RmqConnectionSettings")) .Build(); var serviceProvider = new ServiceCollection() .AddSingleton <ILoggerServiceSerilog>(loggerService) .AddSingleton <IConfigurationSection>(configurationSection) .AddSingleton <IRmqConsumer>(rmqConsumer) .AddSingleton <IRmqPublisher>(rmqPublisher) .AddSingleton <ITextExtractorEngine, TextExtractorEngine>() .BuildServiceProvider(); var engine = serviceProvider.GetService <ITextExtractorEngine>(); engine.Start(); loggerService.Information("Service started"); }); })); }
public void IHaveNewDeploymentMessageIntoThisDeploymentExchangeWithThisData(string exchangeName, Table table) { var rmqPublisher = new RmqPublisherBuilder() .UsingExchange(exchangeName) .UsingDefaultConnectionSetting() .Build(); var messages = table.Rows.Select(s => new { ComponentId = s["ComponentId"], DeploymentType = s["DeploymentType"] }); foreach (var msg in messages) { var messageAsByteArray = Encoding.UTF8.GetBytes( JsonConvert.SerializeObject(msg)); rmqPublisher.Publish(messageAsByteArray); } }