public DeviceController(DeviceControllerContext context /*IDbContextFactory<DeviceControllerContext> dbFactory*/, ILogger <DeviceController> logger) { _context = context; //_dbFactory = dbFactory; _logger = logger; _deviceRepository = new DeviceRepository(_context); _accountRepository = new AccountRepository(_context); }
/// <summary> /// Api Controller /// </summary> /// <param name="context"></param> /// <param name="logger"></param> public ApiController(DeviceControllerContext context, ILogger <DeviceController> logger) { _context = context; _logger = logger; // TODO: Maybe use the DbContextFactory instead of relying on the same one per repo _accountRepository = new AccountRepository(_context); _deviceRepository = new DeviceRepository(_context); _instanceRepository = new InstanceRepository(_context); _assignmentRepository = new AssignmentRepository(_context); _geofenceRepository = new GeofenceRepository(_context); _webhookRepository = new WebhookRepository(_context); _deviceGroupRepository = new DeviceGroupRepository(_context); _ivListRepository = new IVListRepository(_context); }
public DeviceControllerContext Build() { // Build the communications channel var channel = channelFactory.FromConnectionString(connectionString); if (channelShouldBeOpen) { channel.Open(); } // Build the ControllerStatusFactory var statusFactory = new ControllerStatusFactory(timeSource); var fakeTransactionProcessor = new FakeTransactionProcessor(Enumerable.Empty <string>()); var controllerActions = new RxControllerActions(channel, fakeTransactionProcessor); var controllerStateMachine = new ControllerStateMachine(controllerActions, controllerOptions, timeSource, this.logger); controllerStateMachine.ShutterLimitSwitches = initialShutterState; // Build the device controller var controller = new DeviceController( channel, statusFactory, controllerStateMachine, controllerOptions, fakeTransactionProcessor, logger); // Assemble the device controller test context var context = new DeviceControllerContext { Channel = channel, Controller = controller, StateMachine = controllerStateMachine, Actions = controllerActions }; // Wire up any Property Changed notifications if (propertyChangedAction != null) { controller.PropertyChanged += propertyChangedAction; } return(context); }
public static DeviceControllerContext CreateDeviceControllerContext(string connectionString)// where T : DbContext { try { var optionsBuilder = new DbContextOptionsBuilder <DeviceControllerContext>(); optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); var ctx = new DeviceControllerContext(optionsBuilder.Options); //ctx.ChangeTracker.AutoDetectChangesEnabled = false; return(ctx); } catch (Exception ex) { ConsoleExt.WriteError($"[RawSql] Result: {ex.Message}"); Environment.Exit(0); } return(null); }
public DeviceControllerContext Build() { // Build the communications channel var channel = channelFactory.FromConnectionString(connectionString); if (channelShouldBeOpen) { channel.Open(); } // Build the ControllerStatusFactory var statusFactory = new ControllerStatusFactory(timeSource); var controllerActions = new RxControllerActions(channel); var controllerStateMachine = new ControllerStateMachine(controllerActions, controllerOptions, timeSource); controllerStateMachine.ShutterPosition = initialShutterState; if (startInReadyState) { controllerStateMachine.Initialize(new Ready(controllerStateMachine)); } // Build the device controller var controller = new DeviceController(channel, statusFactory, controllerStateMachine, controllerOptions); // Assemble the device controller test context var context = new DeviceControllerContext { Channel = channel, Controller = controller, StateMachine = controllerStateMachine, Actions = controllerActions }; // Wire up any Property Changed notifications if (propertyChangedAction != null) { controller.PropertyChanged += propertyChangedAction; } return(context); }