/// <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(); } }
/// <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); } } }
/// <summary> /// Getting last data from server /// </summary> /// <returns>Result of synchronization</returns> public async Task ServerDataSynchronization() { if (InternetFeaturesEnable) { // Calendars, projects and map events synchronization try { // Contacts synchronization var contactsSynchResult = await InternetRequests.ContactsSynchronizationRequestAsync(); if (contactsSynchResult == 1) { throw new HttpRequestException("Internet connection problem or bad token"); } Debug.WriteLine("Контакты синхронизированы с сервером"); var resultOfSynchronization = await InternetRequests.SynchronizationRequestAsync(); if (resultOfSynchronization == 0) { ShowToastNotification(0); } if (resultOfSynchronization == 1) { ShowToastNotification(1); } } catch (Exception) { ShowToastNotification(1); } Debug.WriteLine("Календари, проекты и события синхронизированы с сервером"); } }