diff --git a/ShengShengBuXi.ConsoleApp/AutoRestart.bat b/ShengShengBuXi.ConsoleApp/AutoRestart.bat index 343a2ea..8a9b661 100644 --- a/ShengShengBuXi.ConsoleApp/AutoRestart.bat +++ b/ShengShengBuXi.ConsoleApp/AutoRestart.bat @@ -1,38 +1,75 @@ @echo off +chcp 936 setlocal enabledelayedexpansion -:: 配置参数 -set LOG_FILE=ShengShengBuXi.log -set MAX_LOG_SIZE=1048576 :: 最大日志大小1MB -set RESTART_DELAY=1 :: 重启延迟(秒) -set APP_NAME=ShengShengBuXi.ConsoleApp.exe +:: Debug mode +set DEBUG=1 -:: 初始化日志 -if not exist "%LOG_FILE%" ( - echo 日志创建时间: %date% %time% > "%LOG_FILE%" - echo ======================================= >> "%LOG_FILE%" +:: Configuration +set APP_NAME=ShengShengBuXi.ConsoleApp.exe +set LOG_FILE=%~dp0ShengShengBuXi.log +set RESTART_DELAY=0 + +:: Create log file +echo [%date% %time%] Batch file started > "%LOG_FILE%" +echo [%date% %time%] Current directory: %cd% >> "%LOG_FILE%" +echo [%date% %time%] Batch file directory: %~dp0 >> "%LOG_FILE%" + +echo [INFO] Checking environment... +echo [INFO] Current directory: %cd% +echo [INFO] Batch file directory: %~dp0 +echo [INFO] Checking program file... + +:: Check if program exists +if not exist "%~dp0%APP_NAME%" ( + echo [ERROR] Cannot find %APP_NAME% + echo [ERROR] Please make sure the batch file and program are in the same directory + echo [INFO] Directory listing: + dir + echo [ERROR] Program file not found >> "%LOG_FILE%" + pause + exit /b 1 ) +echo [INFO] Program file check passed +echo [INFO] Program file check passed >> "%LOG_FILE%" + :restart -:: 检查日志大小并轮转 -for %%F in ("%LOG_FILE%") do set LOG_SIZE=%%~zF -if !LOG_SIZE! gtr %MAX_LOG_SIZE% ( - echo 日志文件过大(!LOG_SIZE!字节),正在轮转... >> "%LOG_FILE%" - move /y "%LOG_FILE%" "ShengShengBuXi_%date:/=-%_%time::=-%.log" >nul - echo 新日志创建时间: %date% %time% > "%LOG_FILE%" - echo ======================================= >> "%LOG_FILE%" +:: Debug info +if defined DEBUG ( + echo [DEBUG] Current directory: %cd% + echo [DEBUG] Program path: %~dp0%APP_NAME% + echo [DEBUG] Log path: %LOG_FILE% + echo [INFO] Preparing to start program... + echo [INFO] Preparing to start program... >> "%LOG_FILE%" ) -:: 记录启动信息 -echo [%date% %time%] 启动 %APP_NAME% >> "%LOG_FILE%" +:: Log start +echo [%date% %time%] Starting %APP_NAME% >> "%LOG_FILE%" -:: 启动程序并重定向输出 -start /b /wait "%APP_NAME%" >> "%LOG_FILE%" 2>&1 +:: Start program +echo [INFO] Starting program... +echo [INFO] Starting program... >> "%LOG_FILE%" -:: 记录退出信息 -echo [%date% %time%] 程序退出,代码: !errorlevel! >> "%LOG_FILE%" -echo [%date% %time%] 将在 %RESTART_DELAY% 秒后重启... >> "%LOG_FILE%" +:: Run program with full path +"%~dp0%APP_NAME%" >> "%LOG_FILE%" 2>&1 -:: 延迟后重启 +:: Check exit status +set EXIT_CODE=%errorlevel% +echo [%date% %time%] Program exited with code: !EXIT_CODE! >> "%LOG_FILE%" + +if !EXIT_CODE! neq 0 ( + echo [WARNING] Program exited abnormally >> "%LOG_FILE%" + echo [WARNING] Program exited with code: !EXIT_CODE! + echo [INFO] Please check log file: %LOG_FILE% + echo Press any key to continue... + pause +) + +:: Restart delay +echo [%date% %time%] Restarting in %RESTART_DELAY% seconds... >> "%LOG_FILE%" +echo [INFO] Restarting in %RESTART_DELAY% seconds... timeout /t %RESTART_DELAY% /nobreak >nul -goto restart \ No newline at end of file + +goto restart + \ No newline at end of file diff --git a/ShengShengBuXi.ConsoleApp/Services/SignalRService.cs b/ShengShengBuXi.ConsoleApp/Services/SignalRService.cs index d8f878a..eb61d07 100644 --- a/ShengShengBuXi.ConsoleApp/Services/SignalRService.cs +++ b/ShengShengBuXi.ConsoleApp/Services/SignalRService.cs @@ -19,6 +19,10 @@ public class SignalRService : ISignalRService private bool _isInitialConnection = true; private const int MAX_RETRY_COUNT = 10; private const int RETRY_INTERVAL_MS = 1000; + private const int HEARTBEAT_INTERVAL_MS = 3000; // 3绉掑彂閫佷竴娆″績璺 + private Timer? _heartbeatTimer; + private DateTime _lastHeartbeatTime = DateTime.MinValue; + private const int HEARTBEAT_TIMEOUT_MS = 60000; // 60绉掓病鏈夊績璺冲氨璁や负鏂紑 /// /// 杩炴帴鐘舵佹敼鍙樹簨浠 @@ -74,9 +78,14 @@ public class SignalRService : ISignalRService _hubConnection = new HubConnectionBuilder() .WithUrl(hubUrl) - .WithAutomaticReconnect() + .WithAutomaticReconnect([TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3)]) .Build(); + // 鍚姩蹇冭烦瀹氭椂鍣 + _heartbeatTimer?.Dispose(); + _heartbeatTimer = new Timer(CheckHeartbeat, null, HEARTBEAT_INTERVAL_MS, HEARTBEAT_INTERVAL_MS); + _lastHeartbeatTime = DateTime.Now; + // 娉ㄥ唽杩炴帴鍏抽棴浜嬩欢 _hubConnection.Closed += async (error) => { @@ -189,6 +198,40 @@ public class SignalRService : ISignalRService } } + /// + /// 妫鏌ュ績璺 + /// + private async void CheckHeartbeat(object? state) + { + try + { + if (_hubConnection == null || _hubConnection.State != HubConnectionState.Connected) + { + return; + } + + // 妫鏌ヤ笂娆″績璺虫椂闂存槸鍚﹁秴鏃 + if ((DateTime.Now - _lastHeartbeatTime).TotalMilliseconds > HEARTBEAT_TIMEOUT_MS) + { + Console.WriteLine("蹇冭烦瓒呮椂锛岃繛鎺ュ彲鑳藉凡鏂紑"); + await _hubConnection.StopAsync(); + return; + } + + // 鍙戦佸績璺 + await RequestLatestConfigAsync(); + _lastHeartbeatTime = DateTime.Now; + } + catch (Exception ex) + { + Console.WriteLine($"蹇冭烦妫娴嬪け璐: {ex.Message}"); + if (_hubConnection != null) + { + await _hubConnection.StopAsync(); + } + } + } + /// /// 娉ㄥ唽涓烘帶鍒跺櫒瀹㈡埛绔 /// @@ -230,6 +273,10 @@ public class SignalRService : ISignalRService _clientId = null; ConnectionStateChanged?.Invoke(this, false); } + + // 鍋滄蹇冭烦瀹氭椂鍣 + _heartbeatTimer?.Dispose(); + _heartbeatTimer = null; } /// @@ -388,6 +435,11 @@ public class SignalRService : ISignalRService catch (Exception ex) { Console.WriteLine($"鑾峰彇鏈鏂伴厤缃け璐: {ex.Message}"); + // 濡傛灉鑾峰彇閰嶇疆澶辫触锛屽彲鑳芥槸杩炴帴宸叉柇寮 + if (_hubConnection != null) + { + await _hubConnection.StopAsync(); + } } } diff --git a/ShengShengBuXi.ConsoleApp/appsettings.json b/ShengShengBuXi.ConsoleApp/appsettings.json index 529168b..7700478 100644 --- a/ShengShengBuXi.ConsoleApp/appsettings.json +++ b/ShengShengBuXi.ConsoleApp/appsettings.json @@ -1,5 +1,5 @@ { - "SignalRHubUrl": "http://localhost:82/audiohub", + "SignalRHubUrl": "http://115.159.44.16/audiohub", "ConfigBackupPath": "config.json", "AutoConnectToServer": true, "AllowOfflineStart": false diff --git a/ShengShengBuXi/Pages/Index.cshtml b/ShengShengBuXi/Pages/Index.cshtml index 67c48ed..847bc05 100644 --- a/ShengShengBuXi/Pages/Index.cshtml +++ b/ShengShengBuXi/Pages/Index.cshtml @@ -140,18 +140,18 @@ fontSize: '40px', // 鍙充晶鏂囧瓧澶у皬 fontWeight: '700', // 鍙充晶鏂囧瓧绮楃粏 fontStyle: 'italic', // 鍙充晶鏂囧瓧鏍峰紡 - typewriterSpeed: 330 // 鍙充晶鏂囧瓧鎵撳瓧鏈洪熷害(姣)锛屽噺鎱㈠埌1/5 + typewriterSpeed: 2000 // 鍙充晶鏂囧瓧鎵撳瓧鏈洪熷害(姣)锛屽鍔犲埌2000姣 }, // 姘存尝绾规晥鏋滈厤缃 waterEffect: { enabled: true, // 鏄惁寮鍚按娉㈢汗 - minInterval: 1600, // 鏈灏忚Е鍙戦棿闅(姣)锛屽鍔犳椂闂 - maxInterval: 8000, // 鏈澶цЕ鍙戦棿闅(姣)锛屽鍔犳椂闂 - simultaneousDrops: 2, // 鍚屾椂瑙﹀彂鐨勬尝绾规暟閲忥紝鍑忓皯鍒2涓 - fadeOutSpeed: 2000, // 鏂囧瓧娓愰殣鏁堟灉鐨勯熷害(姣)锛屽師閫熷害鐨2鍊 - centerBias: 0.6, // 娑熸吉闈犺繎涓績鍖哄煙鐨勫亸濂藉(0-1)锛0涓洪殢鏈猴紝1涓哄彧鍦ㄤ腑蹇冨尯鍩 + minInterval: 1600, // 鏈灏忚Е鍙戦棿闅(姣) + maxInterval: 8000, // 鏈澶цЕ鍙戦棿闅(姣) + simultaneousDrops: 2, // 鍚屾椂瑙﹀彂鐨勬尝绾规暟閲 + fadeOutSpeed: 5000, // 鏂囧瓧娓愰殣鏁堟灉鐨勯熷害(姣)锛屽鍔犲埌5000姣 + centerBias: 0.6, // 娑熸吉闈犺繎涓績鍖哄煙鐨勫亸濂藉(0-1) largeDrop: { - probability: 0.2, // 澶ф稛婕嚭鐜扮殑姒傜巼闄嶄綆鍒0.2 + probability: 0.2, // 澶ф稛婕嚭鐜扮殑姒傜巼 size: 80 // 澶ф稛婕殑澶у皬 } }, @@ -266,7 +266,7 @@ // 鏁存潯鏂囧瓧娓愭樉鏁堟灉 newP.animate( { opacity: 1 }, - 1500, // 璁剧疆鍔ㄧ敾鏃堕暱涓1.5绉 + 2000, // 璁剧疆鍔ㄧ敾鏃堕暱涓2绉 'swing' ); return true; diff --git a/ShengShengBuXi/config/display.json b/ShengShengBuXi/config/display.json index 7ca6e58..f89ff55 100644 --- a/ShengShengBuXi/config/display.json +++ b/ShengShengBuXi/config/display.json @@ -2,20 +2,20 @@ "leftContainer": { "turnPageHeight": 0.5, "fontSize": "16px", - "typewriterSpeed": 50 + "typewriterSpeed": 300 }, "rightContainer": { "fontSize": "40px", "fontWeight": "bolder", "fontStyle": "italic", - "typewriterSpeed": 330 + "typewriterSpeed": 500 }, "waterEffect": { "enabled": true, "minInterval": 1600, "maxInterval": 8000, "simultaneousDrops": 2, - "fadeOutSpeed": 2000, + "fadeOutSpeed": 1200, "centerBias": 0.6, "largeDrop": { "probability": 0.2,