public static IServiceCollection AddMicrophobiaPostgresStorage(this IServiceCollection services, string connectionString, ServiceFactory serviceFactory = null, Action <MicrophobiaConfiguration> configAction = null) { Migrate(connectionString); services .AddDbContext <TaskContext>(options => options.UseNpgsql(connectionString, npgsqlOptions => { npgsqlOptions.MigrationsAssembly(CurrentAssemblyName); }), ServiceLifetime.Transient, ServiceLifetime.Transient) .AddDbContext <SystemLogContext>(options => options.UseNpgsql(connectionString, npgsqlOptions => { npgsqlOptions.MigrationsAssembly(CurrentAssemblyName); }), ServiceLifetime.Transient, ServiceLifetime.Transient) .AddEntityFramework() .AddMicrophobia(); services.AddSingleton(serviceProvider => { var configuration = new MicrophobiaConfiguration(serviceProvider.GetRequiredService <MicrophobiaHubContext>()) { StorageType = Storage.Postgres, ServiceFactory = serviceFactory ?? serviceProvider.GetService }; configAction?.Invoke(configuration); return(configuration); }); return(services); }
public Client(Queue queue, IServiceScopeFactory serviceScopeFactory, MicrophobiaConfiguration config, ILogger <Client> logger) { _queue = queue; _serviceScopeFactory = serviceScopeFactory; _config = config; _logger = logger; }
public DashboardMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, MicrophobiaConfiguration config, MicrophobiaDashboardOptions options) { _config = config; _options = options ?? new MicrophobiaDashboardOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); }
public TaskProcessor(IDataProvider dataProvider, MicrophobiaHubContext taskHubContext, ILogger <TaskProcessor> logger, Runners runners, MicrophobiaConfiguration config) { _dataProvider = dataProvider; _taskHubContext = taskHubContext; _logger = logger; _runners = runners; _config = config; }
public RunnerTests() { var clientsProxyMock = new Mock <IClientProxy>(); var hubClientsMock = new Mock <IHubClients>(); hubClientsMock.SetupGet(x => x.All).Returns(clientsProxyMock.Object); var hubContextMock = new Mock <IHubContext <MicrophobiaHub> >(); hubContextMock.SetupGet(x => x.Clients).Returns(hubClientsMock.Object); var microphobiaContextMock = new MicrophobiaHubContext(hubContextMock.Object); var configuration = new MicrophobiaConfiguration(microphobiaContextMock); _sut = new Runners(_dataProviderMock.Object, configuration); }
public DataProviderTests() { var clientsProxyMock = new Mock <IClientProxy>(); var hubClientsMock = new Mock <IHubClients>(); hubClientsMock.SetupGet(x => x.All).Returns(clientsProxyMock.Object); var hubContextMock = new Mock <IHubContext <MicrophobiaHub> >(); hubContextMock.SetupGet(x => x.Clients).Returns(hubClientsMock.Object); var microphobiaContextMock = new MicrophobiaHubContext(hubContextMock.Object); var dbOptions = new DbContextOptionsBuilder <TaskContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; _context = new TaskContext(dbOptions); var config = new MicrophobiaConfiguration(microphobiaContextMock) { Tag = ConfigTag }; _sut = new DataProvider(_context, config); }
public ClientTestsMultipleThreads() { var clientsProxyMock = new Mock <IClientProxy>(); var hubClientsMock = new Mock <IHubClients>(); hubClientsMock.SetupGet(x => x.All).Returns(clientsProxyMock.Object); var hubContextMock = new Mock <IHubContext <MicrophobiaHub> >(); hubContextMock.SetupGet(x => x.Clients).Returns(hubClientsMock.Object); var microphobiaContextMock = new MicrophobiaHubContext(hubContextMock.Object); var configuration = new MicrophobiaConfiguration(microphobiaContextMock) { PollIntervalMs = 1000, MaxThreads = 2 }; var runnersMock = new Runners(_dataProviderMock.Object, configuration); var serviceProviderMock = new Mock <IServiceProvider>(); serviceProviderMock.Setup(x => x.GetService(typeof(Runners))).Returns(runnersMock); var serviceScopeMock = new Mock <IServiceScope>(); serviceScopeMock.SetupGet(x => x.ServiceProvider).Returns(serviceProviderMock.Object); var serviceScopeFactoryMock = new Mock <IServiceScopeFactory>(); serviceScopeFactoryMock.Setup(x => x.CreateScope()).Returns(serviceScopeMock.Object); var queueMock = new Queue(_dataProviderMock.Object, microphobiaContextMock, serviceScopeFactoryMock.Object); _cancellationTokenSource = new CancellationTokenSource(); _logger = new ClientLogger(); _sut = new Client(queueMock, serviceScopeFactoryMock.Object, configuration, _logger); }
public Runners(IDataProvider dataProvider, MicrophobiaConfiguration config) { _dataProvider = dataProvider; _config = config; }
public DataProvider(TaskContext context, MicrophobiaConfiguration microphobiaConfiguration) { _context = context; _config = microphobiaConfiguration; }
public DashboardMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, MicrophobiaConfiguration config, IOptions <MicrophobiaDashboardOptions> optionsAccessor) : this(next, hostingEnv, loggerFactory, config, optionsAccessor.Value) { }