lots of using-statement fixes

This commit is contained in:
ThatBen 2025-01-16 13:51:29 +01:00
parent c73fa186fc
commit 9a227b3d0e
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
46 changed files with 178 additions and 129 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ obj
bin
.vscode
Tools/AutoClient/datapath
.editorconfig

View File

@ -9,15 +9,15 @@ namespace CodexClient
{
private readonly ILog log;
private readonly IFileManager fileManager;
private readonly ICodexHooksProvider hooksProvider;
private readonly CodexHooksFactory hooksFactor;
private readonly IHttpFactory httpFactory;
private readonly IIProcessControlFactory processControlFactory;
public CodexNodeFactory(ILog log, IFileManager fileManager, ICodexHooksProvider hooksProvider, IHttpFactory httpFactory, IIProcessControlFactory processControlFactory)
public CodexNodeFactory(ILog log, IFileManager fileManager, CodexHooksFactory hooksFactory, IHttpFactory httpFactory, IIProcessControlFactory processControlFactory)
{
this.log = log;
this.fileManager = fileManager;
this.hooksProvider = hooksProvider;
this.hooksFactor = hooksFactory;
this.httpFactory = httpFactory;
this.processControlFactory = processControlFactory;
}
@ -26,9 +26,11 @@ namespace CodexClient
{
var processControl = processControlFactory.CreateProcessControl(instance);
var access = new CodexAccess(log, httpFactory, processControl, instance);
var hooks = hooksProvider.CreateHooks(access.GetName());
var hooks = hooksFactor.CreateHooks(access.GetName());
var marketplaceAccess = CreateMarketplaceAccess(instance, access, hooks);
return new CodexNode(log, access, fileManager, marketplaceAccess, hooks);
var node = new CodexNode(log, access, fileManager, marketplaceAccess, hooks);
node.Initialize();
return node;
}
private IMarketplaceAccess CreateMarketplaceAccess(ICodexInstance instance, CodexAccess access, ICodexNodeHooks hooks)

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin;
using CodexClient;
using CodexContractsPlugin;
using GethPlugin;
using KubernetesWorkflow.Types;

View File

@ -1,6 +1,5 @@
using Core;
using CodexClient;
using KubernetesWorkflow.Types;
using Logging;
using Utils;
namespace CodexPlugin

View File

@ -14,9 +14,9 @@ namespace CodexPlugin
public class CodexNodeGroup : ICodexNodeGroup
{
private readonly CodexNode[] nodes;
private readonly ICodexNode[] nodes;
public CodexNodeGroup(IPluginTools tools, CodexNode[] nodes)
public CodexNodeGroup(IPluginTools tools, ICodexNode[] nodes)
{
this.nodes = nodes;
Version = new DebugInfoVersion();
@ -61,7 +61,6 @@ namespace CodexPlugin
public void EnsureOnline()
{
foreach (var node in nodes) node.Initialize();
var versionResponses = Nodes.Select(n => n.Version);
var first = versionResponses.First();

View File

@ -1,4 +1,5 @@
using CodexPlugin.Hooks;
using CodexClient;
using CodexClient.Hooks;
using Core;
using KubernetesWorkflow;
using KubernetesWorkflow.Types;
@ -7,7 +8,7 @@ using Utils;
namespace CodexPlugin
{
public class CodexStarter : IProcessControl
public class CodexStarter : IIProcessControlFactory
{
private readonly IPluginTools pluginTools;
private readonly CodexContainerRecipe recipe = new CodexContainerRecipe();
@ -24,6 +25,15 @@ namespace CodexPlugin
public CodexHooksFactory HooksFactory { get; } = new CodexHooksFactory();
public IProcessControl CreateProcessControl(ICodexInstance instance)
{
var pod = podMap[instance];
return new CodexContainerProcessControl(pluginTools, pod, onStop: () =>
{
podMap.Remove(instance);
});
}
public RunningPod[] BringOnline(CodexSetup codexSetup)
{
LogSeparator();
@ -47,46 +57,14 @@ namespace CodexPlugin
return containers;
}
public void Stop(ICodexInstance instance, bool waitTillStopped)
{
Log($"Stopping node...");
var pod = podMap[instance];
podMap.Remove(instance);
var workflow = pluginTools.CreateWorkflow();
workflow.Stop(pod, waitTillStopped);
Log("Stopped.");
}
public IDownloadedLog DownloadLog(ICodexInstance instance, LogFile file)
{
var workflow = pluginTools.CreateWorkflow();
var pod = podMap[instance];
return workflow.DownloadContainerLog(pod.Containers.Single());
}
public void DeleteDataDirFolder(ICodexInstance instance)
{
var pod = podMap[instance];
var container = pod.Containers.Single();
try
{
var dataDirVar = container.Recipe.EnvVars.Single(e => e.Name == "CODEX_DATA_DIR");
var dataDir = dataDirVar.Value;
var workflow = pluginTools.CreateWorkflow();
workflow.ExecuteCommand(container, "rm", "-Rfv", $"/codex/{dataDir}/repo");
Log("Deleted repo folder.");
}
catch (Exception e)
{
Log("Unable to delete repo folder: " + e);
}
}
public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningPod[] containers)
{
var codexNodeFactory = new CodexNodeFactory(pluginTools, HooksFactory);
var codexNodeFactory = new CodexNodeFactory(
log: pluginTools.GetLog(),
fileManager: pluginTools.GetFileManager(),
hooksFactory: HooksFactory,
httpFactory: pluginTools,
processControlFactory: this);
var group = CreateCodexGroup(coreInterface, containers, codexNodeFactory);
@ -139,8 +117,7 @@ namespace CodexPlugin
private CodexNodeGroup CreateCodexGroup(CoreInterface coreInterface, RunningPod[] runningContainers, CodexNodeFactory codexNodeFactory)
{
var instances = runningContainers.Select(CreateInstance).ToArray();
var accesses = instances.Select(CreateAccess).ToArray();
var nodes = accesses.Select(codexNodeFactory.CreateOnlineCodexNode).ToArray();
var nodes = instances.Select(codexNodeFactory.CreateCodexNode).ToArray();
var group = new CodexNodeGroup(pluginTools, nodes);
try
@ -156,18 +133,6 @@ namespace CodexPlugin
return group;
}
private CodexAccess CreateAccess(ICodexInstance instance)
{
var crashWatcher = CreateCrashWatcher(instance);
return new CodexAccess(pluginTools, this, instance, crashWatcher);
}
private ICrashWatcher CreateCrashWatcher(ICodexInstance instance)
{
var pod = podMap[instance];
return pluginTools.CreateWorkflow().CreateCrashWatcher(pod.Containers.Single());
}
private ICodexInstance CreateInstance(RunningPod pod)
{
var instance = CodexInstanceContainerExtension.CreateFromPod(pod);
@ -198,4 +163,66 @@ namespace CodexPlugin
pluginTools.GetLog().Log(message);
}
}
public class CodexContainerProcessControl : IProcessControl
{
private readonly IPluginTools tools;
private readonly RunningPod pod;
private readonly Action onStop;
private readonly ContainerCrashWatcher crashWatcher;
public CodexContainerProcessControl(IPluginTools tools, RunningPod pod, Action onStop)
{
this.tools = tools;
this.pod = pod;
this.onStop = onStop;
crashWatcher = tools.CreateWorkflow().CreateCrashWatcher(pod.Containers.Single());
crashWatcher.Start();
}
public void Stop(bool waitTillStopped)
{
Log($"Stopping node...");
var workflow = tools.CreateWorkflow();
workflow.Stop(pod, waitTillStopped);
crashWatcher.Stop();
onStop();
Log("Stopped.");
}
public IDownloadedLog DownloadLog(LogFile file)
{
var workflow = tools.CreateWorkflow();
return workflow.DownloadContainerLog(pod.Containers.Single());
}
public void DeleteDataDirFolder()
{
var container = pod.Containers.Single();
try
{
var dataDirVar = container.Recipe.EnvVars.Single(e => e.Name == "CODEX_DATA_DIR");
var dataDir = dataDirVar.Value;
var workflow = tools.CreateWorkflow();
workflow.ExecuteCommand(container, "rm", "-Rfv", $"/codex/{dataDir}/repo");
Log("Deleted repo folder.");
}
catch (Exception e)
{
Log("Unable to delete repo folder: " + e);
}
}
public bool HasCrashed()
{
return crashWatcher.HasCrashed();
}
private void Log(string message)
{
tools.GetLog().Log(message);
}
}
}

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow;
using CodexClient;
using KubernetesWorkflow;
using Utils;
namespace CodexPlugin

View File

@ -1,4 +1,5 @@
using CodexPlugin.Hooks;
using CodexClient;
using CodexClient.Hooks;
using Core;
using KubernetesWorkflow.Types;

View File

@ -1,5 +1,5 @@
using CodexPlugin.OverwatchSupport.LineConverters;
using KubernetesWorkflow;
using CodexClient;
using CodexPlugin.OverwatchSupport.LineConverters;
using Logging;
using OverwatchTranscript;
using Utils;

View File

@ -1,4 +1,5 @@
using CodexPlugin.Hooks;
using CodexClient;
using CodexClient.Hooks;
using OverwatchTranscript;
using Utils;

View File

@ -1,5 +1,4 @@
using CodexPlugin.Hooks;
using KubernetesWorkflow;
using CodexClient.Hooks;
using Logging;
using OverwatchTranscript;
using Utils;

View File

@ -1,4 +1,6 @@
namespace CodexPlugin.OverwatchSupport
using CodexClient;
namespace CodexPlugin.OverwatchSupport
{
public class IdentityMap
{

View File

@ -1,4 +1,6 @@
namespace CodexPlugin.OverwatchSupport.LineConverters
using CodexClient;
namespace CodexPlugin.OverwatchSupport.LineConverters
{
public class BlockReceivedLineConverter : ILineConverter
{

View File

@ -1,4 +1,6 @@
namespace CodexPlugin.OverwatchSupport.LineConverters
using CodexClient;
namespace CodexPlugin.OverwatchSupport.LineConverters
{
public class BootstrapLineConverter : ILineConverter
{

View File

@ -1,4 +1,6 @@
namespace CodexPlugin.OverwatchSupport.LineConverters
using CodexClient;
namespace CodexPlugin.OverwatchSupport.LineConverters
{
public class DialSuccessfulLineConverter : ILineConverter
{

View File

@ -1,4 +1,6 @@
namespace CodexPlugin.OverwatchSupport.LineConverters
using CodexClient;
namespace CodexPlugin.OverwatchSupport.LineConverters
{
public class PeerDroppedLineConverter : ILineConverter
{

View File

@ -1,4 +1,5 @@
using OverwatchTranscript;
using CodexClient;
using OverwatchTranscript;
namespace CodexPlugin.OverwatchSupport
{

View File

@ -15,7 +15,7 @@ public static class Program
var pluginRoot = FindCodexPluginFolder();
var clientRoot = FindCodexClientFolder();
Console.WriteLine("Located CodexPlugin: " + pluginRoot);
var openApiFile = Path.Combine(pluginRoot, "openapi.yaml");
var openApiFile = Path.Combine(clientRoot, "openapi.yaml");
var clientFile = Path.Combine(clientRoot, "obj", "openapiClient.cs");
var targetFile = Path.Combine(pluginRoot, "ApiChecker.cs");

View File

@ -29,12 +29,12 @@ namespace DistTestCore
/// </summary>
public bool AlwaysDownloadContainerLogs { get; set; }
public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet, string k8sNamespace)
public KubernetesWorkflow.Configuration GetK8sConfiguration(IK8sTimeSet timeSet, string k8sNamespace)
{
return GetK8sConfiguration(timeSet, new DoNothingK8sHooks(), k8sNamespace);
}
public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet, IK8sHooks hooks, string k8sNamespace)
public KubernetesWorkflow.Configuration GetK8sConfiguration(IK8sTimeSet timeSet, IK8sHooks hooks, string k8sNamespace)
{
var config = new KubernetesWorkflow.Configuration(
kubeConfigFile: kubeConfigFile,

View File

@ -6,6 +6,7 @@ using NUnit.Framework;
using NUnit.Framework.Interfaces;
using System.Reflection;
using Utils;
using WebUtils;
using Assert = NUnit.Framework.Assert;
namespace DistTestCore
@ -35,7 +36,7 @@ namespace DistTestCore
fixtureLog = new FixtureLog(logConfig, startTime, deployId);
statusLog = new StatusLog(logConfig, startTime, "dist-tests", deployId);
globalEntryPoint = new EntryPoint(fixtureLog, configuration.GetK8sConfiguration(new DefaultTimeSet(), TestNamespacePrefix), configuration.GetFileManagerFolder());
globalEntryPoint = new EntryPoint(fixtureLog, configuration.GetK8sConfiguration(new DefaultK8sTimeSet(), TestNamespacePrefix), configuration.GetFileManagerFolder());
Initialize(fixtureLog);
}
@ -194,7 +195,8 @@ namespace DistTestCore
var lifecycle = new TestLifecycle(
fixtureLog.CreateTestLog(),
configuration,
GetTimeSet(),
GetWebCallTimeSet(),
GetK8sTimeSet(),
testNamespace,
deployId,
ShouldWaitForCleanup());
@ -241,10 +243,16 @@ namespace DistTestCore
}
}
private ITimeSet GetTimeSet()
private IWebCallTimeSet GetWebCallTimeSet()
{
if (ShouldUseLongTimeouts()) return new LongTimeSet();
return new DefaultTimeSet();
if (ShouldUseLongTimeouts()) return new LongWebCallTimeSet();
return new DefaultWebCallTimeSet();
}
private IK8sTimeSet GetK8sTimeSet()
{
if (ShouldUseLongTimeouts()) return new LongK8sTimeSet();
return new DefaultK8sTimeSet();
}
private bool ShouldWaitForCleanup()

View File

@ -6,6 +6,7 @@ using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
using Logging;
using Utils;
using WebUtils;
namespace DistTestCore
{
@ -18,15 +19,16 @@ namespace DistTestCore
private readonly string deployId;
private readonly List<IDownloadedLog> stoppedContainerLogs = new List<IDownloadedLog>();
public TestLifecycle(TestLog log, Configuration configuration, ITimeSet timeSet, string testNamespace, string deployId, bool waitForCleanup)
public TestLifecycle(TestLog log, Configuration configuration, IWebCallTimeSet webCallTimeSet, IK8sTimeSet k8sTimeSet, string testNamespace, string deployId, bool waitForCleanup)
{
Log = log;
Configuration = configuration;
TimeSet = timeSet;
WebCallTimeSet = webCallTimeSet;
K8STimeSet = k8sTimeSet;
TestNamespace = testNamespace;
TestStart = DateTime.UtcNow;
entryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(timeSet, this, testNamespace), configuration.GetFileManagerFolder(), timeSet);
entryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(k8sTimeSet, this, testNamespace), configuration.GetFileManagerFolder(), webCallTimeSet, k8sTimeSet);
metadata = entryPoint.GetPluginMetadata();
CoreInterface = entryPoint.CreateInterface();
this.deployId = deployId;
@ -37,7 +39,8 @@ namespace DistTestCore
public DateTime TestStart { get; }
public TestLog Log { get; }
public Configuration Configuration { get; }
public ITimeSet TimeSet { get; }
public IWebCallTimeSet WebCallTimeSet { get; }
public IK8sTimeSet K8STimeSet { get; }
public string TestNamespace { get; }
public bool WaitForCleanup { get; }
public CoreInterface CoreInterface { get; }

View File

@ -1,4 +1,5 @@
using CodexPlugin;
using CodexClient;
using CodexPlugin;
using DistTestCore;
using NUnit.Framework;

View File

@ -1,10 +1,5 @@
using CodexPlugin;
using CodexClient;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utils;
namespace CodexTests.BasicTests

View File

@ -1,4 +1,5 @@
using BlockchainUtils;
using CodexClient;
using CodexContractsPlugin;
using CodexNetDeployer;
using CodexPlugin;
@ -15,7 +16,6 @@ using Newtonsoft.Json;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using OverwatchTranscript;
using Utils;
namespace CodexTests
{

View File

@ -1,6 +1,5 @@
using CodexContractsPlugin;
using CodexPlugin;
using GethPlugin;
using CodexClient;
using CodexContractsPlugin;
using NUnit.Framework;
using Utils;

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using FileUtils;
using Logging;
using NUnit.Framework;

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using Logging;
using NUnit.Framework;

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using Logging;
using static CodexTests.Helpers.FullConnectivityHelper;

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using FileUtils;
using Logging;
using Utils;

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using NUnit.Framework;
namespace CodexTests.PeerDiscoveryTests

View File

@ -1,6 +1,5 @@
using CodexContractsPlugin;
using CodexPlugin;
using GethPlugin;
using CodexClient;
using NUnit.Framework;
namespace CodexTests.PeerDiscoveryTests

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using NUnit.Framework;
using Utils;

View File

@ -1,4 +1,5 @@
using CodexPlugin;
using CodexClient;
using CodexPlugin;
using DistTestCore;
using NUnit.Framework;
using Utils;

View File

@ -1,6 +1,6 @@
using CodexContractsPlugin;
using NUnit.Framework;
using NUnit.Framework;
using System.Numerics;
using Utils;
namespace FrameworkTests.CodexContractsPlugin
{

View File

@ -1,4 +1,5 @@
using CodexOpenApi;
using CodexClient;
using CodexOpenApi;
using CodexPlugin;
using Logging;
using Nethereum.Model;

View File

@ -1,6 +1,7 @@
using BiblioTech.Options;
using CodexContractsPlugin;
using GethPlugin;
using Utils;
namespace BiblioTech.Commands
{

View File

@ -1,8 +1,6 @@
using BiblioTech.Options;
using Discord;
using GethPlugin;
using k8s.KubeConfigModels;
using NBitcoin.Secp256k1;
using Utils;
namespace BiblioTech.Commands
{
@ -67,14 +65,14 @@ namespace BiblioTech.Commands
await Program.AdminChecker.SendInAdminChannel($"User {Mention(user)} used '/{Name}' but the provided address is already in use by another user. (address: {newAddress})");
}
private async Task ResponseOK(CommandContext context, IUser user, GethPlugin.EthAddress newAddress)
private async Task ResponseOK(CommandContext context, IUser user, EthAddress newAddress)
{
await context.Followup(new string[]
{
{
"Done! Thank you for joining the test net!",
"By default, the bot will @-mention you with test-net related notifications.",
$"You can enable/disable this behavior with the '/{notifyCommand.Name}' command."
});
});
await Program.AdminChecker.SendInAdminChannel($"User {Mention(user)} used '/{Name}' successfully. ({newAddress})");
}

View File

@ -1,5 +1,5 @@
using GethPlugin;
using Nethereum.Util;
using Nethereum.Util;
using Utils;
namespace BiblioTech.Options
{

View File

@ -1,5 +1,6 @@
using CodexContractsPlugin;
using GethPlugin;
using Utils;
namespace BiblioTech
{

View File

@ -2,6 +2,7 @@
using Discord;
using GethPlugin;
using Newtonsoft.Json;
using Utils;
namespace BiblioTech
{

View File

@ -1,5 +1,5 @@
using GethPlugin;
using Microsoft.AspNetCore.Mvc;
using Utils;
namespace KeyMaker.Controllers
{
@ -10,7 +10,7 @@ namespace KeyMaker.Controllers
[HttpGet]
public KeyResponse Get()
{
var account = EthAccount.GenerateNew();
var account = EthAccountGenerator.GenerateNew();
return new KeyResponse
{

View File

@ -1,7 +1,7 @@
using CodexContractsPlugin;
using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Newtonsoft.Json;
using Utils;
namespace TestNetRewarder
{

View File

@ -1,5 +1,5 @@
using DiscordRewards;
using GethPlugin;
using Utils;
namespace TestNetRewarder
{

View File

@ -1,9 +1,8 @@
using BlockchainUtils;
using CodexContractsPlugin.ChainMonitor;
using DiscordRewards;
using GethPlugin;
using NethereumWorkflow;
using System.Numerics;
using Utils;
namespace TestNetRewarder
{

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using CodexPlugin.OverwatchSupport;
using OverwatchTranscript;

View File

@ -1,4 +1,4 @@
using CodexPlugin;
using CodexClient;
using CodexPlugin.OverwatchSupport;
using OverwatchTranscript;