/// <summary>
        ///     This method will launch the pincode screen if the policy requires it.
        ///     If determined that no pincode screen is required, the flag requiring the pincode will be cleared.
        /// </summary>
        public static async void LaunchPincodeScreen()
        {
            var frame = Window.Current.Content as Frame;

            if (frame != null && typeof(PincodeDialog) != frame.SourcePageType)
            {
                await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    SDKServiceLocator.Get <ILoggingService>().Log(" Launching Pincode Screen", LoggingLevel.Information);
                    Account account = AccountManager.GetAccount();
                    if (account != null)
                    {
                        PincodeOptions options = null;
                        bool required          = AuthStorageHelper.IsPincodeRequired();
                        if (account.Policy != null && !IsPincodeSet())
                        {
                            options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, account, "");
                        }
                        else if (required)
                        {
                            MobilePolicy policy = AuthStorageHelper.GetMobilePolicy();
                            if (account.Policy != null)
                            {
                                if (policy.ScreenLockTimeout < account.Policy.ScreenLockTimeout)
                                {
                                    policy.ScreenLockTimeout = account.Policy.ScreenLockTimeout;
                                    AuthStorageHelper.GetAuthStorageHelper().PersistPincode(policy);
                                }
                                if (policy.PinLength < account.Policy.PinLength)
                                {
                                    options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, account, "");
                                }
                                else
                                {
                                    options = new PincodeOptions(PincodeOptions.PincodeScreen.Locked, account, "");
                                }
                            }
                            else
                            {
                                options = new PincodeOptions(PincodeOptions.PincodeScreen.Locked, account, "");
                            }
                        }
                        if (options != null)
                        {
                            // As per MSDN documentation (https://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx)
                            // the second param of Frame.Navigate must be a basic type otherwise Suspension manager will crash
                            // when serializing frame's state. So we serialize custom object using Json and pass that as the
                            // second param to avoid this crash.
                            frame.Navigate(typeof(PincodeDialog), PincodeOptions.ToJson(options));
                        }
                    }
                });
            }
        }
 private void ErrorFlyout_Closed(object sender, object e)
 {
     if (PincodeOptions.PincodeScreen.Confirm == Options.Screen)
     {
         var options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, Options.User, "");
         // As per MSDN documentation (https://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx)
         // the second param of Frame.Navigate must be a basic type otherwise Suspension manager will crash
         // when serializing frame's state. So we serialize custom object using Json and pass that as the
         // second param to avoid this crash.
         Frame.Navigate(typeof(PincodeDialog), PincodeOptions.ToJson(options));
     }
 }
 private void CreateClicked(object sender, KeyRoutedEventArgs e)
 {
     if (e.Key != VirtualKey.Accept && e.Key != VirtualKey.Enter)
     {
         return;
     }
     e.Handled = true;
     if (Passcode.Password.Length >= Options.User.Policy.PinLength)
     {
         LoggingService.Log("Going to confirmation page", LoggingLevel.Verbose);
         var options = new PincodeOptions(PincodeOptions.PincodeScreen.Confirm, Options.User, Passcode.Password);
         // As per MSDN documentation (https://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx)
         // the second param of Frame.Navigate must be a basic type otherwise Suspension manager will crash
         // when serializing frame's state. So we serialize custom object using Json and pass that as the
         // second param to avoid this crash.
         Frame.Navigate(typeof(PincodeDialog), PincodeOptions.ToJson(options));
     }
     else
     {
         DisplayErrorFlyout(String.Format(LocalizedStrings.GetString("passcode_length"),
                                          Options.User.Policy.PinLength));
     }
 }