1.优化页面;2.修改表达式中mysql存储转义的问题;3.修复已知问题

This commit is contained in:
王海东 2021-12-17 22:39:18 +08:00
parent 5512f0f27a
commit ae75d6005c
14 changed files with 49 additions and 30 deletions

Binary file not shown.

View File

@ -50,11 +50,11 @@ namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
protected override IEnumerable<IGridColumn<DeviceConfig_View>> InitGridHeader()
{
return new List<GridColumn<DeviceConfig_View>>{
this.MakeGridHeader(x => x.DeviceConfigName),
this.MakeGridHeader(x => x.Description),
this.MakeGridHeader(x => x.Value),
this.MakeGridHeader(x => x.DeviceConfigName).SetWidth(100),
this.MakeGridHeader(x => x.Description).SetWidth(100),
this.MakeGridHeader(x => x.Value).SetWidth(100),
this.MakeGridHeader(x => x.DeviceName_view).SetWidth(100),
this.MakeGridHeader(x => x.EnumInfo),
this.MakeGridHeader(x => x.DeviceName_view),
this.MakeGridHeaderAction(width: 200)
};
}
@ -74,7 +74,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
EnumInfo = x.EnumInfo,
DeviceName_view = x.Device.DeviceName,
})
.OrderBy(x => x.ID);
.OrderBy(x => x.DeviceName_view).ThenBy(x=>x.DeviceConfigName);
return query;
}

View File

@ -58,7 +58,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
this.MakeGridHeader(x => x.Value).SetWidth(80),
this.MakeGridHeader(x => x.CookedValue).SetWidth(80),
this.MakeGridHeader(x => x.State).SetWidth(80),
this.MakeGridHeader(x => x.Expressions).SetSort(true).SetWidth(80),
this.MakeGridHeader(x => x.Expressions).SetWidth(150),
//this.MakeGridHeader(x => x.ProtectType).SetSort(true),
this.MakeGridHeader(x => x.DeviceName_view).SetSort(true).SetWidth(90),
this.MakeGridHeader(x=> "detail").SetHide().SetFormat((a,b)=>{
@ -104,7 +104,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
ProtectType = x.ProtectType,
DeviceName_view = x.Device.DeviceName,
})
.OrderBy(x => x.ID);
.OrderBy(x => x.DeviceName_view).ThenBy(x => x.DeviceAddress);
return query;
}

View File

@ -46,7 +46,7 @@ namespace IoTGateway.ViewModel.BasicData
if (FC.ContainsKey("Entity.DeviceId"))
{
StringValues id = (StringValues)FC["Entity.DeviceId"];
var device = DC.Set<Device>().Where(x => x.ID == Guid.Parse(id)).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
var device = DC.Set<Device>().AsNoTracking().Where(x => x.ID == Guid.Parse(id)).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}
@ -58,7 +58,7 @@ namespace IoTGateway.ViewModel.BasicData
var deviceVariable = DC.Set<DeviceVariable>().Where(x => x.ID == varId).SingleOrDefault();
if (deviceVariable != null)
{
var device = DC.Set<Device>().Where(x => x.ID == deviceVariable.DeviceId).Include(x=>x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
var device = DC.Set<Device>().AsNoTracking().Where(x => x.ID == deviceVariable.DeviceId).Include(x=>x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}
@ -66,7 +66,7 @@ namespace IoTGateway.ViewModel.BasicData
case FromVM.Config:
foreach (var deviceConfigId in Ids)
{
var deviceConfig = DC.Set<DeviceConfig>().Where(x => x.ID == deviceConfigId).SingleOrDefault();
var deviceConfig = DC.Set<DeviceConfig>().AsNoTracking().Where(x => x.ID == deviceConfigId).SingleOrDefault();
if (deviceConfig != null)
{
var device = DC.Set<Device>().Where(x => x.ID == deviceConfig.DeviceId).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
@ -78,7 +78,7 @@ namespace IoTGateway.ViewModel.BasicData
case FromVM.Device:
foreach (var deviceId in Ids)
{
var device = DC.Set<Device>().Where(x => x.ID == deviceId).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
var device = DC.Set<Device>().AsNoTracking().Where(x => x.ID == deviceId).Include(x => x.DeviceVariables).Include(x => x.Driver).SingleOrDefault();
if (!devices.Where(x => x.ID == device.ID).Any())
devices.Add(device);
}

View File

@ -1,7 +1,7 @@
@model IoTGateway.ViewModel.BasicData.DeviceConfigVMs.DeviceConfigVM
@inject IStringLocalizer<Program> Localizer;
<wt:form vm="@Model">
<wt:form vm="@Model" height="400">
<wt:row items-per-row="ItemsPerRowEnum.Two">
@*<wt:textbox field="Entity.DeviceConfigName" />*@
@{

View File

@ -4,10 +4,10 @@
<wt:treecontainer items="AllDevices" id-field="Searcher.DeviceId" height="500">
<wt:searchpanel vm="@Model" reset-btn="true">
<wt:row items-per-row="ItemsPerRowEnum.Three">
<wt:combobox field="Searcher.DeviceId" items="Searcher.AllDevices" empty-text="@Localizer["Sys.All"]" />
<wt:textbox field="Searcher.DeviceConfigName" />
<wt:textbox field="Searcher.Value" />
<wt:combobox field="Searcher.DeviceId" items="Searcher.AllDevices" empty-text="@Localizer["Sys.All"]" />
</wt:row>
</wt:searchpanel>
<wt:grid vm="@Model" url="/BasicData/DeviceConfig/Search" />
<wt:grid vm="@Model" url="/BasicData/DeviceConfig/Search" hidden-grid-index="true" />
</wt:treecontainer>

View File

@ -2,7 +2,7 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>IoTGateway</ActiveDebugProfile>
<NameOfLastUsedPublishProfile>D:\Repos\iotgateway\IoTGateway\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>

View File

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_PublishTargetUrl>D:\Repos\iotgateway\IoTGateway\bin\Release\net5.0\publish\</_PublishTargetUrl>
<History>True|2021-12-12T06:11:08.8380502Z;</History>
<_PublishTargetUrl>E:\workbench\iotgateway\IoTGateway\bin\Release\net5.0\publish\</_PublishTargetUrl>
<History>True|2021-12-17T11:11:07.1655146Z;True|2021-12-12T14:11:08.8380502+08:00;</History>
</PropertyGroup>
</Project>

Binary file not shown.

View File

@ -2,11 +2,8 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>../../../IoTGateway/bin/Debug/net5.0/drivers</OutputPath>
<OutputPath>../../../IoTGateway/bin/Debug/net5.0/drivers</OutputPath>
</PropertyGroup>
<ItemGroup>

View File

@ -14,6 +14,7 @@ using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using IoTGateway.DataAccess;
using IoTGateway.Model;
using DynamicExpresso;
namespace Plugin
{
@ -25,6 +26,7 @@ namespace Plugin
public MyMqttClient _MyMqttClient;
private string connnectSetting = IoTBackgroundService.connnectSetting;
private DBTypeEnum DBType = IoTBackgroundService.DBType;
private Interpreter interpreter = new();
public DeviceService(IConfiguration ConfigRoot, DrvierService drvierManager, MyMqttClient myMqttClient)
{
@ -133,7 +135,7 @@ namespace Plugin
p.SetValue(DeviceObj, value);
}
var deviceThread = new DeviceThread(Device, DeviceObj, systemManage.GatewayName, _MyMqttClient);
var deviceThread = new DeviceThread(Device, DeviceObj, systemManage.GatewayName, _MyMqttClient, interpreter);
DeviceThreads.Add(deviceThread);
}
@ -149,12 +151,15 @@ namespace Plugin
public void RemoveDeviceThread(Device Device)
{
var DeviceThread = DeviceThreads.Where(x => x.Device.ID == Device.ID).FirstOrDefault();
if (DeviceThread != null)
if (Device != null)
{
DeviceThread.StopThread();
DeviceThread.Dispose();
DeviceThreads.Remove(DeviceThread);
var DeviceThread = DeviceThreads.Where(x => x.Device.ID == Device.ID).FirstOrDefault();
if (DeviceThread != null)
{
DeviceThread.StopThread();
DeviceThread.Dispose();
DeviceThreads.Remove(DeviceThread);
}
}
}

View File

@ -22,12 +22,13 @@ namespace Plugin
private Task task { get; set; } = null;
private DateTime TsStartDt = new DateTime(1970, 1, 1);
private CancellationTokenSource tokenSource = new CancellationTokenSource();
private Interpreter interpreter = new Interpreter();
private Interpreter Interpreter = null;
public DeviceThread(Device device, IDriver driver, string ProjectId, MyMqttClient myMqttClient)
public DeviceThread(Device device, IDriver driver, string ProjectId, MyMqttClient myMqttClient, Interpreter interpreter)
{
Device = device;
Driver = driver;
Interpreter = interpreter;
Methods = Driver.GetType().GetMethods().Where(x => x.GetCustomAttribute(typeof(MethodAttribute)) != null).ToList();
if (Device.AutoStart)
{
@ -83,7 +84,16 @@ namespace Plugin
DeviceValues[item.ID] = ret;
if (ret.StatusType == VaribaleStatusTypeEnum.Good && !string.IsNullOrWhiteSpace(item.Expressions?.Trim()))
ret.CookedValue = interpreter.Eval(item.Expressions.Replace("raw", ret.Value.ToString()));
{
try
{
ret.CookedValue = interpreter.Eval(DealMysqlStr(item.Expressions).Replace("raw", ret.Value.ToString()));
}
catch (Exception)
{
ret.StatusType = VaribaleStatusTypeEnum.ExpressionError;
}
}
else
ret.CookedValue = ret.Value;
@ -139,6 +149,12 @@ namespace Plugin
Driver.Dispose();
Console.WriteLine($"{Device.DeviceName},释放");
}
//mysql会把一些符号转义没找到原因先临时处理下
private string DealMysqlStr(string Expression)
{
return Expression.Replace("&lt;", ">").Replace("&gt;", "<").Replace("&amp;", "&");
}
}
}

View File

@ -11,6 +11,7 @@ namespace PluginInterface
Good=0,
AddressError,
MethodError,
ExpressionError,
Bad,
UnKnow,
Custome1,