public static void ToGingerHelper(eGingerHelperMsgKey messageKey, object btnHandler = null, params object[] messageArgs) { GingerHelperMsg messageToShow = null; string messageContent = string.Empty; string orgMessageContent = string.Empty; try { // TODO: use TryGet //get the message from pool if ((GingerHelperMsgsPool != null) && GingerHelperMsgsPool.Keys.Contains(messageKey)) { messageToShow = GingerHelperMsgsPool[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() + " "; } ToUser(eUserMsgKeys.StaticErrorMessage, "Cannot find MessageKey: " + messageKey); ToLog(eLogLevel.WARN, "The Ginger Helper message with key: '" + messageKey + "' was not found! and won't show to the user!"); } orgMessageContent = messageToShow.MsgContent; //enter message args if exist if (messageArgs.Length > 0) { messageToShow.MsgContent = string.Format(messageToShow.MsgContent, messageArgs); } if (CurrentAppLogLevel == eAppReporterLoggingLevel.Debug) { ToLog(eLogLevel.INFO, "Showing User Message (GingerHelper): " + messageContent); } else if (AddAllReportingToConsole) { ToConsole(eLogLevel.DEBUG, "Showing User Message (GingerHelper): " + messageContent); } mLastStatusTime.Start(); WorkSpaceReporter.ToStatus(messageToShow.MessageType, orgMessageContent); } catch (Exception ex) { ToLog(eLogLevel.ERROR, "Failed to show the Ginger Helper message with the key: " + messageKey, ex); } }
public static void ToLog(eLogLevel logLevel, string messageToLog, Exception exceptionToLog = null) { if (ReportAllAlsoToConsole) { ToConsole(logLevel, messageToLog, exceptionToLog); } if (logLevel == eLogLevel.DEBUG && AppLoggingLevel != eAppReporterLoggingLevel.Debug) { return; } if (logLevel == eLogLevel.ERROR || logLevel == eLogLevel.FATAL) { ReporterData.ErrorCounter++; } WorkSpaceReporter.ToLog(logLevel, messageToLog, exceptionToLog); }
public static void ToConsole(eLogLevel logLevel, string messageToConsole, Exception exceptionToConsole = null) { try { string msg = messageToConsole; if (exceptionToConsole != null) { string excFullInfo = "Error:" + exceptionToConsole.Message + Environment.NewLine; excFullInfo += "Source:" + exceptionToConsole.Source + Environment.NewLine; excFullInfo += "Stack Trace: " + exceptionToConsole.StackTrace; msg += Environment.NewLine + "Exception Details:" + Environment.NewLine + excFullInfo; } WorkSpaceReporter.ToConsole(logLevel, msg); } catch (Exception ex) { ToLog(eLogLevel.ERROR, "Failed to report to Console", ex); } }
public static void HideStatusMessage() { if (bClosing) { return; } bClosing = true; Task t = new Task(() => { while (mLastStatusTime.ElapsedMilliseconds < 1000) // let the message show for at least one second { Task.Delay(100); } WorkSpaceReporter.ToStatus(eStatusMsgType.INFO, null); mLastStatusTime.Reset(); bClosing = false; }); t.Start(); }
public static eUserMsgSelection ToUser(eUserMsgKey messageKey, params object[] messageArgs) { UserMsg messageToShow = null; string messageText = string.Empty; eUserMsgIcon messageImage = eUserMsgIcon.None; try { //get the message from pool // FIXME improve if as already found !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if ((UserMsgsPool != null) && UserMsgsPool.Keys.Contains(messageKey)) { messageToShow = UserMsgsPool[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.ToUser(txt, "Ginger", eUserMsgOption.OK, eUserMsgIcon.Information, eUserMsgSelection.OK); ToLog(eLogLevel.WARN, "The user message with key: '" + messageKey + "' was not found! and won't show to the user!"); return(eUserMsgSelection.None); } //set the message type switch (messageToShow.MessageType) { case eUserMsgType.ERROR: messageImage = eUserMsgIcon.Error; break; case eUserMsgType.INFO: messageImage = eUserMsgIcon.Information; break; case eUserMsgType.QUESTION: messageImage = eUserMsgIcon.Question; break; case eUserMsgType.WARN: messageImage = eUserMsgIcon.Warning; break; default: messageImage = eUserMsgIcon.Information; break; } //enter message args if exist if (messageArgs.Length > 0) { messageText = string.Format(messageToShow.Message, messageArgs); } else { messageText = messageToShow.Message; } if (AppLoggingLevel == eAppReporterLoggingLevel.Debug) { ToLog(eLogLevel.DEBUG, "Showing User Message: '" + messageText + "'"); } else if (ReportAllAlsoToConsole) { ToConsole(eLogLevel.DEBUG, "Showing User Message: '" + messageText + "'"); } //show the messege and return user selection eUserMsgSelection userSelection = WorkSpaceReporter.ToUser(messageText, messageToShow.Caption, messageToShow.SelectionOptions, messageImage, messageToShow.DefualtSelectionOption); if (AppLoggingLevel == eAppReporterLoggingLevel.Debug) { ToLog(eLogLevel.DEBUG, "User Message Option Selection: '" + userSelection.ToString() + "'"); } else if (ReportAllAlsoToConsole) { ToConsole(eLogLevel.DEBUG, "User Message Option Selection: '" + userSelection.ToString() + "'"); } return(userSelection); } catch (Exception ex) { string txt = "Failed to show the user message with the key: " + messageKey; ToLog(eLogLevel.ERROR, txt, ex); if (ReportAllAlsoToConsole) { ToConsole(eLogLevel.ERROR, txt, ex); } WorkSpaceReporter.ToUser(txt, "Ginger", eUserMsgOption.OK, eUserMsgIcon.Information, eUserMsgSelection.OK); return(eUserMsgSelection.None); } }
private static void HideMessage_Event(object sender, ElapsedEventArgs e) { WorkSpaceReporter.ToStatus(eStatusMsgType.INFO, null); mLastStatusTime.Reset(); bClosing = false; }