20240901-调试修改

dev
nxiaoxiao 1 year ago
parent d9e25fd97c
commit 81f06d24e6

@ -46,7 +46,13 @@ namespace OMS.NET.Common
}
if (Members![elementId.ToString()] == null)
{
Members![elementId.ToString()] = elementType;
Members![elementId.ToString()] = elementType switch {
"point" => 1,
"line" => 2,
"area" => 3,
"curve" => 4,
_ => throw new Exception("图层添加:不支持的元素类型"),
};
Structure!.AsArray().Add(elementId);
HasChange = true;
UpdateToDb();

@ -242,6 +242,14 @@ namespace OMS.NET.Common
? value
: "";
/// <summary>
/// 底图的默认类型
/// default empty
/// </summary>
public string ServerConfigBaseMapType => _config.TryGetValue("ServerConfigBaseMapType", out string? value)
? value
: "realistic";
public ServerConfig()
{
//do nothing,everything default

@ -13,7 +13,7 @@ namespace OMS.NET.DbClass
public int Phase { get; set; }
public int? Width { get; set; }
public string? ChildRelations { get; set; }
public string? FatherRelations { get; set; }
public string? FatherRelation { get; set; }
public string? ChildNodes { get; set; }
public string? FatherNode { get; set; }
public string? Details { get; set; }
@ -33,8 +33,8 @@ namespace OMS.NET.DbClass
{
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
connection.Open();
var query = @"INSERT INTO map_0_data (type, points, point, color, phase, width, child_relations, father_relations, child_nodes, father_node, details, custom)
VALUES (@Type, @Points, @Point, @Color, @Phase, @Width, @ChildRelations, @FatherRelations, @ChildNodes, @FatherNode, @Details, @Custom)";
var query = @"INSERT INTO map_0_data (type, points, point, color, phase, width, child_relations, father_relation, child_nodes, father_node, details, custom)
VALUES (@Type, @Points, @Point, @Color, @Phase, @Width, @ChildRelations, @FatherRelation, @ChildNodes, @FatherNode, @Details, @Custom)";
using MySqlCommand command = new(query, connection);
command.Parameters.AddWithValue("@Type", mapData.Type);
command.Parameters.AddWithValue("@Points", mapData.Points);
@ -43,7 +43,7 @@ namespace OMS.NET.DbClass
command.Parameters.AddWithValue("@Phase", mapData.Phase);
command.Parameters.AddWithValue("@Width", mapData.Width ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@ChildRelations", mapData.ChildRelations ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@FatherRelations", mapData.FatherRelations ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@FatherRelation", mapData.FatherRelation ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@ChildNodes", mapData.ChildNodes ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@FatherNode", mapData.FatherNode ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@Details", mapData.Details ?? (object)DBNull.Value);
@ -57,7 +57,7 @@ namespace OMS.NET.DbClass
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
connection.Open();
var query = @"UPDATE map_0_data SET type = @Type, points = @Points, point = @Point, color = @Color, phase = @Phase, width = @Width,
child_relations = @ChildRelations, father_relations = @FatherRelations, child_nodes = @ChildNodes, father_node = @FatherNode,
child_relations = @ChildRelations, father_relation = @FatherRelation, child_nodes = @ChildNodes, father_node = @FatherNode,
details = @Details, custom = @Custom WHERE id = @Id";
using MySqlCommand command = new(query, connection);
command.Parameters.AddWithValue("@Id", mapData.Id);
@ -68,7 +68,7 @@ namespace OMS.NET.DbClass
command.Parameters.AddWithValue("@Phase", mapData.Phase);
command.Parameters.AddWithValue("@Width", mapData.Width ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@ChildRelations", mapData.ChildRelations ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@FatherRelations", mapData.FatherRelations ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@FatherRelation", mapData.FatherRelation ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@ChildNodes", mapData.ChildNodes ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@FatherNode", mapData.FatherNode ?? (object)DBNull.Value);
command.Parameters.AddWithValue("@Details", mapData.Details ?? (object)DBNull.Value);
@ -90,7 +90,7 @@ namespace OMS.NET.DbClass
{
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
connection.Open();
var query = @"SELECT id, type, points, point, color, phase, width, child_relations, father_relations, child_nodes, father_node, details, custom
var query = @"SELECT id, type, points, point, color, phase, width, child_relations, father_relation, child_nodes, father_node, details, custom
FROM map_0_data WHERE id = @Id";
using MySqlCommand command = new(query, connection);
command.Parameters.AddWithValue("@Id", id);
@ -107,7 +107,7 @@ namespace OMS.NET.DbClass
Phase = reader.GetInt32("phase"),
Width = reader["width"] as int?,
ChildRelations = reader["child_relations"] as string,
FatherRelations = reader["father_relations"] as string,
FatherRelation = reader["father_relation"] as string,
ChildNodes = reader["child_nodes"] as string,
FatherNode = reader["father_node"] as string,
Details = reader["details"] as string,
@ -139,7 +139,7 @@ namespace OMS.NET.DbClass
Phase = reader.GetInt32("phase"),
Width = reader.IsDBNull(reader.GetOrdinal("width")) ? (int?)null : reader.GetInt32("width"),
ChildRelations = reader.IsDBNull(reader.GetOrdinal("child_relations")) ? null : reader.GetString("child_relations"),
FatherRelations = reader.IsDBNull(reader.GetOrdinal("father_relations")) ? null : reader.GetString("father_relations"),
FatherRelation = reader.IsDBNull(reader.GetOrdinal("father_relation")) ? null : reader.GetString("father_relation"),
ChildNodes = reader.IsDBNull(reader.GetOrdinal("child_nodes")) ? null : reader.GetString("child_nodes"),
FatherNode = reader.IsDBNull(reader.GetOrdinal("father_node")) ? null : reader.GetString("father_node"),
Details = reader.IsDBNull(reader.GetOrdinal("details")) ? null : reader.GetString("details"),

@ -21,18 +21,19 @@ namespace OMS.NET.Instructs
if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查
try
{
char[] charsToTrim = { '"' };
long id = Data.GetProperty("id").GetInt64();
string type = Data.GetProperty("type").GetString();
string points = Data.GetProperty("points").GetString();
string point = Data.GetProperty("point").GetString();
string? color = Data.GetProperty("color").GetString();
string type = Data.GetProperty("type").GetRawText().Trim(charsToTrim);
string points = Data.GetProperty("points").GetRawText();
string point = Data.GetProperty("point").GetRawText().Trim(charsToTrim);
string? color = Data.GetProperty("color").GetRawText().Trim(charsToTrim);
int? width = Data.GetProperty("width").GetInt32();
string? childRelations = Data.GetProperty("childRelations").GetString();
string? fatherRelations = Data.GetProperty("fatherRelations").GetString();
string? childNodes = Data.GetProperty("childNodes").GetString();
string? fatherNode = Data.GetProperty("fatherNode").GetString();
string? details = Data.GetProperty("details").GetString();
string? custom = Data.GetProperty("custom").GetString();
// string? childRelations = Data.GetProperty("childRelations").GetString();
// string? fatherRelation = Data.GetProperty("fatherRelation").GetString();
// string? childNodes = Data.GetProperty("childNodes").GetString();
// string? fatherNode = Data.GetProperty("fatherNode").GetString();
string? details = Data.GetProperty("details").GetRawText().Trim(charsToTrim);
string? custom = Data.GetProperty("custom").GetRawText().Trim(charsToTrim);
//validations todo
//假设所有数据均合法
MapData mapData = new()
@ -42,10 +43,10 @@ namespace OMS.NET.Instructs
Point = Util.JsonToBase64(point),
Color = color,
Width = width,
ChildRelations = childRelations,
FatherRelations = fatherRelations,
ChildNodes = childNodes,
FatherNode = fatherNode,
// ChildRelations = childRelations,
// FatherRelation = fatherRelation,
// ChildNodes = childNodes,
// FatherNode = fatherNode,
Details = Util.JsonToBase64(details),
Custom = Util.JsonToBase64(custom)
};

@ -31,7 +31,8 @@ namespace OMS.NET.Instructs
max_zoom = GlobalArea.ServerConfig.MaxZoom,
min_zoom = GlobalArea.ServerConfig.MinZoom,
default_zoom = GlobalArea.ServerConfig.DefaultZoom,
base_map_url = GlobalArea.ServerConfig.BaseMapUrl
base_map_url = GlobalArea.ServerConfig.BaseMapUrl,
base_map_type = GlobalArea.ServerConfig.ServerConfigBaseMapType
}
});
});

@ -1,4 +1,5 @@
using System.Globalization;
using System.Text.Json;
using WebSocketSharp;
namespace OMS.NET.Instructs
@ -14,43 +15,52 @@ namespace OMS.NET.Instructs
{
return Task.Run(() =>
{
if (Time != null)
if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查
try
{
//时间解析
string format = "yyyy-MM-dd HH:mm:ss";
DateTime clientDateTime = DateTime.ParseExact(Time, format, CultureInfo.InvariantCulture);
//Console.WriteLine("Converted DateTime: " + clientDateTime);
string serverImgPath = GlobalArea.ServerConfig.Img;
if (File.Exists(serverImgPath))
string time = Data.GetProperty("time").GetString();
if (time != null)
{
DateTime serverImgLastModified = File.GetLastWriteTime(serverImgPath);
Instruct res = new()
//时间解析
string format = "yyyy-MM-dd HH:mm:ss";
DateTime clientDateTime = DateTime.ParseExact(time, format, CultureInfo.InvariantCulture);
//Console.WriteLine("Converted DateTime: " + clientDateTime);
string serverImgPath = GlobalArea.ServerConfig.Img;
if (File.Exists(serverImgPath))
{
IsResponse = true,
Type = "send_serverImg"
};
if (serverImgLastModified > clientDateTime)
{
byte[] imageBytes = File.ReadAllBytes(serverImgPath);
string imageFileType = GetImageFileType(imageBytes);
string base64String = $"data:image/{imageFileType};base64," + Convert.ToBase64String(imageBytes);
//Console.WriteLine("Base64 Encoded Image: " + base64String);
res.Data = new
DateTime serverImgLastModified = File.GetLastWriteTime(serverImgPath);
Instruct res = new()
{
@string = base64String,
time = serverImgLastModified.ToString(format),
IsResponse = true,
Type = "send_serverImg"
};
}
else
{
res.Data = new
if (serverImgLastModified > clientDateTime)
{
@string = ""
};
byte[] imageBytes = File.ReadAllBytes(serverImgPath);
string imageFileType = GetImageFileType(imageBytes);
string base64String = $"data:image/{imageFileType};base64," + Convert.ToBase64String(imageBytes);
res.Data = new
{
@string = base64String,
time = serverImgLastModified.ToString(format),
};
}
else
{
res.Data = new
{
@string = ""
};
}
ResponseOrBroadcastInstructs.Add(res);
}
ResponseOrBroadcastInstructs.Add(res);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
});
}

@ -23,11 +23,15 @@ namespace OMS.NET.Instructs
{
long id = Data.GetProperty("id").GetInt64();
string updateId = Data.GetProperty("updateId").GetString();
string points = Data.GetProperty("points").GetString()!;
string point = Data.GetProperty("point").GetString()!;
string points = Data.GetProperty("points").GetRawText();//todo
MapData mapData = MapData.Get(id) ?? throw new Exception($"数据库中未能找到id为{id}的元素");
mapData.Points = Util.JsonToBase64(points);
mapData.Point = Util.JsonToBase64(point);
if (Data.TryGetProperty("point", out JsonElement pointNode))
{
mapData.Point = Util.JsonToBase64(pointNode.GetRawText());
}
if (MapData.Update(mapData) == -1) throw new Exception("数据库修改失败");
ResponseOrBroadcastInstructs.Add(new Instruct()

@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS map_0_data (
phase INT(1) NOT NULL,
width INT(11),
child_relations MEDIUMTEXT,
father_relations VARCHAR(255),
father_relation VARCHAR(255),
child_nodes MEDIUMTEXT,
father_node VARCHAR(255),
details MEDIUMTEXT,

Loading…
Cancel
Save