1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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;
- }
- }
- }
|