// Loaded plugin public Plugin(string className, IPRoConPluginInterface type) { this.ClassName = className; this.Type = type; this.IsLoaded = true; this.IsEnabled = false; this.RegisteredEvents = new List<string>(); }
// Loaded plugin public Plugin(string className, IPRoConPluginInterface type) { this.ClassName = className; this.Type = type; this.IsLoaded = true; this.IsEnabled = false; this.RegisteredEvents = new List <string>(); }
public void AddLoadedPlugin(string className, IPRoConPluginInterface type) { if (this.Contains(className) == false) { this.Add(new Plugin(className, type)); } else { this.SetItem(this.IndexOf(this[className]), new Plugin(className, type)); } }
/// <summary> /// Precompile code to check error. /// </summary> /// <param name="sourceCode">source code</param> /// <returns></returns> public bool CompilePlugin(string sourceCode) { CompilerParameters parameters = new CompilerParameters(); parameters.ReferencedAssemblies.Add("System.dll"); parameters.ReferencedAssemblies.Add("System.Core.dll"); parameters.ReferencedAssemblies.Add("System.Data.dll"); parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll"); parameters.ReferencedAssemblies.Add("System.Xml.dll"); parameters.ReferencedAssemblies.Add("MySql.Data.dll"); parameters.ReferencedAssemblies.Add("PRoCon.Core.dll"); parameters.GenerateInMemory = false; parameters.GenerateExecutable = false; #if DEBUG parameters.IncludeDebugInformation = true; #else parameters.IncludeDebugInformation = false; #endif using (CodeDomProvider codeDomProvider = new CSharpCodeProvider(new Dictionary <string, string>() { { "CompilerVersion", "v3.5" } })) { CompilerResults results = codeDomProvider.CompileAssemblyFromSource(parameters, sourceCode); // check for syntax and reference errors if (results.Errors.HasErrors == true && results.Errors[0].ErrorNumber != "CS0016") { Output.Error("Update file compilation error!"); foreach (CompilerError cError in results.Errors) { if (cError.ErrorNumber != "CS0016" && cError.IsWarning == false) { Output.Error("(Line: {0}, C: {1}) {2}: {3}", cError.Line, cError.Column, cError.ErrorNumber, cError.ErrorText); } } return(false); } // check for interface error Assembly assembly = results.CompiledAssembly; Type objType = assembly.GetTypes().FirstOrDefault(_ => _.GetInterfaces().Contains(typeof(IPRoConPluginInterface))); if (objType != null) { IPRoConPluginInterface obj = assembly.CreateInstance(objType.FullName) as IPRoConPluginInterface; Output.Information("Plugin:{0} {1}", obj.GetPluginName(), obj.GetPluginVersion()); return(true); } Output.Error("Not found implementation of {0}!", typeof(IPRoConPluginInterface).Name); return(false); } }
public IPRoConPluginInterface Create(string assemblyFile, string typeName, object[] constructArguments) { IPRoConPluginInterface loadedPlugin = (IPRoConPluginInterface)Activator.CreateInstanceFrom( assemblyFile, typeName, false, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, constructArguments, null, null).Unwrap(); this.LoadedPlugins.Add(loadedPlugin); return(loadedPlugin); }