消除IDE报警
This commit is contained in:
parent
f923971391
commit
a7a097e952
@ -38,12 +38,12 @@ namespace PLCSharp
|
||||
ForegroundWindow();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
LoadConfig();
|
||||
//数据库
|
||||
_ = containerRegistry.RegisterSingleton<DatasContext>();
|
||||
_ = Container.Resolve<DatasContext>();
|
||||
|
||||
RegisterEvents(); // 捕获全局异常
|
||||
LoadConfig();
|
||||
|
||||
//Module中的初始化晚于这里,所以不能在Module中注册全局使用的实例,比如NavigateModel
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ namespace PLCSharp.Core.Tools
|
||||
PointsQueue.TryDequeue(out PointF point);
|
||||
Points.Add(point);
|
||||
}
|
||||
await Application.Current?.Dispatcher.BeginInvoke(() =>
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
WriteableBitmap writeableBitmap = _imgSource;
|
||||
int width = (int)writeableBitmap.Width;
|
||||
@ -89,7 +89,7 @@ namespace PLCSharp.Core.Tools
|
||||
public static System.Windows.Media.Color GetRandColor(int start = 0, int end = 256)
|
||||
{
|
||||
// 创建一个Random对象
|
||||
Random random = new Random();
|
||||
Random random = new();
|
||||
|
||||
// 生成一个0到255之间的随机整数作为红色分量
|
||||
byte red = Convert.ToByte(random.Next(start, end));
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using Prism.Mvvm;
|
||||
|
||||
@ -73,7 +73,7 @@ namespace PLCSharp.Core.Tools
|
||||
return to;
|
||||
}
|
||||
|
||||
public bool Equals(XPoint other)
|
||||
public bool Equals(XPoint? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
// 避免浮点数精度问题,通常使用一个极小值 Epsilon 进行比较
|
||||
|
||||
@ -7,7 +7,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Style", "IDE1006:命名样式")]
|
||||
[assembly: SuppressMessage("Style", "IDE0290:使用主构造函数")]
|
||||
[assembly: SuppressMessage("Performance", "SYSLIB1045:转换为“GeneratedRegexAttribute”。")]
|
||||
[assembly: SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<挂起>", Scope = "member", Target = "~M:PLCSharp.VVMs.Workflows.Script.CustomTextEditor.OnDataContextChanged(System.Object,System.Windows.DependencyPropertyChangedEventArgs)")]
|
||||
[assembly: SuppressMessage("Usage", "VSTHRD001:Avoid legacy thread switching APIs")]
|
||||
[assembly: SuppressMessage("Style", "IDE0305:简化集合初始化")]
|
||||
[assembly: SuppressMessage("Usage", "VSTHRD003:Avoid awaiting foreign Tasks")]
|
||||
[assembly: SuppressMessage("Usage", "VSTHRD001:Avoid legacy thread switching APIs")]
|
||||
|
||||
@ -21,19 +21,16 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.17" />
|
||||
<PackageReference Include="MiniExcel" Version="1.45.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
<PackageReference Include="OpenCvSharp5.Windows" Version="5.0.0.20260713" />
|
||||
<PackageReference Include="OpenCvSharp5.Windows" Version="5.0.0.20260718" />
|
||||
<PackageReference Include="Prism.DryIoc" Version="9.0.537" />
|
||||
<PackageReference Include="RoslynPad.Editor.Windows" Version="5.0.0" />
|
||||
<!--<PackageReference Include="SourceGear.sqlite3" Version="3.50.4.5" />-->
|
||||
<!--<PackageReference Include="SqlSugarCore" Version="5.1.4.214" />-->
|
||||
<PackageReference Include="System.IO.Ports" Version="10.0.9" />
|
||||
<PackageReference Include="System.IO.Ports" Version="10.0.10" />
|
||||
<!-- 覆盖传递依赖 SQLitePCLRaw.lib.e_sqlite3 至修复版本 3.50.3(CVE-2025-6965,2.x 全部受影响且已弃用) -->
|
||||
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.50.3" />
|
||||
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.53.3" />
|
||||
<PackageReference Include="ZXing.Net" Version="0.16.11" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="SDK\Camera\MvCameraControl.Net.dll">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
@ -29,7 +29,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
|
||||
|
||||
/// <summary>打开串口</summary>
|
||||
public bool Open()
|
||||
public override void Open()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -42,13 +42,13 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
_port.Open();
|
||||
Connected = true;
|
||||
Log($"串口 {IP_SerialPort} 已打开");
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"打开串口失败: {ex.Message}");
|
||||
Connected = false;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title => "Modbus RTU 客户端";
|
||||
public static string Title => "Modbus RTU 客户端";
|
||||
|
||||
/// <summary>
|
||||
/// Request关闭
|
||||
@ -180,7 +180,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
{
|
||||
if (Client.LogQueue.TryDequeue(out string log))
|
||||
{
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
Logs.Add(new ErrorLog(log));
|
||||
}));
|
||||
|
||||
@ -31,7 +31,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
|
||||
private readonly ConnectsModel _ConnectsModel;
|
||||
private string _Title = "Modbus TCP 客户端";
|
||||
private bool _hasSubscribedCollection;
|
||||
|
||||
/// <summary>
|
||||
/// 标题
|
||||
@ -97,7 +96,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
{
|
||||
if (Client.LogQueue.TryDequeue(out string log))
|
||||
{
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
Logs.Add(new ErrorLog(log));
|
||||
}));
|
||||
|
||||
@ -200,7 +200,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
{
|
||||
if (Server.LogQueue.TryDequeue(out string log))
|
||||
{
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
Logs.Add(new ErrorLog(log));
|
||||
}));
|
||||
|
||||
@ -102,7 +102,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
{
|
||||
if (Client.LogQueue.TryDequeue(out string log))
|
||||
{
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
Logs.Add(new ErrorLog(log));
|
||||
}));
|
||||
|
||||
@ -102,7 +102,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
if ((Client as SocketClient).LogQueue.TryDequeue(out string log))
|
||||
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
Logs.Add(new ErrorLog(log));
|
||||
}));
|
||||
|
||||
@ -107,7 +107,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
if (!(Server as SocketServer).LogQueue.IsEmpty)
|
||||
{
|
||||
if ((Server as SocketServer).LogQueue.TryDequeue(out string log))
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
Logs.Add(new ErrorLog(log));
|
||||
}));
|
||||
|
||||
@ -214,7 +214,7 @@ namespace PLCSharp.VVMs.Homepage
|
||||
}
|
||||
private static void Dispatch(Action action)
|
||||
{
|
||||
_= Application.Current.Dispatcher.BeginInvoke(action);
|
||||
_= Application.Current.Dispatcher.InvokeAsync(action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using Prism.Mvvm;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using Prism.Mvvm;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
@ -23,7 +24,7 @@ namespace PLCSharp.VVMs.Robots
|
||||
/// </summary>
|
||||
public Guid RobotID { get; set; }
|
||||
|
||||
private string _Name;
|
||||
private string _Name = "";
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
@ -33,7 +34,7 @@ namespace PLCSharp.VVMs.Robots
|
||||
set { SetProperty(ref _Name, value); }
|
||||
}
|
||||
|
||||
private string _StartName;
|
||||
private string _StartName = "";
|
||||
/// <summary>
|
||||
/// 首点名(原点 (0,0))
|
||||
/// </summary>
|
||||
@ -43,7 +44,7 @@ namespace PLCSharp.VVMs.Robots
|
||||
set { SetProperty(ref _StartName, value); }
|
||||
}
|
||||
|
||||
private string _XEndName;
|
||||
private string _XEndName = "";
|
||||
/// <summary>
|
||||
/// X方向尾点名((XCount-1, 0))
|
||||
/// </summary>
|
||||
@ -53,7 +54,7 @@ namespace PLCSharp.VVMs.Robots
|
||||
set { SetProperty(ref _XEndName, value); }
|
||||
}
|
||||
|
||||
private string _YEndName;
|
||||
private string _YEndName = "";
|
||||
/// <summary>
|
||||
/// Y方向尾点名((0, YCount-1))
|
||||
/// </summary>
|
||||
|
||||
@ -46,7 +46,7 @@ namespace PLCSharp.VVMs.Vision.Camera
|
||||
{
|
||||
SetProperty(ref _ShowMat, value);
|
||||
if (value == null) return;
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
if (_ImgSrc != null
|
||||
&& _ShowMat.Width == _ImgSrc.PixelWidth
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Prism.Mvvm;
|
||||
|
||||
|
||||
namespace PLCSharp.VVMs.Vision
|
||||
{
|
||||
/// <summary>
|
||||
@ -8,7 +8,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
/// </summary>
|
||||
public class LocalVariableItem : BindableBase
|
||||
{
|
||||
private string _Name;
|
||||
private string _Name = "";
|
||||
/// <summary>
|
||||
/// 变量名称
|
||||
/// </summary>
|
||||
@ -18,7 +18,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
set { SetProperty(ref _Name, value); }
|
||||
}
|
||||
|
||||
private string _VarType;
|
||||
private string _VarType = "";
|
||||
/// <summary>
|
||||
/// 变量类型:Point / Line / Circle / Rect / Double
|
||||
/// </summary>
|
||||
@ -28,7 +28,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
set { SetProperty(ref _VarType, value); }
|
||||
}
|
||||
|
||||
private string _StrValue;
|
||||
private string _StrValue = "";
|
||||
[JsonIgnore]
|
||||
public string StrValue
|
||||
{
|
||||
@ -36,11 +36,11 @@ namespace PLCSharp.VVMs.Vision
|
||||
set { SetProperty(ref _StrValue, value); }
|
||||
}
|
||||
|
||||
private object? _RawValue;
|
||||
private object _RawValue = "";
|
||||
/// <summary>
|
||||
/// 原始值
|
||||
/// </summary>
|
||||
public object? RawValue
|
||||
public object RawValue
|
||||
{
|
||||
get { return _RawValue; }
|
||||
set
|
||||
@ -58,6 +58,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == null) break ;
|
||||
r = JsonConvert.DeserializeObject<Pos>(value.ToString());
|
||||
}
|
||||
SetProperty(ref _RawValue, r);
|
||||
@ -72,6 +73,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == null) break;
|
||||
r = JsonConvert.DeserializeObject<Line>(value.ToString());
|
||||
}
|
||||
SetProperty(ref _RawValue, r);
|
||||
@ -86,6 +88,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == null) break;
|
||||
r = JsonConvert.DeserializeObject<Circle>(value.ToString());
|
||||
}
|
||||
SetProperty(ref _RawValue, r);
|
||||
@ -100,6 +103,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == null) break;
|
||||
r = JsonConvert.DeserializeObject<Rect>(value.ToString());
|
||||
}
|
||||
|
||||
@ -118,6 +122,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value == null) break;
|
||||
r = JsonConvert.DeserializeObject<Barcode>(value.ToString());
|
||||
}
|
||||
|
||||
@ -133,9 +138,9 @@ namespace PLCSharp.VVMs.Vision
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,25 +177,25 @@ namespace PLCSharp.VVMs.Vision
|
||||
return $"位置(X:{pt.X:F4}, Y:{pt.Y:F4}), 角度:({pt.Angle:F4})";
|
||||
else
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
|
||||
case "Line":
|
||||
if (val is Line line)
|
||||
return $"(X:{line.From.X:F4}, Y:{line.From.Y:F4}) -> (X:{line.To.X:F4}, Y:{line.To.Y:F4})";
|
||||
else
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
|
||||
case "Circle":
|
||||
if (val is Circle c)
|
||||
return $"中心(X:{c.Center.X:F4} Y:{c.Center.Y:F4}) 半径=({c.Radius:F4})";
|
||||
else
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
|
||||
case "Rect":
|
||||
if (val is Rect r)
|
||||
return $"中心:(X:{r.Center.X:F4}, Y:{r.Center.Y:F4}) 宽高:({r.Width:F4} × {r.Height:F4}) 角度:({r.Center.Angle:F4})";
|
||||
else
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
|
||||
case "Double":
|
||||
return ((double)val).ToString("F4");
|
||||
|
||||
|
||||
@ -285,7 +285,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
{
|
||||
SetProperty(ref _ShowMat, value);
|
||||
if (value == null) return;
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
public bool Execute(VisionFunction func, VisionFlow item)
|
||||
{
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
func.DrawCommands.Clear();
|
||||
func.EditImageEdit?.Remove("DrawOverlay");
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using OpenCvSharp;
|
||||
using PLCSharp.Core.Common;
|
||||
@ -17,7 +17,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 视觉功能的执行单元,包含流程步骤列表(VisionFlows)、参数集合(Params)和运行时图像缓存
|
||||
/// </summary>
|
||||
@ -350,7 +350,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
public List<DrawCommand> DrawCommands { get; set; } = [];
|
||||
public async Task RenderDrawAsync()
|
||||
{
|
||||
await System.Windows.Application.Current.Dispatcher.BeginInvoke(() =>
|
||||
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
if (DrawCommands == null || DrawCommands.Count <= 0) return;
|
||||
var commands = DrawCommands.ToList();
|
||||
|
||||
@ -43,7 +43,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
{
|
||||
SetProperty(ref _ShowMat, value);
|
||||
if (value == null) return;
|
||||
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
_ = System.Windows.Application.Current.Dispatcher.InvokeAsync(new Action(() =>
|
||||
{
|
||||
if (_ImgSrc != null
|
||||
&& _ShowMat.Width == _ImgSrc.PixelWidth
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
using ICSharpCode.AvalonEdit.Editing;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
@ -85,38 +85,51 @@ namespace PLCSharp.VVMs.Workflows.Script
|
||||
Focus();
|
||||
}
|
||||
#nullable enable
|
||||
#pragma warning disable IDE0079 // 请删除不必要的忽略
|
||||
#pragma warning disable VSTHRD100 // Avoid async void methods
|
||||
private async void OnDataContextChanged(object? sender, DependencyPropertyChangedEventArgs args)
|
||||
#pragma warning restore VSTHRD100 // Avoid async void methods
|
||||
#pragma warning restore IDE0079 // 请删除不必要的忽略
|
||||
{
|
||||
var workingDirectory = Directory.GetCurrentDirectory();
|
||||
try
|
||||
{
|
||||
|
||||
_host = new CustomRoslynHost(additionalAssemblies:
|
||||
[
|
||||
Assembly.Load("RoslynPad.Roslyn.Windows"),
|
||||
var workingDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
_host = new CustomRoslynHost(additionalAssemblies:
|
||||
[
|
||||
Assembly.Load("RoslynPad.Roslyn.Windows"),
|
||||
Assembly.Load("RoslynPad.Editor.Windows"),
|
||||
|
||||
],
|
||||
RoslynHostReferences.NamespaceDefault.With(assemblyReferences:
|
||||
[
|
||||
typeof(object).Assembly,
|
||||
RoslynHostReferences.NamespaceDefault.With(assemblyReferences:
|
||||
[
|
||||
typeof(object).Assembly,
|
||||
typeof(Mat).Assembly,
|
||||
typeof(App).Assembly,
|
||||
]
|
||||
));
|
||||
]
|
||||
));
|
||||
|
||||
|
||||
var documentId = await InitializeAsync(_host, new ClassificationHighlightColors(),
|
||||
workingDirectory, string.Empty, SourceCodeKind.Script);
|
||||
var documentId = await InitializeAsync(_host, new ClassificationHighlightColors(),
|
||||
workingDirectory, string.Empty, SourceCodeKind.Script);
|
||||
|
||||
_document = _host.GetDocument(documentId);
|
||||
_document = _host.GetDocument(documentId);
|
||||
|
||||
// 如果有初始化前暂存的文本,现在应用
|
||||
if (_pendingText != null && Document != null)
|
||||
// 如果有初始化前暂存的文本,现在应用
|
||||
if (_pendingText != null && Document != null)
|
||||
{
|
||||
Document.Text = _pendingText;
|
||||
Text = _pendingText;
|
||||
_pendingText = null;
|
||||
}
|
||||
|
||||
} // 原有的代码
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
Document.Text = _pendingText;
|
||||
Text = _pendingText;
|
||||
_pendingText = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
@ -210,7 +223,7 @@ namespace PLCSharp.VVMs.Workflows.Script
|
||||
set => SetValue(FontSizeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty =
|
||||
public new static readonly DependencyProperty FontSizeProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(FontSize),
|
||||
typeof(double),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user