Beispiel #1
0
        /// <summary>
        /// Try sign in with token
        /// </summary>
        private async Task AppSignInWithToken()
        {
            var res = await FileSystemRequests.LoadUserEmailAndTokenFromFileAsync();

            if (string.IsNullOrEmpty(res.email) || string.IsNullOrEmpty(res.token))
            {
                return;
            }

            try
            {
                if (!InternetRequests.CheckForInternetConnection())
                {
                    return;
                }

                var requestResult = await InternetRequests.PostRequestAsync(InternetRequests.PostRequestDestination.SignInWithToken);

                if (requestResult == 0)
                {
                    await InternetRequests.ContactsSynchronizationRequestAsync();

                    ResourceLoader = ResourceLoader.GetForCurrentView("App");

                    // Save user local data for using after sign in
                    ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
                    User currentUser = new User();
                    await currentUser.LoadUserFromFileAsync();

                    localSettings.Values["email"] = currentUser.Email.ToLower() ?? $"{ResourceLoader.GetString("/App/Unknown")}@gmail.com";

                    if (Window.Current.Content is Frame frame)
                    {
                        frame.Navigate(typeof(StartPage));
                    }

                    await StartPageViewModel.Instance.ServerDataSynchronization();
                }
            }
            catch (Exception ex)
            {
                await(new Windows.UI.Popups.MessageDialog($"{ex.Message}\n" +
                                                          $"{ResourceLoader.GetString("/App/SignInWithTokenError")}", $"{ResourceLoader.GetString("/App/SignInErrorHeader")}")).ShowAsync();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Regular synchronization of calendars, projects and map events
 /// </summary>
 /// <returns>Result of synchronization</returns>
 public async Task CategoriesSynchronization()
 {
     // Start synchronization if internet connection enabled
     if (InternetFeaturesEnable && InternetRequests.CheckForInternetConnection())
     {
         try
         {
             // Synchronization updated categories
             if (await InternetRequests.SynchronizationRequestAsync() == 1)
             {
                 ShowToastNotification(1);
             }
         }
         catch (Exception)
         {
             ShowToastNotification(1);
         }
     }
 }