农场设备管理代码(1)

using Dias_Interface;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Dias_Farm

{

public class staticDevice

{

public static List<DeviceInfo> DEVLIST = new List<DeviceInfo>();

public static void Init(string mainid)

{

DEVLIST.Clear();

string path = System.IO.Path.Combine(Environment.CurrentDirectory, "Data", $"DeviceList_{mainid}.Dat");

if (System.IO.File.Exists(path))

{

string data = System.IO.File.ReadAllText(path, Encoding.UTF8);

DEVLIST = DataBus.StringToObject<List<DeviceInfo>>(data);

if (DEVLIST == null)

DEVLIST = new List<DeviceInfo>();

}

if (DEVLIST.Count <= 0)

{

DataDeviceInfo dvi = new DataDeviceInfo(new Setting("Device_Data_Set"))

{

Id = "1001",

Name = "场温度",

Value = 23.50,

Status = 0,

Type = DeviceType.Data,

Description = "场室外温度"

};

dvi.Set.Set("Unit", "℃");

DEVLIST.Add(dvi);

DataDeviceInfo dvi1 = new DataDeviceInfo(new Setting("Device_Contol_Set"))

{

Id = "1002",

Name = "供水闸",

Value = 0,

Status = 0,

Type = DeviceType.Control,

Description = "总水匣开关"

};

DEVLIST.Add(dvi1);

}

}

public static void Add(DeviceInfo dev)

{

if (DEVLIST.Find(s => s.Id == dev.Id) == null)

{

DEVLIST.Add(dev);

}

}

public static DeviceInfo GetDeviceById(string id)

{

return DEVLIST.FirstOrDefault(s => s.Id == id) as DeviceInfo;

}

public static bool RemoveById(string id)

{

return DEVLIST.RemoveAll(s => s.Id == id)==1;

}

public static void Save(string mainid)

{

string path = System.IO.Path.Combine(Environment.CurrentDirectory, "Data", $"DeviceList_{mainid}.Dat");

string data=DataBus.ObjectToString(DEVLIST);

System.IO.File.WriteAllText(path, data,Encoding.UTF8);

}

}

}

相关推荐
❀搜不到1 小时前
isat-sam分割导出掩码图
开发语言·python
geovindu1 小时前
java: Memento Pattern
java·开发语言·后端·备忘录模式·行为模式
曾阿伦2 小时前
Trae CN Python环境调试debug指南
开发语言·python
PPPPickup2 小时前
基础知识差缺补漏-面试版持续更新
java·开发语言
兔兔兔兔12 小时前
记录C++ 3
开发语言·c++
黄鸭部落格ShiYuYuanFang2 小时前
【分享】软考每日一练与解析-计组 8/12
java·开发语言
m0_617493942 小时前
Python 使用 cryptography 实现数据加密与解密
开发语言·python
大白同学4212 小时前
初始Qt——了解Qt背景
开发语言·qt
万山寒2 小时前
python依赖包导出离线安装到没有外网的服务器
服务器·开发语言·python