Try to connect on NFC App Start with Server

This commit is contained in:
TheJoKlLa 2023-02-21 22:14:16 +01:00
parent 4790de0f78
commit b9bb50df87

View File

@ -19,6 +19,8 @@ using Borepin.Service;
using FabAccessAPI; using FabAccessAPI;
using FabAccessAPI.Schema; using FabAccessAPI.Schema;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic;
using Prism.Services;
namespace Borepin namespace Borepin
{ {
@ -56,14 +58,51 @@ namespace Borepin
protected override async void OnAppLinkRequestReceived(Uri uri) protected override async void OnAppLinkRequestReceived(Uri uri)
{ {
if(uri.LocalPath.StartsWith("/resource/", StringComparison.OrdinalIgnoreCase)) IPageDialogService pageDialogService = Container.Resolve<IPageDialogService>();
{
string resource_id = uri.LocalPath.Remove(0, "/resource/".Length);
if (Container.IsRegistered<IAPIService>()) if (uri.LocalPath.StartsWith("/resource/", StringComparison.OrdinalIgnoreCase))
{
if (Container.IsRegistered<IAPIService>() && Container.IsRegistered<ILoginStorageService>())
{ {
string resource_id = uri.LocalPath.Remove(0, "/resource/".Length);
IAPIService apiService = Container.Resolve<IAPIService>(); IAPIService apiService = Container.Resolve<IAPIService>();
IAPI api = apiService.GetAPI(); IAPI api = apiService.GetAPI();
// TODO Preferred Account
if (!api.IsConnected)
{
ILoginStorageService loginStorageService = Container.Resolve<ILoginStorageService>();
List<ConnectionData> list = (List<ConnectionData>)await loginStorageService.GetList().ConfigureAwait(false);
ConnectionData connectionData = list.Find(x => string.Equals(x.Host.Host, uri.Host, StringComparison.OrdinalIgnoreCase));
if(connectionData == null)
{
Device.BeginInvokeOnMainThread(async () =>
{
await pageDialogService.DisplayAlertAsync("NFC connect failed", "No ConnectionData", "Ok").ConfigureAwait(false);
});
return;
}
try
{
await api.Connect(connectionData).ConfigureAwait(false);
}
catch (Exception ex)
{
// TODO
Device.BeginInvokeOnMainThread(async () =>
{
await pageDialogService.DisplayAlertAsync("NFC connect failed", ex.ToString(), "Ok").ConfigureAwait(false);
});
return;
}
}
if (api.IsConnected) if (api.IsConnected)
{ {
if (string.Equals(uri.Host, api.ConnectionData.Host.Host, StringComparison.OrdinalIgnoreCase)) if (string.Equals(uri.Host, api.ConnectionData.Host.Host, StringComparison.OrdinalIgnoreCase))
@ -87,7 +126,15 @@ namespace Borepin
} }
} }
} }
else
{
Device.BeginInvokeOnMainThread(async () =>
{
await pageDialogService.DisplayAlertAsync("Intent", "No Services", "Ok").ConfigureAwait(false);
});
}
} }
} }
protected override void RegisterTypes(IContainerRegistry containerRegistry) protected override void RegisterTypes(IContainerRegistry containerRegistry)