コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: n17solutions/microphobia
 public Client(Queue queue, IServiceScopeFactory serviceScopeFactory, MicrophobiaConfiguration config, ILogger <Client> logger)
 {
     _queue = queue;
     _serviceScopeFactory = serviceScopeFactory;
     _config = config;
     _logger = logger;
 }
コード例 #3
0
 public DashboardMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, MicrophobiaConfiguration config,
                            MicrophobiaDashboardOptions options)
 {
     _config  = config;
     _options = options ?? new MicrophobiaDashboardOptions();
     _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options);
 }
コード例 #4
0
 public TaskProcessor(IDataProvider dataProvider, MicrophobiaHubContext taskHubContext, ILogger <TaskProcessor> logger, Runners runners, MicrophobiaConfiguration config)
 {
     _dataProvider   = dataProvider;
     _taskHubContext = taskHubContext;
     _logger         = logger;
     _runners        = runners;
     _config         = config;
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public Runners(IDataProvider dataProvider, MicrophobiaConfiguration config)
 {
     _dataProvider = dataProvider;
     _config       = config;
 }
コード例 #9
0
 public DataProvider(TaskContext context, MicrophobiaConfiguration microphobiaConfiguration)
 {
     _context = context;
     _config  = microphobiaConfiguration;
 }
コード例 #10
0
 public DashboardMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, MicrophobiaConfiguration config,
                            IOptions <MicrophobiaDashboardOptions> optionsAccessor)
     : this(next, hostingEnv, loggerFactory, config, optionsAccessor.Value)
 {
 }