Esempio n. 1
0
 protected virtual void OnBadgeTapped(BadgeEventArgs e) => BadgeTapped?.Invoke(this, e);
Esempio n. 2
0
        private async void Nfc_BadgeTapped(object sender, BadgeEventArgs e)
        {
            if (!Settings.CheckInEnabled)
            {
                var toastContent = new ToastContent()
                {
                    Visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = "Badge scanned"
                                },
                                new AdaptiveText()
                                {
                                    Text = "ID: " + e.uuid
                                },
                            }
                        }
                    }
                };
                var toast = new ToastNotification(toastContent.GetXml())
                {
                    ExpirationTime = DateTime.Now.AddSeconds(10)
                };
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }

            if (Settings.CheckInEnabled)
            {
                string name;
                if (Settings.CheckInAction)
                {
                    name = await CheckInAPI.CheckIn(e.uuid, Settings.CheckInTag);
                }
                else
                {
                    name = await CheckInAPI.CheckOut(e.uuid, Settings.CheckInTag);
                }

                var toastContent = new ToastContent()
                {
                    Visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = $"Checked {(Settings.CheckInAction ? "in" : "out")} user"
                                },
                                new AdaptiveText()
                                {
                                    Text = name != null ? $"Name: {name}" : "Invalid tag"
                                },
                            }
                        }
                    }
                };
                var toast = new ToastNotification(toastContent.GetXml())
                {
                    ExpirationTime = DateTime.Now.AddSeconds(10)
                };
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }
            if (Settings.WebSocketsEnabled)
            {
                // Run on UI thread
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        await SportalFrame.InvokeScriptAsync("eval", new string[] { $"nfcService.onReceiveID(\"{e.uuid}\")" });
                    }
                    catch (Exception err)
                    {
                        Debug.WriteLine($"{err.Message}: {err.StackTrace}");
                    }
                });
            }
            if (Settings.ClipboardEnabled)
            {
                var package = new DataPackage();
                package.RequestedOperation = DataPackageOperation.Copy;
                package.SetText(e.uuid);

                // Clipboard operations must occur on the UI thread
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                    try
                    {
                        Clipboard.SetContent(package);
                    }
                    catch (Exception err)
                    {
                        Debug.WriteLine($"{err.Message}: {err.StackTrace}");
                    }
                });
            }
            if (Settings.ScanLogEnabled)
            {
                StorageFile logFile = await Settings.GetScanLogLocation();

                await FileIO.AppendTextAsync(logFile, $"[{DateTime.Now.ToShortDateString()} {DateTime.Now.ToLongTimeString()}] Scanned badge: {e.uuid}\r\n");
            }
        }