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);
}
/// <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>
/// Get a list of all destinations, registered or supplied by a plugin
/// </summary>
@ -75,12 +97,7 @@ namespace Greenshot.Helpers {
public static List<IDestination> GetAllDestinations() {
List<IDestination> destinations = new List<IDestination>();
destinations.AddRange(RegisteredDestinations.Values);
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) {
var dests = plugin.Destinations();
if (dests != null) {
destinations.AddRange(dests);
}
}
destinations.AddRange(GetPluginDestinations());
destinations.Sort();
return destinations;
}
@ -97,11 +114,9 @@ namespace Greenshot.Helpers {
if (RegisteredDestinations.ContainsKey(designation)) {
return RegisteredDestinations[designation];
}
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) {
foreach(IDestination destination in plugin.Destinations()) {
if (designation.Equals(destination.Designation)) {
return destination;
}
foreach (IDestination destination in GetPluginDestinations()) {
if (designation.Equals(destination.Designation)) {
return destination;
}
}
return null;

View file

@ -39,21 +39,25 @@ namespace Greenshot.Helpers {
if (!"Greenshot.Processors".Equals(ProcessorType.Namespace)) {
continue;
}
if (!ProcessorType.IsAbstract) {
IProcessor Processor;
try {
Processor = (IProcessor)Activator.CreateInstance(ProcessorType);
} catch (Exception e) {
LOG.ErrorFormat("Can't create instance of {0}", ProcessorType);
LOG.Error(e);
continue;
}
if (Processor.isActive) {
LOG.DebugFormat("Found Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
RegisterProcessor(Processor);
} else {
LOG.DebugFormat("Ignoring Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
try {
if (!ProcessorType.IsAbstract) {
IProcessor Processor;
try {
Processor = (IProcessor)Activator.CreateInstance(ProcessorType);
} catch (Exception e) {
LOG.ErrorFormat("Can't create instance of {0}", ProcessorType);
LOG.Error(e);
continue;
}
if (Processor.isActive) {
LOG.DebugFormat("Found Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
RegisterProcessor(Processor);
} else {
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);
}
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>
/// Get a list of all Processors, registered or supplied by a plugin
/// </summary>
/// <returns></returns>
public static List<IProcessor> GetAllProcessors() {
List<IProcessor> Processors = new List<IProcessor>();
Processors.AddRange(RegisteredProcessors.Values);
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) {
Processors.AddRange(plugin.Processors());
}
Processors.Sort();
return Processors;
List<IProcessor> processors = new List<IProcessor>();
processors.AddRange(RegisteredProcessors.Values);
processors.AddRange(GetPluginsProcessors());
processors.Sort();
return processors;
}
/// <summary>
@ -93,11 +113,9 @@ namespace Greenshot.Helpers {
if (RegisteredProcessors.ContainsKey(designation)) {
return RegisteredProcessors[designation];
}
foreach(IGreenshotPlugin plugin in PluginHelper.instance.Plugins.Values) {
foreach(IProcessor Processor in plugin.Processors()) {
if (designation.Equals(Processor.Designation)) {
return Processor;
}
foreach (IProcessor processor in GetPluginsProcessors()) {
if (designation.Equals(processor.Designation)) {
return processor;
}
}
return null;

View file

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

View file

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

View file

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