You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using System.Text.Json;
|
|
using OMS.NET.Common;
|
|
|
|
namespace OMS.NET.Instructs
|
|
{
|
|
public class RenameLayerInstruct : Instruct
|
|
{
|
|
public RenameLayerInstruct()
|
|
{
|
|
Type = "broadcast";
|
|
Class = "renameLayer";
|
|
}
|
|
|
|
public override Task Handler(string wsid)
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查不通过则直接退出
|
|
if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查
|
|
try
|
|
{
|
|
|
|
long id = Data.GetProperty("id").GetInt64();
|
|
string name = Data.GetProperty("name").GetString();
|
|
if (GlobalArea.IsLayerNameRepeat(name)) throw new Exception("存在名称重复");
|
|
LayerData layerData = GlobalArea.GetLayerDataByLayerId(id) ?? throw new Exception($"未找到MapLayer {id}");
|
|
layerData.Structure!.AsArray().RemoveAt(0);
|
|
layerData.Structure!.AsArray().Insert(0, name);
|
|
layerData.UpdateToDb();
|
|
|
|
string conveyor = GlobalArea.GetLoginEmailByID(wsid);
|
|
string time = GlobalArea.GetCurrentTime();
|
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
|
{
|
|
IsBroadcast = true,
|
|
Type = "broadcast",
|
|
Class = "renameLayer",
|
|
Conveyor = conveyor,
|
|
Time = time,
|
|
Data = new
|
|
{
|
|
id = id,
|
|
name = name,
|
|
}
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
} |