You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoT.Shared/Application/Models/NotifyModel.cs

109 lines
3.6 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Infrastructure.Models
{
public class NotifyModel
{
[Required]
public string Name { get; set; }
[Required]
public string Number { get; set; }
[Required]
public string CategoryNumber { get; set; }
[Required]
public string CategoryName { get; set; }
[Required]
public string Icon { get; set; }
[Required]
public string BaseUrl { get; set; }
[Required]
public string ApiPath { get; set; }
public bool IsOnline { get; set; }
[Required]
public long Timestamp { get; set; }
public List<DataModel> Data { get; set; } = new List<DataModel>();
public NotifyModel()
{
this.Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
}
public List<KeyValuePair<string, string>> ToList()
{
var list = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>(nameof(CategoryName), CategoryName),
new KeyValuePair<string, string>(nameof(CategoryNumber), CategoryNumber),
new KeyValuePair<string, string>(nameof(Name), Name),
new KeyValuePair<string, string>(nameof(Number), Number),
new KeyValuePair<string, string>(nameof(Icon), Icon),
new KeyValuePair<string, string>(nameof(BaseUrl), BaseUrl),
new KeyValuePair<string, string>(nameof(ApiPath), ApiPath),
new KeyValuePair<string, string>(nameof(IsOnline), IsOnline.ToString()),
};
for (int i = 0; i < Data.Count; i++)
{
var item = Data[i];
if (!string.IsNullOrEmpty(item.Value))
{
list.Add(new KeyValuePair<string, string>($"Data[{i}].Type", item.Type.ToString()));
list.Add(new KeyValuePair<string, string>($"Data[{i}].Key", item.Key));
list.Add(new KeyValuePair<string, string>($"Data[{i}].Name", item.Name));
list.Add(new KeyValuePair<string, string>($"Data[{i}].Value", item.Value.ToString()));
list.Add(new KeyValuePair<string, string>($"Data[{i}].Unit", item.Unit));
list.Add(new KeyValuePair<string, string>($"Data[{i}].Description", item.Description));
list.Add(new KeyValuePair<string, string>($"Data[{i}].Order", item.DisplayOrder.ToString()));
}
}
list.RemoveAll(o => string.IsNullOrEmpty(o.Value));
return list;
}
}
public class DataModel
{
[Display(Name = "类型")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Type { get; set; }
[Display(Name = "键")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Key { get; set; }
[Display(Name = "名称")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Name { get; set; }
[Display(Name = "值")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Value { get; set; }
[Display(Name = "单位")]
public string Unit { get; set; }
[Display(Name = "描述")]
public string Description { get; set; }
[Display(Name = "序号")]
public int DisplayOrder { get; set; }
}
public enum DataValueType
{
Int,
Float,
Text,
Date
}
}