separate load functionality from inference client to loader client. Call loader client from inference to get the model.

remove dummy dlls, remove resource loader from c#.

TODO: Load dlls separately by Loader UI and loader client

WIP
This commit is contained in:
Alex Bezdieniezhnykh
2025-06-06 20:04:03 +03:00
parent 500db31142
commit 7750025631
54 changed files with 353 additions and 571 deletions
+30 -13
View File
@@ -27,8 +27,14 @@ public class LoaderClient(LoaderClientConfig config, ILogger logger, Cancellatio
CreateNoWindow = true
};
process.OutputDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.ErrorDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.OutputDataReceived += (_, e) =>
{
if (e.Data != null) Console.WriteLine(e.Data);
};
process.ErrorDataReceived += (_, e) =>
{
if (e.Data != null) Console.WriteLine(e.Data);
};
process.Start();
}
catch (Exception e)
@@ -44,28 +50,39 @@ public class LoaderClient(LoaderClientConfig config, ILogger logger, Cancellatio
_dealer.Connect($"tcp://{config.ZeroMqHost}:{config.ZeroMqPort}");
}
public void Send(RemoteCommand command) =>
_dealer.SendFrame(MessagePackSerializer.Serialize(command));
public void Login(ApiCredentials credentials)
{
var result = SendCommand(RemoteCommand.Create(CommandType.Login, credentials));
if (result.CommandType != CommandType.Ok)
throw new Exception(result.Message);
}
public MemoryStream LoadFile(string filename, string folder)
{
var result = SendCommand(RemoteCommand.Create(CommandType.Load, new LoadFileData(filename, folder)));
if (result.Data?.Length == 0)
throw new Exception($"Can't load {filename}. Returns 0 bytes");
return new MemoryStream(result.Data!);
}
private RemoteCommand SendCommand(RemoteCommand command, int retryCount = 15, int retryDelayMs = 400)
{
try
{
Send(RemoteCommand.Create(CommandType.Load, new LoadFileData(filename, folder)));
_dealer.SendFrame(MessagePackSerializer.Serialize(command));
var retries = 10;
var tryNum = 0;
while (!ct.IsCancellationRequested && tryNum++ < retries)
while (!ct.IsCancellationRequested && tryNum++ < retryCount)
{
if (!_dealer.TryReceiveFrameBytes(TimeSpan.FromMilliseconds(150), out var bytes))
if (!_dealer.TryReceiveFrameBytes(TimeSpan.FromMilliseconds(retryDelayMs), out var bytes))
continue;
var resultCommand = MessagePackSerializer.Deserialize<RemoteCommand>(bytes, cancellationToken: ct);
if (resultCommand.Data?.Length == 0)
throw new Exception($"Can't load {filename}. Returns 0 bytes");
return new MemoryStream(resultCommand.Data!);
var res = MessagePackSerializer.Deserialize<RemoteCommand>(bytes, cancellationToken: ct);
if (res.CommandType == CommandType.Error)
throw new Exception(res.Message);
return res;
}
throw new Exception($"Can't load file {filename} after {retries} retries");
throw new Exception($"Sent {command} {retryCount} times. No response from client.");
}
catch (Exception e)
{
@@ -1,8 +0,0 @@
using Azaion.CommonSecurity.DTO.Commands;
namespace Azaion.CommonSecurity.Services;
public interface IResourceLoader
{
MemoryStream LoadFile(string fileName, string? folder, TimeSpan? timeout = null);
}