Example #1
0
        private async void ProtectedAccessSuspending(object sender, ProtectedAccessSuspendingEventArgs args)
        {
            string logFileContent = "";

            Windows.Foundation.Deferral deferal = args.GetDeferral();

            // Protect any sensitive data in Memory so that it cannot be accessed while the device is  locked
            // You should encrypt or destory any copies of sensitve data while device is going to a locked state.

            IBuffer inputBuffer = CryptographicBuffer.ConvertStringToBinary(m_SecretMessage,
                                                                            BinaryStringEncoding.Utf8);
            BufferProtectUnprotectResult procBuffer = await DataProtectionManager.ProtectAsync(inputBuffer, m_EnterpriseID);

            m_protectedBuffer = procBuffer.Buffer;

            deferal.Complete();

            m_areKeysDropped = true;

            var settings = ApplicationData.Current.LocalSettings;

            settings.Values[m_taskName] += "\nApp got DPL suspend event";

            StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

            StorageFile logFile = await localFolder.CreateFileAsync("SuspendLog.txt",
                                                                    CreationCollisionOption.OpenIfExists);

            logFileContent += "\r\n" + DateTime.Now + ":" + "Got DPL Protected Suspended";
            logFileContent += "\r\n" + "Protection Status:" + procBuffer.ProtectionInfo.Status;

            await FileIO.AppendTextAsync(logFile, logFileContent);
        }
Example #2
0
        private async void BusAttachment_CredentialsRequested(AllJoynBusAttachment sender, AllJoynCredentialsRequestedEventArgs args)
        {
            Windows.Foundation.Deferral credentialsDeferral = args.GetDeferral();

            if ((args.Credentials.AuthenticationMechanism == AllJoynAuthenticationMechanism.EcdhePsk) ||
                (args.Credentials.AuthenticationMechanism == AllJoynAuthenticationMechanism.EcdheSpeke))
            {
                m_authenticateClicked    = new TaskCompletionSource <bool>();
                AuthenticationVisibility = Visibility.Visible;

                UpdateStatusAsync("Please enter the key.", NotifyType.StatusMessage);
                await m_authenticateClicked.Task;
                m_authenticateClicked = null;

                if (!string.IsNullOrEmpty(m_key))
                {
                    args.Credentials.PasswordCredential.Password = m_key;
                }
                else
                {
                    UpdateStatusAsync("Please enter a key.", NotifyType.ErrorMessage);
                }
            }
            else if (args.Credentials.AuthenticationMechanism == AllJoynAuthenticationMechanism.EcdheNull)
            {
            }
            else
            {
                UpdateStatusAsync("Unexpected authentication mechanism.", NotifyType.ErrorMessage);
            }

            credentialsDeferral.Complete();
        }
Example #3
0
        private async void App_EnteredBackground(object sender, EnteredBackgroundEventArgs e)
        {
            Windows.Foundation.Deferral deferral = e.GetDeferral();
            await ServiceLocator.Current.GetService <SuspendAndResumeService>().SaveStateAsync();

            deferral.Complete();
        }
        private void OnPairRequestedAsyncCallback(
            DeviceInformationCustomPairing sender,
            DevicePairingRequestedEventArgs args)
        {
            this.log.Info("OnPairRequested", () => string.Format("Paring kind {0}", args.PairingKind.ToString()));

            BT_PairInfoRequest pairInfo = new BT_PairInfoRequest();

            pairInfo.DeviceName = args.DeviceInformation.Name;

            switch (args.PairingKind)
            {
            case DevicePairingKinds.ConfirmOnly:
                // Windows itself will pop the confirmation dialog as part of "consent" if this is running on Desktop or Mobile
                // If this is an App for 'Windows IoT Core' or a Desktop and Console application
                // where there is no Windows Consent UX, you may want to provide your own confirmation.
                args.Accept();
                break;

            case DevicePairingKinds.ProvidePin:
                // A PIN may be shown on the target device and the user needs to enter the matching PIN on
                // this Windows device. Get a deferral so we can perform the async request to the user.
                using (Windows.Foundation.Deferral collectPinDeferral = args.GetDeferral()) {
                    pairInfo.PinRequested = true;
                    if (this.BT_PairInfoRequested != null)
                    {
                        this.BT_PairInfoRequested(this, pairInfo);
                    }
                    else
                    {
                        this.log.Error(9999, "No subscriber to pin request");
                    }

                    this.log.Info("OnPairRequested",
                                  () => string.Format("Pin '{0}' Response:{1}",
                                                      pairInfo.Pin, pairInfo.Response));

                    if (pairInfo.Response)
                    {
                        // TODO Check for the result to see if you go ahead
                    }

                    if (!string.IsNullOrEmpty(pairInfo.Pin))
                    {
                        args.Accept(pairInfo.Pin);
                    }
                    // TODO - needs to be disposed
                    collectPinDeferral.Complete();
                };
                break;
            }
        }
 /// <summary>
 /// gets called if the app is minimized or closed or suspended (by system)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void App_EnteredBackground(object sender, EnteredBackgroundEventArgs e)
 {
     Windows.Foundation.Deferral def = e.GetDeferral();
     AppHolder.EnteredBackground();
     def.Complete();
 }
Example #6
0
        public PrismApplicationBase()
        {
            InternalInitialize();
            _logger.Log("[App.Constructor()]", Category.Info, Priority.None);

            CoreApplication.Exiting += (s, e) =>
            {
                StopArgs stopArgs = new StopArgs(StopKind.CoreApplicationExiting)
                {
                    CoreApplicationEventArgs = e
                };
                OnStop(stopArgs);
                OnStopAsync(stopArgs);
            };

            WindowService.WindowCreatedCallBacks.Add(Guid.Empty, args =>
            {
                WindowService.WindowCreatedCallBacks.Remove(Guid.Empty);

                args.Window.Closed += (s, e) =>
                {
                    OnStop(new StopArgs(StopKind.CoreWindowClosed)
                    {
                        CoreWindowEventArgs = e
                    });
                    OnStopAsync(new StopArgs(StopKind.CoreWindowClosed)
                    {
                        CoreWindowEventArgs = e
                    }).RunSynchronously();
                };

                SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += async(s, e) =>
                {
                    Windows.Foundation.Deferral deferral = e.GetDeferral();
                    try
                    {
                        OnStop(new StopArgs(StopKind.CloseRequested)
                        {
                            CloseRequestedPreviewEventArgs = e
                        });
                        await OnStopAsync(new StopArgs(StopKind.CloseRequested)
                        {
                            CloseRequestedPreviewEventArgs = e
                        });
                    }
                    finally
                    {
                        deferral.Complete();
                    }
                };
            });

            base.Suspending += async(s, e) =>
            {
                new SuspensionUtilities().SetSuspendDate(DateTime.Now);
                Windows.ApplicationModel.SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
                try
                {
                    StopArgs stopArgs = new StopArgs(StopKind.Suspending)
                    {
                        SuspendingEventArgs = e
                    };
                    OnStop(stopArgs);
                    await OnStopAsync(stopArgs);
                }
                finally
                {
                    deferral.Complete();
                }
            };

            base.Resuming += async(s, e) =>
            {
                ResumeArgs resumeArgs = new ResumeArgs
                {
                    PreviousExecutionState = ApplicationExecutionState.Suspended,
                };
                StartArgs startArgs = new StartArgs(resumeArgs, StartKinds.ResumeInMemory);
                await InternalStartAsync(startArgs);
            };
        }