private static void PrintPluginHelp(string pluginName, Dictionary <string, Type> components) { if (components.ContainsKey(pluginName)) { IBackupPlugin db = components[pluginName].GetConstructor(new Type[0]).Invoke(new object[0]) as IBackupPlugin; Console.WriteLine(db.CommandLineHelp); } }
private static void PrintComponents(Dictionary <string, Type> components) { foreach (string key in components.Keys) { IBackupPlugin db = components[key].GetConstructor(new Type[0]).Invoke(new object[0]) as IBackupPlugin; Console.WriteLine("\t" + db.Name); } }
private static void FindPlugins(Assembly dll, Dictionary <string, Type> result, string interfaceName) { foreach (Type t in dll.GetTypes()) { try { if (t.IsPublic) { if (!((t.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract)) { if (t.GetInterface(interfaceName) != null) { object o = t.GetConstructor(new Type[0]).Invoke(new object[0]); IBackupPlugin test = o as IBackupPlugin; if (test != null) { string name = test.Name.ToLowerInvariant(); if (name.Contains("|") || name.Contains("(")) { throw new ArgumentException(string.Format("The name of the plugin, {0}, cannot contain these characters: |, (", name)); } if (result.ContainsKey(name)) { throw new ArgumentException(string.Format("plugin found twice: {0}", name)); } result.Add(name, t); } } } } } catch (Exception e) { throw new Exception(string.Format("Warning: Plugin not loaded due to error: {0}", e.Message), e); } } }