예제 #1
0
 private async void OpenButton_Click(object sender, RoutedEventArgs e)
 {
     if (GridMdp.Visibility == Visibility.Visible)
     {
         if (await PasswordBusiness.DoesFileCypherExist())
         {
             ((Frame)Window.Current.Content).Navigate(typeof(StartPageView), ModeOuvertureEnum.FichierDejaExistant);
         }
         else
         {
             ((Frame)Window.Current.Content).Navigate(typeof(StartPageView), ModeOuvertureEnum.FichierACreer);
         }
     }
     else
     {
         ((Frame)Window.Current.Content).Navigate(typeof(MainPageView));
     }
 }
예제 #2
0
        /// <summary>
        /// Lance l'application
        /// </summary>
        /// <param name="recherche">la recherche commandé par cortana sinon null</param>
        /// <param name="fichier">le fichier à ouvrir dans la page de partage</param>
        /// <returns></returns>
        private async Task LaunchApp(string recherche, StorageFile fichier)
        {
            var 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;
                rootFrame.Navigated        += OnNavigated;

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

                // Register a handler for BackRequested events and set the
                // visibility of the Back button
                SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    rootFrame.CanGoBack ?
                    AppViewBackButtonVisibility.Visible :
                    AppViewBackButtonVisibility.Collapsed;
            }

            if (rootFrame.Content == null)
            {
                await ContexteAppli.Initialize(true, fichier);

                bool ouvertureReussi;

                if (fichier != null)
                {
                    if (StringUtils.GetExtension(fichier.Name) == ContexteStatic.Extension)
                    {
                        ouvertureReussi = rootFrame.Navigate(typeof(StartPageView), ModeOuvertureEnum.FichierDejaExistant);
                    }
                    else if (StringUtils.GetExtension(fichier.Name) == ContexteStatic.ExtensionPartage)
                    {
                        if (await PasswordBusiness.DoesFileCypherExist())
                        {
                            ouvertureReussi = rootFrame.Navigate(typeof(RecupPasswordView), fichier);
                        }
                        else
                        {
                            ouvertureReussi = rootFrame.Navigate(typeof(StartPageView), ModeOuvertureEnum.FichierACreer);
                        }
                    }
                    else
                    {
                        ouvertureReussi = false;
                    }
                }
                else
                {
                    if (await PasswordBusiness.DoesFileCypherExist())
                    {
                        if (!string.IsNullOrWhiteSpace(recherche))
                        {
                            ouvertureReussi = rootFrame.Navigate(typeof(ResultCortanaView), recherche);
                        }
                        else
                        {
                            ouvertureReussi = rootFrame.Navigate(typeof(StartPageView), ModeOuvertureEnum.FichierDejaExistant);
                        }
                    }
                    else
                    {
                        ouvertureReussi = rootFrame.Navigate(typeof(StartPageView), ModeOuvertureEnum.FichierACreer);
                    }
                }

                if (!ouvertureReussi)
                {
                    throw new Exception(ResourceLoader.GetForCurrentView("Errors").GetString("erreurDemarrage"));
                }
                Window.Current.Activate();
            }
        }
예제 #3
0
        /// <summary>
        /// Méthode se lancant lors de l'appel de cortana pour l'appli
        /// </summary>
        /// <param name="taskInstance"></param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //lancement de cortana, récupération des objets nécéssaires
            _serviceDeferral       = taskInstance.GetDeferral();
            taskInstance.Canceled += (sender, reason) => _serviceDeferral?.Complete();
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            _voiceCommandServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
            _voiceCommandServiceConnection.VoiceCommandCompleted += (sender, args) => _serviceDeferral?.Complete();
            var    identifiant = (await _voiceCommandServiceConnection.GetVoiceCommandAsync()).Properties["site"][0].ToLower();
            string message;
            var    openApp   = false;
            var    openTiles = false;
            var    tiles     = new List <VoiceCommandContentTile>();

            //Initialisation de l'appli
            await ContexteAppli.Initialize(false, null);

            //si le fichier existe
            if (await PasswordBusiness.DoesFileCypherExist())
            {
                //si cortana est autorisé
                if (ContexteAppli.IsCortanaActive)
                {
                    //récupération du mot de passe
                    var mdp = await CortanaBusiness.GetPasswordUser();

                    if (!string.IsNullOrWhiteSpace(mdp))
                    {
                        //chargement du fichier
                        if (await PasswordBusiness.Load(mdp, false))
                        {
                            tiles = CortanaBusiness.GetMotDePasseTile(identifiant, ContexteAppli.DossierMere);

                            if (tiles.Count == 0)
                            {
                                message = GetString("cortanaAucunIdentifiant");
                            }
                            else if (tiles.Count > 10)
                            {
                                message = GetString("cortanaPlusieursResultats");
                                openApp = true;
                            }
                            else
                            {
                                message   = GetString("cortanaIdentifiantsTrouves");
                                openTiles = true;
                            }
                        }
                        else
                        {
                            message = GetString("cortanaEchecFichier");
                            openApp = true;
                        }
                    }
                    else
                    {
                        message = GetString("cortanaEchecFichier");
                        openApp = true;
                    }
                }
                else
                {
                    message = GetString("cortanaLanceApp");
                    openApp = true;
                }
            }
            else
            {
                message = GetString("cortanaAucunIdentifiant");
            }

            var userPrompt = new VoiceCommandUserMessage
            {
                DisplayMessage = message,
                SpokenMessage  = message
            };

            if (openApp)
            {
                var response = VoiceCommandResponse.CreateResponse(userPrompt);
                response.AppLaunchArgument = identifiant;
                await _voiceCommandServiceConnection.RequestAppLaunchAsync(response);
            }
            else if (openTiles)
            {
                var response = VoiceCommandResponse.CreateResponse(userPrompt, tiles);
                await _voiceCommandServiceConnection.ReportSuccessAsync(response);
            }
            else
            {
                var response = VoiceCommandResponse.CreateResponse(userPrompt);
                await _voiceCommandServiceConnection.ReportSuccessAsync(response);
            }
        }