Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4fc8c047a | ||
|
|
5a2639f96c |
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.18
|
1.0.20
|
||||||
|
|||||||
@@ -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.18</AssemblyVersion>
|
<AssemblyVersion>1.0.20</AssemblyVersion>
|
||||||
<Version>1.0.18</Version>
|
<Version>1.0.20</Version>
|
||||||
<FileVersion>1.0.18</FileVersion>
|
<FileVersion>1.0.20</FileVersion>
|
||||||
<InformationalVersion>1.0.18</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;
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,16 @@ namespace MonsterMonitor.Services
|
|||||||
public void Start(AppSettings settings)
|
public void Start(AppSettings settings)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
Connect();
|
try
|
||||||
|
{
|
||||||
|
Connect();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Error("Не удалось запустить SSH-туннель с первого раза: " + ex.Message);
|
||||||
|
ReconnectSoon();
|
||||||
|
}
|
||||||
|
|
||||||
StartMonitor();
|
StartMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user