Example #1
0
        void RefreshDeviceList(IReadOnlyList <SecondaryAuthenticationFactorInfo> deviceList, int slectedIndex)
        {
            string          dateString = string.Empty;
            listContent     listItem;
            List <DateTime> dateList = new List <DateTime>();
            int             cpt      = 0;

            for (int index = 0; index < deviceList.Count; ++index)
            {
                SecondaryAuthenticationFactorInfo deviceInfo = deviceList.ElementAt(index);
                //Debug.WriteLine(deviceInfo.DeviceConfigurationData);

                listItem = new listContent();
                //DateTime now = DateTime.Now;
                listItem.deviceFriendlyName = deviceInfo.DeviceFriendlyName;

                listItem.deviceGUID = deviceInfo.DeviceId;
                int count = deviceInfo.DeviceFriendlyName.Count();
                listItem.date       = DateTime.Parse(ExtractDateFromDeviceInfo(deviceInfo));
                dateString          = CommomMethods.FormatDate(listItem.date);
                listItem.dateString = dateString;
                if (DeviceListBox.Items.Count > index - cpt)
                {
                    DeviceListBox.Items.Remove(DeviceListBox.Items.ElementAt(index - cpt));
                    cpt++;
                }
            }
            for (int index = 0; index < deviceList.Count; ++index)
            {
                SecondaryAuthenticationFactorInfo deviceInfo = deviceList.ElementAt(index);

                listItem = new listContent();
                listItem.deviceFriendlyName = deviceInfo.DeviceFriendlyName;
                listItem.deviceGUID         = deviceInfo.DeviceId;
                int count = deviceInfo.DeviceFriendlyName.Count();

                listItem.date       = DateTime.Parse(ExtractDateFromDeviceInfo(deviceInfo));
                dateString          = CommomMethods.FormatDate(listItem.date);
                listItem.dateString = dateString;
                if (index == deviceList.Count - 1)
                {
                    listItem.isVisible = false;
                }
                else
                {
                    listItem.isVisible = true;
                }
                DeviceListBox.Items.Add(listItem);
            }
        }
        private async void StackRegsiter_tapped(object sender, TappedRoutedEventArgs e)
        {
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 0);
            MessageDialog myDlg;
            bool          executeFinally = true;

            if ((sender is StackPanel) && (e.OriginalSource is TextBlock))
            {
                ((Grid)((StackPanel)sender).Parent).Children.ElementAt(3).Visibility = Visibility.Visible;
                ((StackPanel)sender).Children.ElementAt(1).Visibility = Visibility.Collapsed;
            }
            string deviceFriendlyName = NameYourDevice.Text.Trim();

            var    loader = new Windows.ApplicationModel.Resources.ResourceLoader();
            string deviceNameAlreadyUsedContent = loader.GetString("DeviceNameAlreadyUsed_content_error");
            string deviceNameAlreadyUsedTitle   = loader.GetString("DeviceNameAlreadyUsed_title_error");

            string deviceAlreadyRegisteredContent = loader.GetString("DeviceAlreadyRegistered_content_error");
            string deviceAlreadyRegisteredTitle   = loader.GetString("DeviceAlreadyRegistered_title_error");

            try
            {
                IReadOnlyList <SecondaryAuthenticationFactorInfo> deviceList = await SecondaryAuthenticationFactorRegistration.FindAllRegisteredDeviceInfoAsync(SecondaryAuthenticationFactorDeviceFindScope.User);

                foreach (SecondaryAuthenticationFactorInfo device in deviceList)
                {
                    if (device.DeviceFriendlyName == deviceFriendlyName)
                    {
                        throw new Exception(deviceNameAlreadyUsedContent);
                    }
                }
                await CommomMethods.RegisterDevice_Click(deviceFriendlyName);
            }
            catch (Exception ex)
            {
                if (ex.Message == deviceNameAlreadyUsedContent)
                {
                    myDlg = new MessageDialog(ex.Message, deviceNameAlreadyUsedTitle);

                    await myDlg.ShowAsync();

                    this.Frame.Navigate(typeof(RegisterDevice));
                    executeFinally = false;
                }
                else if (ex.Message == deviceAlreadyRegisteredContent)
                {
                    myDlg = new MessageDialog(deviceAlreadyRegisteredContent, deviceAlreadyRegisteredTitle);
                    await myDlg.ShowAsync();

                    this.Frame.Navigate(typeof(waitingForDevice));
                    executeFinally = false;
                }
                else
                {
                    IReadOnlyList <SecondaryAuthenticationFactorInfo> deviceList = await SecondaryAuthenticationFactorRegistration.FindAllRegisteredDeviceInfoAsync(SecondaryAuthenticationFactorDeviceFindScope.User);

                    if (deviceList.Count > 0)
                    {
                        this.Frame.Navigate(typeof(MainPage), "false");
                    }
                    else
                    {
                        this.Frame.Navigate(typeof(waitingForDevice));
                    }
                }
            }
            finally
            {
                if (executeFinally)
                {
                    this.Frame.Navigate(typeof(MainPage), "false");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            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 (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

                bool          isSupported;
                MessageDialog myDlg;
                isSupported = await KeyCredentialManager.IsSupportedAsync();

                if (!isSupported)
                {
                    var    loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                    string PleaseSetUpPinContent = loader.GetString("PleaseSetupPin_content_error");
                    string PleaseSetUpPinTitle   = loader.GetString("PleaseSetupPin_title_error");

                    myDlg = new MessageDialog(PleaseSetUpPinContent, PleaseSetUpPinTitle);
                    await myDlg.ShowAsync();

                    Application.Current.Exit();
                    return;
                }

                IReadOnlyList <SecondaryAuthenticationFactorInfo> registeredDeviceList = await SecondaryAuthenticationFactorRegistration.FindAllRegisteredDeviceInfoAsync(
                    SecondaryAuthenticationFactorDeviceFindScope.User);

                if (registeredDeviceList.Count == 0)
                {
                    rootFrame.Navigate(typeof(waitingForDevice), e.Arguments);
                }
                else
                {
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
            }
            // Ensure the current window is active

            CommomMethods.SetWindowSize();
            Window.Current.Activate();
        }