Compare commits

...
1 Commits
Author SHA1 Message Date
kislovdm a4fc8c047a auth
.NET Core Desktop / build (Debug) (push) Has been cancelled
2026-04-27 01:44:48 +03:00
4 changed files with 53 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.19 1.0.20
+4 -4
View File
@@ -6,10 +6,10 @@
<LangVersion>7.3</LangVersion> <LangVersion>7.3</LangVersion>
<RootNamespace>MonsterMonitor</RootNamespace> <RootNamespace>MonsterMonitor</RootNamespace>
<AssemblyName>devenv</AssemblyName> <AssemblyName>devenv</AssemblyName>
<AssemblyVersion>1.0.19</AssemblyVersion> <AssemblyVersion>1.0.20</AssemblyVersion>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<FileVersion>1.0.19</FileVersion> <FileVersion>1.0.20</FileVersion>
<InformationalVersion>1.0.19</InformationalVersion> <InformationalVersion>1.0.20</InformationalVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Costura.Fody" Version="6.0.0"> <PackageReference Include="Costura.Fody" Version="6.0.0">
@@ -10,6 +10,7 @@ namespace MonsterMonitor.Services
private readonly SsConfigService _ssConfig; private readonly SsConfigService _ssConfig;
private ProcessMonitorService _processMonitor; private ProcessMonitorService _processMonitor;
private SshTunnelService _sshTunnel; private SshTunnelService _sshTunnel;
private IAuthMonitor _authMonitor;
public AppController(LogService log, PowerManagementService power) public AppController(LogService log, PowerManagementService power)
{ {
@@ -25,10 +26,12 @@ namespace MonsterMonitor.Services
_power.PreventSleep(); _power.PreventSleep();
_processMonitor = new ProcessMonitorService(_log); _processMonitor = new ProcessMonitorService(_log);
_sshTunnel = new SshTunnelService(_log); _sshTunnel = new SshTunnelService(_log);
_authMonitor = new AuthMonitor(settings);
_ssConfig.EnsureConfig(settings); _ssConfig.EnsureConfig(settings);
_processMonitor.Start(settings.SsProcessPath, settings.SsArguments); _processMonitor.Start(settings.SsProcessPath, settings.SsArguments);
_sshTunnel.Start(settings); _sshTunnel.Start(settings);
_ = _authMonitor.StartMonitor();
_log.Info("Сервисы приложения запущены."); _log.Info("Сервисы приложения запущены.");
} }
@@ -38,6 +41,9 @@ namespace MonsterMonitor.Services
_sshTunnel?.Dispose(); _sshTunnel?.Dispose();
_sshTunnel = null; _sshTunnel = null;
_authMonitor?.StopMonitor();
_authMonitor = null;
_processMonitor?.Dispose(); _processMonitor?.Dispose();
_processMonitor = null; _processMonitor = null;
+42 -4
View File
@@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using MonsterMonitor.Models; using MonsterMonitor.Models;
@@ -20,6 +21,8 @@ namespace MonsterMonitor.Services
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private readonly AppSettings _settings; private readonly AppSettings _settings;
private CancellationTokenSource _monitorCancellation;
private Task _monitorTask;
public AuthMonitor(AppSettings settings) public AuthMonitor(AppSettings settings)
{ {
@@ -36,12 +39,39 @@ namespace MonsterMonitor.Services
public async Task StartMonitor() public async Task StartMonitor()
{ {
_ = Task.Run(async () => await CheckProcess()); StopMonitor();
_monitorCancellation = new CancellationTokenSource();
_monitorTask = Task.Run(async () => await CheckProcess(_monitorCancellation.Token));
await Task.CompletedTask;
} }
private async Task CheckProcess() public void StopMonitor()
{ {
while (true) if (_monitorCancellation == null)
{
return;
}
_monitorCancellation.Cancel();
try
{
_monitorTask?.Wait(TimeSpan.FromSeconds(1));
}
catch
{
// Ignore shutdown errors.
}
finally
{
_monitorCancellation.Dispose();
_monitorCancellation = null;
_monitorTask = null;
}
}
private async Task CheckProcess(CancellationToken token)
{
while (!token.IsCancellationRequested)
{ {
try try
{ {
@@ -70,7 +100,14 @@ namespace MonsterMonitor.Services
MessageBox.Show(ex.Message + ex.StackTrace); MessageBox.Show(ex.Message + ex.StackTrace);
} }
await Task.Delay(TimeSpan.FromSeconds(3)); try
{
await Task.Delay(TimeSpan.FromSeconds(3), token);
}
catch (TaskCanceledException)
{
break;
}
} }
} }
} }
@@ -78,5 +115,6 @@ namespace MonsterMonitor.Services
public interface IAuthMonitor public interface IAuthMonitor
{ {
Task StartMonitor(); Task StartMonitor();
void StopMonitor();
} }
} }