コード例 #1
0
 void LoadConfiguration()
 {
     DownloadCertificate()
     .ContinueWith(certificateTask => {
         if (!certificateTask.IsFaulted && certificateTask.Result != null)
         {
             DialogHelper.AskForPassword(AppResources.INPUT_PKCS12_PASSWORD, AppResources.CONFIGURATION_TITLE).ContinueWith(
                 senhaTask => {
                 if (!senhaTask.IsFaulted)
                 {
                     try
                     {
                         Stream certificate = certificateTask.Result;
                         if (VerifyCertificate(certificate, senhaTask.Result))
                         {
                             Pkcs12FileHelper.Save(certificate).ContinueWith(saveTask => {
                                 if (!saveTask.IsFaulted)
                                 {
                                     Application.Current.Properties[Const.CONFIG_OK]      = true;
                                     Application.Current.Properties[Const.CONFIG_VERSION] = Const.CONFIG_VALUE_CURRENT_VERSION;
                                     Application.Current.SavePropertiesAsync().Wait();
                                     //Sends the current gcm token to the server if it exists
                                     SendNotificationToken().Wait();
                                     OpenDocumentListPage();
                                 }
                                 else
                                 {
                                     ShowErrorMessage(ExceptionHelper.GetMessage(AppResources.CERTIFICATE_SAVE_ERROR, saveTask.Exception.InnerException),
                                                      () => Application.Current.MainPage = new LoginPage());
                                 }
                             });
                         }
                     }
                     catch (IOException)
                     {
                         //probably a wrong pkcs12 password was supplied. Try again.
                         ShowErrorMessage(AppResources.WRONG_PKCS12_PASSWORD, () => LoadConfiguration());
                     }
                     catch (Exception e)
                     {
                         string errorMsg = ExceptionHelper.GetMessage(AppResources.WRONG_PKCS12_PASSWORD, e);
                         ShowErrorMessage(errorMsg, () => Application.Current.MainPage = new LoginPage());
                     }
                 }
                 else
                 {
                     string errorMsg = ExceptionHelper.GetMessage(AppResources.ASK_PASSWORD_ERROR, senhaTask.Exception.InnerException);
                     ShowErrorMessage(errorMsg, () => Application.Current.MainPage = new LoginPage());
                 }
             });
         }
         else
         {
             string errorMsg = ExceptionHelper.GetMessage(AppResources.CERTIFICATE_LOAD_ERROR, certificateTask.Exception.InnerException);
             ShowErrorMessage(errorMsg, () => Application.Current.MainPage = new LoginPage());
         }
     });
 }