Former-commit-id: fdc1f59da10dd29b4f7053a2c47cf42649e621b8
TangShanKaiPing
wanggang 6 years ago
parent 4a02b5d0aa
commit 0b7845111a

Binary file not shown.

Binary file not shown.

@ -10,9 +10,12 @@
public const string ApiCallback = nameof(ApiCallback);
public const string UpdateNodeResponse = nameof(UpdateNodeResponse); //上传节点
public const string UpdateProductResponse = nameof(UpdateProductResponse);//上传产品、接口和参数
public const string UpdateProductResponse = nameof(UpdateProductResponse);//上传产品
public const string UpdateApiResponse = nameof(UpdateApiResponse);//上传接口
public const string UpdateParameterResponse = nameof(UpdateParameterResponse);//上传参数
public const string UpdateDeviceIdListResponse = nameof(UpdateDeviceIdListResponse);//上传节点设备Id列表
public const string UpdateDeviceResponse = nameof(UpdateDeviceResponse);//上传节点设备和数据
public const string UpdateDeviceResponse = nameof(UpdateDeviceResponse);//上传设备
public const string UpdateDataResponse = nameof(UpdateDataResponse);//上传数据
public const string UpdateCommandIdListResponse = nameof(UpdateCommandIdListResponse);//上传命令Id列表
public const string UpdateCommandResponse = nameof(UpdateCommandResponse);//上传命令

@ -1,10 +1,8 @@
using Application.Domain.Entities;
using Application.Models;
using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Domain;
using Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
@ -47,52 +45,6 @@ namespace IoT.Shared.Services
this._iotTiggerRepo = iotTiggerRepo;
}
#region 服务端响应节点上传数据
public void UpdateProduct(string message)
{
using var scope = this._services.CreateScope();
var repo = scope.ServiceProvider.GetService<IRepository<Product>>();
var model = message.FromJson<Product>();
var entity = repo.Table().Include(o => o.Apis).ThenInclude(o => o.Parameters).FirstOrDefault(o => o.Id == model.Id);
if (entity == null)
{
repo.Add(model);
repo.SaveChanges();
}
}
public void UpdateDevice(string message)
{
var model = message.FromJson<Device>();
using var scope = this._services.CreateScope();
var repo = scope.ServiceProvider.GetService<IRepository<Device>>();
var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.Id == model.Id);
if (device == null)
{
device = new Device
{
Id = model.Id,
ProductId = model.ProductId,
};
repo.Add(device);
}
device.From(model);
foreach (var data in model.Data)
{
var data2 = device.Data.FirstOrDefault(o => o.Id == data.Id);
if (data2 == null)
{
data2 = new Data
{
Id = data.Id,
};
}
data2.From(data);
}
repo.SaveChanges();
}
public void UpdateList<T>(string message, Expression<Func<T, bool>> predicate) where T : BaseEntity
{
using var scope = this._services.CreateScope();
@ -106,8 +58,6 @@ namespace IoT.Shared.Services
repo.SaveChanges();
}
#endregion 服务端响应节点上传数据
#region private
public void Update<T>(string message) where T : BaseEntity
@ -156,14 +106,5 @@ namespace IoT.Shared.Services
}
#endregion private
#region 后台编辑
public void EditCommand(EditCommandModel model)
{
throw new NotImplementedException();
}
#endregion 后台编辑
}
}

@ -71,9 +71,17 @@ namespace IoTCenter.Services
{
this._dataService.Update<Node>(message);
}
else if (method == Methods.UpdateProductResponse)//接收产品、接口和参数
else if (method == Methods.UpdateProductResponse)//接收产品
{
this._dataService.UpdateProduct(message);
this._dataService.Update<Product>(message);
}
else if (method == Methods.UpdateApiResponse)//接收接口
{
this._dataService.Update<Api>(message);
}
else if (method == Methods.UpdateParameterResponse)//接收参数
{
this._dataService.Update<Parameter>(message);
}
else if (method == Methods.UpdateDeviceIdListResponse)//接收设备Id列表
{
@ -81,7 +89,11 @@ namespace IoTCenter.Services
}
else if (method == Methods.UpdateDeviceResponse)//接收设备和数据
{
this._dataService.UpdateDevice(message);
this._dataService.Update<Device>(message);
}
else if (method == Methods.UpdateDataResponse)//接收设备和数据
{
this._dataService.Update<Data>(message);
}
else if (method == Methods.UpdateCommandIdListResponse)//接收命令Id列表
{

@ -884,7 +884,9 @@
console.log($(this).html());
if (!$(this).hasClass('Stop')) {
var number = $('#camera').val();
ajax('/App/Exec', { number: number, method: '/Onvif/Stop' }, 'post');
setTimeout(function () {
ajax('/App/Exec', { number: number, method: '/Onvif/Stop' }, 'post');
}, 500);
}
return false;
});

@ -184,22 +184,24 @@ namespace IoT.Shared.Services
public void OnConnected()
{
Console.WriteLine($"{_notifyHost} OnConnected");
//上传节点
this.UpdateEntityIdList<Node>(null, Methods.UpdateNodeResponse);
//上传产品
this.UpdateEntityIdList<Product>(null, Methods.UpdateProductResponse, o => o.Include(o => o.Apis).ThenInclude(o => o.Parameters));
this.UpdateEntityIdList<Product>(null, Methods.UpdateProductResponse);
//上传设备Id列表、设备和数据
this.UpdateEntityIdList<Device>(Methods.UpdateDeviceIdListResponse, null);
using var scope = this.applicationServices.CreateScope();
var repo = scope.ServiceProvider.GetService<IRepository<Device>>();
var devices = repo.ReadOnlyTable().ToList();
foreach (var device in devices)
{
device.Data = device.Data.Where(o => !o.Hidden).ToList();
this.SendToServer(Methods.UpdateDeviceResponse, device);
}
//上传接口
this.UpdateEntityIdList<Api>(null, Methods.UpdateApiResponse);
//上传参数
this.UpdateEntityIdList<Parameter>(null, Methods.UpdateParameterResponse);
//上传设备Id列表、设备
this.UpdateEntityIdList<Device>(Methods.UpdateDeviceIdListResponse, Methods.UpdateDeviceResponse);
//上传数据
this.UpdateEntityIdList<Data>(null, Methods.UpdateDataResponse, null, o => !o.Hidden);
//上传命令Id列表、命令
this.UpdateEntityIdList<IoTTigger>(Methods.UpdateCommandIdListResponse, Methods.UpdateCommandResponse);

Loading…
Cancel
Save