diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GeothermalResearchInstitute.ServerConsole.csproj b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GeothermalResearchInstitute.ServerConsole.csproj index ff3e9705..196e6c7e 100644 --- a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GeothermalResearchInstitute.ServerConsole.csproj +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GeothermalResearchInstitute.ServerConsole.csproj @@ -12,6 +12,7 @@ + diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GrpcService/DeviceServiceImpl.cs b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GrpcService/DeviceServiceImpl.cs index c26a11b3..a2acbd3c 100644 --- a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GrpcService/DeviceServiceImpl.cs +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/GrpcService/DeviceServiceImpl.cs @@ -147,10 +147,26 @@ public override Task UpdateDevice(UpdateDeviceRequest request, ServerCal switch (path) { case "working_mode": + deviceStates.WorkingMode = request.Device.WorkingMode; break; case "device_option": + deviceStates.SummerTemperature = request.Device.DeviceOption.SummerTemperature; + deviceStates.WinterTemperature = request.Device.DeviceOption.WinterTemperature; + deviceStates.WarmCapacity = request.Device.DeviceOption.WarmCapacity; + deviceStates.ColdCapacity = request.Device.DeviceOption.ColdCapacity; + deviceStates.FlowCapacity = request.Device.DeviceOption.FlowCapacity; + deviceStates.RateCapacity = request.Device.DeviceOption.RateCapacity; + deviceStates.MotorMode = request.Device.DeviceOption.MotorMode; + deviceStates.WaterPumpMode = request.Device.DeviceOption.WaterPumpMode; break; case "controls": + deviceStates.DevicePower = request.Device.Controls.DevicePower; + deviceStates.ExhaustPower = request.Device.Controls.ExhaustPower; + deviceStates.HeatPumpAuto = request.Device.Controls.HeatPumpAuto; + deviceStates.HeatPumpPower = request.Device.Controls.HeatPumpPower; + deviceStates.HeatPumpFanOn = request.Device.Controls.HeatPumpFanOn; + deviceStates.HeatPumpCompressorOn = request.Device.Controls.HeatPumpCompressorOn; + deviceStates.HeatPumpFourWayReversingValue = request.Device.Controls.HeatPumpFourWayReversingValue; break; default: throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid update_mask.")); diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContext.cs b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContext.cs index a38c03c4..c314da92 100644 --- a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContext.cs +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContext.cs @@ -9,13 +9,13 @@ namespace GeothermalResearchInstitute.ServerConsole.Model { public class BjdireContext : DbContext { + public BjdireContext(DbContextOptions options) + : base(options) + { + } + public DbSet DevicesActualStates { get; set; } public DbSet DevicesDesiredStates { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite("Data Source=bjdire.sqlite"); - } } } diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContextFactory.cs b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContextFactory.cs new file mode 100644 index 00000000..fc035765 --- /dev/null +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/BjdireContextFactory.cs @@ -0,0 +1,20 @@ +// +// Copyright Shuai Zhang. All rights reserved. +// Licensed under the GPLv3 license. See LICENSE file in the project root for full license information. +// + +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; + +namespace GeothermalResearchInstitute.ServerConsole.Model +{ + public class BjdireContextFactory : IDesignTimeDbContextFactory + { + public BjdireContext CreateDbContext(string[] args) + { + var builder = new DbContextOptionsBuilder(); + Program.DbContextOptionsBuilderAction.Invoke(builder); + return new BjdireContext(builder.Options); + } + } +} diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/DeviceStates.cs b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/DeviceStates.cs index 848405dc..37a0008e 100644 --- a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/DeviceStates.cs +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Model/DeviceStates.cs @@ -3,10 +3,7 @@ // Licensed under the GPLv3 license. See LICENSE file in the project root for full license information. // -using System; using System.ComponentModel.DataAnnotations; -using System.Net; -using System.Net.NetworkInformation; using GeothermalResearchInstitute.v1; namespace GeothermalResearchInstitute.ServerConsole.Model diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Program.cs b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Program.cs index 093fe33a..5df1569a 100644 --- a/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Program.cs +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole/Program.cs @@ -3,11 +3,12 @@ // Licensed under the GPLv3 license. See LICENSE file in the project root for full license information. // -using System.Net.NetworkInformation; +using System; using GeothermalResearchInstitute.ServerConsole.GrpcService; using GeothermalResearchInstitute.ServerConsole.Model; using GeothermalResearchInstitute.v1; using Grpc.Core; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -17,6 +18,9 @@ namespace GeothermalResearchInstitute.ServerConsole { internal class Program { + internal static readonly Action DbContextOptionsBuilderAction = + builder => builder.UseSqlite("Data Source=bjdire.sqlite"); + private static void Main(string[] args) { var host = new HostBuilder() @@ -51,20 +55,19 @@ private static void Main(string[] args) if (env.IsDevelopment()) { - // TODO(zhangshuai.ds): Add fake clients. + // TODO(zhangshuai.ds): Add fake data. + builder.AddDbContext(options => options.UseInMemoryDatabase("bjdire")); } else { - // TODO(zhangshuai.ds): Add real clients. + // Database. + builder.AddDbContext(DbContextOptionsBuilderAction); } // Configuration options. builder.Configure(context.Configuration); builder.Configure(context.Configuration); - // Database. - builder.AddDbContext(); - // Grpc services. builder.AddSingleton(serviceProvider => {