/// <summary> /// Save the current search online. /// </summary> /// <param name="word">String searched</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private static async Task SaveDictionarySearchAsync(string word) { UserActivityDictionarySearch dictSearch = new UserActivityDictionarySearch() { ActivityId = BritishEnglishDictionarySearchID, Word = word }; Tools.Logger.Log("DictionaryLog", "Start logging procedure (ID: " + dictSearch.ActivityId + ", Word: " + dictSearch.Word + ")"); ExerciseSubmissionApi dictSearchSubmissionEndpoint = new ExerciseSubmissionApi(App.OAuth2Account, dictSearch); Tools.Logger.Log("DictionaryLog", "Send data to the server"); Task dictSearchSubmissionTask = Task.Run(async() => await dictSearchSubmissionEndpoint.CallEndpointAsync()); await dictSearchSubmissionTask; if (dictSearchSubmissionTask.IsFaulted) { Tools.Logger.Log("DictionaryLog", "Exception", dictSearchSubmissionTask.Exception); // Prevent the inner exception from terminating the program. foreach (Exception ex in dictSearchSubmissionTask.Exception.InnerExceptions) { Tools.Logger.Log("DictionaryLog", "Inner exception", ex); } } else { Tools.Logger.Log("DictionaryLog", "Data received. Everything is OK!"); } }
/// <summary> /// Event handler /// </summary> /// <param name="sender">Sender param</param> /// <param name="e">evet param</param> private async void SaveButton_Clicked(object sender, EventArgs e) { bool userChoice = await this.DisplayAlert( Properties.Resources.ButtonSave, Properties.Resources.UserMessageSaveAndOverrideQuestion, Properties.Resources.ButtonSaveAndOverride, Properties.Resources.ButtonCancel); if (userChoice) { try { // Save the current status await this.AnalyzeText(); ExerciseSubmissionApi exSubAPI = new ExerciseSubmissionApi( App.OAuth2Account, new UserActivityEssay() { ActivityId = this.ex.Uid, Text = this.ex.Contents }); await exSubAPI.CallEndpointAsync(); } catch (OperationCanceledException ex) { await Tools.Logger.LogWithErrorMessage(this, Properties.Resources.EssayExerciseViewSaveExceptionOpCanceled, ex); } catch (UnsuccessfulApiCallException ex) { await Tools.Logger.LogWithErrorMessage(this, Properties.Resources.EssayExerciseViewSaveExceptionAPI, ex); } catch (Exception ex) { await Tools.Logger.LogWithErrorMessage(this, Properties.Resources.EssayExerciseViewSaveExceptionUnknown, ex); } } }