/// <summary> /// Loggs a gui message /// </summary> /// <param name="message"></param> /// <param name="level"></param> internal void GuiLogMessage(IPlugin sender, GuiLogEventArgs args) { if (OnGuiLogNotificationOccured != null) { OnGuiLogNotificationOccured(sender, args); } }
/// <summary> /// GuiLogNotificationOccured /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void GuiLogNotificationOccured(IPlugin sender, GuiLogEventArgs args) { //Check if the logging event is Warning or Error and set the State of the PluginModel to //the corresponding PluginModelState if (args.NotificationLevel == NotificationLevel.Warning) { foreach (PluginModel pluginModel in this.WorkspaceModel.GetAllPluginModels()) { if (pluginModel.Plugin == sender) { pluginModel.State = PluginModelState.Warning; pluginModel.GuiNeedsUpdate = true; } } } if (args.NotificationLevel == NotificationLevel.Error) { foreach (PluginModel pluginModel in this.WorkspaceModel.GetAllPluginModels()) { if (pluginModel.Plugin == sender) { pluginModel.State = PluginModelState.Error; pluginModel.GuiNeedsUpdate = true; } } } if (OnGuiLogNotificationOccured != null) { switch (((WorkspaceManagerSettings)this.Settings).LogLevel) { case 3: //Error if (args.NotificationLevel == NotificationLevel.Debug || args.NotificationLevel == NotificationLevel.Info || args.NotificationLevel == NotificationLevel.Warning) { return; } break; case 2: //Warning if (args.NotificationLevel == NotificationLevel.Debug || args.NotificationLevel == NotificationLevel.Info) { return; } break; case 1: //Info if (args.NotificationLevel == NotificationLevel.Debug) { return; } break; } OnGuiLogNotificationOccured(sender, args); } }
/// <summary> /// Returns the log as json string /// </summary> /// <param name="sender"></param> /// <param name="args"></param> /// <returns></returns> public static string GetLogJsonString(IPlugin sender, GuiLogEventArgs args) { return(string.Format("{{\"log\":{{\"logtime\":\"{0}\",\"logtype\":\"{1}\",\"sender\":\"{2}\",\"message\":\"{3}\"}}}}", DateTime.Now, args.NotificationLevel, sender == null ? "null" : sender.GetPluginInfoAttribute().Caption, EscapeString(args.Message == null ? "null" : args.Message))); }
/// <summary> /// Loggs a message to the logging mechanism of CrypTool /// </summary> /// <param name="Message"></param> /// <param name="notificationLevel"></param> public void GuiLogMessage(string Message, NotificationLevel notificationLevel) { if (OnGuiLogNotificationOccured != null) { GuiLogEventArgs args = new GuiLogEventArgs(Message, this, notificationLevel); args.Title = "-"; OnGuiLogNotificationOccured(this, args); } }
/// <summary> /// Loggs a gui message /// </summary> /// <param name="message"></param> /// <param name="level"></param> internal void GuiLogMessage(string message, NotificationLevel level) { if (OnGuiLogNotificationOccured != null) { var args = new GuiLogEventArgs(message, null, level); args.Title = "-"; OnGuiLogNotificationOccured(null, args); } }
public void GuiLogMessage(string message, NotificationLevel notificationLevel) { if (OnGuiLogNotificationOccured == null) { return; } var args = new GuiLogEventArgs(message, this, notificationLevel) { Title = "-" }; OnGuiLogNotificationOccured(this, args); }
public void OnGuiLogNotificationOccured(object sender, GuiLogEventArgs arg) { if (!silent) { if (!this.Dispatcher.CheckAccess()) { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle, new GuiLogNotificationDelegate(OnGuiLogNotificationOccuredTS), sender, new object[] { arg }); } else { OnGuiLogNotificationOccuredTS(sender, arg); } } }
/// <summary> /// Logs guilog to console based on error level and verbosity /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnGuiLogNotificationOccured(IPlugin sender, GuiLogEventArgs args) { if (args.NotificationLevel < _loglevel) { return; } if (_verbose) { Console.WriteLine("GuiLog:{0}:{1}:{2}:{3}", DateTime.Now, args.NotificationLevel, (sender != null ? sender.GetType().Name : "null"), args.Message); } if (_jsonoutput) { Console.WriteLine(JsonHelper.GetLogJsonString(sender, args)); } }
/// <summary> /// The method shows a new log entry in the GUI. It must be called only from the GUI thread! For /// log messages from other threads use GuiLogMessage() /// </summary> /// <param name="sender"></param> /// <param name="arg">Information about the log message</param> public void OnGuiLogNotificationOccuredTS(object sender, GuiLogEventArgs arg) { try { statusBarTextCounter++; LogMessage logMessage = new LogMessage(); // Attention: The string value of enum will be used to find appropritate imgage. logMessage.LogLevel = arg.NotificationLevel; logMessage.Nr = statusBarTextCounter; if (arg.Plugin != null) { logMessage.Plugin = arg.Plugin.GetPluginInfoAttribute().Caption; logMessage.Title = arg.Title; } else if (sender is string) { logMessage.Plugin = sender as string; logMessage.Title = "-"; } else { logMessage.Plugin = Resource.crypTool; logMessage.Title = "-"; } logMessage.Time = arg.DateTime.Hour.ToString("00") + ":" + arg.DateTime.Minute.ToString("00") + ":" + arg.DateTime.Second.ToString("00") + ":" + arg.DateTime.Millisecond.ToString("000"); logMessage.Message = arg.Message; if (listFilter.Contains(arg.NotificationLevel)) { TextBlock textBlock = new TextBlock(); textBlock.Text = logMessage.LogLevel + ": " + logMessage.Time + ": " + arg.Message; statusBarItem.Content = textBlock; if (arg.Message.Length >= 64) { notifyIcon.Text = arg.Message.Substring(0, 63); } else { notifyIcon.Text = arg.Message; } } collectionLogMessages.Add(logMessage); //Not more than 1000 messages allowed: if (collectionLogMessages.Count > 1000) { LogMessage firstLogMessage = collectionLogMessages[0]; switch (firstLogMessage.LogLevel) { case NotificationLevel.Debug: debugCounter--; textBlockDebugsCount.Text = string.Format("{0:0,0}", debugCounter); break; case NotificationLevel.Info: infoCounter--; textBlockInfosCount.Text = string.Format("{0:0,0}", infoCounter); break; case NotificationLevel.Warning: warningCounter--; textBlockWarningsCount.Text = string.Format("{0:0,0}", warningCounter); break; case NotificationLevel.Error: errorCounter--; textBlockErrosCount.Text = string.Format("{0:0,0}", errorCounter); break; case NotificationLevel.Balloon: balloonCounter--; textBlockBalloonsCount.Text = string.Format("{0:0,0}", balloonCounter); break; } collectionLogMessages.Remove(firstLogMessage); } SetMessageCount(); switch (arg.NotificationLevel) { case NotificationLevel.Debug: debugCounter++; textBlockDebugsCount.Text = string.Format("{0:0,0}", debugCounter); break; case NotificationLevel.Info: infoCounter++; textBlockInfosCount.Text = string.Format("{0:0,0}", infoCounter); break; case NotificationLevel.Warning: warningCounter++; textBlockWarningsCount.Text = string.Format("{0:0,0}", warningCounter); break; case NotificationLevel.Error: errorCounter++; textBlockErrosCount.Text = string.Format("{0:0,0}", errorCounter); break; case NotificationLevel.Balloon: balloonCounter++; textBlockBalloonsCount.Text = string.Format("{0:0,0}", balloonCounter); break; } ScrollToLast(); //Balloon: if (WindowState == WindowState.Minimized) { int ms = Settings.Default.BallonVisibility_ms; if (arg.NotificationLevel == NotificationLevel.Balloon && Settings.Default.ShowBalloonLogMessagesInBalloon) { notifyIcon.ShowBalloonTip(ms, Properties.Resources.Balloon_Message, arg.Message, ToolTipIcon.Info); } else if (arg.NotificationLevel == NotificationLevel.Error && Settings.Default.ShowErrorLogMessagesInBalloon) { notifyIcon.ShowBalloonTip(ms, Properties.Resources.Error_Message, arg.Message, ToolTipIcon.Error); } else if (arg.NotificationLevel == NotificationLevel.Info && Settings.Default.ShowInfoLogMessagesInBalloon) { notifyIcon.ShowBalloonTip(ms, Properties.Resources.Information_Message, arg.Message, ToolTipIcon.Info); } else if (arg.NotificationLevel == NotificationLevel.Warning && Settings.Default.ShowWarningLogMessagesInBalloon) { notifyIcon.ShowBalloonTip(ms, Properties.Resources.Warning_Message, arg.Message, ToolTipIcon.Warning); } else if (arg.NotificationLevel == NotificationLevel.Debug && Settings.Default.ShowDebugLogMessagesInBalloon) { notifyIcon.ShowBalloonTip(ms, Properties.Resources.Debug_Message, arg.Message, ToolTipIcon.Info); } } } catch (Exception) { //OnGuiLogNotificationOccuredTS(this, new GuiLogEventArgs(exception.Message, null, NotificationLevel.Error)); <--- causes recursion (StackOverflowException) } }
void alphabetPresentation_OnGuiLogNotificationOccured(IPlugin sender, GuiLogEventArgs args) { GuiLogMessage(args.Message, args.NotificationLevel); }
public static void GuiLogMessage(GuiLogNotificationEventHandler del, IPlugin plugin, GuiLogEventArgs args) { if (del == null) { return; } Delegate[] delegates = del.GetInvocationList(); if (AsynchronousGuiLogMessage) { AsyncCallback cleanUp = delegate(IAsyncResult asyncResult) { asyncResult.AsyncWaitHandle.Close(); }; foreach (GuiLogNotificationEventHandler sink in delegates) { sink.BeginInvoke(plugin, args, cleanUp, null); } } else { foreach (GuiLogNotificationEventHandler sink in delegates) { sink.Invoke(plugin, args); } } }
// catches LogNotification from settings private void settings_OnGuiLogNotificationOccured(IPlugin sender, GuiLogEventArgs args) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(args.Message, this, args.NotificationLevel)); }