private void PluginsListItemCheck(object sender, ItemCheckEventArgs e) { try { var p = (CustomPlugin)PluginsList.Items[e.Index]; WritePluginSettings(p.AssemblyName, e.NewValue.Equals(CheckState.Checked)); if (e.NewValue.Equals(CheckState.Checked)) { if (!PluginCompiler.LoadedPlugins.Contains(p.AssemblyName)) { PluginCompiler.PluginLoad(p.AssemblyName); } } else { if (PluginCompiler.LoadedPlugins.Contains(p.AssemblyName)) { PluginCompiler.PluginUnload(p.AssemblyName); } } } catch (Exception d) { Logging.Write("Could not load plugin: " + d); } }
private void MainLoad(object sender, EventArgs e) { LBVersion.Text = string.Format("LazyBot Evolution V{0}", LazyVersion); expandableSplitter1.Expanded = false; DoLoad.Load(); LoadCustomClasses(); LoadEngines(); SelectEngine.SelectedIndex = SelectEngine.FindStringExact(LazySettings.SelectedEngine, -1); SelectCombat.SelectedIndex = SelectEngine.FindStringExact(LazySettings.SelectedCombat, -1); if (SelectEngine.SelectedIndex == -1) { SelectEngine.SelectedIndex = 0; } if (SelectCombat.SelectedIndex == -1) { SelectCombat.SelectedIndex = 0; } PluginCompiler.RecompileAll(); PluginCompiler.StartSavedPlugins(); LoadPluginButtons(); RegisterHotKeys(); Engine.StateChange += UpdateStateChange; ObjectManager.NoAttach += LogOut; #if RELEASE CBDebug.Checked = LazySettings.DebugLog; #endif //#if DEBUG // buttonX1.Visible = true; // buttonX2.Visible = true; I Dont Like To Look At this In debug //#endif }
public void CompileFrom_GivenEmptyCode_ShouldThrowException() { var compiler = new PluginCompiler(Mock.Of <IAssemblyReferenceProvider>()); compiler.Invoking(c => c.CompileFrom(null)).ShouldThrow <ArgumentException>(); compiler.Invoking(c => c.CompileFrom(string.Empty)).ShouldThrow <ArgumentException>(); }
public void CompileFrom_GivenEmptyCode_ShouldThrowException() { var compiler = new PluginCompiler(Mock.Of<IAssemblyReferenceProvider>()); compiler.Invoking(c => c.CompileFrom(null)).ShouldThrow<ArgumentException>(); compiler.Invoking(c => c.CompileFrom(string.Empty)).ShouldThrow<ArgumentException>(); }
private void InitializePluginCompiler() { Log.Write(Log.Levels.Debug, "CONF", "initializing plugin compiler..."); string pluginRoot = Path.Combine(MFW3D.Global.Settings.DirectoryPath, "Plugins"); compiler = new PluginCompiler(pluginRoot); //加载默认插件 if (File.Exists(Application.StartupPath + "/Plugins.dll")) { Assembly assembly = Assembly.LoadFrom(Application.StartupPath + "/Plugins.dll"); compiler.FindPlugins(assembly); compiler.FindPlugins(); compiler.LoadStartupPlugins(); } //加载所有插件的内容 DirectoryInfo TheFolder = new DirectoryInfo(pluginRoot); foreach (FileInfo NextFile in TheFolder.GetFiles()) { if (NextFile.Name.Length < 3) { continue; } if (NextFile.Name.Substring(NextFile.Name.Length - 4, 4) != ".dll") { continue; } Assembly assembly = Assembly.LoadFrom( AppDomain.CurrentDomain.BaseDirectory + NextFile.Name); compiler.FindPlugins(assembly); compiler.FindPlugins(); compiler.LoadStartupPlugins(); } }
public void CompileFrom_GivenSourceCodeWithErrors_ShouldThrowException() { const string sourceCode = @"namespace Test { public class Foo { public void Bar() { System.Console.WriteLine(""Bar."") } } }"; var mscorlibReference = MetadataReference.CreateFromFile(typeof(int).Assembly.Location); var compiler = new PluginCompiler(Mock.Of <IAssemblyReferenceProvider>(provider => provider.CollectMetadataReferences(It.IsAny <Assembly>()) == mscorlibReference.AsEnumerable())); compiler.Invoking(c => c.CompileFrom(sourceCode)).ShouldThrow <PluginCompilationException>(); }
public void CompileFrom_GivenSourceCodeWithErrors_ShouldThrowException() { const string sourceCode = @"namespace Test { public class Foo { public void Bar() { System.Console.WriteLine(""Bar."") } } }"; var mscorlibReference = MetadataReference.CreateFromFile(typeof(int).Assembly.Location); var compiler = new PluginCompiler(Mock.Of<IAssemblyReferenceProvider>(provider => provider.CollectMetadataReferences(It.IsAny<Assembly>()) == mscorlibReference.AsEnumerable())); compiler.Invoking(c => c.CompileFrom(sourceCode)).ShouldThrow<PluginCompilationException>(); }
public void CompileFrom_GivenCompilableSourceCode_ShouldProvideGeneratedAssembly() { const string sourceCode = @"namespace Test { public class Foo { public void Bar() { System.Console.WriteLine(""Bar."");} } }"; var mscorlibReference = MetadataReference.CreateFromFile(typeof(int).Assembly.Location); var compiler = new PluginCompiler(Mock.Of <IAssemblyReferenceProvider>(provider => provider.CollectMetadataReferences(It.IsAny <Assembly>()) == mscorlibReference.AsEnumerable())); var result = compiler.CompileFrom(sourceCode); result.Should().DefineType("Test", "Foo").And.Reference(typeof(string).Assembly); }
public void CompileFrom_GivenCompilableSourceCode_ShouldProvideGeneratedAssembly() { const string sourceCode = @"namespace Test { public class Foo { public void Bar() { System.Console.WriteLine(""Bar."");} } }"; var mscorlibReference = MetadataReference.CreateFromFile(typeof (int).Assembly.Location); var compiler = new PluginCompiler(Mock.Of<IAssemblyReferenceProvider>(provider => provider.CollectMetadataReferences(It.IsAny<Assembly>()) == mscorlibReference.AsEnumerable())); var result = compiler.CompileFrom(sourceCode); result.Should().DefineType("Test", "Foo").And.Reference(typeof(string).Assembly); }
private IEnumerator Reload() { Debug.Log("Unloading plugins"); PluginLoader.UnloadAllPlugins(); Debug.Log("Recompiling plugins"); yield return(PluginCompiler.Load()); Debug.Log("Reloading plugins"); yield return(PluginLoader.Load()); Debug.Log("Recompilation done"); _isRecompiling = false; }
private void InitializePluginCompiler() { Log.Write(Log.Levels.Debug, "CONF", "initializing plugin compiler..."); this.splashScreen.SetText("Initializing plugins..."); string pluginRoot = Path.Combine(PluginEngineGlobal.DirectoryPath, "Plugins"); compiler = new PluginCompiler(pluginRoot); //#if DEBUG // Search for plugins in worldwind.exe (plugin development/debugging aid) //compiler.FindPlugins(Assembly.GetExecutingAssembly()); Assembly assembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "WorldWind.exe"); compiler.FindPlugins(assembly); //#endif compiler.FindPlugins(); compiler.LoadStartupPlugins(); }
private void InitializePluginCompiler() { this.m_compiler = new PluginCompiler(this.worldViewer1); this.m_compiler.LoadPlugin(); this.m_compiler.LoadStartUpPlugin(); }
public void CompilePluginIntoAssembly_Plugin_Valid_Case() { string pluginName = "TestPlugin"; Method MoveMouse = new Method() { Name = "DoMoveMouse", AccessModifier = AccessModifierEnum.INTERNAL, ReturnType = null, Parameters = new List <MethodParameter>() { new MethodParameter() { Name = "xPos", ParamType = typeof(int) }, new MethodParameter() { Name = "yPos", ParamType = typeof(int) } }, Statements = new List <Statement>() { new Statement() { Content = "if(xPos == 1){/*move mouse*/}" } } }; PluginClass plugin = new PluginClass() { Name = pluginName, Namespace = "Joel.Testar", Interfaces = new List <Interface>() { new Interface() { Name = "IPlugin" } }, UsingClauses = new List <UsingClause>() { new UsingClause() { Name = "Plugin.Interfaces" } }, Methods = new List <Method>() { MoveMouse, new Method() { Name = "Configure" }, new Method() { Name = "PreProcess" }, new Method() { Name = "Process" }, new Method() { Name = "GetResult", ReturnType = typeof(IPluginResult), Statements = new List <Statement>() { new Statement() { Content = "return null;" } } } } }; var assembly = PluginCompiler.CompilePluginIntoAssembly(plugin); var plugins = assembly.GetAllPlugins(); var firstPlugin = plugins.FirstOrDefault(plug => plug.Name == pluginName); Assert.IsNotNull(firstPlugin); Assert.IsTrue(typeof(IPlugin).IsAssignableFrom(firstPlugin)); }
public void CompilePluginIntoAssembly_Plugin_Without_Name() { PluginClass plugin = new PluginClass(); PluginCompiler.CompilePluginIntoAssembly(plugin); }
public void CompilePluginIntoAssembly_Null_Plugin() { PluginClass plugin = null; PluginCompiler.CompilePluginIntoAssembly(plugin); }