using System;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
using DMS.WPF.Models;
namespace DMS.WPF.Models;
///
/// 表示变量数据与MQTT服务器之间的关联模型,包含MQTT别名。
///
public partial class VariableMqtt : ObservableObject
{
public VariableMqtt()
{
}
public VariableMqtt(Variable variable, Mqtt mqtt)
{
if (mqtt != null && variable != null)
{
Variable = variable;
Mqtt = mqtt;
MqttAlias = MqttAlias != String.Empty ? MqttAlias : variable.Name;
}
}
///
/// 关联的唯一标识符。
///
public int Id { get; set; }
///
/// 关联的变量数据ID。
///
public int VariableId { get; set; }
///
/// 关联的MQTT服务器ID。
///
public int MqttId { get; set; }
///
/// 变量在该MQTT服务器上的别名。
///
[ObservableProperty]
private string _mqttAlias = string.Empty;
///
/// 变量的唯一标识符(S7地址或OPC UA NodeId)。
///
public string Identifier
{
get
{
if (Variable!=null)
{
if (Variable.ProtocolType == ProtocolType.S7)
{
return Variable.S7Address;
}
else if (Variable.ProtocolType == ProtocolType.OpcUA)
{
return Variable.OpcUaNodeId;
}
}
return string.Empty;
}
}
///
/// 创建时间。
///
public DateTime CreateTime { get; set; } = DateTime.Now;
///
/// 更新时间。
///
public DateTime UpdateTime { get; set; } = DateTime.Now;
///
/// 导航属性:关联的变量数据。
///
public Variable Variable { get; set; }
///
/// 导航属性:关联的MQTT服务器。
///
public Mqtt Mqtt { get; set; }
}