コード例 #1
0
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            //TODO: Implement better logger handling.
            loggerFactory.AddConsole(LogLevel.Information);

            IOptions <ModuleSystemOptions> options = app.ApplicationServices.GetService <IOptions <ModuleSystemOptions> >();

            if (options.Value.ApplicationConfigurationModulesPaths != null)
            {
                foreach (string path in options.Value.ApplicationConfigurationModulesPaths)
                {
                    //Only one should be in the app.
                    //ORDER MATTERS!
                    ModuleLoader loader = new ModuleLoader(path);

                    IRegisterModule module = Activator.CreateInstance(loader.GetType <ApplicationConfigurationModule>(), new object[] { app, loggerFactory }) as IRegisterModule;

                    if (module == null)
                    {
                        throw new InvalidOperationException($"Failed to create an instance for derived {nameof(ApplicationConfigurationModule)} Type: {loader.GetType<ApplicationConfigurationModule>().FullName}.");
                    }

                    //Register the module.
                    module.Register();
                }
            }

            //Register MVC last in the pipeline. NO OTHER MODULE SHOULD REGISTER THIS!
            app.UseMvc();
        }
コード例 #2
0
 public Controller(IUserInterface ui, IConditionerData database, IRegisterModule registerModule, ITestingModule testingModule,
                   ISearchingModule searchingModule, IValidityModule validityModule, IStatusModule statusModule)
 {
     this.ui              = ui;
     this.database        = database;
     this.registerModule  = registerModule;
     this.testingModule   = testingModule;
     this.searchingModule = searchingModule;
     this.validityModule  = validityModule;
     this.statusModule    = statusModule;
 }
コード例 #3
0
 public Controller(IUserInterface ui, IConditionerData database, IRegisterModule registerModule, ITestingModule testingModule, 
     ISearchingModule searchingModule, IValidityModule validityModule, IStatusModule statusModule)
 {
     this.ui = ui;
     this.database = database;
     this.registerModule = registerModule;
     this.testingModule = testingModule;
     this.searchingModule = searchingModule;
     this.validityModule = validityModule;
     this.statusModule = statusModule;
 }
コード例 #4
0
 public CHIP8(Func <bool[, ], Task> writeDisplay,
              IRegisterModule registerModule,
              IStackModule stackModule,
              MemoryModule memoryModule,
              IRandomModule randomModule)
 {
     updateDisplay       = writeDisplay;
     this.registerModule = registerModule;
     this.stackModule    = stackModule;
     this.ram            = memoryModule;
     this.random         = randomModule;
 }
コード例 #5
0
ファイル: CHIP8Factory.cs プロジェクト: WereGoingOcean/CHIP8
 public static CHIP8 GetChip8(Func <bool[, ], Task> writeDisplay = null,
                              IRegisterModule registers          = null,
                              IStackModule stack   = null,
                              MemoryModule mem     = null,
                              IRandomModule random = null)
 {
     return(new CHIP8(writeDisplay ?? (x => Task.CompletedTask),
                      registers ?? new RegisterModule(),
                      stack ?? new StackModule(),
                      mem
                      ?? new MemoryModule(Enumerable.Repeat((byte)0x0,
                                                            4096)),
                      random ?? new RandomModule()));
 }
コード例 #6
0
        public virtual void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging();
            services.AddOptions();

            //configures the JSON DTO for the module options and database options
            services.Configure <ModuleSystemOptions>(Configuration.GetSection(nameof(ModuleSystemOptions)));

            services.Configure <DatabaseConfigOptions>(Configuration.GetSection(nameof(DatabaseConfigOptions)));

            //temporarily generate a service provider
            IServiceProvider provider = services.BuildServiceProvider();

            IOptions <ModuleSystemOptions>   moduleOptions   = provider.GetService <IOptions <ModuleSystemOptions> >();
            IOptions <DatabaseConfigOptions> databaseOptions = provider.GetService <IOptions <DatabaseConfigOptions> >();

            if (moduleOptions?.Value == null)
            {
                throw new InvalidOperationException($"Couldn't create {nameof(ModuleSystemOptions)} from modules.json.");
            }

            if (databaseOptions == null || databaseOptions.Value == null)
            {
                throw new InvalidOperationException($"Couldn't create {nameof(DatabaseConfigOptions)} from database.json.");
            }

            //TODO: Add support for multiple DB providers
            //Add DB services depending on the config
            if (databaseOptions.Value.useInMemoryDatabase)
            {
                services.AddEntityFrameworkInMemoryDatabase();
            }
            else
            {
                services.AddEntityFrameworkMySql();
            }

            //Register Mvc services and aquire builder
            IMvcBuilder mvcBuilder = services.AddMvc();

            try
            {
                //This means we have no services that need registering
                if (moduleOptions.Value.ServiceRegistrationModulesPaths == null)
                {
                    return;
                }

                foreach (string path in moduleOptions.Value.ServiceRegistrationModulesPaths)
                {
                    ModuleLoader loader = new ModuleLoader(path);

                    foreach (Type serviceRegisterType in loader.GetTypes <ServiceRegistrationModule>())
                    {
                        IRegisterModule module = Activator.CreateInstance(serviceRegisterType, new object[] { services, (Action <DbContextOptionsBuilder>)((DbContextOptionsBuilder options) =>
                            {
                                if (databaseOptions.Value.useInMemoryDatabase)
                                {
                                    options.UseInMemoryDatabase();
                                }
                                else
                                {
                                    options.UseMySql(databaseOptions.Value.DatabaseConnectionString);
                                }
                            }) }) as IRegisterModule;

                        if (module == null)
                        {
                            throw new InvalidOperationException($"Failed to create an instance for derived {nameof(ServiceRegistrationModule)} Type: {serviceRegisterType.FullName}.");
                        }

                        //Register the module.
                        module.Register();
                    }

                    foreach (Type serviceRegisterType in loader.GetTypes <MvcBuilderServiceRegistrationModule>())
                    {
                        IRegisterModule module = Activator.CreateInstance(serviceRegisterType, new object[] { mvcBuilder }) as IRegisterModule;

                        if (module == null)
                        {
                            throw new InvalidOperationException($"Failed to create an instance for derived {nameof(MvcBuilderServiceRegistrationModule)} Type: {serviceRegisterType.FullName}.");
                        }

                        //Register the module.
                        module.Register();
                    }
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"Encountered Exception in Module registration: {e.Message}", e);
            }
        }