Former-commit-id: 700319900bdac5cb88439e5290f33e8778b0ce42
TangShanKaiPing
wanggang 6 years ago
parent b3332970a2
commit 530b494328

@ -14,15 +14,11 @@ namespace Infrastructure.Data
{ {
public class EfDbContext : DbContext public class EfDbContext : DbContext
{ {
public static readonly ILoggerFactory DebugLogFactory = LoggerFactory.Create(builder => public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder =>
{ {
builder.AddConsole(); builder.AddConsole();
}); });
public static readonly ILoggerFactory ProductLogFactory = LoggerFactory.Create(builder =>
{
});
private readonly IHostEnvironment _env; private readonly IHostEnvironment _env;
private readonly IConfiguration _cfg; private readonly IConfiguration _cfg;
@ -34,14 +30,7 @@ namespace Infrastructure.Data
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
if (this._cfg.GetValue<bool>("debug", false)) optionsBuilder?.UseLoggerFactory(MyLoggerFactory);
{
optionsBuilder?.UseLoggerFactory(DebugLogFactory);
}
else
{
optionsBuilder?.UseLoggerFactory(ProductLogFactory);
}
optionsBuilder?.EnableSensitiveDataLogging(); optionsBuilder?.EnableSensitiveDataLogging();
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

@ -1,8 +1,10 @@
using Infrastructure.Application; using Application.Domain.Entities;
using Infrastructure.Application;
using Infrastructure.Data; using Infrastructure.Data;
using Infrastructure.Domain; using Infrastructure.Domain;
using Infrastructure.Events; using Infrastructure.Events;
using Infrastructure.Extensions; using Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -84,6 +86,13 @@ namespace IoT.Shared.Services
entity.From(model); entity.From(model);
if (repo.SaveChanges() > 0) if (repo.SaveChanges() > 0)
{ {
if (entity is Data)
{
var data = entity as Data;
data.Device = scope.ServiceProvider.GetService<IRepository<Device>>().ReadOnlyTable().Include(o => o.Node)
.Where(o => o.Id == data.DeviceId)
.Select(o => new Device { DisplayName = o.DisplayName, Node = new Node { Name = o.Node.Name } }).FirstOrDefault();
}
var eventPublisher = scope.ServiceProvider.GetService<IEventPublisher>(); var eventPublisher = scope.ServiceProvider.GetService<IEventPublisher>();
if (isNew) if (isNew)
{ {

@ -4,7 +4,7 @@
<div class="weui-cells"> <div class="weui-cells">
<div class="weui-cell weui-cell_active weui-cell_access" v-for="message in store.state.messages"> <div class="weui-cell weui-cell_active weui-cell_access" v-for="message in store.state.messages">
<div class="weui-cell__bd"> <div class="weui-cell__bd">
<span class="badge badge-success" style="margin-left: 5px;">{{message.name}}:{{message.value}} {{message.unit}} {{message.description}}</span> <span class="badge badge-success" style="margin-left: 5px;">{{message.device.node.name}}{{message.device.displayName}}{{message.name}}:{{message.value}} {{message.unit}} {{message.description}}</span>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save