begin application build overhaul
This commit is contained in:
41
Services/AttachService.cs
Normal file
41
Services/AttachService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using UnifiedFarmLauncher.Models;
|
||||
|
||||
namespace UnifiedFarmLauncher.Services
|
||||
{
|
||||
public class AttachService
|
||||
{
|
||||
private readonly SshService _sshService;
|
||||
private readonly WorkerControllerService _controllerService;
|
||||
|
||||
public AttachService(SshService sshService, WorkerControllerService controllerService)
|
||||
{
|
||||
_sshService = sshService;
|
||||
_controllerService = controllerService;
|
||||
}
|
||||
|
||||
public async Task AttachToWorkerAsync(WorkerConfig worker, string workerType, bool commandOnly = false, string? command = null)
|
||||
{
|
||||
await _controllerService.DeployAttachHelperAsync(worker);
|
||||
|
||||
var remoteBasePath = await _sshService.GetWorkerBasePathAsync(worker);
|
||||
var remoteHelper = $"{remoteBasePath.Replace("\\", "/")}/attach-helper.ps1";
|
||||
|
||||
var paramsBlock = $"-WorkerName \"{worker.Name}\" -WorkerType \"{workerType}\"";
|
||||
if (commandOnly)
|
||||
{
|
||||
paramsBlock += " -CommandOnly";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(command))
|
||||
{
|
||||
paramsBlock += $" -Command \"{command}\"";
|
||||
}
|
||||
|
||||
var remoteCmd = $"powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -File \"{remoteHelper}\" {paramsBlock}";
|
||||
|
||||
_sshService.StartInteractiveSsh(worker, remoteCmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user