mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 13:06:31 +00:00
queue + local sqlite WIP
This commit is contained in:
+18
-38
@@ -1,14 +1,16 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Azaion.Annotator;
|
||||
using Azaion.Annotator.Extensions;
|
||||
using Azaion.Common;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.CommonSecurity;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Azaion.CommonSecurity.Services;
|
||||
using Azaion.Dataset;
|
||||
using LibVLCSharp.Shared;
|
||||
using MediatR;
|
||||
@@ -17,7 +19,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||
|
||||
@@ -32,38 +33,7 @@ public partial class App
|
||||
|
||||
private AzaionApiClient _apiClient = null!;
|
||||
private IResourceLoader _resourceLoader = null!;
|
||||
|
||||
private static AzaionApiClient CreateApiClient(ApiCredentials credentials)
|
||||
{
|
||||
ApiConfig apiConfig;
|
||||
try
|
||||
{
|
||||
if (!File.Exists(Constants.CONFIG_PATH))
|
||||
throw new FileNotFoundException(Constants.CONFIG_PATH);
|
||||
var configStr = File.ReadAllText(Constants.CONFIG_PATH);
|
||||
apiConfig = JsonConvert.DeserializeObject<AppConfig>(configStr)!.ApiConfig;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
apiConfig = new ApiConfig
|
||||
{
|
||||
Url = "https://api.azaion.com",
|
||||
RetryCount = 3,
|
||||
TimeoutSeconds = 40
|
||||
};
|
||||
}
|
||||
|
||||
var api = new AzaionApiClient(new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(apiConfig.Url),
|
||||
Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds)
|
||||
});
|
||||
|
||||
api.EnterCredentials(credentials);
|
||||
return api;
|
||||
}
|
||||
|
||||
private Stream _securedConfig = null!;
|
||||
|
||||
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
@@ -83,8 +53,9 @@ public partial class App
|
||||
var login = new Login();
|
||||
login.CredentialsEntered += async (s, args) =>
|
||||
{
|
||||
_apiClient = CreateApiClient(args);
|
||||
_apiClient = AzaionApiClient.Create(args);
|
||||
_resourceLoader = new ResourceLoader(_apiClient, args);
|
||||
_securedConfig = await _resourceLoader.Load("secured-config.json");
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (_, a) => _resourceLoader.LoadAssembly(a.Name);
|
||||
|
||||
StartMain();
|
||||
@@ -110,7 +81,8 @@ public partial class App
|
||||
_host = Host.CreateDefaultBuilder()
|
||||
.ConfigureAppConfiguration((context, config) => config
|
||||
.AddCommandLine(Environment.GetCommandLineArgs())
|
||||
.AddJsonFile(Constants.CONFIG_PATH, optional: true, reloadOnChange: true))
|
||||
.AddJsonFile(SecurityConstants.CONFIG_PATH, optional: true, reloadOnChange: true)
|
||||
.AddJsonStream(_securedConfig))
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddSingleton<MainSuite>();
|
||||
@@ -121,9 +93,9 @@ public partial class App
|
||||
|
||||
services.Configure<AppConfig>(context.Configuration);
|
||||
services.ConfigureSection<ApiConfig>(context.Configuration);
|
||||
services.ConfigureSection<QueueConfig>(context.Configuration);
|
||||
services.ConfigureSection<DirectoriesConfig>(context.Configuration);
|
||||
services.ConfigureSection<AnnotationConfig>(context.Configuration);
|
||||
services.ConfigureSection<AnnotatorWindowConfig>(context.Configuration);
|
||||
services.ConfigureSection<AIRecognitionConfig>(context.Configuration);
|
||||
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
|
||||
|
||||
@@ -144,6 +116,7 @@ public partial class App
|
||||
});
|
||||
services.AddSingleton<AnnotatorEventHandler>();
|
||||
services.AddSingleton<VLCFrameExtractor>();
|
||||
services.AddSingleton<IDbFactory, DbFactory>();
|
||||
|
||||
services.AddHttpClient<AzaionApiClient>((sp, client) =>
|
||||
{
|
||||
@@ -152,6 +125,10 @@ public partial class App
|
||||
client.Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds);
|
||||
});
|
||||
|
||||
services.AddSingleton<FailsafeAnnotationsProducer>();
|
||||
|
||||
services.AddSingleton<AnnotationService>();
|
||||
|
||||
services.AddSingleton<DatasetExplorer>();
|
||||
services.AddSingleton<IGalleryManager, GalleryManager>();
|
||||
|
||||
@@ -159,6 +136,9 @@ public partial class App
|
||||
services.AddSingleton<IAzaionModule, DatasetExplorerModule>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
Annotation.InitializeDirs(_host.Services.GetRequiredService<IOptions<DirectoriesConfig>>().Value);
|
||||
|
||||
_mediator = _host.Services.GetRequiredService<IMediator>();
|
||||
_logger = _host.Services.GetRequiredService<ILogger<App>>();
|
||||
_formState = _host.Services.GetRequiredService<FormState>();
|
||||
|
||||
Reference in New Issue
Block a user