// Occurs whenever valid fault report has been provided and it require to be persisted. private void OnReportDataUploadRequired(object sender, UserWithSaturn5FaultReportEventArgs e) { // Displays appropriate logs informing user that application began uploading the saturn 5 confirmation data. this._consolesServices.OnConfirmBackInFaultySaturn5BySerialNumber_UploadingSaturn5ReportingFaultDataBegan(sender, e); // Report the fault based on the FaultReportCreationForm Task reportingFaultTask = this._saturn5Services.ReportFaultAsync(e.Saturn5.SerialNumber, e.User.Username, e.Description); reportingFaultTask.ContinueWith((t) => { switch (t.Status) { case TaskStatus.RanToCompletion: // ... execute if successfully reported the fault // Get just reported fault: Saturn5Issue fault = this._saturn5Services.GetLastUnresolvedFault(e.Saturn5.SerialNumber); this.OnUploadingSaturn5ReportingFaultDataSucceed(sender, new UserWithFaultySaturn5EventArgs(e.User, e.Saturn5, fault)); break; case TaskStatus.Faulted: // ... execute if failed to report the fault this.OnUploadingSaturn5ReportingFaultDataFailed(sender, e); break; case TaskStatus.Canceled: // ... execute if attempt to report the fault has been canceled. this.OnUploadingSaturn5ReportingFaultDataCanceled(sender, e); break; } }, TaskScheduler.FromCurrentSynchronizationContext()); }
// Occurs whenever attempt to commit fault data upload has been canceled private void OnUploadingSaturn5ReportingFaultDataCanceled(object sender, UserWithSaturn5FaultReportEventArgs e) { // Displays appropriate logs informing user that application canceled obtaining user data. this._consolesServices.OnConfirmBackInFaultySaturn5BySerialNumber_UploadingSaturn5ReportingFaultDataCanceled(sender, e); this._consolesServices.OnBackToIdle(sender, e); // Clears the content of all of the main form text boxes displaying User/Satur5 etc. data. this._dataDisplayServices.ClearAllDataDisplayTextBoxes(sender, e); // Clears info boxes this._dataDisplayServices.ClearInfoBoxes(sender, e); // Enables/Disables appropriate controls. this._controlsEnabler.OnConfirmBackInFaultySaturn5BySerialNumber_UploadingSaturn5ReportingFaultDataCanceled(sender, e); }
// Occurs whenever attempt to commit fault data upload failed private void OnUploadingSaturn5ReportingFaultDataFailed(object sender, UserWithSaturn5FaultReportEventArgs e) { // Print operation failure logs. this._consolesServices.OnConfirmBackInFaultySaturn5BySerialNumber_UploadingSaturn5ReportingFaultDataFailed(sender, e); // Ask user what to do in case of failure DialogResult result = MessageBox.Show($"Failed to report Saturn 5 unit fault. Would You like to retry? Or would you like to cancel and close the application.", "Failed to report Saturn 5 unit fault.", MessageBoxButtons.RetryCancel); if (result == DialogResult.Retry) { // If user pressed 'Retry' button, reattempt to connect with database. this.OnReportDataUploadRequired(sender, e); return; } // Otherwise close the application. this._form.Close(); }