Example #1
0
        private async void OnResuming(object sender, object e)
        {
            await SharedState.LogAsync("Scannit: RESUMING!");

            await SharedState.SetAsync(SharedState.IsApplicationInForeground, true);

            await Scanner.StartScanner();
        }
Example #2
0
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // Ensure the current window is active

                SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
                Window.Current.Activate();
            }

            // If we were suspended, Resuming will fire and take care of this
            if (e.PreviousExecutionState != ApplicationExecutionState.Suspended)
            {
                await SharedState.SetAsync(SharedState.IsApplicationInForeground, true);

                await Scanner.StartScanner();
            }
        }
        private async void Reader_CardAdded(SmartCardReader sender, CardAddedEventArgs args)
        {
            await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): CardAdded event fired.");

            try
            {
                TravelCard card = await CardOperations.ReadTravelCardAsync(args.SmartCard);

                if (card != null)
                {
                    await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Successful read card.");

                    Task updateCardTask = SharedState.SetAsync(SharedState.LastSeenCard, card.RawValues);
                    await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): LastSeenCard updated.");


                    Task updateTimestampTask = SharedState.SetAsync(SharedState.LastSeenTimestamp, DateTimeOffset.UtcNow);
                    await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): LastSeenTimestamp updated.");

                    if (await SharedState.GetAsync <bool>(SharedState.IsApplicationInForeground))
                    {
                        await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Application is in the foreground. Changed Progress value.");

                        _taskInstance.Progress = 2;
                    }
                    else
                    {
                        await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Application is in the background. Post toast notification.");


                        PostToastNotification(card);
                    }
                }
            }
            catch (Exception ex)
            {
                await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Failed to read travel card! Exception: {ex}\nStack trace: {ex.StackTrace}");
            }
        }
Example #4
0
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
            var newSession = new ExtendedExecutionSession
            {
                Reason = ExtendedExecutionReason.SavingData
            };

            newSession.Revoked += NewSession_Revoked;

            ExtendedExecutionResult result = await newSession.RequestExtensionAsync();

            if (result == ExtendedExecutionResult.Allowed)
            {
                await SharedState.LogAsync("Scannit: SUSPENDING!");

                await SharedState.SetAsync(SharedState.IsApplicationInForeground, false);

                newSession.Revoked -= NewSession_Revoked;
                newSession.Dispose();
                newSession = null;
            }
            deferral.Complete();
        }