更新密码数据123
This commit is contained in:
@@ -44,9 +44,11 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
private static readonly TimeSpan ResetButtonPendingTimeout = TimeSpan.FromMilliseconds(800);
|
||||
private static readonly TimeSpan TestButtonPendingTimeout = TimeSpan.FromSeconds(5);
|
||||
private static readonly TimeSpan RealtimeCurveTraceInterval = TimeSpan.FromSeconds(1);
|
||||
private static readonly TimeSpan LicenseCheckInterval = TimeSpan.FromMinutes(1);
|
||||
|
||||
private readonly SlipResistanceDeviceService deviceService = new();
|
||||
private readonly SlipExcelExportService excelExportService = new();
|
||||
private readonly MachineLicenseService licenseService;
|
||||
private readonly DispatcherTimer refreshTimer;
|
||||
private readonly Stopwatch runStopwatch = new();
|
||||
private readonly List<SlipDataPoint> currentRun = [];
|
||||
@@ -71,6 +73,12 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
private double slidingStartDisplacementMm;
|
||||
private double? slidingStartTimeSeconds;
|
||||
private int activeRunLubricantIndex;
|
||||
private DateTime lastLicenseCheckAt = DateTime.MinValue;
|
||||
private bool isLicenseLockPending;
|
||||
private bool licenseLockRequestedRaised;
|
||||
private string licenseLockMessage = string.Empty;
|
||||
|
||||
public event Action<string>? LicenseLockRequested;
|
||||
|
||||
[ObservableProperty]
|
||||
private string testNumber = $"SLIP-{DateTime.Now:yyyyMMdd-HHmm}";
|
||||
@@ -275,8 +283,13 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
}
|
||||
];
|
||||
|
||||
public MainWindowViewModel()
|
||||
public MainWindowViewModel() : this(new MachineLicenseService())
|
||||
{
|
||||
}
|
||||
|
||||
public MainWindowViewModel(MachineLicenseService licenseService)
|
||||
{
|
||||
this.licenseService = licenseService;
|
||||
Log.Information("初始化主页面 ViewModel");
|
||||
Series =
|
||||
[
|
||||
@@ -294,6 +307,7 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
refreshTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(20) };
|
||||
refreshTimer.Tick += (_, _) => RefreshFromDevice();
|
||||
refreshTimer.Start();
|
||||
RefreshLicenseState();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -325,7 +339,7 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
[RelayCommand]
|
||||
private async Task StartTest()
|
||||
{
|
||||
if (!IsTestButtonEnabled)
|
||||
if (!IsTestButtonEnabled || isLicenseLockPending)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -487,16 +501,16 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private Task LiftMotion() => RunDeviceCommand(deviceService.ApplyOldLiftAsync(), "提升按老代码逻辑执行:M4=0, M5=1");
|
||||
private Task LiftMotion() => RunLicensedDeviceCommand(deviceService.ApplyOldLiftAsync, "提升按老代码逻辑执行:M4=0, M5=1");
|
||||
|
||||
[RelayCommand]
|
||||
private Task LowerMotion() => RunDeviceCommand(deviceService.ApplyOldLowerAsync(), "下降按老代码逻辑执行:M5=0, M4=1");
|
||||
private Task LowerMotion() => RunLicensedDeviceCommand(deviceService.ApplyOldLowerAsync, "下降按老代码逻辑执行:M5=0, M4=1");
|
||||
|
||||
[RelayCommand]
|
||||
private Task MoveLeftMotion() => RunDeviceCommand(deviceService.ToggleOldMoveLeftAsync(), "左移按老代码逻辑切换 M1");
|
||||
private Task MoveLeftMotion() => RunLicensedDeviceCommand(deviceService.ToggleOldMoveLeftAsync, "左移按老代码逻辑切换 M1");
|
||||
|
||||
[RelayCommand]
|
||||
private Task MoveRightMotion() => RunDeviceCommand(deviceService.ToggleOldMoveRightAsync(), "右移按老代码逻辑切换 M2");
|
||||
private Task MoveRightMotion() => RunLicensedDeviceCommand(deviceService.ToggleOldMoveRightAsync, "右移按老代码逻辑切换 M2");
|
||||
|
||||
public Task StopAllMotionAsync() => RunDeviceCommand(deviceService.StopAllMotionAsync(), "全部运动已停止");
|
||||
|
||||
@@ -624,9 +638,24 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
deviceService.Dispose();
|
||||
}
|
||||
|
||||
public void RefreshLicenseState()
|
||||
{
|
||||
var check = licenseService.Check(updateHeartbeat: true);
|
||||
lastLicenseCheckAt = DateTime.UtcNow;
|
||||
isLicenseLockPending = !check.CanUseSoftware;
|
||||
licenseLockMessage = check.Message;
|
||||
if (!isLicenseLockPending)
|
||||
{
|
||||
licenseLockRequestedRaised = false;
|
||||
}
|
||||
|
||||
UpdateTestButtonState(deviceService.CurrentSnapshot);
|
||||
}
|
||||
|
||||
private void RefreshFromDevice()
|
||||
{
|
||||
var device = deviceService.CurrentSnapshot;
|
||||
CheckRuntimeLicense(device);
|
||||
if (device.IsConnected)
|
||||
{
|
||||
DeviceStatus = device.IsTestRunning ? "联机 / 测试中" : device.IsResetting ? "联机 / 复位中" : "联机 / 待机";
|
||||
@@ -699,6 +728,14 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
|
||||
private void UpdateTestButtonState(SlipDeviceSnapshot device)
|
||||
{
|
||||
if (isLicenseLockPending)
|
||||
{
|
||||
ClearTestButtonFeedback();
|
||||
TestButtonText = "授权到期";
|
||||
IsTestButtonEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (device.IsTestRunning)
|
||||
{
|
||||
ClearTestButtonFeedback();
|
||||
@@ -720,6 +757,26 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
IsTestButtonEnabled = true;
|
||||
}
|
||||
|
||||
private void CheckRuntimeLicense(SlipDeviceSnapshot device)
|
||||
{
|
||||
if (DateTime.UtcNow - lastLicenseCheckAt >= LicenseCheckInterval)
|
||||
{
|
||||
var check = licenseService.Check(updateHeartbeat: true);
|
||||
lastLicenseCheckAt = DateTime.UtcNow;
|
||||
isLicenseLockPending = !check.CanUseSoftware;
|
||||
licenseLockMessage = check.Message;
|
||||
}
|
||||
|
||||
if (isLicenseLockPending
|
||||
&& !device.IsTestRunning
|
||||
&& !device.IsResetting
|
||||
&& !licenseLockRequestedRaised)
|
||||
{
|
||||
licenseLockRequestedRaised = true;
|
||||
LicenseLockRequested?.Invoke(licenseLockMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginResetButtonFeedback()
|
||||
{
|
||||
isResetButtonPending = true;
|
||||
@@ -1313,6 +1370,17 @@ namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private Task RunLicensedDeviceCommand(Func<Task> command, string successMessage)
|
||||
{
|
||||
if (isLicenseLockPending)
|
||||
{
|
||||
CurrentStatus = "软件使用时效已到,仅允许停止或复位设备。";
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
return RunDeviceCommand(command(), successMessage);
|
||||
}
|
||||
|
||||
private void WriteNumericSetting(string value, Func<double, Task> writer, string label)
|
||||
{
|
||||
if (isLoadingDeviceSettings || !TryParseDouble(value, out var numericValue))
|
||||
|
||||
Reference in New Issue
Block a user