using GDNXFD.Data; using Microsoft.CSharp; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace GDNXFD.Alert.Interpreter { public class ExpressionCompilerResults { private CompilerResults compilerResults; private AlertRule alertRule; public ExpressionCompilerResults(CompilerResults results, AlertRule ar) { compilerResults = results; alertRule = ar; } public bool HasErrors { get { if (compilerResults == null || compilerResults.Errors == null) return false; return compilerResults.Errors.HasErrors; } } public bool HasWarnings { get { if (compilerResults == null || compilerResults.Errors == null) return false; return compilerResults.Errors.HasWarnings; } } public string ErrorText { get { if (this.HasErrors) { string msg = string.Empty; foreach (CompilerError ce in compilerResults.Errors) { if (ce.IsWarning) continue; msg += ce.ErrorText; } return msg; } return null; } } public string WarningText { get { if (this.HasWarnings) { string msg = string.Empty; foreach (CompilerError ce in compilerResults.Errors) { if (ce.IsWarning) msg += ce.ErrorText; } return msg; } return null; } } public Assembly ResultAssembly { get { if (compilerResults != null) return compilerResults.CompiledAssembly; return null; } } public StringCollection Output { get { if (compilerResults != null) return compilerResults.Output; return null; } } public AlertRuleInterpreter ExpInterpreter { get { if (this.ResultAssembly != null) { Type fType = ResultAssembly.GetTypes()[0]; return (AlertRuleInterpreter)ResultAssembly.CreateInstance(fType.FullName, false, BindingFlags.Default, null, new object[] { alertRule }, null, null); } return null; } } } }