From b9bb50df87846e822c4b1d56614728e70e565202 Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Tue, 21 Feb 2023 22:14:16 +0100 Subject: [PATCH] Try to connect on NFC App Start with Server --- Borepin/Borepin/App.xaml.cs | 55 ++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/Borepin/Borepin/App.xaml.cs b/Borepin/Borepin/App.xaml.cs index 2ce7da7..e8c4d4c 100644 --- a/Borepin/Borepin/App.xaml.cs +++ b/Borepin/Borepin/App.xaml.cs @@ -19,6 +19,8 @@ using Borepin.Service; using FabAccessAPI; using FabAccessAPI.Schema; using System.Threading.Tasks; +using System.Collections.Generic; +using Prism.Services; namespace Borepin { @@ -56,14 +58,51 @@ namespace Borepin protected override async void OnAppLinkRequestReceived(Uri uri) { - if(uri.LocalPath.StartsWith("/resource/", StringComparison.OrdinalIgnoreCase)) - { - string resource_id = uri.LocalPath.Remove(0, "/resource/".Length); + IPageDialogService pageDialogService = Container.Resolve(); - if (Container.IsRegistered()) + if (uri.LocalPath.StartsWith("/resource/", StringComparison.OrdinalIgnoreCase)) + { + if (Container.IsRegistered() && Container.IsRegistered()) { + string resource_id = uri.LocalPath.Remove(0, "/resource/".Length); + IAPIService apiService = Container.Resolve(); IAPI api = apiService.GetAPI(); + + // TODO Preferred Account + if (!api.IsConnected) + { + ILoginStorageService loginStorageService = Container.Resolve(); + List list = (List)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 (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)