failsafe load dlls

add user config queue offsets
throttle improvements
This commit is contained in:
Alex Bezdieniezhnykh
2025-04-17 01:19:48 +03:00
parent 0237e279a5
commit 0c66607ed7
32 changed files with 320 additions and 188 deletions
+36 -18
View File
@@ -1,8 +1,12 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.Unicode;
using System.Windows;
using System.Windows.Threading;
using Azaion.Annotator;
using Azaion.Common;
using Azaion.Common.Database;
using Azaion.Common.DTO;
using Azaion.Common.DTO.Config;
@@ -11,8 +15,10 @@ 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 LazyCache;
using LibVLCSharp.Shared;
using MediatR;
using Microsoft.Extensions.Configuration;
@@ -35,12 +41,14 @@ public partial class App
private IInferenceClient _inferenceClient = null!;
private IResourceLoader _resourceLoader = null!;
private IAuthProvider _authProvider = null!;
private Stream _securedConfig = null!;
private Stream _systemConfig = null!;
private static readonly Guid KeyPressTaskId = Guid.NewGuid();
private readonly ICache _cache = new MemoryCache();
private readonly IHardwareService _hardwareService = new HardwareService();
private IAzaionApi _azaionApi = null!;
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
_logger.LogError(e.Exception, e.Exception.Message);
@@ -83,21 +91,32 @@ public partial class App
var secureAppConfig = ReadSecureAppConfig();
_inferenceClient = new InferenceClient(new OptionsWrapper<InferenceClientConfig>(secureAppConfig.InferenceClientConfig));
_resourceLoader = new ResourceLoader(_inferenceClient);
_authProvider = new AuthProvider(_inferenceClient);
var login = new Login();
login.Closed += (sender, args) =>
{
if (!login.MainSuiteOpened)
_inferenceClient.Stop();
};
login.CredentialsEntered += (_, credentials) =>
login.CredentialsEntered += async (_, credentials) =>
{
credentials.Folder = secureAppConfig.InferenceClientConfig.ResourcesFolder;
_authProvider.Login(credentials);
_securedConfig = _resourceLoader.LoadFile("config.secured.json");
_systemConfig = _resourceLoader.LoadFile("config.system.json");
credentials.Folder = secureAppConfig.DirectoriesConfig.ApiResourcesDirectory;
_inferenceClient.Send(RemoteCommand.Create(CommandType.Login, credentials));
_azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(SecurityConstants.API_URL) }, _cache, credentials, _hardwareService);
try
{
_securedConfig = _resourceLoader.LoadFile("config.secured.json");
_systemConfig = _resourceLoader.LoadFile("config.system.json");
}
catch (Exception e)
{
Console.WriteLine(e);
_securedConfig = new MemoryStream("{}"u8.ToArray());
var systemConfig = new
{
AnnotationConfig = Constants.DefaultAnnotationConfig,
AIRecognitionConfig = Constants.DefaultAIRecognitionConfig,
ThumbnailConfig = Constants.DefaultThumbnailConfig,
};
_systemConfig = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(systemConfig)));
}
AppDomain.CurrentDomain.AssemblyResolve += (_, a) =>
{
@@ -168,14 +187,13 @@ public partial class App
services.ConfigureSection<InferenceClientConfig>(context.Configuration);
services.ConfigureSection<GpsDeniedClientConfig>(context.Configuration);
services.AddSingleton<IInferenceClient>(_inferenceClient);
services.AddSingleton<IInferenceClient, InferenceClient>();
services.AddSingleton<IGpsMatcherClient, GpsMatcherClient>();
services.AddSingleton<IResourceLoader>(_resourceLoader);
services.AddSingleton<IAuthProvider>(_authProvider);
services.AddSingleton<IInferenceService, InferenceService>();
services.AddSingleton<IGpsMatcherService, GpsMatcherService>();
services.AddSingleton<ISatelliteDownloader, SatelliteDownloader>();
services.AddHttpClient();
services.AddSingleton(_azaionApi);
#endregion
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
@@ -220,7 +238,7 @@ public partial class App
{
var args = (KeyEventArgs)e;
var keyEvent = new KeyEvent(sender, args, _formState.ActiveWindow);
_ = ThrottleExt.ThrottleRunFirst(() => _mediator.Publish(keyEvent), KeyPressTaskId, TimeSpan.FromMilliseconds(50));
_ = ThrottleExt.Throttle(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50));
}
protected override async void OnExit(ExitEventArgs e)