/// <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)); } } }); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { // start with a default PincodeOptions object Options = new PincodeOptions(PincodeOptions.PincodeScreen.Create, AccountManager.GetAccount(), ""); if (e.Parameter != null) { try { Options = PincodeOptions.FromJson((string)e.Parameter); } catch { // it is not a valid PincodeOptions object so ignore and keep using the default one } } if (Options != null) { switch (Options.Screen) { case PincodeOptions.PincodeScreen.Locked: SetupLocked(); break; case PincodeOptions.PincodeScreen.Confirm: SetupConfirm(); break; default: SetupCreate(); break; } } else { SetupCreate(); } Passcode.Password = ""; Rect bounds = Window.Current.Bounds; // This screen will adjust size for "narrow" views; if the view is sufficiently narrow it will fill the screen and move text to the top, so it can be seen with virtual keyboard. if (bounds.Width < MinimumWidthForBarMode) { PincodeContainer.Height = bounds.Height; PincodeWindow.VerticalAlignment = VerticalAlignment.Top; } else { // Act as a "bar" for screens that have enough horizontal resolution. PincodeWindow.VerticalAlignment = VerticalAlignment.Center; PincodeContainer.Height = BarModeHeight; } }
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)); } }
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) { PlatformAdapter.SendToCustomLogger("PincodeDialog.CreateClicked - 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)); } }
/// <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)); } } }); } }
/// <summary> /// Serialize PincodeOptions object as a JSON string /// </summary> /// <param name="pincodeOptions"></param> /// <returns></returns> public static string ToJson(PincodeOptions pincodeOptions) { return(JsonConvert.SerializeObject(pincodeOptions)); }
/// <summary> /// Serialize PincodeOptions object as a JSON string /// </summary> /// <param name="pincodeOptions"></param> /// <returns></returns> public static string ToJson(PincodeOptions pincodeOptions) { return JsonConvert.SerializeObject(pincodeOptions); }