mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
add loader and versioning
This commit is contained in:
+17
-28
@@ -13,7 +13,6 @@ using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.CommonSecurity;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Azaion.CommonSecurity.DTO.Commands;
|
||||
using Azaion.CommonSecurity.Services;
|
||||
using Azaion.Dataset;
|
||||
using CommandLine;
|
||||
@@ -35,7 +34,7 @@ public partial class App
|
||||
private FormState _formState = null!;
|
||||
private IHost _host = null!;
|
||||
private static readonly Guid KeyPressTaskId = Guid.NewGuid();
|
||||
|
||||
private LoaderClient _loaderClient = null!;
|
||||
|
||||
private readonly ICache _cache = new MemoryCache();
|
||||
private readonly CancellationTokenSource _mainCTokenSource = new();
|
||||
@@ -65,25 +64,13 @@ public partial class App
|
||||
|
||||
private void ErrorHandling(IEnumerable<Error> obj)
|
||||
{
|
||||
Log.Fatal($"Error happened: {string.Join(",", obj.Select(x => x.Tag))}");
|
||||
}
|
||||
|
||||
private static InitConfig ReadInitConfig()
|
||||
{
|
||||
try
|
||||
Log.Fatal($"Error happened: {string.Join(",", obj.Select(x =>
|
||||
{
|
||||
if (!File.Exists(SecurityConstants.CONFIG_PATH))
|
||||
throw new FileNotFoundException(SecurityConstants.CONFIG_PATH);
|
||||
var configStr = File.ReadAllText(SecurityConstants.CONFIG_PATH);
|
||||
var config = JsonConvert.DeserializeObject<InitConfig>(configStr);
|
||||
|
||||
return config ?? SecurityConstants.DefaultInitConfig;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return SecurityConstants.DefaultInitConfig;
|
||||
}
|
||||
if (x is MissingRequiredOptionError err)
|
||||
return $"{err.Tag} {err.NameInfo.NameText}";
|
||||
return x.Tag.ToString();
|
||||
} ))}");
|
||||
Current.Shutdown();
|
||||
}
|
||||
|
||||
private Stream GetSystemConfig(LoaderClient loaderClient, string apiDir)
|
||||
@@ -120,15 +107,15 @@ public partial class App
|
||||
private void Start(ApiCredentials credentials)
|
||||
{
|
||||
new ConfigUpdater().CheckConfig();
|
||||
var initConfig = ReadInitConfig();
|
||||
var initConfig = SecurityConstants.ReadInitConfig();
|
||||
var apiDir = initConfig.DirectoriesConfig.ApiResourcesDirectory;
|
||||
var loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, _mainCTokenSource.Token);
|
||||
_loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, _mainCTokenSource.Token);
|
||||
|
||||
#if DEBUG
|
||||
loaderClient.StartClient();
|
||||
_loaderClient.StartClient();
|
||||
#endif
|
||||
loaderClient.Connect(); //Client app should be already started by LoaderUI
|
||||
loaderClient.Login(credentials);
|
||||
_loaderClient.Connect(); //Client app should be already started by LoaderUI
|
||||
_loaderClient.Login(credentials);
|
||||
|
||||
var azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(initConfig.InferenceClientConfig.ApiUrl) }, _cache, credentials);
|
||||
|
||||
@@ -136,8 +123,8 @@ public partial class App
|
||||
.ConfigureAppConfiguration((_, config) => config
|
||||
.AddCommandLine(Environment.GetCommandLineArgs())
|
||||
.AddJsonFile(SecurityConstants.CONFIG_PATH, optional: true, reloadOnChange: true)
|
||||
.AddJsonStream(GetSystemConfig(loaderClient, apiDir))
|
||||
.AddJsonStream(GetSecuredConfig(loaderClient, apiDir)))
|
||||
.AddJsonStream(GetSystemConfig(_loaderClient, apiDir))
|
||||
.AddJsonStream(GetSecuredConfig(_loaderClient, apiDir)))
|
||||
.UseSerilog()
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
@@ -155,7 +142,7 @@ public partial class App
|
||||
#region External Services
|
||||
|
||||
services.ConfigureSection<LoaderClientConfig>(context.Configuration);
|
||||
services.AddSingleton(loaderClient);
|
||||
services.AddSingleton(_loaderClient);
|
||||
|
||||
services.ConfigureSection<InferenceClientConfig>(context.Configuration);
|
||||
services.AddSingleton<IInferenceClient, InferenceClient>();
|
||||
@@ -226,6 +213,8 @@ public partial class App
|
||||
protected override async void OnExit(ExitEventArgs e)
|
||||
{
|
||||
base.OnExit(e);
|
||||
_loaderClient.Stop();
|
||||
_loaderClient.Dispose();
|
||||
await _host.StopAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user