mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:36:31 +00:00
rework to have only 1 exe!
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="MediatR" Version="12.4.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -13,6 +13,11 @@ public class Constants
|
||||
public const string DEFAULT_API_URL = "https://api.azaion.com/";
|
||||
public const int DEFAULT_API_RETRY_COUNT = 3;
|
||||
public const int DEFAULT_API_TIMEOUT_SECONDS = 40;
|
||||
|
||||
public const string CLAIM_NAME_ID = "nameid";
|
||||
public const string CLAIM_EMAIL = "unique_name";
|
||||
public const string CLAIM_ROLE = "role";
|
||||
|
||||
#endregion ApiConfig
|
||||
|
||||
#region DirectoriesConfig
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Windows.Media;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class AnnotationResult
|
||||
{
|
||||
[JsonProperty(PropertyName = "f")]
|
||||
public string Image { get; set; } = null!;
|
||||
|
||||
[JsonProperty(PropertyName = "t")]
|
||||
public TimeSpan Time { get; set; }
|
||||
|
||||
public double Lat { get; set; }
|
||||
public double Lon { get; set; }
|
||||
public List<Detection> Detections { get; set; } = new();
|
||||
|
||||
#region For XAML Form
|
||||
|
||||
[JsonIgnore]
|
||||
public string TimeStr => $"{Time:h\\:mm\\:ss}";
|
||||
|
||||
[JsonIgnore]
|
||||
public string ClassName { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
public Color ClassColor0 { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Color ClassColor1 { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Color ClassColor2 { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Color ClassColor3 { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
using CommandLine;
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class ApiCredentials
|
||||
public class ApiCredentials(string email, string password) : EventArgs
|
||||
{
|
||||
[Option('e', "email", Required = true, HelpText = "The email for authorization.")]
|
||||
public string Email { get; set; } = null!;
|
||||
|
||||
[Option('p', "password", Required = true, HelpText = "The password for authorization.")]
|
||||
public string Password { get; set; } = null!;
|
||||
public string Email { get; set; } = email;
|
||||
public string Password { get; set; } = password;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class FormState
|
||||
{
|
||||
public MediaFileInfo? CurrentMedia { get; set; }
|
||||
public string VideoName => string.IsNullOrEmpty(CurrentMedia?.Name)
|
||||
? ""
|
||||
: Path.GetFileNameWithoutExtension(CurrentMedia.Name).Replace(" ", "");
|
||||
|
||||
public string CurrentMrl { get; set; } = null!;
|
||||
public Size CurrentVideoSize { get; set; }
|
||||
public TimeSpan CurrentVideoLength { get; set; }
|
||||
|
||||
public TimeSpan? BackgroundTime { get; set; }
|
||||
public int CurrentVolume { get; set; } = 100;
|
||||
public ObservableCollection<AnnotationResult> AnnotationResults { get; set; } = [];
|
||||
public WindowEnum ActiveWindow { get; set; }
|
||||
|
||||
public string GetTimeName(TimeSpan? ts) => $"{VideoName}_{ts:hmmssf}";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class MediaFileInfo
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string Path { get; set; } = null!;
|
||||
public TimeSpan Duration { get; set; }
|
||||
public string DurationStr => $"{Duration:h\\:mm\\:ss}";
|
||||
public bool HasAnnotations { get; set; }
|
||||
public MediaTypes MediaType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public enum MediaTypes
|
||||
{
|
||||
None = 0,
|
||||
Video = 1,
|
||||
Image = 2
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public enum RoleEnum
|
||||
{
|
||||
None = 0,
|
||||
Operator = 10, //only annotator is available. Could send annotations to queue.
|
||||
Validator = 20, //annotator + dataset explorer. This role allows to receive annotations from the queue.
|
||||
CompanionPC = 30,
|
||||
Admin = 40, //
|
||||
ResourceUploader = 50, //Uploading dll and ai models
|
||||
ApiAdmin = 1000 //everything
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class User
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
public RoleEnum Role { get; set; }
|
||||
|
||||
public User(IEnumerable<Claim> claims)
|
||||
{
|
||||
var claimDict = claims.ToDictionary(x => x.Type, x => x.Value);
|
||||
|
||||
Id = Guid.Parse(claimDict[Constants.CLAIM_NAME_ID]);
|
||||
Email = claimDict[Constants.CLAIM_EMAIL];
|
||||
if (!Enum.TryParse(claimDict[Constants.CLAIM_ROLE], out RoleEnum role))
|
||||
role = RoleEnum.None;
|
||||
Role = role;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.Security;
|
||||
using System.Text;
|
||||
using Azaion.Common.DTO;
|
||||
using Newtonsoft.Json;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
|
||||
namespace Azaion.Common.Services;
|
||||
|
||||
@@ -15,7 +16,9 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
|
||||
|
||||
private string Email { get; set; } = null!;
|
||||
private SecureString Password { get; set; } = new();
|
||||
|
||||
private string JwtToken { get; set; } = null!;
|
||||
public User User { get; set; } = null!;
|
||||
|
||||
public void EnterCredentials(ApiCredentials credentials)
|
||||
{
|
||||
@@ -35,7 +38,7 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
|
||||
return await response.Content.ReadAsStreamAsync();
|
||||
}
|
||||
|
||||
private async Task<string> Authorize()
|
||||
private async Task Authorize()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Email) || Password.Length == 0)
|
||||
throw new Exception("Email or password is empty! Please do EnterCredentials first!");
|
||||
@@ -59,19 +62,23 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
|
||||
if (string.IsNullOrEmpty(result?.Token))
|
||||
throw new Exception("JWT Token not found in response");
|
||||
|
||||
return result.Token;
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var token = handler.ReadJwtToken(result.Token);
|
||||
|
||||
User = new User(token.Claims);
|
||||
JwtToken = result.Token;
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> Send(HttpClient client, HttpRequestMessage request)
|
||||
{
|
||||
if (string.IsNullOrEmpty(JwtToken))
|
||||
JwtToken = await Authorize();
|
||||
await Authorize();
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JwtToken);
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
JwtToken = await Authorize();
|
||||
await Authorize();
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JwtToken);
|
||||
response = await client.SendAsync(request);
|
||||
}
|
||||
@@ -88,4 +95,4 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
|
||||
httpClient.Dispose();
|
||||
Password.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Azaion.Common.Services;
|
||||
|
||||
public interface IHardwareService
|
||||
{
|
||||
Task<HardwareInfo> GetHardware();
|
||||
HardwareInfo GetHardware();
|
||||
}
|
||||
|
||||
public class HardwareService : IHardwareService
|
||||
@@ -23,11 +23,11 @@ public class HardwareService : IHardwareService
|
||||
"lscpu | grep 'Model name:' | cut -d':' -f2 && " +
|
||||
"lspci | grep VGA | cut -d':' -f3\"";
|
||||
|
||||
public async Task<HardwareInfo> GetHardware()
|
||||
public HardwareInfo GetHardware()
|
||||
{
|
||||
try
|
||||
{
|
||||
var output = await RunCommand(Environment.OSVersion.Platform == PlatformID.Win32NT
|
||||
var output = RunCommand(Environment.OSVersion.Platform == PlatformID.Win32NT
|
||||
? WIN32_GET_HARDWARE_COMMAND
|
||||
: UNIX_GET_HARDWARE_COMMAND);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class HardwareService : IHardwareService
|
||||
return macAddress ?? string.Empty;
|
||||
}
|
||||
|
||||
private async Task<string> RunCommand(string command)
|
||||
private string RunCommand(string command)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -91,8 +91,8 @@ public class HardwareService : IHardwareService
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
|
||||
process.Start();
|
||||
var result = await process.StandardOutput.ReadToEndAsync();
|
||||
await process.WaitForExitAsync();
|
||||
var result = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
|
||||
@@ -46,8 +46,9 @@ public class ResourceLoader(AzaionApiClient api, ApiCredentials credentials) : I
|
||||
public async Task<MemoryStream> Load(string fileName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var hardwareService = new HardwareService();
|
||||
var hardwareInfo = await hardwareService.GetHardware();
|
||||
var encryptedStream = await api.GetResource(fileName, credentials.Password, hardwareInfo);
|
||||
var hardwareInfo = hardwareService.GetHardware();
|
||||
|
||||
var encryptedStream = Task.Run(() => api.GetResource(fileName, credentials.Password, hardwareInfo), cancellationToken).Result;
|
||||
|
||||
var key = Security.MakeEncryptionKey(credentials.Email, credentials.Password, hardwareInfo.Hash);
|
||||
var stream = new MemoryStream();
|
||||
|
||||
Reference in New Issue
Block a user