|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|