CodeTemplate.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace GDNXFD.Alert.Interpreter
  7. {
  8. public class CodeTemplate
  9. {
  10. public const string Outline = @"
  11. using System;
  12. using GDNXFD.Data;
  13. namespace GDNXFD.Alert.Interpreter
  14. {{
  15. public class {0} : AlertRuleInterpreter
  16. {{
  17. public {0}(AlertRule alertRule) : base(alertRule) {{ }}
  18. public override bool Interpret(string objectId, AlertObjectType objectType)
  19. {{
  20. {1}
  21. {2}
  22. }}
  23. {3}
  24. }}
  25. }}
  26. ";
  27. public const string AIDeclare = "double {0} = dataProvider.FindAIValue(\"{0}\",objectId,objectType, ref dataInfo);";
  28. public const string DIDeclare = "bool {0} = dataProvider.FindDIValue(\"{0}\",objectId,objectType, ref dataInfo);";
  29. public const string ReturnStatement = "return {0};";
  30. public const string SustainMethod = @"
  31. public bool Sustain_{0}(string objectId, AlertObjectType objectType, int duration, int interval = 60)
  32. {{
  33. DateTime tEnd = DateTime.Now;
  34. DateTime tStart = DateTime.Now.AddSeconds(0 - duration);
  35. {1}
  36. for (int i = 0; i<{2}; i++)
  37. {{
  38. if ({3})
  39. continue;
  40. else
  41. return false;
  42. }}
  43. return true;
  44. }}";
  45. public const string AIsDeclare = "double[] {0} = dataProvider.FindAIHistorySnap(\"{0}\", objectId, objectType, tStart, tEnd, interval);";
  46. public const string DIsDeclare = "bool[] {0} = dataProvider.FindDIHistorySnap(\"{0}\", objectId, objectType, tStart, tEnd, interval);";
  47. public const string BoolSustainDeclare = "bool bool{0} = {1};";
  48. public const string SustainCallString = "Sustain_{0}(objectId, objectType, {1},{2})";
  49. }
  50. }