LANCommander/LANCommander.SDK/Clients/ScriptClient.cs

53 lines
1.8 KiB
C#
Raw Permalink Normal View History

using LANCommander.SDK.Extensions;
using LANCommander.SDK.Helpers;
2024-08-05 20:29:12 -05:00
using LANCommander.SDK.Models;
using LANCommander.SDK.PowerShell;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Linq;
using System.Threading;
2024-08-05 20:29:12 -05:00
using System.Threading.Tasks;
using LANCommander.SDK.Abstractions;
using Microsoft.Extensions.DependencyInjection;
2024-08-05 20:29:12 -05:00
namespace LANCommander.SDK.Services
2024-08-05 20:29:12 -05:00
{
2026-02-10 17:34:35 -06:00
public partial class ScriptClient(
ILogger<ScriptClient> logger,
IServiceProvider serviceProvider,
ISettingsProvider settingsProvider,
PowerShellScriptFactory powerShellScriptFactory,
IConnectionClient connectionClient)
2024-08-05 20:29:12 -05:00
{
public bool Debug { get; set; }
private static bool SupportsCurrentRuntime(System.Collections.Generic.IEnumerable<SDK.Models.Manifest.Script> scripts, Enums.ScriptType type)
{
var platforms = scripts?.FirstOrDefault(s => s.Type == type)?.Platforms ?? Enums.RuntimePlatform.None;
return EnvironmentHelper.SupportsCurrentRuntime(platforms);
}
private static bool SupportsCurrentRuntime(System.Collections.Generic.IEnumerable<SDK.Models.Script> scripts, Enums.ScriptType type)
{
var platforms = scripts?.FirstOrDefault(s => s.Type == type)?.Platforms ?? Enums.RuntimePlatform.None;
return EnvironmentHelper.SupportsCurrentRuntime(platforms);
}
private async Task<bool> RunScriptExternallyAsync(PowerShellScript script)
{
var scriptRunners = serviceProvider.GetServices<IScriptInterceptor>();
foreach (var scriptRunner in scriptRunners)
{
if (await scriptRunner.ExecuteAsync(script))
return true;
}
return false;
}
2024-08-05 20:29:12 -05:00
}
}