示例#1
0
        public static SailbotContext GetContext()
        {
            var optionsBuilder = new DbContextOptionsBuilder <SailbotContext>();

            optionsBuilder.UseSqlServer(CONNECTION_STRING);

            var context = new SailbotContext(optionsBuilder.Options);

            return(context);
        }
示例#2
0
        public IActionResult UpdateForm(IFormCollection formCollection)
        {
            var     sensorID   = int.Parse(formCollection["SensorID"].FirstOrDefault());
            var     sensorType = formCollection["SensorType"].FirstOrDefault();
            ISensor sensor     = null;
            var     type       = SailbotContext.GetSensorType(sensorType);

            switch (sensorType)
            {
            case "Wind":
                sensor = new SensorManager <Wind>(context).GetSensor(sensorID);
                break;

            case "WinchMotor":
                sensor = new SensorManager <WinchMotor>(context).GetSensor(sensorID);
                break;

            case "RudderMotor":
                sensor = new SensorManager <RudderMotor>(context).GetSensor(sensorID);
                break;

            case "GPS":
                sensor = new SensorManager <GPS>(context).GetSensor(sensorID);
                break;

            case "BoomAngle":
                sensor = new SensorManager <BoomAngle>(context).GetSensor(sensorID);
                break;

            case "BMS":
                sensor = new SensorManager <BMS>(context).GetSensor(sensorID);
                break;

            case "Accelerometer":
                sensor = new SensorManager <Accelerometer>(context).GetSensor(sensorID);
                break;

            default:
                break;
            }

            var modifiableColumnManager = new ModifiableColumnManager(context);
            var columns = modifiableColumnManager.GetModifiableColumns(sensorType);

            foreach (var column in columns)
            {
                var newValue = formCollection[column].FirstOrDefault();
                var property = type.GetProperty(column);
                property.SetValue(sensor, Convert.ChangeType(newValue, property.PropertyType), null);
            }

            context.SaveChanges();

            return(RedirectToAction("Sensor", new { type = sensorType }));
        }
示例#3
0
        public IActionResult GetUpdateForm(string type, int sensorID)
        {
            var     modifiableColumnManager = new ModifiableColumnManager(context);
            ISensor sensor = null;

            switch (type)
            {
            case "Wind":
                sensor = new SensorManager <Wind>(context).GetSensor(sensorID);
                break;

            case "WinchMotor":
                sensor = new SensorManager <WinchMotor>(context).GetSensor(sensorID);
                break;

            case "RudderMotor":
                sensor = new SensorManager <RudderMotor>(context).GetSensor(sensorID);
                break;

            case "GPS":
                sensor = new SensorManager <GPS>(context).GetSensor(sensorID);
                break;

            case "BoomAngle":
                sensor = new SensorManager <BoomAngle>(context).GetSensor(sensorID);
                break;

            case "BMS":
                sensor = new SensorManager <BMS>(context).GetSensor(sensorID);
                break;

            case "Accelerometer":
                sensor = new SensorManager <Accelerometer>(context).GetSensor(sensorID);
                break;

            default:
                break;
            }

            var model = new SensorFormViewModel
            {
                Sensor  = sensor,
                Type    = SailbotContext.GetSensorType(type),
                Columns = modifiableColumnManager.GetModifiableColumns(type)
            };

            return(PartialView("../Boat/SensorDetail/SensorUpdate", model));
        }
示例#4
0
        public IActionResult Sensor(string type)
        {
            List <ISensor> sensors;

            switch (type)
            {
            case "Wind":
                sensors = new SensorManager <Wind>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            case "WinchMotor":
                sensors = new SensorManager <WinchMotor>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            case "RudderMotor":
                sensors = new SensorManager <RudderMotor>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            case "GPS":
                sensors = new SensorManager <GPS>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            case "BoomAngle":
                sensors = new SensorManager <BoomAngle>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            case "BMS":
                sensors = new SensorManager <BMS>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            case "Accelerometer":
                sensors = new SensorManager <Accelerometer>(context).GetAll().Select(i => i as ISensor).ToList();
                break;

            default:
                return(null);
            }

            var model = new SensorViewModel
            {
                Sensors       = sensors,
                Type          = SailbotContext.GetSensorType(type),
                RenderButtons = true
            };

            return(View("../Boat/SensorDetail/SensorDetail", model));
        }
 public ModifiableColumnRepository(SailbotContext context)
 {
     this.context = context;
 }
示例#6
0
 public ModifiableColumnManager(SailbotContext context)
 {
     modifiableColumnRepository = new ModifiableColumnRepository(context);
 }
示例#7
0
 public SensorRepository(SailbotContext context)
 {
     this.context = context;
 }
示例#8
0
 public SensorManager(SailbotContext context)
 {
     sensorRepository = new SensorRepository <T>(context);
 }
示例#9
0
 public RayeController(SailbotContext context)
 {
     this.context = context;
 }
示例#10
0
 public SensorViewComponent(SailbotContext context)
 {
     this.context = context;
 }
示例#11
0
 public SensorDetailController(SailbotContext context)
 {
     this.context = context;
 }