123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using NLog;
- using OCPPPacket.Packet.Feature;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OCPPServer.Handler
- {
- public class FeatureHandler
- {
- private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
- List<Feature> featureList;
- public FeatureHandler()
- {
- this.featureList = new List<Feature>();
- }
- public void AddFeatureProfile(Feature feature)
- {
- featureList.Add(feature);
- }
- public Feature FindFeatureByConfirm(Type confirm)
- {
- return FindFeature(confirm, featureList);
- }
- public Feature FindFeatureByRequest(Type request)
- {
- return FindFeature(request, featureList);
- }
- public bool FeatureContains(Feature feature, Type seektype)
- {
- bool contains = false;
- if(feature.GetRequestType() == seektype)
- {
- contains |= true;
- }
- if(feature.GetConfirmationType() == seektype)
- {
- contains |= true;
- }
- //old coding type
- ////contains |= feature.getAction().Equals(object1);
- //contains |= feature.GetRequestType() == object1;
- //contains |= feature.GetConfirmationType() == object1;
- return contains;
- }
- public Feature FindFeature(Type needle, List<Feature> featureList)
- {
- Feature output = null;
- foreach (Feature feature in featureList)
- {
- if (FeatureContains(feature, needle))
- {
- output = feature;
- break;
- }
- }
- return output;
- }
- public Feature FindFeatureByAction(string v)
- {
- try
- {
- Feature output = null;
- foreach (Feature feature in featureList)
- {
- if (TestfeatureContains(feature, v))
- {
- output = feature;
- break;
- }
- }
- return output;
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- throw new ApplicationException(ex.ToString());
- }
- }
- public bool TestfeatureContains(Feature feature, string v)
- {
- try
- {
- bool contains = false;
- contains |= feature.GetAction().Equals(v);
- return contains;
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- throw new ApplicationException(ex.ToString());
- }
- }
- }
- }
|