private CompiledCodeProperties CallCsharpCompiler(ProgramProperties programProperties) { CsharpCodeCompiler csharpCodeCompiler = new CsharpCodeCompiler(_compiledCodeProperties); CodeCompiler codeCompiler = new CodeCompiler(csharpCodeCompiler); return(codeCompiler.Compile(programProperties.CodeText)); }
/// <summary> /// Processes the queried notification text parser. /// </summary> /// <param name="result">The result.</param> private static void OnDownloaded(DownloadResult <string> result) { if (result.Error != null) { // Reset query pending flag s_queryPending = false; EveMonClient.Trace(result.Error.Message); return; } string[] referenceAssemblies = { typeof(Enumerable).Assembly.Location, typeof(YamlNode).Assembly.Location, }; // Revert to internal parser if the compilation fails for any reason s_parser = CodeCompiler.GenerateAssembly <EveNotificationTextParser>( referenceAssemblies, result.Result) ?? new InternalEveNotificationTextParser(); // Reset query pending flag // after we compiled the parser s_queryPending = false; s_cachedUntil = DateTime.UtcNow.AddHours(12); // Notify the subscribers NotificationTextParserUpdated?.ThreadSafeInvoke(null, EventArgs.Empty); }
public bool TrySetNewAssembly(params string[] code) { try { if (playerAppDomain != null) { AppDomain.Unload(playerAppDomain); playerAppDomain = null; GC.Collect(); } var parsed = CodeCompiler.Parse(PlayerData.PlayerId, code.Select(CodeHelper.GetCodeWithDLL)); var compiled = CodeCompiler.Compile(parsed); if (!compiled) { return(false); } var appDomain = CodeRunner.GetExecutor(PlayerData.PlayerId); if (appDomain != null) { playerCode = code; playerAppDomain = appDomain; } return(true); } catch (Exception e) { Console.WriteLine("Exception while compiling:"); Console.WriteLine(e.ToString()); } return(false); }
public void CompileAssemblyTest() { var fileName1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "code1.cs"); if (!File.Exists(fileName1)) { using (var stream = new StreamWriter(fileName1, false, Encoding.GetEncoding(0))) { stream.WriteLine(CODE1); } } var fileName2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "code2.cs"); if (!File.Exists(fileName2)) { using (var stream = new StreamWriter(fileName2, false, Encoding.GetEncoding(0))) { stream.WriteLine(CODE2); } } var compiler = new CodeCompiler(); compiler.Assemblies.Add("system.xml.dll"); compiler.Assemblies.Add("system.data.dll"); var assembly = compiler.CompileAssembly(new string[] { fileName1, fileName2 }); Assert.IsNotNull(assembly); Assert.AreEqual(assembly.GetExportedTypes().Length, 2); }
private void AddPrintTpl(string printData, List <string> param) { if (!PrintCodeObjDic.ContainsKey(printData)) { PrintCodeObj printCodeObj = new PrintCodeObj(); // 4.CompilerResults string str = GenerateCode(printData, param); str = str.Replace("'", "\""); CompilerResults cr = CodeCompiler.CompileAssemblyFromSource(ObjCompilerParameters, str); if (cr.Errors.HasErrors) { //MessageBox.Show("编译错误:"); //foreach (CompilerError err in cr.Errors) //{ // MessageBox.Show(err.ErrorText); //} } else { Assembly objAssembly = cr.CompiledAssembly; printCodeObj.PrintCodeType = objAssembly.GetType("DynamicCodeGenerate.LodopClass"); printCodeObj.DestObj = printCodeObj.PrintCodeType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null); } PrintCodeObjDic.Add(printData, printCodeObj); } }
public void CompileDelegateWithCodeDomTest() { var compiler = new CodeCompiler(); var unit = new CodeCompileUnit(); var ns = new CodeNamespace("Test"); unit.Namespaces.Add(ns); var td = new CodeTypeDeclaration("TestClass"); ns.Types.Add(td); var md = new CodeMemberMethod(); md.Name = "HelloWorld"; md.Attributes = MemberAttributes.Public; td.Members.Add(md); md.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "name")); md.Statements.Add(new CodeSnippetStatement("return \"Hello \" + name;")); md.ReturnType = new CodeTypeReference(typeof(string)); var func = compiler.CompileDelegate <Func <string, string> >(unit); Assert.IsNotNull(func); Assert.AreEqual("Hello fireasy", func("fireasy")); }
/// <summary> /// 编译程序集 /// </summary> /// <param name="coder"></param> public static void Compile(XPCCoder coder) { var assemblyFileName = _getAssemblyFileName(coder.VirtualPath); DeleteAssembly(assemblyFileName); CodeCompiler.CompileCSharp(assemblyFileName, coder.UserPath, coder.GIPath, coder.GPath); }
private void Execute(object obj) { try { Status.Description = "Running"; StateHelper.Put(_runningPath, "Start runing..."); var references = new List <string> { "Iveely.CloudComputing.Client.exe", "Iveely.Framework.dll", "System.Xml.dll", "System.Xml.Linq.dll", "NDatabase3.dll" }; CodeCompiler.Execode(obj.ToString(), Status.Packet.ClassName, references, new object[] { Status.Packet.ReturnIp, Status.Packet.Port, _machineName, _servicePort, Status.Packet.TimeStamp, Status.Packet.AppName }); StateHelper.Put(_runningPath, "Finished with success!"); Program.SetStatus(Status.Packet.AppName, "Success"); } catch (Exception exception) { Logger.Error(exception); StateHelper.Put(_runningPath, "Finished with " + exception); Program.SetStatus(Status.Packet.AppName, "Fisnihed with " + exception); } }
public void TestDelegateIn() { var code = "public class A { public int test(int r) { return r * 100; } }"; var func = new CodeCompiler().CompileDelegate <Func <int, int> >(code); Assert.AreEqual(10000, func(100)); }
public void TestDelegate() { var code = "public class A { public int test() { return 1; } }"; var func = new CodeCompiler().CompileDelegate <Func <int> >(code); Assert.AreEqual(1, func()); }
public void TestClass() { var code = "public class A { public int test() { return 1; } }"; var type = new CodeCompiler().CompileType(code); Assert.AreEqual("A", type.Name); }
public static void SetCodeCompiler(CodeCompiler codeCompiler) { #if FEATURE_CONCURRENT Volatile.Write(ref _codeCompiler, codeCompiler); #else _codeCompiler = codeCompiler; #endif }
public void Compile_WhenTheGrammarHasAnErrorExpressionInTheMiddleOfASequenceWrappedInParentheses_ThrowsException() { var grammar = new PegParser().Parse("a = 'OK' (#error{ \"OK\" }) 'OK'"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); Assert.That(() => parser.Parse("OK"), Throws.InstanceOf <FormatException>().With.Message.EqualTo("OK")); }
private static void RecompilePlugins() { if (BotMain.IsRunning) { BotMain.Stop(false, "Recompiling Plugin!"); while (BotMain.BotThread.IsAlive) { Thread.Sleep(0); } } var EnabledPlugins = PluginManager.GetEnabledPlugins().ToArray(); foreach (var p in PluginManager.Plugins) { p.Enabled = false; } PluginManager.ShutdownAllPlugins(); Logger.DBLog.DebugFormat("Disposing All Routines"); foreach (var r in RoutineManager.Routines) { r.Dispose(); } string sDemonBuddyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string sTrinityPluginPath = FolderPaths.PluginPath; CodeCompiler FunkyCode = new CodeCompiler(sTrinityPluginPath); //FunkyCode.ParseFilesForCompilerOptions(); Logger.DBLog.DebugFormat("Recompiling Funky Bot"); FunkyCode.Compile(); Logger.DBLog.DebugFormat(FunkyCode.CompiledToLocation); Logger.DBLog.DebugFormat("Clearing all treehooks"); TreeHooks.Instance.ClearAll(); Logger.DBLog.DebugFormat("Disposing of current bot"); BotMain.CurrentBot.Dispose(); Logger.DBLog.DebugFormat("Removing old Assemblies"); CodeCompiler.DeleteOldAssemblies(); BrainBehavior.CreateBrain(); Logger.DBLog.DebugFormat("Reloading Plugins"); PluginManager.ReloadAllPlugins(sDemonBuddyPath + @"\Plugins\"); Logger.DBLog.DebugFormat("Enabling Plugins"); PluginManager.SetEnabledPlugins(EnabledPlugins); Logger.DBLog.DebugFormat("Reloading Routines"); RoutineManager.Reload(); }
public AbstractCompilerTester() { assemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(a => !a.IsDynamic && !string.IsNullOrEmpty(a.Location)) .GroupBy(x => x.FullName) .Select(x => x.First()) .ToList(); compiler = new CodeCompiler(); }
public void CompileTypeTest() { var compiler = new CodeCompiler(); var type = compiler.CompileType(CODE1); Assert.IsNotNull(type); Assert.AreEqual(type.Name, "TestClass1"); }
public void CompileDelegateUnassignMethodTest() { var compiler = new CodeCompiler(); var action = compiler.CompileDelegate <Action>(CODE1); Assert.IsNotNull(action); Assert.AreEqual("HelloWorld", action.Method.Name); }
public void TestFile(string filename) { var path = GetTestDataFilePath2(filename); var references = GetReferencedAssemblies(GetTargetFrameworkId()).ToArray(); var assembly = CodeCompiler.CompileSource(path, references); DoTestSolution(assembly); }
public void CreateLoanType() { AccountType accountType = TestUtility.CreateSavingsAccountType(); Assembly assembly = CodeCompiler.Compile(CodeGenerator.GenerateAccountType(accountType)); Type type = assembly.GetType("Accounts.Runtime.Model." + accountType.ClassName); Account account = (Account)Activator.CreateInstance(type); }
public CodeExecutor( CodeExecutionConfiguration configuration, CodeCompiler compiler, DockerContainerExecutor executor) { _configuration = configuration; _compiler = compiler; _executor = executor; }
public void Compile_WithCaseSensitivityCombinations_ProducesCorrectParser(string subject, string match, string unmatch) { var grammar = new PegParser().Parse(subject); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); Assert.That(parser.Parse(match), Is.EqualTo(match)); Assert.That(() => parser.Parse(unmatch), Throws.Exception); }
public void Compile_WithSimpleLeftRecursion_ProducesCorrectParser() { var grammar = new PegParser().Parse("a <int> -memoize = a:a '+' b:b { a + b } / b; b <int> = c:[0-9] { int.Parse(c) };"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <int>(compiled); Assert.That(parser.Parse("1+3"), Is.EqualTo(4)); }
public void Compile_WithStartRule_ProducesCorrectParser() { var grammar = new PegParser().Parse("@start b; a = #error{ \"wrong start rule\" }; b = 'OK';"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); Assert.That(parser.Parse("OK"), Is.EqualTo("OK")); }
public void Compile_WhenTheGrammarContainsAnAndExpression_ExecutesExpression() { var grammar = new PegParser().Parse("a = &other 'OK'; other <int> = 'OK' { 0 }"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); Assert.That(parser.Parse("OK"), Is.EqualTo("OK")); }
public void Compile_WhenTheGrammarContainsANotCodeExpression_ExecutesExpression() { var grammar = new PegParser().Parse("a = !{false} 'OK'"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); Assert.That(parser.Parse("OK"), Is.EqualTo("OK")); }
public void Compile_WhenTheGrammarContainsAParseExpression_ExecutesTheParseExpression() { var grammar = new PegParser().Parse("a = #parse{ this.ReturnHelper<string>(state, ref state, _ => \"OK\") };"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); Assert.That(parser.Parse(string.Empty), Is.EqualTo("OK")); }
public Form1() { InitializeComponent(); _writer = new TextBoxStreamWriter(LogOutput); Console.SetOut(_writer); CardTemplate.DatabasePath = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + "\\"; CardTemplate.LoadAll(); StreamReader str = new StreamReader(CardTemplate.DatabasePath + "Bots/SmartCC/Config/useProfiles"); string useDefaut = str.ReadLine(); str.Close(); if (useDefaut == "true") { string star = CardTemplate.DatabasePath; Application.EnableVisualStyles(); Application.Run(new ProfileSelector(CardTemplate.DatabasePath)); } else { using (CodeCompiler compiler = new CodeCompiler(CardTemplate.DatabasePath + "Bots\\SmartCC\\Profiles\\Defaut\\", CardTemplate.DatabasePath)) { if (compiler.Compile()) { } } String path = CardTemplate.DatabasePath + "Bots/SmartCC/Profile.current"; using (var stream = new FileStream(path, FileMode.Truncate)) { using (var writer = new StreamWriter(stream)) { writer.WriteLine("Defaut"); writer.Close(); } } } s = new Simulation(); ValuesInterface.LoadValuesFromFile(); ProfileInterface.LoadBehavior(); Seed = new Board(); Seed.HeroEnemy = Card.Create("HERO_01", true, GenerateId()); Seed.HeroFriend = Card.Create("HERO_02", false, GenerateId()); Seed.HeroFriend.CurrentHealth = 30; Seed.HeroFriend.MaxHealth = 30; Seed.HeroEnemy.CurrentHealth = 30; Seed.HeroEnemy.MaxHealth = 30; Seed.ManaAvailable = 10; ClearUI(ActionDenotator.NEW); UpdateUI(); }
public void Compile_WhenTheResultOfAnAndExpressionIsReturned_ReturnsTheResultOfTheAndExpression([Range(0, 9)] int value) { var grammar = new PegParser().Parse("a <int> = x:&(<int> d:. { int.Parse(d) }) { x }"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <int>(compiled); var result = parser.Parse(value.ToString()); Assert.That(result, Is.EqualTo(value)); }
public void CompileDelegateTest() { var compiler = new CodeCompiler(); var func = compiler.CompileDelegate <Func <int, int, decimal, decimal> >(CODE1, "Calcuate"); Assert.IsNotNull(func); Assert.AreEqual(15, func(10, 20, 0.5m)); }
public void Compile_WhenTheGrammarHasACodeAssertion_RespectsTheReturnValueOfTheExpression(bool expression, string assertion, string expected) { var grammar = new PegParser().Parse($"a = 'OK' {assertion}{{ {expression.ToString().ToLower()} }} / ;"); var compiled = PegCompiler.Compile(grammar); var parser = CodeCompiler.Compile <string>(compiled); var result = parser.Parse("OK"); Assert.That(result, Is.EqualTo(expected)); }
private void button1_Click(object sender, EventArgs e) { Console.OutputEncoding = Encoding.UTF8; using (CodeCompiler compiler = new CodeCompiler(BotDirectory + "Bots\\SmartCC\\Profiles\\"+comboBox1.SelectedItem.ToString()+"\\", BotDirectory)) { if (compiler.Compile()) { } else { } } Close(); StreamWriter writer = new StreamWriter(BotDirectory + "Bots\\SmartCC\\Profile.current"); writer.WriteLine(comboBox1.SelectedItem.ToString().Substring(1)); writer.Close(); }
void CompileFiles() { filePaths = filePaths.Where(x => File.Exists(x)).ToArray(); var options = new CompilerParameters(); options.GenerateExecutable = false; options.GenerateInMemory = true; options.ReferencedAssemblies.AddRange(assemblyReferences); var compiler = new CodeCompiler(); var result = compiler.CompileAssemblyFromFileBatch(options, filePaths.ToArray()); foreach (var err in result.Errors) { manager.logWriter.WriteLine(err); } this.assembly = result.CompiledAssembly; }
private static void RecompilePlugins() { if (BotMain.IsRunning) { BotMain.Stop(false, "Recompiling Plugin!"); while (BotMain.BotThread.IsAlive) Thread.Sleep(0); } var EnabledPlugins = PluginManager.GetEnabledPlugins().ToArray(); PluginManager.ShutdownAllPlugins(); DBLog.DebugFormat("Removing Funky from plugins"); while (PluginManager.Plugins.Any(p => p.Plugin.Name == "Funky")) { PluginManager.Plugins.Remove(PluginManager.Plugins.First(p => p.Plugin.Name == "Funky")); } DBLog.DebugFormat("Clearing all treehooks"); TreeHooks.Instance.ClearAll(); DBLog.DebugFormat("Disposing of current bot"); BotMain.CurrentBot.Dispose(); DBLog.DebugFormat("Removing old Assemblies"); CodeCompiler.DeleteOldAssemblies(); string sDemonBuddyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string sTrinityPluginPath = sDemonBuddyPath + @"\Plugins\FunkyBot\"; CodeCompiler FunkyCode = new CodeCompiler(sTrinityPluginPath); FunkyCode.ParseFilesForCompilerOptions(); DBLog.DebugFormat("Recompiling Funky Plugin"); FunkyCode.Compile(); DBLog.DebugFormat(FunkyCode.CompiledToLocation); TreeHooks.Instance.ClearAll(); BrainBehavior.CreateBrain(); DBLog.DebugFormat("Reloading Plugins"); PluginManager.ReloadAllPlugins(sDemonBuddyPath + @"\Plugins\"); DBLog.DebugFormat("Enabling Plugins"); PluginManager.SetEnabledPlugins(EnabledPlugins); }
internal static void RecompileSelectedPlugin(Object sender, EventArgs e) { var FBD = new System.Windows.Forms.FolderBrowserDialog(); string sDemonBuddyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); FBD.SelectedPath = sDemonBuddyPath + @"\Plugins\"; System.Windows.Forms.DialogResult PluginLocationResult = FBD.ShowDialog(); if (PluginLocationResult == System.Windows.Forms.DialogResult.OK && !String.IsNullOrEmpty(FBD.SelectedPath)) { Logger.DBLog.DebugFormat(FBD.SelectedPath); if (BotMain.IsRunning) { BotMain.Stop(false, "Recompiling Plugin!"); while (BotMain.BotThread.IsAlive) Thread.Sleep(0); } var EnabledPlugins = PluginManager.GetEnabledPlugins().ToArray(); foreach (var p in PluginManager.Plugins) { p.Enabled = false; } PluginManager.ShutdownAllPlugins(); //FunkyBot.Logger.DBLog.DebugFormat("Removing {0} from plugins", FunkyRoutine.lastSelectedPC.Plugin.Name); //while (PluginManager.Plugins.Any(p => p.Plugin.Name == FunkyRoutine.lastSelectedPC.Plugin.Name)) //{ // PluginManager.Plugins.Remove(PluginManager.Plugins.First(p => p.Plugin.Name == FunkyRoutine.lastSelectedPC.Plugin.Name)); //} Logger.DBLog.DebugFormat("Clearing all treehooks"); TreeHooks.Instance.ClearAll(); Logger.DBLog.DebugFormat("Disposing of current bot"); BotMain.CurrentBot.Dispose(); Logger.DBLog.DebugFormat("Removing old Assemblies"); CodeCompiler.DeleteOldAssemblies(); CodeCompiler FunkyCode = new CodeCompiler(FBD.SelectedPath); //FunkyCode.ParseFilesForCompilerOptions(); Logger.DBLog.DebugFormat("Recompiling Plugin"); FunkyCode.Compile(); Logger.DBLog.DebugFormat(FunkyCode.CompiledToLocation); TreeHooks.Instance.ClearAll(); BrainBehavior.CreateBrain(); Logger.DBLog.DebugFormat("Reloading Plugins"); PluginManager.ReloadAllPlugins(sDemonBuddyPath + @"\Plugins\"); Logger.DBLog.DebugFormat("Enabling Plugins"); PluginManager.SetEnabledPlugins(EnabledPlugins); } }
private static void RecompilePlugins() { if (BotMain.IsRunning) { BotMain.Stop(false, "Recompiling Plugin!"); while (BotMain.BotThread.IsAlive) Thread.Sleep(0); } var EnabledPlugins = PluginManager.GetEnabledPlugins().ToArray(); foreach (var p in PluginManager.Plugins) { p.Enabled = false; } PluginManager.ShutdownAllPlugins(); Logger.DBLog.DebugFormat("Disposing All Routines"); foreach (var r in RoutineManager.Routines) { r.Dispose(); } string sDemonBuddyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string sTrinityPluginPath = FolderPaths.PluginPath; CodeCompiler FunkyCode = new CodeCompiler(sTrinityPluginPath); //FunkyCode.ParseFilesForCompilerOptions(); Logger.DBLog.DebugFormat("Recompiling Funky Bot"); FunkyCode.Compile(); Logger.DBLog.DebugFormat(FunkyCode.CompiledToLocation); Logger.DBLog.DebugFormat("Clearing all treehooks"); TreeHooks.Instance.ClearAll(); Logger.DBLog.DebugFormat("Disposing of current bot"); BotMain.CurrentBot.Dispose(); Logger.DBLog.DebugFormat("Removing old Assemblies"); CodeCompiler.DeleteOldAssemblies(); BrainBehavior.CreateBrain(); Logger.DBLog.DebugFormat("Reloading Plugins"); PluginManager.ReloadAllPlugins(sDemonBuddyPath + @"\Plugins\"); Logger.DBLog.DebugFormat("Enabling Plugins"); PluginManager.SetEnabledPlugins(EnabledPlugins); Logger.DBLog.DebugFormat("Reloading Routines"); RoutineManager.Reload(); }
public override void UpdateSelf() { base.UpdateSelf(); if (Input.Keys[Key.Tilde] == InputState.Release) { if (!Open) { OpenConsole(); } else { CloseConsole(); } } if (Input.Keys[Key.Enter] == InputState.Release) { var builder = new StringBuilder(); foreach (var pair in ExposedReferences) { if (pair.Value == null) throw new Exception("Console object " + pair.Key + " is bound to null"); builder.Append(GetFriendlyTypeName(pair.Value.GetType()) + " " + pair.Key + ", "); } var code = @" using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using FireflyGL; using FireflyGL.Utility; namespace FireflyGL { class DebugConsole { static void Run(" + builder.ToString() + @"StringWriter writer) { var stdOut = Console.Out; Console.SetOut(writer); " + input.Text + @" Console.SetOut(stdOut); } } }"; var compiler = new CodeCompiler(); compiler.Compile(code); var results = compiler.Results; if (results.Errors.HasErrors) { for (int i = 0; i < results.Errors.Count; ++i) { PushText(results.Errors[i].ErrorText); } } else { try { var writer = new StringWriter(); compiler.Run(ExposedReferences.Values.ToArray(), writer); PushText(writer.ToString()); history.Add(input.Text); currentHistory = history.Count; input.Text = ""; writer.Dispose(); } catch (Exception e) { } } } if (Input.Keys[Key.Up] == InputState.Release) { if (currentHistory > 0) { currentHistory--; input.Text = history[currentHistory]; input.CursorPosition = input.Text.Length; } } if (Input.Keys[Key.Down] == InputState.Release) { if (currentHistory < history.Count - 1) { currentHistory++; input.Text = history[currentHistory]; input.CursorPosition = input.Text.Length; } } }
public void Setup() { this.toTest = new CodeCompiler(); }