Skip to content

Commit

Permalink
[GeothermalResearchInstitute] Fix for dotnet-ef.
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoona committed Sep 15, 2019
1 parent 95190ed commit fbef3bd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" DevelopmentDependency="true" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,26 @@ public override Task<Device> 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."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace GeothermalResearchInstitute.ServerConsole.Model
{
public class BjdireContext : DbContext
{
public BjdireContext(DbContextOptions<BjdireContext> options)
: base(options)
{
}

public DbSet<DeviceActualStates> DevicesActualStates { get; set; }

public DbSet<DeviceDesiredStates> DevicesDesiredStates { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=bjdire.sqlite");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// <copyright file="BjdireContextFactory.cs" company="Shuai Zhang">
// Copyright Shuai Zhang. All rights reserved.
// Licensed under the GPLv3 license. See LICENSE file in the project root for full license information.
// </copyright>

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace GeothermalResearchInstitute.ServerConsole.Model
{
public class BjdireContextFactory : IDesignTimeDbContextFactory<BjdireContext>
{
public BjdireContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<BjdireContext>();
Program.DbContextOptionsBuilderAction.Invoke(builder);
return new BjdireContext(builder.Options);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
// Licensed under the GPLv3 license. See LICENSE file in the project root for full license information.
// </copyright>

using System;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Net.NetworkInformation;
using GeothermalResearchInstitute.v1;

namespace GeothermalResearchInstitute.ServerConsole.Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// Licensed under the GPLv3 license. See LICENSE file in the project root for full license information.
// </copyright>

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;
Expand All @@ -17,6 +18,9 @@ namespace GeothermalResearchInstitute.ServerConsole
{
internal class Program
{
internal static readonly Action<DbContextOptionsBuilder> DbContextOptionsBuilderAction =
builder => builder.UseSqlite("Data Source=bjdire.sqlite");

private static void Main(string[] args)
{
var host = new HostBuilder()
Expand Down Expand Up @@ -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<BjdireContext>(options => options.UseInMemoryDatabase("bjdire"));
}
else
{
// TODO(zhangshuai.ds): Add real clients.
// Database.
builder.AddDbContext<BjdireContext>(DbContextOptionsBuilderAction);
}

// Configuration options.
builder.Configure<AuthenticationOptions>(context.Configuration);
builder.Configure<DeviceOptions>(context.Configuration);

// Database.
builder.AddDbContext<BjdireContext>();

// Grpc services.
builder.AddSingleton(serviceProvider =>
{
Expand Down

0 comments on commit fbef3bd

Please sign in to comment.