Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/LogExpert/Classes/Columnizer/ColumnizerPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ public static ILogLineColumnizer CloneColumnizer(ILogLineColumnizer columnizer)
return null;
}
ConstructorInfo cti = columnizer.GetType().GetConstructor(Type.EmptyTypes);

if (cti != null)
{
object o = cti.Invoke(new object[] { });
if (o is IColumnizerConfigurator)
if (o is IColumnizerConfigurator configurator)
{
((IColumnizerConfigurator)o).LoadConfig(ConfigManager.ConfigDir);
configurator.LoadConfig(ConfigManager.Settings.preferences.PortableMode ? ConfigManager.PortableModeDir : ConfigManager.ConfigDir);
}
return (ILogLineColumnizer)o;
}
Expand Down
2 changes: 1 addition & 1 deletion src/LogExpert/Classes/Persister/Persister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static string BuildPersisterFileName(string logFileName, Preferences pre
}
case SessionSaveLocation.ApplicationStartupDir:
{
dir = Application.StartupPath;
dir = Application.StartupPath + Path.DirectorySeparatorChar + "sessionfiles";
file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName);
break;
}
Expand Down
71 changes: 37 additions & 34 deletions src/LogExpert/Classes/PluginRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ public class PluginRegistry

private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();

private static readonly object lockObject = new object();
private static PluginRegistry instance = null;
private static readonly object _lockObject = new object();
private static PluginRegistry _instance;

private readonly IFileSystemCallback fileSystemCallback = new FileSystemCallback();
private readonly IList<ILogExpertPlugin> pluginList = new List<ILogExpertPlugin>();
private readonly IFileSystemCallback _fileSystemCallback = new FileSystemCallback();
private readonly IList<ILogExpertPlugin> _pluginList = new List<ILogExpertPlugin>();

private readonly IDictionary<string, IKeywordAction> registeredKeywordsDict =
new Dictionary<string, IKeywordAction>();
private readonly IDictionary<string, IKeywordAction> _registeredKeywordsDict = new Dictionary<string, IKeywordAction>();

#endregion

Expand Down Expand Up @@ -60,14 +59,14 @@ private PluginRegistry()

public static PluginRegistry GetInstance()
{
lock (lockObject)
lock (_lockObject)
{
if (instance == null)
if (_instance == null)
{
instance = new PluginRegistry();
_instance = new PluginRegistry();
}

return instance;
return _instance;
}
}

Expand All @@ -78,16 +77,19 @@ public static PluginRegistry GetInstance()
internal void LoadPlugins()
{
_logger.Info("Loading plugins...");
this.RegisteredColumnizers = new List<ILogLineColumnizer>();
this.RegisteredColumnizers.Add(new DefaultLogfileColumnizer());
this.RegisteredColumnizers.Add(new TimestampColumnizer());
this.RegisteredColumnizers.Add(new SquareBracketColumnizer());
this.RegisteredColumnizers.Add(new ClfColumnizer());
this.RegisteredFileSystemPlugins.Add(new LocalFileSystem());

RegisteredColumnizers = new List<ILogLineColumnizer>();
RegisteredColumnizers.Add(new DefaultLogfileColumnizer());
RegisteredColumnizers.Add(new TimestampColumnizer());
RegisteredColumnizers.Add(new SquareBracketColumnizer());
RegisteredColumnizers.Add(new ClfColumnizer());
RegisteredFileSystemPlugins.Add(new LocalFileSystem());

string pluginDir = Application.StartupPath + Path.DirectorySeparatorChar + "plugins";

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(ColumnizerResolveEventHandler);
currentDomain.AssemblyResolve += ColumnizerResolveEventHandler;

if (Directory.Exists(pluginDir))
{
string[] dllNames = Directory.GetFiles(pluginDir, "*.dll");
Expand Down Expand Up @@ -119,16 +121,17 @@ internal void LoadPlugins()
if (cti != null)
{
object o = cti.Invoke(new object[] { });
this.RegisteredColumnizers.Add((ILogLineColumnizer) o);
if (o is IColumnizerConfigurator)
RegisteredColumnizers.Add((ILogLineColumnizer) o);

if (o is IColumnizerConfigurator configurator)
{
((IColumnizerConfigurator) o).LoadConfig(ConfigManager.ConfigDir);
configurator.LoadConfig(ConfigManager.Settings.preferences.PortableMode ? ConfigManager.PortableModeDir : ConfigManager.ConfigDir);
}

if (o is ILogExpertPlugin)
if (o is ILogExpertPlugin plugin)
{
this.pluginList.Add(o as ILogExpertPlugin);
(o as ILogExpertPlugin).PluginLoaded();
_pluginList.Add(plugin);
plugin.PluginLoaded();
}

_logger.Info("Added columnizer {0}", type.Name);
Expand Down Expand Up @@ -188,13 +191,13 @@ internal void LoadPlugins()
internal IKeywordAction FindKeywordActionPluginByName(string name)
{
IKeywordAction action = null;
this.registeredKeywordsDict.TryGetValue(name, out action);
_registeredKeywordsDict.TryGetValue(name, out action);
return action;
}

internal void CleanupPlugins()
{
foreach (ILogExpertPlugin plugin in this.pluginList)
foreach (ILogExpertPlugin plugin in _pluginList)
{
plugin.AppExiting();
}
Expand All @@ -207,7 +210,7 @@ internal IFileSystemPlugin FindFileSystemForUri(string uriString)
_logger.Debug("Trying to find file system plugin for uri {0}", uriString);
}

foreach (IFileSystemPlugin fs in this.RegisteredFileSystemPlugins)
foreach (IFileSystemPlugin fs in RegisteredFileSystemPlugins)
{
if (_logger.IsDebugEnabled)
{
Expand Down Expand Up @@ -238,15 +241,15 @@ private bool TryAsContextMenu(Type type)
IContextMenuEntry me = TryInstantiate<IContextMenuEntry>(type);
if (me != null)
{
this.RegisteredContextMenuPlugins.Add(me);
RegisteredContextMenuPlugins.Add(me);
if (me is ILogExpertPluginConfigurator)
{
((ILogExpertPluginConfigurator) me).LoadConfig(ConfigManager.ConfigDir);
}

if (me is ILogExpertPlugin)
{
this.pluginList.Add(me as ILogExpertPlugin);
_pluginList.Add(me as ILogExpertPlugin);
(me as ILogExpertPlugin).PluginLoaded();
}

Expand All @@ -262,16 +265,16 @@ private bool TryAsKeywordAction(Type type)
IKeywordAction ka = TryInstantiate<IKeywordAction>(type);
if (ka != null)
{
this.RegisteredKeywordActions.Add(ka);
this.registeredKeywordsDict.Add(ka.GetName(), ka);
RegisteredKeywordActions.Add(ka);
_registeredKeywordsDict.Add(ka.GetName(), ka);
if (ka is ILogExpertPluginConfigurator)
{
((ILogExpertPluginConfigurator) ka).LoadConfig(ConfigManager.ConfigDir);
}

if (ka is ILogExpertPlugin)
{
this.pluginList.Add(ka as ILogExpertPlugin);
_pluginList.Add(ka as ILogExpertPlugin);
(ka as ILogExpertPlugin).PluginLoaded();
}

Expand All @@ -285,23 +288,23 @@ private bool TryAsKeywordAction(Type type)
private bool TryAsFileSystem(Type type)
{
// file system plugins can have optional constructor with IFileSystemCallback argument
IFileSystemPlugin fs = TryInstantiate<IFileSystemPlugin>(type, this.fileSystemCallback);
IFileSystemPlugin fs = TryInstantiate<IFileSystemPlugin>(type, _fileSystemCallback);
if (fs == null)
{
fs = TryInstantiate<IFileSystemPlugin>(type);
}

if (fs != null)
{
this.RegisteredFileSystemPlugins.Add(fs);
RegisteredFileSystemPlugins.Add(fs);
if (fs is ILogExpertPluginConfigurator)
{
((ILogExpertPluginConfigurator) fs).LoadConfig(ConfigManager.ConfigDir);
}

if (fs is ILogExpertPlugin)
{
this.pluginList.Add(fs as ILogExpertPlugin);
_pluginList.Add(fs as ILogExpertPlugin);
(fs as ILogExpertPlugin).PluginLoaded();
}

Expand Down
13 changes: 9 additions & 4 deletions src/LogExpert/Config/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ public static ConfigManager Instance
public static string ConfigDir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "LogExpert";

/// <summary>
/// Application.StartupPath + portableMode.json
/// Application.StartupPath + portable
/// </summary>
public static string PortableMode => Application.StartupPath + Path.DirectorySeparatorChar + "portableMode.json";
public static string PortableModeDir => Application.StartupPath + Path.DirectorySeparatorChar + "portable";

/// <summary>
/// portableMode.json
/// </summary>
public static string PortableModeSettingsFileName => "portableMode.json";

public static Settings Settings => Instance._settings;

Expand Down Expand Up @@ -99,7 +104,7 @@ private Settings Load()

string dir;

if (!File.Exists(PortableMode))
if (File.Exists(PortableModeDir + Path.DirectorySeparatorChar + PortableModeSettingsFileName) == false)
{
_logger.Info("Load settings standard mode");
dir = ConfigDir;
Expand Down Expand Up @@ -294,7 +299,7 @@ private void Save(Settings settings, SettingsFlags flags)
_logger.Info("Saving settings");
lock (this)
{
string dir = File.Exists(PortableMode) ? Application.StartupPath : ConfigDir;
string dir = Settings.preferences.PortableMode ? Application.StartupPath : ConfigDir;

if (!Directory.Exists(dir))
{
Expand Down
6 changes: 4 additions & 2 deletions src/LogExpert/Config/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public class Preferences
public int pollingInterval = 250;

public bool reverseAlpha = false;


public bool PortableMode { get; set; }

/// <summary>
/// Save Directory of the last logfile
/// </summary>
Expand All @@ -75,7 +77,7 @@ public class Preferences
public bool setLastColumnWidth;

public bool showBubbles = true;

public bool showColumnFinder;

public Color showTailColor = Color.FromKnownColor(KnownColor.Blue);
Expand Down
2 changes: 1 addition & 1 deletion src/LogExpert/Dialogs/FilterSelectorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/LogExpert/Dialogs/FilterSelectorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Windows.Forms;
using LogExpert.Config;
// using System.Linq;

namespace LogExpert.Dialogs
{
Expand All @@ -22,7 +21,7 @@ public FilterSelectorForm(IList<ILogLineColumnizer> existingColumnizerList, ILog
SelectedColumnizer = currentColumnizer;
_callback = callback;
InitializeComponent();
filterComboBox.SelectedIndexChanged += filterComboBox_SelectedIndexChanged;
filterComboBox.SelectedIndexChanged += OnFilterComboBoxSelectedIndexChanged;

// for the currently selected columnizer use the current instance and not the template instance from
// columnizer registry. This ensures that changes made in columnizer config dialogs
Expand Down Expand Up @@ -62,7 +61,7 @@ public FilterSelectorForm(IList<ILogLineColumnizer> existingColumnizerList, ILog

#region Events handler

private void filterComboBox_SelectedIndexChanged(object sender, EventArgs e)
private void OnFilterComboBoxSelectedIndexChanged(object sender, EventArgs e)
{
ILogLineColumnizer col = _columnizerList[filterComboBox.SelectedIndex];
SelectedColumnizer = col;
Expand All @@ -73,11 +72,18 @@ private void filterComboBox_SelectedIndexChanged(object sender, EventArgs e)
}


private void configButton_Click(object sender, EventArgs e)
private void OnConfigButtonClick(object sender, EventArgs e)
{
if (SelectedColumnizer is IColumnizerConfigurator)
if (SelectedColumnizer is IColumnizerConfigurator configurator)
{
((IColumnizerConfigurator) SelectedColumnizer).Configure(_callback, ConfigManager.ConfigDir);
string configDir = ConfigManager.ConfigDir;

if (ConfigManager.Settings.preferences.PortableMode)
{
configDir = ConfigManager.PortableModeDir;
}

configurator.Configure(_callback, configDir);
IsConfigPressed = true;
}
}
Expand Down
26 changes: 19 additions & 7 deletions src/LogExpert/Dialogs/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void FillDialog()

private void FillPortableMode()
{
checkBoxPortableMode.CheckState = File.Exists(ConfigManager.PortableMode) ? CheckState.Checked : CheckState.Unchecked;
checkBoxPortableMode.CheckState = Preferences.PortableMode ? CheckState.Checked : CheckState.Unchecked;
}

private void DisplayFontName()
Expand Down Expand Up @@ -446,15 +446,15 @@ private void SavePluginSettings()
{
if (entry is ILogExpertPluginConfigurator configurator)
{
configurator.SaveConfig(ConfigManager.ConfigDir);
configurator.SaveConfig(checkBoxPortableMode.Checked ? ConfigManager.PortableModeDir : ConfigManager.ConfigDir);
}
}

foreach (IKeywordAction entry in PluginRegistry.GetInstance().RegisteredKeywordActions)
{
if (entry is ILogExpertPluginConfigurator configurator)
{
configurator.SaveConfig(ConfigManager.ConfigDir);
configurator.SaveConfig(checkBoxPortableMode.Checked ? ConfigManager.PortableModeDir : ConfigManager.ConfigDir);
}
}
}
Expand Down Expand Up @@ -789,26 +789,38 @@ private void OnPortableModeCheckedChanged(object sender, EventArgs e)
{
switch (checkBoxPortableMode.CheckState)
{
case CheckState.Checked when !File.Exists(ConfigManager.PortableMode):
case CheckState.Checked when !File.Exists(ConfigManager.PortableModeDir + Path.DirectorySeparatorChar + ConfigManager.PortableModeSettingsFileName):
{
using (File.Create(ConfigManager.PortableMode))
if (Directory.Exists(ConfigManager.PortableModeDir) == false)
{
Directory.CreateDirectory(ConfigManager.PortableModeDir);
}

using (File.Create(ConfigManager.PortableModeDir + Path.DirectorySeparatorChar + ConfigManager.PortableModeSettingsFileName))
break;
}
case CheckState.Unchecked when File.Exists(ConfigManager.PortableMode):
case CheckState.Unchecked when File.Exists(ConfigManager.PortableModeDir + Path.DirectorySeparatorChar + ConfigManager.PortableModeSettingsFileName):
{
File.Delete(ConfigManager.PortableMode);
File.Delete(ConfigManager.PortableModeDir + Path.DirectorySeparatorChar + ConfigManager.PortableModeSettingsFileName);
break;
}
}

switch (checkBoxPortableMode.CheckState)
{
case CheckState.Unchecked:
{
checkBoxPortableMode.Text = @"Activate Portable Mode";
Preferences.PortableMode = false;
break;
}

case CheckState.Checked:
{
Preferences.PortableMode = true;
checkBoxPortableMode.Text = @"Deactivate Portable Mode";
break;
}
}
}
catch (Exception exception)
Expand Down
Loading