using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EVCB_OCPP.Packet.Messages.Basic { public class Queue { //public Dictionary requestQueue; public Dictionary requestQueue; public Queue() { //requestQueue = new Dictionary(); requestQueue = new Dictionary(); } /// /// 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. /// //public String store(Type request) public string store(IRequest request) { string UniqueId = Guid.NewGuid().ToString(); requestQueue.Add(UniqueId, request); return UniqueId; } /// /// 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. /// //public String store(Type request) public void store(IRequest request, string UniqueId) { requestQueue.Add(UniqueId, request); } /// /// 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} /// //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; } } }