// Occurs whenever validation of the value provided by the user failed, and the user didn't agree to retry. private void OnProvidedShortIdValidationFailed(object sender, UserWithSaturn5ShortIdEventArgs e) { // Displays appropriate logs informing user about empty short id input being provided. this._consolesServices.OnAllocateSaturn5ByShortId_ProvidedShortIdValidationFailed(sender, e); // Close the application. this._form.Close(); }
// Occurs whenever user pressed enter when appropriate for this UI task validation box is enable, // and right before a validation of provided by the user value will begin. private void OnProvidedShortIdValidationBegan(object sender, UserWithSaturn5ShortIdEventArgs e) { // Subscribe to appropriate cancellation method this.ChangeCancelationMethodForShortIdInput(e); // Displays appropriate logs informing user about empty short id input being provided. this._consolesServices.OnAllocateSaturn5ByShortId_ProvidedShortIdValidationBegan(sender, e); }
// Occurs whenever app canceled to obtain saturn 5 data from provided valid short id. private void OnCancelToRetrieveSaturn5Data(object sender, UserWithSaturn5ShortIdEventArgs e) { // Displays appropriate logs informing user that application canceled obtaining saturn 5 data. this._consolesServices.OnRetrievingSaturn5DataByShortIdCanceled(sender, new Saturn5ShortIdEventArgs(e.ShortId)); this._consolesServices.OnBackToIdle(sender, e); // Clears info boxes this._dataDisplayServices.ClearInfoBoxes(sender, e); // Clears the content of all of the main form text boxes displaying User/Satur5 etc. data. this._dataDisplayServices.ClearAllDataDisplayTextBoxes(sender, e); // Enable appropriate controls. this._controlsEnabler.OnAllocateSaturn5ByShortId_CancelToRetrieveSaturn5Data(sender, e); }
// Occurs whenever validation of the value provided by the user has been canceled. private void OnProvidedShortIdValidationCanceled(object sender, UserWithSaturn5ShortIdEventArgs e) { // Stop listening for short idtext box input. this.StopListenForShortIdInput(); // Enables/Disables appropriate controls. this._controlsEnabler.OnAllocateSaturn5ByShortId_ProvidedShortIdValidationCanceled(sender, e); // Displays appropriate logs informing this._consolesServices.OnAllocateSaturn5ByShortId_ProvidedShortIdValidationCanceled(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); }
// Occurs whenever app fails to obtain saturn 5 data from provided valid short id. private void OnFailToRetrieveSaturn5Data(object sender, UserWithSaturn5ShortIdEventArgs e) { // Displays appropriate logs informing user that application failed to obtaining saturn 5 data . this._consolesServices.OnRetrievingSaturn5DataByShortIdFailed(sender, new Saturn5ShortIdEventArgs(e.ShortId)); // Ask user what to do in case of failure DialogResult result = MessageBox.Show($"Application failed to obtain saturn 5 data using provided barcode: {e.ShortId} {Environment.NewLine}Would You like to Retry or Cancel the operation?", "Failed to obtain saturn 5 data.", MessageBoxButtons.RetryCancel); switch (result) { case DialogResult.Cancel: this.OnCancelToRetrieveSaturn5Data(sender, e); break; case DialogResult.Retry: this.OnValidShortIdProvided(sender, e); break; } }
// Occurs whenever user provided valid short id into the appropriate preBrief text box private void OnValidShortIdProvided(object sender, UserWithSaturn5ShortIdEventArgs e) { // Stop listening for saturn 5 short id this.StopListenForShortIdInput(); // Displays appropriate logs informing user about valid short id being provided. this._consolesServices.OnAllocateSaturn5ByShortId_ValidShortIdProvided(sender, new Saturn5ShortIdEventArgs(e.ShortId)); // Disables saturn short id input text box this._controlsEnabler.OnAllocateSaturn5ByShortId_ValidShortIdProvided(sender, e); // Displays appropriate logs informing user that application began to obtaining Saturn5 data based on the provided short id this._consolesServices.OnRetrievingSaturn5DataByShortIdBegan(sender, new Saturn5ShortIdEventArgs(e.ShortId)); // Set text boxes according to the current state of the UITask. this._dataDisplayServices.OnRetrievingSaturn5DataByShortIdBegan(sender, new Saturn5ShortIdEventArgs(e.ShortId)); // Attempt to obtain saturn 5 data... Task <Saturn5> getSaturn5Task = this._saturn5Services.GetByShortIdAsync(e.ShortId); getSaturn5Task.ContinueWith((t) => { switch (t.Status) { case TaskStatus.RanToCompletion: // ... execute if succeed to obtain saturn 5 data. this.OnSuccessfullyRetrievedSaturn5Data(sender, new UserWithSaturn5EventArgs(e.User, t.Result)); break; case TaskStatus.Faulted: // ... execute if failed to obtain saturn 5 data. this.OnFailToRetrieveSaturn5Data(sender, e); break; case TaskStatus.Canceled: // ... execute if attempt to obtain saturn 5 data has been canceled. this.OnCancelToRetrieveSaturn5Data(sender, e); break; } }, TaskScheduler.FromCurrentSynchronizationContext()); }
private void StopListenForShortIdInput() { if (this.tbxPreBriefSaturn5Barcode.InvokeRequired) { Action d = new Action(StopListenForShortIdInput); if (!this.tbxPreBriefSaturn5Barcode.IsDisposed) { this.tbxPreBriefSaturn5Barcode.Invoke(d); } } else if (!this.tbxPreBriefSaturn5Barcode.IsDisposed) { this.AwaitingShortIdCanceled -= this.OnAwaitingShortIdCanceled; this.ValidatingShortIdCanceled -= this.OnProvidedShortIdValidationCanceled; this.tbxPreBriefSaturn5Barcode.InputValidationBegan -= this.OnProvidedShortIdValidationBegan; this.tbxPreBriefSaturn5Barcode.InputValidationFailed -= this.OnProvidedShortIdValidationFailed; this.tbxPreBriefSaturn5Barcode.InputValidationCanceled -= this.OnProvidedShortIdValidationCanceled; this.tbxPreBriefSaturn5Barcode.ValidInputValueProvided -= this.OnValidShortIdProvided; this.tbxPreBriefSaturn5Barcode.EmptyInputValueProvided -= this.OnEmptyShortIdProvided; this.tbxPreBriefSaturn5Barcode.InvalidInputValueProvided -= this.OnInvalidShortIdProvided; this._shortIdValidationCancelationArgs = null; } }
private void ChangeCancelationMethodForShortIdInput(UserWithSaturn5ShortIdEventArgs e) { if (this.tbxPreBriefSaturn5Barcode.InvokeRequired) { Action <UserWithSaturn5ShortIdEventArgs> d = new Action <UserWithSaturn5ShortIdEventArgs>(ChangeCancelationMethodForShortIdInput); if (!this.tbxPreBriefSaturn5Barcode.IsDisposed) { this.tbxPreBriefSaturn5Barcode.Invoke(d, e); } } else if (!this.tbxPreBriefSaturn5Barcode.IsDisposed) { this._shortIdValidationCancelationArgs = e; this.AwaitingShortIdCanceled -= this.OnAwaitingShortIdCanceled; //this.AwaitingShortIdCanceled += this.OnAwaitingShortIdCanceled; this.ValidatingShortIdCanceled -= this.OnProvidedShortIdValidationCanceled; this.ValidatingShortIdCanceled += this.OnProvidedShortIdValidationCanceled; this.tbxPreBriefSaturn5Barcode.InputValidationCanceled -= this.OnProvidedShortIdValidationCanceled; this.tbxPreBriefSaturn5Barcode.InputValidationCanceled += this.OnProvidedShortIdValidationCanceled; } }
// Occurs whenever user will provide invalid short id. private void OnInvalidShortIdProvided(object sender, UserWithSaturn5ShortIdEventArgs e) { // Displays appropriate logs informing user about invalid short id being provided. this._consolesServices.OnAllocateSaturn5ByShortId_InvalidShortIdProvided(sender, e); }
// Occurs whenever user will provide empty value in place of valid short id number. private void OnEmptyShortIdProvided(object sender, UserWithSaturn5ShortIdEventArgs e) { // Displays appropriate logs informing user about empty short id number input being provided. this._consolesServices.OnAllocateSaturn5ByShortId_EmptyShortIdProvided(sender, e); }