Making the plugins behave more stable, fixing a part of Bug #3528518

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1899 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-05-23 09:21:02 +00:00
parent 2ae58d5c6c
commit 2d88d8e588
5 changed files with 98 additions and 47 deletions

View file

@ -68,6 +68,28 @@ namespace Greenshot.Helpers {
RegisteredDestinations.Add(destination.Designation, destination); RegisteredDestinations.Add(destination.Designation, destination);
} }
/// <summary>
/// Method to get all the destinations from the plugins
/// </summary>
/// <returns>List<IDestination></returns>
private static List<IDestination> GetPluginDestinations() {
List<IDestination> destinations = new List<IDestination>();
foreach (PluginAttribute pluginAttribute in PluginHelper.instance.Plugins.Keys) {
IGreenshotPlugin plugin = PluginHelper.instance.Plugins[pluginAttribute];
try {
var dests = plugin.Destinations();
if (dests != null) {
destinations.AddRange(dests);
}
} catch (Exception ex) {
LOG.ErrorFormat("Couldn't get destinations from the plugin {0}", pluginAttribute.Name);
LOG.Error(ex);
}
}
destinations.Sort();
return destinations;
}
/// <summary> /// <summary>
/// Get a list of all destinations, registered or supplied by a plugin /// Get a list of all destinations, registered or supplied by a plugin
/// </summary> /// </summary>
@ -75,12 +97,7 @@ namespace Greenshot.Helpers {
public static List<IDestination> GetAllDestinations() { public static List<IDestination> GetAllDestinations() {
List<IDestination> destinations = new List<IDestination>(); List<IDestination> destinations = new List<IDestination>();
destinations.AddRange(RegisteredDestinations.Values); destinations.AddRange(RegisteredDestinations.Values);
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) { destinations.AddRange(GetPluginDestinations());
var dests = plugin.Destinations();
if (dests != null) {
destinations.AddRange(dests);
}
}
destinations.Sort(); destinations.Sort();
return destinations; return destinations;
} }
@ -97,13 +114,11 @@ namespace Greenshot.Helpers {
if (RegisteredDestinations.ContainsKey(designation)) { if (RegisteredDestinations.ContainsKey(designation)) {
return RegisteredDestinations[designation]; return RegisteredDestinations[designation];
} }
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) { foreach (IDestination destination in GetPluginDestinations()) {
foreach(IDestination destination in plugin.Destinations()) {
if (designation.Equals(destination.Designation)) { if (designation.Equals(destination.Designation)) {
return destination; return destination;
} }
} }
}
return null; return null;
} }

View file

@ -39,6 +39,7 @@ namespace Greenshot.Helpers {
if (!"Greenshot.Processors".Equals(ProcessorType.Namespace)) { if (!"Greenshot.Processors".Equals(ProcessorType.Namespace)) {
continue; continue;
} }
try {
if (!ProcessorType.IsAbstract) { if (!ProcessorType.IsAbstract) {
IProcessor Processor; IProcessor Processor;
try { try {
@ -55,6 +56,9 @@ namespace Greenshot.Helpers {
LOG.DebugFormat("Ignoring Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation); LOG.DebugFormat("Ignoring Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
} }
} }
} catch (Exception ex) {
LOG.ErrorFormat("Error loading processor {0}, message: ", ProcessorType.FullName, ex.Message);
}
} }
} }
@ -67,18 +71,34 @@ namespace Greenshot.Helpers {
RegisteredProcessors.Add(Processor.Designation, Processor); RegisteredProcessors.Add(Processor.Designation, Processor);
} }
private static List<IProcessor> GetPluginsProcessors() {
List<IProcessor> processors = new List<IProcessor>();
foreach (PluginAttribute pluginAttribute in PluginHelper.instance.Plugins.Keys) {
IGreenshotPlugin plugin = PluginHelper.instance.Plugins[pluginAttribute];
try {
var procs = plugin.Processors();
if (procs != null) {
processors.AddRange(procs);
}
} catch (Exception ex) {
LOG.ErrorFormat("Couldn't get processors from the plugin {0}", pluginAttribute.Name);
LOG.Error(ex);
}
}
processors.Sort();
return processors;
}
/// <summary> /// <summary>
/// Get a list of all Processors, registered or supplied by a plugin /// Get a list of all Processors, registered or supplied by a plugin
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static List<IProcessor> GetAllProcessors() { public static List<IProcessor> GetAllProcessors() {
List<IProcessor> Processors = new List<IProcessor>(); List<IProcessor> processors = new List<IProcessor>();
Processors.AddRange(RegisteredProcessors.Values); processors.AddRange(RegisteredProcessors.Values);
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) { processors.AddRange(GetPluginsProcessors());
Processors.AddRange(plugin.Processors()); processors.Sort();
} return processors;
Processors.Sort();
return Processors;
} }
/// <summary> /// <summary>
@ -93,11 +113,9 @@ namespace Greenshot.Helpers {
if (RegisteredProcessors.ContainsKey(designation)) { if (RegisteredProcessors.ContainsKey(designation)) {
return RegisteredProcessors[designation]; return RegisteredProcessors[designation];
} }
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) { foreach (IProcessor processor in GetPluginsProcessors()) {
foreach(IProcessor Processor in plugin.Processors()) { if (designation.Equals(processor.Designation)) {
if (designation.Equals(Processor.Designation)) { return processor;
return Processor;
}
} }
} }
return null; return null;

View file

@ -40,19 +40,28 @@ namespace GreenshotConfluencePlugin {
private static ConfluenceConfiguration config = IniConfig.GetIniSection<ConfluenceConfiguration>(); private static ConfluenceConfiguration config = IniConfig.GetIniSection<ConfluenceConfiguration>();
private static Image confluenceIcon = null; private static Image confluenceIcon = null;
private Confluence.Page page; private Confluence.Page page;
public static bool IsInitialized {
get;
private set;
}
static ConfluenceDestination() { static ConfluenceDestination() {
IsInitialized = false;
try {
Uri confluenceIconUri = new Uri("/GreenshotConfluencePlugin;component/Images/Confluence.ico", UriKind.Relative); Uri confluenceIconUri = new Uri("/GreenshotConfluencePlugin;component/Images/Confluence.ico", UriKind.Relative);
using (Stream iconStream = Application.GetResourceStream(confluenceIconUri).Stream) { using (Stream iconStream = Application.GetResourceStream(confluenceIconUri).Stream) {
using (Image tmpImage = Image.FromStream(iconStream)) { using (Image tmpImage = Image.FromStream(iconStream)) {
confluenceIcon = ImageHelper.Clone(tmpImage); confluenceIcon = ImageHelper.Clone(tmpImage);
} }
} }
IsInitialized = true;
} catch (Exception ex) {
LOG.ErrorFormat("Problem in the confluence static initializer: {0}", ex.Message);
}
} }
public ConfluenceDestination() { public ConfluenceDestination() {
} }
public ConfluenceDestination(Confluence.Page page) { public ConfluenceDestination(Confluence.Page page) {
this.page = page; this.page = page;
} }

View file

@ -84,7 +84,11 @@ namespace GreenshotConfluencePlugin {
} }
public IEnumerable<IDestination> Destinations() { public IEnumerable<IDestination> Destinations() {
if (ConfluenceDestination.IsInitialized) {
yield return new ConfluenceDestination(); yield return new ConfluenceDestination();
} else {
yield break;
}
} }
public IEnumerable<IProcessor> Processors() { public IEnumerable<IProcessor> Processors() {
@ -106,8 +110,13 @@ namespace GreenshotConfluencePlugin {
if(config.IsDirty) { if(config.IsDirty) {
IniConfig.Save(); IniConfig.Save();
} }
try {
TranslationManager.Instance.TranslationProvider = new LanguageXMLTranslationProvider(); TranslationManager.Instance.TranslationProvider = new LanguageXMLTranslationProvider();
//resources = new ComponentResourceManager(typeof(JiraPlugin)); //resources = new ComponentResourceManager(typeof(JiraPlugin));
} catch (Exception ex) {
LOG.ErrorFormat("Problem in ConfluencePlugin.Initialize: {0}", ex.Message);
return false;
}
return true; return true;
} }

View file

@ -49,7 +49,7 @@ namespace GreenshotPlugin.Core {
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
LOG.Warn(ex); LOG.WarnFormat("Problem getting subclasses of type: {0}, message: {1}", type.FullName, ex.Message);
} }
} }
return list; return list;