Former-commit-id: 7e79927c9e783a5cc02fe976b2a6c6385dbc1b8b
TangShanKaiPing
wanggang 5 years ago
parent 6a32fac057
commit 035f1143e9

@ -1,6 +1,7 @@
using Infrastructure.Application;
using Microsoft.AspNetCore.Mvc;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace Application.Models
@ -29,6 +30,7 @@ namespace Application.Models
public Guid? DataId { get; set; }
[Display(Name = "触发规则")]
[Description("示例value==\"开\"")]
[Remote("ConditionValid", "Ajax", "Admin", AdditionalFields = "DataId")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Condition { get; set; }

@ -194,7 +194,7 @@ namespace IoT.Shared.Areas.Admin.Controlls
{
var list = this._dataRepo.ReadOnlyTable()
.Where(o => !o.Hidden && o.DeviceId == parentId)
.Select(o => new { o.Id, Name = $"{o.Name} {o.Value} {o.Description}" })
.Select(o => new { o.Id, Name = $"{o.Name}[当前数据:{o.Value})(当前状态:{o.Description}]" })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}

@ -76,15 +76,12 @@ namespace IoTNode.DeviceServices
public void UpdateDevice(IRepository<Device> repo, Device device)
{
if (repo.SaveChanges() > 0)
{
this.SendToServer(Methods.EditDevice, device.To<EditDeviceModel>());
}
repo.SaveChanges();
}
public void UpdateData(IRepository<Device> repo, Device device, Data data)
{
var data2 = device.AddorUpdateData(data);
device.AddorUpdateData(data);
repo.SaveChanges();
}
@ -114,7 +111,6 @@ namespace IoTNode.DeviceServices
OpenApiService.UpdateApi(product);
productRepo.Add(product);
productRepo.SaveChanges();
//this.SendToServer(Methods.UpdateProductResponse, product);
}
return product;
}

@ -173,7 +173,7 @@ namespace IoTNode.DeviceServices.FBee
deviceRepo.Add(device);
}
device.Ip = ip;
this.UpdateDevice(deviceRepo, device);
deviceRepo.SaveChanges();
}
var gateways = deviceRepo.ReadOnlyTable().Where(o => o.Product.Name == "FBee网关").ToList();
foreach (var gateway in gateways)
@ -555,7 +555,7 @@ namespace IoTNode.DeviceServices.FBee
};
deviceRepo.Add(device);
device.IsOnline = online;
this.UpdateDevice(deviceRepo, device);
deviceRepo.SaveChanges();
if (device.Name == "红外转发器")
{
var buttons = new List<ButtonModel>() { new ButtonModel { Name = "测试", Value = "603", Order = 0 } }.ToJson(true);
@ -565,7 +565,7 @@ namespace IoTNode.DeviceServices.FBee
else
{
device.IsOnline = online;
this.UpdateDevice(deviceRepo, device);
deviceRepo.SaveChanges();
}
this.UpdateData(deviceRepo, device, device.CreateData(Keys.DeviceId, deviceId, DeviceDataType.Int, Keys.DeviceId, hidden: true, timestamp: timestamp));
this.UpdateData(deviceRepo, device, device.CreateData(Keys.Address, address, DeviceDataType.String, Keys.Address, hidden: true, timestamp: timestamp));
@ -1000,7 +1000,7 @@ namespace IoTNode.DeviceServices.FBee
var password = ms.ReadASIIString(20);
device.UserName = userName;
device.Password = password;
this.UpdateDevice(deviceRepo, device);
deviceRepo.SaveChanges();
ms.ReadByte();
ms.ReadByte();
ms.ReadByte();
@ -1250,9 +1250,7 @@ namespace IoTNode.DeviceServices.FBee
var status = props.First().Value[0];
if (status == 0x00)//离网
{
var model = device.To<EditDeviceModel>();
deviceRepo.Delete(device);
this.SendToServer("DeleteDevice", model);
DeleteDevice(deviceRepo, device);
}
else if (status == 0x03)//入网
{
@ -1379,6 +1377,20 @@ namespace IoTNode.DeviceServices.FBee
}
}
private static void DeleteDevice(IRepository<Device> deviceRepo, Device device)
{
try
{
var model = device.To<EditDeviceModel>();
deviceRepo.Delete(device);
deviceRepo.SaveChanges();
}
catch (Exception ex)
{
ex.PrintStack();
}
}
private string GetDescription(string key, short value)
{
if (key == Keys.Light)

@ -139,7 +139,7 @@ namespace IoTNode.DeviceServices.Onvif
NodeId = node.Id
};
deviceRepo.Add(device);
this.UpdateDevice(deviceRepo, device);
deviceRepo.SaveChanges();
var fileName = $"ffmpeg-{Helper.Instance.GetRunTime()}{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}";
var file = Path.Combine(this._env.WebRootPath, fileName);
var pushValue = device.Data.FirstOrDefault(o => o.Name == "推流")?.Value ?? "是";
@ -156,7 +156,7 @@ namespace IoTNode.DeviceServices.Onvif
needAuth = true;
device.UserName ??= GetSetting("camera.usr");
device.Password ??= GetSetting("camera.pwd");
this.UpdateDevice(deviceRepo, device);
deviceRepo.SaveChanges();
profiles = this._onvifDeviceManagement.GetProfiles(ipCamera.DeviceUrl, ipCamera.MediaUrl, device.UserName, device.Password);
if (string.IsNullOrEmpty(profiles))
{

@ -105,7 +105,7 @@ namespace IoTNode.DeviceServices.SerialPortManager
Icon = "serialport"
};
repo.Add(device);
this.UpdateDevice(repo, device);
repo.SaveChanges();
var buttons = new List<SPCommandModel>() { new SPCommandModel { Name = "测试", PortName = "/dev/ttyS0", BaudRate = 9600, Parity = 0, DataBits = 8, StopBits = 1, Message = "0123456789ABCDEF" } }.ToJson(true);
this.UpdateData(repo, device, device.CreateData("Buttons", buttons, DeviceDataType.String, "指令", timestamp: DateTimeOffset.Now.ToUnixTimeMilliseconds()));
}

@ -1,4 +1,4 @@
using System.Reflection;
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyInformationalVersion("1.0.0.506")]
[assembly: AssemblyInformationalVersion("1.0.0.507")]
Loading…
Cancel
Save