示例#1
0
        /// <summary>
        /// Handles displaying relevant messages to the user from the inputs
        /// <see cref="IResponse.Messages"/> are displayed as a bullet point list
        /// </summary>
        /// <param name="parentControl"></param>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="response">The <see cref="IResponse"/> to handle</param>
        /// <param name="showSuccessMessage">Defines if the <see cref="IResponse.Success"/> is true then show a success message</param>
        /// <param name="ignoreResponseMessage">If <see cref="IResponse.Success"/> is true and ignoreResponseMessage is also true then messages from response are ignored</param>
        /// <param name="successMessage">If <see cref="IResponse.Success"/> and ignoreResponseMessage are true then successMessage is used in <see cref="MessageBox"/> message</param>
        public static bool AlertResponse(Control parentControl, string operationTitle, IResponse response, bool showSuccessMessage = false,
                                         bool ignoreResponseMessage = false, string successMessage = "Processed successfully")
        {
            if (response == null)
            {
                AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(parentControl), operationTitle, "Provided response is null.", string.Empty, string.Empty,
                                          AlertType.Error, AlertButtons.Ok);
                return(false);
            }

            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            var message = string.Empty;

            if (response.Messages != null && response.Messages.Any())
            {
                message = AlertDisplayHandler.SingleMessage(response.Messages.ToList());
            }

            if (!response.Success)
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    message = "An unknown error has occured. The response yield no error detail.";
                }

                AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(parentControl), operationTitle, message, response.Title, ExceptionDetail(response),
                                          AlertType.Error, AlertButtons.Ok);
                return(response.Success);
            }

            if (!showSuccessMessage)
            {
                return(response.Success);
            }

            if (ignoreResponseMessage)
            {
                message = successMessage;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    message = successMessage;
                }
            }

            AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(parentControl), operationTitle, message, response.Title, ExceptionDetail(response),
                                      AlertType.Success, AlertButtons.Ok);
            return(response.Success);
        }
示例#2
0
        /// <summary>
        /// Handles displaying relevant messages to the user from the inputs
        /// </summary>
        /// <param name="parentControl"></param>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="message">The message text</param>
        public static DialogResult ShowWarning(Control parentControl, string operationTitle, string message)
        {
            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            if (message == null)
            {
                message = string.Empty;
            }

            return(AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(parentControl), operationTitle, message, string.Empty, string.Empty, AlertType.Warning,
                                             AlertButtons.Ok));
        }
示例#3
0
        /// <summary>
        /// Handles displaying relevant messages to the user from the inputs
        /// </summary>
        /// <param name="parentControl"></param>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="messages">The message list</param>
        /// <param name="alertButtons">Alert buttons</param>
        /// <param name="alertType">Alert type</param>
        public static DialogResult Alert(Control parentControl, string operationTitle, List <string> messages, AlertButtons alertButtons,
                                         AlertType alertType)
        {
            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            if (messages == null)
            {
                messages = new List <string>();
            }

            return(AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(parentControl), operationTitle, messages, string.Empty, string.Empty,
                                             alertType, alertButtons));
        }
示例#4
0
        /// <summary>
        /// Handles displaying relevant messages to the user from the inputs
        /// </summary>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="message">The message text</param>
        /// <param name="alertButtons">Alert buttons</param>
        /// <param name="alertType">Alert type</param>
        public static DialogResult Alert(string operationTitle, string message, AlertButtons alertButtons,
                                         AlertType alertType)
        {
            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            if (message == null)
            {
                message = string.Empty;
            }

            return(AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(), operationTitle, message, string.Empty, string.Empty, alertType,
                                             alertButtons));
        }
示例#5
0
        /// <summary>
        /// Handles displaying relevent messages to the user from the inputs
        /// </summary>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="messages">The message list</param>
        /// <param name="alertButtons"></param>
        /// <param name="alertType">The type of message box</param>
        public static DialogResult Alert(string operationTitle, List <string> messages, AlertButtons alertButtons,
                                         AlertType alertType)
        {
            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            if (messages == null)
            {
                messages = new List <string>();
            }

            return(AlertDisplayHandler.Alert(operationTitle, SingleMessage(messages),
                                             alertType, alertButtons));
        }
示例#6
0
        /// <summary>
        /// Handles displaying relevent messages to the user from the inputs
        /// </summary>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="message">The message text</param>
        /// <param name="alertButtons"></param>
        /// <param name="alertType">The type of message box</param>
        public static DialogResult Alert(string operationTitle, string message, AlertButtons alertButtons,
                                         AlertType alertType)
        {
            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            if (message == null)
            {
                message = string.Empty;
            }

            return(AlertDisplayHandler.Alert(operationTitle, message, alertType,
                                             alertButtons));
        }
示例#7
0
        /// <summary>
        /// Handles displaying relevant messages to the user from the inputs
        /// </summary>
        /// <param name="parentControl"></param>
        /// <param name="operationTitle">The title of the message box</param>
        /// <param name="messages">The messages</param>
        public static DialogResult ShowWarning(Control parentControl, string operationTitle, List <string> messages)
        {
            if (string.IsNullOrWhiteSpace(operationTitle))
            {
                operationTitle = "Operation";
            }

            var message = string.Empty;

            if (messages != null && messages.Any())
            {
                message = AlertDisplayHandler.SingleMessage(messages);
            }

            return(AlertDisplayHandler.Alert(HelperMethods.GetCurrentlyActiveForm(parentControl), operationTitle, message, string.Empty, string.Empty, AlertType.Warning,
                                             AlertButtons.Ok));
        }
示例#8
0
        internal static string ExceptionDetail(IResponse response)
        {
            if (response == null || !response.HasException)
            {
                return(string.Empty);
            }

            var richTextBox = new RichTextBox
            {
                SelectionFont      = new Font("Segoe UI", 18),
                SelectionColor     = Color.Red,
                SelectionAlignment = HorizontalAlignment.Left,
            };

            var hasDetail = false;

            //Exception Messages
            if (response.Exception != null)
            {
                richTextBox.SelectedText  = "Exception Messages";
                richTextBox.SelectedText  = Environment.NewLine;
                richTextBox.SelectionFont = new Font("Segoe UI", 13);
                richTextBox.SelectedText  = AlertDisplayHandler.SingleMessage(response.Exception.GetExceptionMessages());
                richTextBox.SelectedText  = Environment.NewLine;
                hasDetail = true;
            }

            //StackTrace
            if (response.Exception?.StackTrace != null)
            {
                richTextBox.SelectionColor = Color.Red;
                richTextBox.SelectionFont  = new Font("Segoe UI", 18);
                richTextBox.SelectedText   = "Stack Trace";
                richTextBox.SelectedText   = Environment.NewLine;
                richTextBox.SelectionFont  = new Font("Segoe UI", 13);
                richTextBox.SelectedText   = response.Exception.StackTrace;
                hasDetail = true;
            }

            return(hasDetail ? richTextBox.Rtf : string.Empty);
        }
示例#9
0
        private async Task ExecuteAsync()
        {
            while (true)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                Visible  = true;
                Response = await ExecuteRequestAsync();

                stopWatch.Stop();
                var stopWatchSeconds = stopWatch.Elapsed.TotalSeconds;
                if (stopWatchSeconds < 1)
                {
                    //If process was very quick, add a second delay to avoid sudden flickering
                    await Task.Delay(TimeSpan.FromSeconds(1));
                }

                Visible = false;

                if (!Response.Success)
                {
                    //Break if operation was cancelled
                    if (Response.Cancelled)
                    {
                        break;
                    }

                    if (CanRetry)
                    {
                        var buttons        = Response.Cancelled ? AlertButtons.Ok : AlertButtons.RetryCancel;
                        var retrySelection = AlertDisplayHandler.Alert(this, FormTitle, Response.Messages.ToList(),
                                                                       Response.Title, SweetAlerts.ExceptionDetail(Response),
                                                                       AlertType.Error, buttons);

                        if (retrySelection != DialogResult.Retry)
                        {
                            return;
                        }
                        if (MessagesRichTextBox != null)
                        {
                            MessagesRichTextBox.Text = string.Empty;
                        }

                        continue;
                    }

                    AlertDisplayHandler.Alert(this, FormTitle, Response.Messages.ToList(),
                                              Response.Title, SweetAlerts.ExceptionDetail(Response),
                                              AlertType.Error, AlertButtons.Ok);
                    break;
                }

                //Break if operation was cancelled
                if (Response.Cancelled)
                {
                    break;
                }

                var rtf = MessagesRichTextBox != null &&
                          !string.IsNullOrWhiteSpace(MessagesRichTextBox.Text)
                    ? MessagesRichTextBox.Rtf
                    : string.Empty;

                var successMessages = Response.Messages.ToList();
                if (!successMessages.Any())
                {
                    successMessages.Add("Processed successfully");
                }

                if (ShowSuccessMessage)
                {
                    if (IgnoreResponseMessage)
                    {
                        successMessages = new List <string>
                        {
                            !string.IsNullOrWhiteSpace(SuccessMessage) ? SuccessMessage : "Processed successfully"
                        };
                    }

                    AlertDisplayHandler.AlertRtf(this, FormTitle, successMessages, Response.Title,
                                                 string.Empty, rtf, AlertType.Success, AlertButtons.Ok);
                }
                break;
            }
        }