Эх сурвалжийг харах

Fix OCPP2.0 StatusNotification

Jessica Tseng 4 жил өмнө
parent
commit
df397fce2a

+ 1 - 1
EVCB_OCPP.Domain/Properties/AssemblyInfo.cs

@@ -35,4 +35,4 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
 
-[assembly: AssemblyInformationalVersion("1f1f448")]
+[assembly: AssemblyInformationalVersion("63ae964")]

+ 1 - 1
EVCB_OCPP.MailService/Properties/AssemblyInfo.cs

@@ -35,4 +35,4 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
 
-[assembly: AssemblyInformationalVersion("1f1f448")]
+[assembly: AssemblyInformationalVersion("63ae964")]

+ 1 - 1
EVCB_OCPP.Packet/Properties/AssemblyInfo.cs

@@ -35,4 +35,4 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
 
-[assembly: AssemblyInformationalVersion("1f1f448")]
+[assembly: AssemblyInformationalVersion("63ae964")]

+ 2 - 0
EVCB_OCPP.Packet20/EVCB_OCPP.Packet20.csproj

@@ -204,10 +204,12 @@
     <Compile Include="Features\CoreProfile.cs" />
     <Compile Include="Features\Core\BootNotificationFeature.cs" />
     <Compile Include="Features\Core\HeartbeatFeature.cs" />
+    <Compile Include="Features\Core\StatusNotificationFeature.cs" />
     <Compile Include="Features\Feature.cs" />
     <Compile Include="Features\Profile.cs" />
     <Compile Include="Messages\AuthorizeRequest.cs" />
     <Compile Include="Messages\AuthorizeResponse.cs" />
+    <Compile Include="Messages\Basic\Queue.cs" />
     <Compile Include="Messages\BootNotificationRequest.cs" />
     <Compile Include="Messages\BootNotificationResponse.cs" />
     <Compile Include="Messages\CancelReservationRequest.cs" />

+ 27 - 0
EVCB_OCPP.Packet20/Features/Core/StatusNotificationFeature.cs

@@ -0,0 +1,27 @@
+using EVCB_OCPP.Packet20.Messages;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.Packet20.Features.Core
+{
+    public class StatusNotificationFeature : Feature
+    {
+        public override string GetAction()
+        {
+            return Actions.StatusNotification.ToString();
+        }
+
+        public override Type GetConfirmationType()
+        {
+            return typeof(StatusNotificationResponse);
+        }
+
+        public override Type GetRequestType()
+        {
+            return typeof(StatusNotificationRequest);
+        }
+    }
+}

+ 1 - 1
EVCB_OCPP.Packet20/Features/CoreProfile.cs

@@ -18,7 +18,7 @@ namespace EVCB_OCPP.Packet20.Features
             features.Add(new HeartbeatFeature());
             //features.Add(new StartTransactionFeature());
             //features.Add(new ChangeConfigurationFeature());
-            //features.Add(new StatusNotificationFeature());
+            features.Add(new StatusNotificationFeature());
             //features.Add(new StopTransactionFeature());
             //features.Add(new MeterValuesFeature());
             //features.Add(new RemoteStartTransactionFeature());

+ 71 - 0
EVCB_OCPP.Packet20/Messages/Basic/Queue.cs

@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.Packet20.Messages.Basic
+{
+    public class Queue
+    {
+        //public Dictionary<string, Type> requestQueue;
+        public Dictionary<string, IRequest> requestQueue;
+
+        public Queue()
+        {
+            //requestQueue = new Dictionary<string, Type>();
+            requestQueue = new Dictionary<string, IRequest>();
+        }
+
+        /// <summary>
+        /// Store a {Request} and get a unique identifier to fetch it later on.
+        /// param request: the {Request}.
+        /// return: a unique identifier used to fetch the request.
+        /// </summary>
+        //public String store(Type request)
+        public string store(IRequest request)
+        {
+            string UniqueId = Guid.NewGuid().ToString();
+            requestQueue.Add(UniqueId, request);
+            return UniqueId;
+        }
+
+        /// <summary>
+        /// Store a {Request} and get a unique identifier to fetch it later on.
+        /// param request: the {Request}.
+        /// return: a unique identifier used to fetch the request.
+        /// </summary>
+        //public String store(Type request)
+        public void store(IRequest request, string UniqueId)
+        {
+            requestQueue.Add(UniqueId, request);
+        }
+
+        /// <summary>
+        /// Restore a {Request} using a unique identifier.
+        /// The identifier can only be used once.
+        /// If no Request was found, null is returned.
+        /// param ticket:    unique identifier returned when {Request} was initially stored.
+        /// return: the stored {Request}
+        /// </summary>
+        //public Type restoreRequest(String ticket)
+        public IRequest RestoreRequest(string UniqueId)
+        {
+            //Type request = null;
+            IRequest request = null;
+            try
+            {
+                if (requestQueue.ContainsKey(UniqueId))
+                    request = requestQueue[UniqueId];
+
+                requestQueue.Remove(UniqueId);
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+            return request;
+        }
+
+    }
+}

+ 11 - 1
EVCB_OCPP.Packet20/Messages/StatusNotificationRequest.cs

@@ -11,7 +11,7 @@ using System.Threading.Tasks;
 
 namespace EVCB_OCPP.Packet20.Messages
 {
-    public class StatusNotificationRequest
+    public class StatusNotificationRequest:IRequest
     {
         /// <summary>
         /// The time for which the status is reported. If
@@ -42,6 +42,16 @@ namespace EVCB_OCPP.Packet20.Messages
         /// </summary>
         [Required]
         public int ConnectorId { set; get; }
+        public string Action { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
 
+        public bool TransactionRelated()
+        {
+            return false;
+        }
+
+        public bool Validate()
+        {
+            return Validator.TryValidateObject(this, new ValidationContext(this), null, true);
+        }
     }
 }

+ 17 - 1
EVCB_OCPP.Packet20/Messages/StatusNotificationResponse.cs

@@ -1,12 +1,28 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
 namespace EVCB_OCPP.Packet20.Messages
 {
-   public class StatusNotificationResponse
+    public class StatusNotificationResponse : IConfirmation
     {
+        private IRequest _request = null;
+        public IRequest GetRequest()
+        {
+            return _request;
+        }
+
+        public void SetRequest(IRequest request)
+        {
+            _request = request;
+        }
+
+        public bool Validate()
+        {
+            return Validator.TryValidateObject(this, new ValidationContext(this), null, true);
+        }
     }
 }

+ 1 - 1
EVCB_OCPP.Packet20/Properties/AssemblyInfo.cs

@@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
-[assembly: AssemblyInformationalVersion("1f1f448")]
+[assembly: AssemblyInformationalVersion("63ae964")]