ExpressionCompilerResults.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using GDNXFD.Data;
  2. using Microsoft.CSharp;
  3. using System;
  4. using System.CodeDom.Compiler;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace GDNXFD.Alert.Interpreter
  12. {
  13. public class ExpressionCompilerResults
  14. {
  15. private CompilerResults compilerResults;
  16. private AlertRule alertRule;
  17. public ExpressionCompilerResults(CompilerResults results, AlertRule ar)
  18. {
  19. compilerResults = results;
  20. alertRule = ar;
  21. }
  22. public bool HasErrors
  23. {
  24. get
  25. {
  26. if (compilerResults == null ||
  27. compilerResults.Errors == null)
  28. return false;
  29. return compilerResults.Errors.HasErrors;
  30. }
  31. }
  32. public bool HasWarnings
  33. {
  34. get
  35. {
  36. if (compilerResults == null ||
  37. compilerResults.Errors == null)
  38. return false;
  39. return compilerResults.Errors.HasWarnings;
  40. }
  41. }
  42. public string ErrorText
  43. {
  44. get
  45. {
  46. if (this.HasErrors)
  47. {
  48. string msg = string.Empty;
  49. foreach (CompilerError ce in compilerResults.Errors)
  50. {
  51. if (ce.IsWarning)
  52. continue;
  53. msg += ce.ErrorText;
  54. }
  55. return msg;
  56. }
  57. return null;
  58. }
  59. }
  60. public string WarningText
  61. {
  62. get
  63. {
  64. if (this.HasWarnings)
  65. {
  66. string msg = string.Empty;
  67. foreach (CompilerError ce in compilerResults.Errors)
  68. {
  69. if (ce.IsWarning)
  70. msg += ce.ErrorText;
  71. }
  72. return msg;
  73. }
  74. return null;
  75. }
  76. }
  77. public Assembly ResultAssembly
  78. {
  79. get
  80. {
  81. if (compilerResults != null)
  82. return compilerResults.CompiledAssembly;
  83. return null;
  84. }
  85. }
  86. public StringCollection Output
  87. {
  88. get
  89. {
  90. if (compilerResults != null)
  91. return compilerResults.Output;
  92. return null;
  93. }
  94. }
  95. public AlertRuleInterpreter ExpInterpreter
  96. {
  97. get
  98. {
  99. if (this.ResultAssembly != null)
  100. {
  101. Type fType = ResultAssembly.GetTypes()[0];
  102. return (AlertRuleInterpreter)ResultAssembly.CreateInstance(fType.FullName, false, BindingFlags.Default, null, new object[] { alertRule }, null, null);
  103. }
  104. return null;
  105. }
  106. }
  107. }
  108. }