public static bool ExecuteAlgorithm(this Bitmap bmp, string algorithmName, params object[] args) { if (!IPAlgorithmManager.algorithms.ContainsKey(algorithmName)) { ImgTools.Error("Error: cannot find algorithm with name '{0}'", algorithmName); return(false); } return(IPAlgorithmManager.algorithms[algorithmName].Execute(bmp, args)); }
public static int LoadAlgorithmsFromFile(string binaryPath, bool silent = false) { int count = 0; try { foreach (var type in Assembly.LoadFile(binaryPath).GetTypes()) { if ((!type.IsClass) || type.IsNotPublic) { continue; } if (typeof(ProcessingAlgorithm).IsAssignableFrom(type)) { try { var pa = Activator.CreateInstance(type) as ProcessingAlgorithm; if (!algorithms.ContainsKey(pa.GetName())) { algorithms[pa.GetName()] = pa; count++; } } catch (Exception) { if (!silent) { ImgTools.Error("Error: failed to instantiate algorithm '{0}' in file '{1}'!", type.Name, binaryPath); } continue; } } } } catch (Exception) { if (!silent) { ImgTools.Error("Error: cannot load algorithms from file '{0}'!", binaryPath); } } return(count); }