mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 00:53:51 -07:00
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:
parent
2ae58d5c6c
commit
2d88d8e588
5 changed files with 98 additions and 47 deletions
|
@ -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,11 +114,9 @@ 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;
|
||||||
|
|
|
@ -39,21 +39,25 @@ namespace Greenshot.Helpers {
|
||||||
if (!"Greenshot.Processors".Equals(ProcessorType.Namespace)) {
|
if (!"Greenshot.Processors".Equals(ProcessorType.Namespace)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!ProcessorType.IsAbstract) {
|
try {
|
||||||
IProcessor Processor;
|
if (!ProcessorType.IsAbstract) {
|
||||||
try {
|
IProcessor Processor;
|
||||||
Processor = (IProcessor)Activator.CreateInstance(ProcessorType);
|
try {
|
||||||
} catch (Exception e) {
|
Processor = (IProcessor)Activator.CreateInstance(ProcessorType);
|
||||||
LOG.ErrorFormat("Can't create instance of {0}", ProcessorType);
|
} catch (Exception e) {
|
||||||
LOG.Error(e);
|
LOG.ErrorFormat("Can't create instance of {0}", ProcessorType);
|
||||||
continue;
|
LOG.Error(e);
|
||||||
}
|
continue;
|
||||||
if (Processor.isActive) {
|
}
|
||||||
LOG.DebugFormat("Found Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
|
if (Processor.isActive) {
|
||||||
RegisterProcessor(Processor);
|
LOG.DebugFormat("Found Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
|
||||||
} else {
|
RegisterProcessor(Processor);
|
||||||
LOG.DebugFormat("Ignoring Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation);
|
} 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);
|
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;
|
||||||
|
|
|
@ -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() {
|
||||||
Uri confluenceIconUri = new Uri("/GreenshotConfluencePlugin;component/Images/Confluence.ico", UriKind.Relative);
|
IsInitialized = false;
|
||||||
using (Stream iconStream = Application.GetResourceStream(confluenceIconUri).Stream) {
|
try {
|
||||||
using (Image tmpImage = Image.FromStream(iconStream)) {
|
Uri confluenceIconUri = new Uri("/GreenshotConfluencePlugin;component/Images/Confluence.ico", UriKind.Relative);
|
||||||
confluenceIcon = ImageHelper.Clone(tmpImage);
|
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() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfluenceDestination(Confluence.Page page) {
|
public ConfluenceDestination(Confluence.Page page) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,11 @@ namespace GreenshotConfluencePlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IDestination> Destinations() {
|
public IEnumerable<IDestination> Destinations() {
|
||||||
yield return new ConfluenceDestination();
|
if (ConfluenceDestination.IsInitialized) {
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
TranslationManager.Instance.TranslationProvider = new LanguageXMLTranslationProvider();
|
try {
|
||||||
//resources = new ComponentResourceManager(typeof(JiraPlugin));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue