iotgateway/IoTGateway.ViewModel/BasicData/DeviceVMs/AttributeVM.cs

57 lines
2.1 KiB
C#
Raw Normal View History

2022-03-24 13:38:11 +00:00
using Microsoft.EntityFrameworkCore;
using Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using IoTGateway.Model;
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
{
public class AttributeVM : BaseVM
{
public string { get; set; }
public string { get; set; }
public void Request()
{
using (var transaction = DC.BeginTransaction())
{
try
{
2022-05-09 15:57:46 +00:00
var device = DC.Set<Device>().Where(x => x.ID == Guid.Parse(FC["id"].ToString())).Include(x => x.Parent).Include(x => x.DeviceVariables).Include(x => x.DeviceConfigs).Include(x => x.Driver).FirstOrDefault();
2022-03-24 13:38:11 +00:00
if (device == null)
= "复制失败,找不到设备";
else
{
2025-01-11 15:23:33 +00:00
var messageService = Wtm.ServiceProvider.GetService(typeof(MessageService)) as MessageService;
messageService.RequestAttributes(device.DeviceName, true, device.DeviceConfigs.Where(x => x.DataSide == DataSide.AnySide).Select(x => x.DeviceConfigName).ToArray());
2022-03-24 13:38:11 +00:00
}
DC.SaveChanges();
transaction.Commit();
= "请求成功";
var pluginManager = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
pluginManager?.UpdateDevice(device);
}
catch (Exception ex)
{
transaction.Rollback();
= $"请求超时,{ex}";
}
}
}
protected override void InitVM()
{
var device = DC.Set<Device>().AsNoTracking().Include(x => x.Parent).Where(x => x.ID == Guid.Parse(FC["id"].ToString())).FirstOrDefault();
= $"{device?.Parent?.DeviceName}===>{device?.DeviceName}";
base.InitVM();
}
}
}