コード例 #1
0
        private void XDataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            MessageInfo  messageInfo = (MessageInfo)xDataGrid.SelectedValue;
            eUserMsgKeys mess        = messageInfo.MessageKey;

            Amdocs.Ginger.Common.MessageBoxResult messageBoxResult = Reporter.ToUser(mess, "%1", "%2", "%3");
            MessageBox.Show("You selected: " + messageBoxResult);
        }
コード例 #2
0
        public static MessageBoxResult ToUser(eUserMsgKeys messageKey, params object[] messageArgs)
        {
            UserMessage     messageToShow = null;
            string          messageText   = string.Empty;
            MessageBoxImage messageImage  = MessageBoxImage.None;

            try
            {
                //get the message from pool
                if ((UserMessagesPool != null) && UserMessagesPool.Keys.Contains(messageKey))
                {
                    messageToShow = UserMessagesPool[messageKey];
                }
                if (messageToShow == null)
                {
                    // We do want to pop the error message so below is just in case...
                    string mess = "";
                    foreach (object o in messageArgs)
                    {
                        mess += o.ToString() + " ";
                    }
                    MessageBox.Show(messageKey.ToString() + " - " + mess);

                    ToLog(eLogLevel.WARN, "The user message with key: '" + messageKey + "' was not found! and won't show to the user!");
                    return(MessageBoxResult.None);
                }

                //set the message type
                switch (messageToShow.MessageType)
                {
                case eMessageType.ERROR:
                    messageImage = MessageBoxImage.Error;
                    break;

                case eMessageType.INFO:
                    messageImage = MessageBoxImage.Information;
                    break;

                case eMessageType.QUESTION:
                    messageImage = MessageBoxImage.Question;
                    break;

                case eMessageType.WARN:
                    messageImage = MessageBoxImage.Warning;
                    break;

                default:
                    messageImage = MessageBoxImage.Information;
                    break;
                }

                //enter message args if exist
                if (messageArgs.Length > 0)
                {
                    messageText = string.Format(messageToShow.Message, messageArgs);
                }
                else
                {
                    messageText = messageToShow.Message;
                }

                //show the messege and return user selection
                //adding owner window to the message so it will appear on top of any other window including splash screen
                //return MessageBox.Show(messageText, messageToShow.Caption, messageToShow.ButtonsType, messageImage, messageToShow.DefualtResualt);

                if (CurrentAppLogLevel == eAppLogLevel.Debug)
                {
                    ToLog(eLogLevel.INFO, "Showing User Message (Pop-Up): '" + messageText + "'");
                }
                else if (AddAllReportingToConsole)
                {
                    ToConsole("Showing User Message (Pop-Up): '" + messageText + "'");
                }

                MessageBoxResult userSelection = MessageBoxResult.None; //????

                //Show msgbox from Main Window STA
                MainWindowDispatcher.Invoke(() => {
                    Window msgOwnerWin = new Window
                    {
                        Width                 = 0.001,
                        Height                = 0.001,
                        Topmost               = true,
                        ShowInTaskbar         = false,
                        ShowActivated         = true,
                        WindowStyle           = WindowStyle.None,
                        WindowStartupLocation = WindowStartupLocation.CenterScreen
                    };
                    msgOwnerWin.Show();
                    msgOwnerWin.Hide();
                    userSelection = MessageBox.Show(msgOwnerWin, messageText, messageToShow.Caption, messageToShow.ButtonsType,
                                                    messageImage, messageToShow.DefualtResualt);
                    msgOwnerWin.Close();

                    return(userSelection);
                });


                if (CurrentAppLogLevel == eAppLogLevel.Debug)
                {
                    ToLog(eLogLevel.INFO, "User Selection for Pop-Up Message: '" + userSelection.ToString() + "'");
                }
                else if (AddAllReportingToConsole)
                {
                    ToConsole("User Selection for Pop-Up Message: '" + userSelection.ToString() + "'");
                }

                return(userSelection);
            }
            catch (Exception ex)
            {
                ToLog(eLogLevel.ERROR, "Failed to show the user message with the key: " + messageKey, ex);
                MessageBox.Show("Failed to show the user message with the key: " + messageKey);
                return(MessageBoxResult.None);
            }
        }
コード例 #3
0
        public static MessageBoxResult ToUser(eUserMsgKeys messageKey, params object[] messageArgs)
        {
            UserMessage     messageToShow = null;
            string          messageText   = string.Empty;
            MessageBoxImage messageImage  = MessageBoxImage.None;

            try
            {
                //get the message from pool
                if ((UserMessagesPool != null) && UserMessagesPool.Keys.Contains(messageKey))
                {
                    messageToShow = UserMessagesPool[messageKey];
                }
                if (messageToShow == null)
                {
                    // We do want to pop the error message so below is just in case...
                    string mess = "";
                    foreach (object o in messageArgs)
                    {
                        mess += o.ToString() + " ";
                    }
                    MessageBox.Show(messageKey.ToString() + " - " + mess);

                    ToLog(eLogLevel.WARN, "The user message with key: '" + messageKey + "' was not found! and won't show to the user!");
                    return(MessageBoxResult.None);
                }

                //set the message type
                switch (messageToShow.MessageType)
                {
                case eMessageType.ERROR:
                    messageImage = MessageBoxImage.Error;
                    break;

                case eMessageType.INFO:
                    messageImage = MessageBoxImage.Information;
                    break;

                case eMessageType.QUESTION:
                    messageImage = MessageBoxImage.Question;
                    break;

                case eMessageType.WARN:
                    messageImage = MessageBoxImage.Warning;
                    break;

                default:
                    messageImage = MessageBoxImage.Information;
                    break;
                }

                //enter message args if exist
                if (messageArgs.Length > 0)
                {
                    messageText = string.Format(messageToShow.Message, messageArgs);
                }
                else
                {
                    messageText = messageToShow.Message;
                }

                //show the messege and return user selection
                //adding owner window to the message so it will appear on top of any other window including splash screen

                if (CurrentAppLogLevel == eAppLogLevel.Debug)
                {
                    ToLog(eLogLevel.INFO, "Showing User Message (Pop-Up): '" + messageText + "'");
                }
                else if (AddAllReportingToConsole)
                {
                    ToConsole("Showing User Message (Pop-Up): '" + messageText + "'");
                }

                MessageBoxResult userSelection = MessageBoxResult.None; //????

                //TODO: find a better option than loop...
                while (userSelection == null)
                {
                    Thread.Sleep(100);
                }

                if (CurrentAppLogLevel == eAppLogLevel.Debug)
                {
                    ToLog(eLogLevel.INFO, "User Selection for Pop-Up Message: '" + userSelection.ToString() + "'");
                }
                else if (AddAllReportingToConsole)
                {
                    ToConsole("User Selection for Pop-Up Message: '" + userSelection.ToString() + "'");
                }

                return(userSelection);
            }
            catch (Exception ex)
            {
                ToLog(eLogLevel.ERROR, "Failed to show the user message with the key: " + messageKey, ex);
                MessageBox.Show("Failed to show the user message with the key: " + messageKey);
                return(MessageBoxResult.None);
            }
        }
コード例 #4
0
        public static MessageBoxResult ToUser(eUserMsgKeys messageKey, params object[] messageArgs)
        {
            UserMessage     messageToShow = null;
            string          messageText   = string.Empty;
            MessageBoxImage messageImage  = MessageBoxImage.None;

            try
            {
                //get the message from pool

                // FIXME improve if as already found !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                if ((UserMessagesPool != null) && UserMessagesPool.Keys.Contains(messageKey))
                {
                    messageToShow = UserMessagesPool[messageKey];
                }
                if (messageToShow == null) // Message not found in message pool
                {
                    // We do want to pop the error message so below is just in case...
                    string mess = "";
                    foreach (object o in messageArgs)
                    {
                        mess += o.ToString() + " ";
                    }

                    string txt = messageKey.ToString() + " - " + mess + "{Error message key not found!}";
                    WorkSpaceReporter.MessageBoxShow(txt, "Ginger", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);

                    ToLog(eLogLevel.WARN, "The user message with key: '" + messageKey + "' was not found! and won't show to the user!");
                    return(MessageBoxResult.None);
                }

                //set the message type
                switch (messageToShow.MessageType)
                {
                case eMessageType.ERROR:
                    messageImage = MessageBoxImage.Error;
                    break;

                case eMessageType.INFO:
                    messageImage = MessageBoxImage.Information;
                    break;

                case eMessageType.QUESTION:
                    messageImage = MessageBoxImage.Question;
                    break;

                case eMessageType.WARN:
                    messageImage = MessageBoxImage.Warning;
                    break;

                default:
                    messageImage = MessageBoxImage.Information;
                    break;
                }

                //enter message args if exist
                if (messageArgs.Length > 0)
                {
                    messageText = string.Format(messageToShow.Message, messageArgs);
                }
                else
                {
                    messageText = messageToShow.Message;
                }

                if (CurrentAppLogLevel == eAppReporterLoggingLevel.Debug)
                {
                    ToLog(eLogLevel.INFO, "Showing User Message (Pop-Up): '" + messageText + "'");
                }
                else if (AddAllReportingToConsole)
                {
                    ToConsole(eLogLevel.DEBUG, "Showing User Message (Pop-Up): '" + messageText + "'");
                }

                //show the messege and return user selection
                MessageBoxResult userSelection = WorkSpaceReporter.MessageBoxShow(messageText, messageToShow.Caption, messageToShow.ButtonsType, messageImage, messageToShow.DefualtResualt);


                if (CurrentAppLogLevel == eAppReporterLoggingLevel.Debug)
                {
                    ToLog(eLogLevel.INFO, "User Selection for Pop-Up Message: '" + userSelection.ToString() + "'");
                }
                else if (AddAllReportingToConsole)
                {
                    ToConsole(eLogLevel.DEBUG, "User Selection for Pop-Up Message: '" + userSelection.ToString() + "'");
                }

                return(userSelection);
            }
            catch (Exception ex)
            {
                ToLog(eLogLevel.ERROR, "Failed to show the user message with the key: " + messageKey, ex);

                string txt = "Failed to show the user message with the key: " + messageKey;
                WorkSpaceReporter.MessageBoxShow(txt, "Ginger", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);

                return(MessageBoxResult.None);
            }
        }