FeatureHandler.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using NLog;
  2. using OCPPPacket.Packet.Feature;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OCPPServer.Handler
  9. {
  10. public class FeatureHandler
  11. {
  12. private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
  13. List<Feature> featureList;
  14. public FeatureHandler()
  15. {
  16. this.featureList = new List<Feature>();
  17. }
  18. public void AddFeatureProfile(Feature feature)
  19. {
  20. featureList.Add(feature);
  21. }
  22. public Feature FindFeatureByConfirm(Type confirm)
  23. {
  24. return FindFeature(confirm, featureList);
  25. }
  26. public Feature FindFeatureByRequest(Type request)
  27. {
  28. return FindFeature(request, featureList);
  29. }
  30. public bool FeatureContains(Feature feature, Type seektype)
  31. {
  32. bool contains = false;
  33. if(feature.GetRequestType() == seektype)
  34. {
  35. contains |= true;
  36. }
  37. if(feature.GetConfirmationType() == seektype)
  38. {
  39. contains |= true;
  40. }
  41. //old coding type
  42. ////contains |= feature.getAction().Equals(object1);
  43. //contains |= feature.GetRequestType() == object1;
  44. //contains |= feature.GetConfirmationType() == object1;
  45. return contains;
  46. }
  47. public Feature FindFeature(Type needle, List<Feature> featureList)
  48. {
  49. Feature output = null;
  50. foreach (Feature feature in featureList)
  51. {
  52. if (FeatureContains(feature, needle))
  53. {
  54. output = feature;
  55. break;
  56. }
  57. }
  58. return output;
  59. }
  60. public Feature FindFeatureByAction(string v)
  61. {
  62. try
  63. {
  64. Feature output = null;
  65. foreach (Feature feature in featureList)
  66. {
  67. if (TestfeatureContains(feature, v))
  68. {
  69. output = feature;
  70. break;
  71. }
  72. }
  73. return output;
  74. }
  75. catch (Exception ex)
  76. {
  77. logger.Error(ex);
  78. throw new ApplicationException(ex.ToString());
  79. }
  80. }
  81. public bool TestfeatureContains(Feature feature, string v)
  82. {
  83. try
  84. {
  85. bool contains = false;
  86. contains |= feature.GetAction().Equals(v);
  87. return contains;
  88. }
  89. catch (Exception ex)
  90. {
  91. logger.Error(ex);
  92. throw new ApplicationException(ex.ToString());
  93. }
  94. }
  95. }
  96. }