using Microsoft.CSharp; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using GDNXFD.Data; namespace GDNXFD.Alert.Interpreter { public class ExpressionCompiler { public static ExpressionCompilerResults CompileExpression(AlertRule alertRule) { if (alertRule == null) return null; CodeDomProvider cpd = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters(); cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("GDNXFD.Alert.Interpreter.dll"); cp.ReferencedAssemblies.Add("GDNXFD.Data.dll"); cp.GenerateExecutable = false; CodeGenerator cGen = new CodeGenerator(alertRule.Id, alertRule.Expression); string sourceCode = cGen.ToClassString(); CompilerResults cr = cpd.CompileAssemblyFromSource(cp, sourceCode); return new ExpressionCompilerResults(cr, alertRule); } } }