Implementato sdk honeywell e metodi per lo scanner barcode

This commit is contained in:
2026-02-24 17:49:25 +01:00
parent e8adb76256
commit 7fa96eeb09
27 changed files with 477 additions and 53 deletions

View File

@@ -1,5 +1,4 @@
using System.Data;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using SteUp.Data.LocalDb;
@@ -7,6 +6,8 @@ using SteUp.Data.LocalDb.EntityServices;
using SteUp.Maui.Core.Services;
using SteUp.Maui.Core.System;
using SteUp.Maui.Core.System.Network;
using SteUp.Shared.Core.BarcodeReader;
using SteUp.Shared.Core.BarcodeReader.Contracts;
using SteUp.Shared.Core.Data;
using SteUp.Shared.Core.Data.Contracts;
using SteUp.Shared.Core.Interface;
@@ -14,6 +15,7 @@ using SteUp.Shared.Core.Interface.IntegryApi;
using SteUp.Shared.Core.Interface.LocalDb;
using SteUp.Shared.Core.Interface.System;
using SteUp.Shared.Core.Interface.System.Network;
using SteUp.Shared.Core.Messages.Scanner;
using SteUp.Shared.Core.Messages.Scheda;
using SteUp.Shared.Core.Services;
@@ -21,49 +23,55 @@ namespace SteUp.Maui.Core;
public static class CoreModule
{
public static void RegisterAppServices(this MauiAppBuilder builder)
extension(MauiAppBuilder builder)
{
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
builder.Services.AddScoped<ISteupDataService, SteupDataService>();
}
public static void RegisterIntegryServices(this MauiAppBuilder builder)
{
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
builder.Services.AddScoped<IIntegrySteupService, IntegrySteupService>();
}
public static void RegisterSystemService(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<IAttachedService, AttachedService>();
}
public static void AddAuthorizationCore(this MauiAppBuilder builder)
{
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AppAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
provider.GetRequiredService<AppAuthenticationStateProvider>());
}
public static void RegisterMessageServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IMessenger, WeakReferenceMessenger>();
builder.Services.AddSingleton<NewSchedaService>();
}
public static void RegisterDbServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IDbPathProvider, DbPathProvider>();
builder.Services.AddDbContext<AppDbContext>((sp, options) =>
public void RegisterAppServices()
{
var dbPath = sp.GetRequiredService<IDbPathProvider>().GetDbPath();
options.UseSqlite($"Filename={dbPath}");
});
builder.Services.AddSingleton<IDbInitializer, DbInitializer>();
builder.Services.AddSingleton<IIspezioniService, IspezioniService>();
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
builder.Services.AddScoped<ISteupDataService, SteupDataService>();
builder.Services.AddSingleton<IBarcodeManager, BarcodeManager>();
}
public void RegisterIntegryServices()
{
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
builder.Services.AddScoped<IIntegrySteupService, IntegrySteupService>();
}
public void RegisterSystemService()
{
builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<IAttachedService, AttachedService>();
builder.Services.AddSingleton<IBarcodeReaderService, HoneywellScannerService>();
}
public void AddAuthorizationCore()
{
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AppAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
provider.GetRequiredService<AppAuthenticationStateProvider>());
}
public void RegisterMessageServices()
{
builder.Services.AddSingleton<IMessenger, WeakReferenceMessenger>();
builder.Services.AddSingleton<NewSchedaService>();
builder.Services.AddSingleton<OnScannerService>();
}
public void RegisterDbServices()
{
builder.Services.AddSingleton<IDbPathProvider, DbPathProvider>();
builder.Services.AddDbContext<AppDbContext>((sp, options) =>
{
var dbPath = sp.GetRequiredService<IDbPathProvider>().GetDbPath();
options.UseSqlite($"Filename={dbPath}");
});
builder.Services.AddSingleton<IDbInitializer, DbInitializer>();
builder.Services.AddSingleton<IIspezioniService, IspezioniService>();
}
}
}

View File

@@ -0,0 +1,24 @@
using SteUp.Shared.Core.BarcodeReader.Contracts;
using SteUp.Shared.Core.BarcodeReader.Dto;
using SteUp.Shared.Core.Interface.System;
namespace SteUp.Maui.Core.System;
public partial class HoneywellScannerService : IBarcodeReaderService
{
protected Action<BarcodeScanDto>? OnScanSuccessful;
protected Action<Exception>? OnScanFailed;
public partial bool IsRightAdapter();
public partial void Init(Action onDeviceReady);
public partial void Deinit();
public partial string GetAdapterName();
public partial void OnKeyEvent(object keyEvent);
public partial void ChangeSettings(List<(string Key, object Value)> settings);
public void Register(Action<BarcodeScanDto> onScanSuccessful, Action<Exception> onScanFailed)
{
OnScanSuccessful = onScanSuccessful;
OnScanFailed = onScanFailed;
}
}

View File

@@ -0,0 +1,140 @@
using Android.OS;
using Com.Honeywell.Aidc;
using SteUp.Shared.Core.BarcodeReader.Dto;
namespace SteUp.Maui.Core.System;
public partial class HoneywellScannerService
{
private AidcManager? _aidcManager;
private BarcodeReader? _barcodeReader;
private static readonly List<string> CompatibleModels = ["EDA50", "EDA51", "EDA52", "CT60"];
public partial bool IsRightAdapter()
{
return CompatibleModels.Contains(Build.Model ?? string.Empty);
}
public partial string GetAdapterName() => "Honeywell";
public partial void Init(Action onDeviceReady)
{
if (!IsRightAdapter())
throw new Exception($"Adapter non trovato per il modello: {Build.Model}");
AidcManager.Create(
Android.App.Application.Context,
new AidcCreatedCallback(this, onDeviceReady)
);
}
public partial void Deinit()
{
_barcodeReader?.Close();
_barcodeReader = null;
_aidcManager?.Close();
_aidcManager = null;
}
public partial void OnKeyEvent(object keyEvent)
{
// Honeywell gestisce il trigger hardware internamente, non serve implementazione
}
public partial void ChangeSettings(List<(string Key, object Value)> settings)
{
if (_barcodeReader == null) return;
var properties = GetDefaultProperties();
foreach (var (key, value) in settings)
{
switch (key)
{
case "TRIGGER_SCAN_MODE":
var scanMode = (string)value switch
{
"ONE_SHOT" => BarcodeReader.TriggerScanModeOneshot,
"CONTINUOUS" => BarcodeReader.TriggerScanModeContinuous,
"READ_ON_SECOND_TRIGGER_PRESS" => BarcodeReader.TriggerScanModeReadOnSecondTriggerPress,
"READ_ON_RELEASE" => BarcodeReader.TriggerScanModeReadOnRelease,
_ => BarcodeReader.TriggerScanModeOneshot
};
properties[BarcodeReader.PropertyTriggerScanMode] = scanMode!;
break;
case "TRIGGER_SCAN_DELAY":
properties[BarcodeReader.PropertyTriggerScanDelay] = int.Parse((string)value);
break;
}
}
_barcodeReader.SetProperties(properties);
try { _barcodeReader.Claim(); }
catch (ScannerUnavailableException ex) { OnScanFailed?.Invoke(ex); }
}
private void RegisterListenersInternal()
{
_barcodeReader?.AddBarcodeListener(new BarcodeEventListener(this));
}
private void DispatchEvent(BarcodeReadEvent e)
{
var dto = new BarcodeScanDto
{
StringValue = e.BarcodeData,
Type = e.CodeId,
Name = e.CodeId
};
OnScanSuccessful?.Invoke(dto);
}
private static Dictionary<string, Java.Lang.Object> GetDefaultProperties() => new()
{
{ BarcodeReader.PropertyEan8Enabled, true },
{ BarcodeReader.PropertyEan13Enabled, true },
{ BarcodeReader.PropertyCode39Enabled, true },
{ BarcodeReader.PropertyCode128Enabled, true },
{ BarcodeReader.PropertyGs1128Enabled, true },
{ BarcodeReader.PropertyUpcAEnable, true },
{ BarcodeReader.PropertyEan8CheckDigitTransmitEnabled, true },
{ BarcodeReader.PropertyEan13CheckDigitTransmitEnabled, true },
{ BarcodeReader.PropertyUpcACheckDigitTransmitEnabled, true }
};
private class AidcCreatedCallback(HoneywellScannerService service, Action onDeviceReady)
: Java.Lang.Object, AidcManager.ICreatedCallback
{
public void OnCreated(AidcManager? manager)
{
service._aidcManager = manager;
try
{
if (manager == null) throw new Exception("AidcManager null");
service._barcodeReader = manager.CreateBarcodeReader();
service.RegisterListenersInternal();
}
catch (Exception ex)
{
service.OnScanFailed?.Invoke(ex);
}
onDeviceReady.Invoke();
}
}
private class BarcodeEventListener(HoneywellScannerService service)
: Java.Lang.Object, BarcodeReader.IBarcodeListener
{
public void OnBarcodeEvent(BarcodeReadEvent? e) => service.DispatchEvent(e!);
public void OnFailureEvent(BarcodeFailureEvent? e) =>
service.OnScanFailed?.Invoke(new Exception($"Scan failure: {e}"));
}
}

View File

@@ -0,0 +1,17 @@
namespace SteUp.Maui.Core.System;
public partial class HoneywellScannerService
{
public partial bool IsRightAdapter() => false;
public partial void Init(Action onDeviceReady) =>
throw new NotSupportedException("Honeywell SDK non disponibile su iOS.");
public partial void Deinit() { }
public partial string GetAdapterName() => "Honeywell";
public partial void OnKeyEvent(object keyEvent) { }
public partial void ChangeSettings(List<(string Key, object Value)> settings) { }
}

View File

@@ -124,6 +124,10 @@
<PackageReference Include="SkiaSharp" Version="3.119.2" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<ProjectReference Include="..\Steup.HoneywellScanner\Steup.HoneywellScanner.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SteUp.Shared\SteUp.Shared.csproj" />
<ProjectReference Include="..\SteUp.Data\SteUp.Data.csproj" />