Compare commits
2 Commits
2e71f68428
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8daa1df8e9 | |||
| 7776e6c7ab |
@@ -9,7 +9,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ncalc" Version="1.3.8" />
|
<PackageReference Include="ncalc" Version="1.3.8" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.5-beta1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.5-beta1" />
|
||||||
<PackageReference Include="System.IO.Ports" Version="11.0.0-preview.4.26230.115" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ namespace MainModule.ViewModels
|
|||||||
string json = System.IO.File.ReadAllText(filePath);
|
string json = System.IO.File.ReadAllText(filePath);
|
||||||
Newtonsoft.Json.JsonConvert.PopulateObject(json, _systemConfig);
|
Newtonsoft.Json.JsonConvert.PopulateObject(json, _systemConfig);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_systemConfig = new SystemConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//容器解析顺序不要改变!!!
|
//容器解析顺序不要改变!!!
|
||||||
_scopedContext = _scope.Resolve<ScopedContext>();
|
_scopedContext = _scope.Resolve<ScopedContext>();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.215-preview13" />
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.215-preview13" />
|
||||||
<PackageReference Include="System.IO.Ports" Version="11.0.0-preview.4.26230.115" />
|
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -29,52 +29,7 @@ namespace UIShare.GlobalVariable
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// 根据标题(格子标识)加载独立的配置文件
|
|
||||||
/// </summary>
|
|
||||||
public static SystemConfig Load(string title)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(title))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("配置标题不能为空", nameof(title));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 临时实例化一个对象以获取默认的 SystemPath
|
|
||||||
var dummy = new SystemConfig();
|
|
||||||
string configPath = Path.Combine(dummy.SystemPath, $"{title}.json");
|
|
||||||
|
|
||||||
if (!File.Exists(configPath))
|
|
||||||
{
|
|
||||||
// 如果不存在,创建一个带 Title 的默认配置并保存
|
|
||||||
var defaultConfig = new SystemConfig { Title = title };
|
|
||||||
EnsureDefaultCanDevice(defaultConfig);
|
|
||||||
Save(defaultConfig);
|
|
||||||
return defaultConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_fileLock)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string json = File.ReadAllText(configPath);
|
|
||||||
var config = JsonConvert.DeserializeObject<SystemConfig>(json, new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
TypeNameHandling = TypeNameHandling.All
|
|
||||||
});
|
|
||||||
|
|
||||||
config ??= new SystemConfig { Title = title };
|
|
||||||
EnsureDefaultCanDevice(config);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LoggerHelper.ErrorWithNotify(title, $"格子 [{title}] 配置加载失败: {ex.Message}");
|
|
||||||
var fallback = new SystemConfig { Title = title };
|
|
||||||
EnsureDefaultCanDevice(fallback);
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存指定的配置实例
|
/// 保存指定的配置实例
|
||||||
|
|||||||
Reference in New Issue
Block a user