public MainWindow() { InitializeComponent(); client = new FeedbackClient(); }
/// <summary> /// Execute the action. /// </summary> /// <param name="parameter"></param> public async void Execute(object parameter) { // Lock content. _parentViewModel.IsContentEditable = false; // Validate network. if (!InternetConnectivityDetector.HasInternetConnection) { await ShowInetConnectionFailedMessageDialogAsync(); _parentViewModel.IsContentEditable = true; return; } ImageUploadResult imageResult = null; // If image is present, starting uploading. if (_parentViewModel.IsUploadingImageChecked) { // Reset values. _parentViewModel.IsImageUploadingFinished = false; _parentViewModel.ImageUploadProgressValue = 0.0; try { var file = await StorageFile.GetFileFromPathAsync(_parentViewModel._imagePath); var task = file.UploadImageAsync(); // Report progress to UI. task.Progress += async(info, progressInfo) => { await _parentViewModel._dispatcher.RunAsync(CoreDispatcherPriority.High, () => _parentViewModel.ImageUploadProgressValue = progressInfo); }; // Await result. imageResult = await task; } catch (RequestThrottledException) { await HandleThrottledRequestsAsync(); return; } catch (HttpRequestException) { await HandleErrorsAsync(); return; } catch (FileNotFoundException) { // Ignore file } catch (FeedbackServerErrorException) { await HandleErrorsAsync(); return; } catch (COMException) { await ShowCertIssueAsync(); return; } } // Upload feedback. _parentViewModel.IsImageUploadingFinished = true; try { var type = (_parentViewModel.IsBugChecked) ? FeedbackType.Bug : FeedbackType.Suggestion; // To prevent Akismet false rejections, place title into content if content is empty. if (string.IsNullOrEmpty(_parentViewModel.Content)) { _parentViewModel.Content = _parentViewModel.Title; } await FeedbackClient.SendfeedbackAsync(type, _parentViewModel.Title, _parentViewModel.Content, _parentViewModel.Contact, imageResult); } catch (RequestThrottledException) { await HandleThrottledRequestsAsync(); return; } catch (HttpRequestException) { await HandleErrorsAsync(); return; } catch (FeedbackServerErrorException) { await HandleErrorsAsync(); return; } catch (COMException) { await ShowCertIssueAsync(); return; } // Clean up await ShowFinishedAsync(); }