Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Use abstract endpoint (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Nov 11, 2019
1 parent 68710ed commit 55aca27
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/UniversalDashboard/Controllers/ComponentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ComponentController(IExecutionService executionService, IDashboardService
_connectionManager = connectionManager;
}

private async Task<IActionResult> RunScript(Endpoint endpoint, Dictionary<string, object> parameters = null, bool noSerialization = false)
private async Task<IActionResult> RunScript(AbstractEndpoint endpoint, Dictionary<string, object> parameters = null, bool noSerialization = false)
{
try {
var variables = new Dictionary<string, object> {
Expand Down
26 changes: 13 additions & 13 deletions src/UniversalDashboard/Execution/EndpointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace UniversalDashboard.Execution
{
public class EndpointService : IEndpointService
{
private readonly List<Endpoint> _restEndpoints;
private readonly List<Endpoint> _scheduledEndpoints;
private readonly List<AbstractEndpoint> _restEndpoints;
private readonly List<AbstractEndpoint> _scheduledEndpoints;
private static readonly Logger logger = LogManager.GetLogger("EndpointService");

private static IEndpointService _instance;

public ConcurrentDictionary<string, Endpoint> Endpoints { get; private set; }
public ConcurrentDictionary<string, AbstractEndpoint> Endpoints { get; private set; }
public ISessionManager SessionManager { get; private set; }

public static IEndpointService Instance
Expand All @@ -37,14 +37,14 @@ public static IEndpointService Instance

private EndpointService()
{
Endpoints = new ConcurrentDictionary<string, Endpoint>();
Endpoints = new ConcurrentDictionary<string, AbstractEndpoint>();
SessionManager = new SessionManager();

_restEndpoints = new List<Endpoint>();
_scheduledEndpoints = new List<Endpoint>();
_restEndpoints = new List<AbstractEndpoint>();
_scheduledEndpoints = new List<AbstractEndpoint>();
}

public void Register(Endpoint callback)
public void Register(AbstractEndpoint callback)
{
if (!callback.HasCallback)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ public void Unregister(string name, string sessionId)
{
if (Endpoints.ContainsKey(name))
{
Endpoints.TryRemove(name, out Endpoint endpoint);
Endpoints.TryRemove(name, out AbstractEndpoint endpoint);
logger.Debug("Endpoint found. Removing endpoint.");
}
}
Expand All @@ -119,13 +119,13 @@ public void Unregister(string name, string sessionId)
if (session.Endpoints.ContainsKey(name))
{
logger.Debug("Session endpoint found. Removing endpoint.");
session.Endpoints.TryRemove(name, out Endpoint value);
session.Endpoints.TryRemove(name, out AbstractEndpoint value);
}
}
}
}

public Endpoint Get(string name, string sessionId)
public AbstractEndpoint Get(string name, string sessionId)
{
logger.Debug($"Get() {name} {sessionId}");
if (sessionId != null)
Expand All @@ -150,7 +150,7 @@ public Endpoint Get(string name, string sessionId)
return null;
}

public Endpoint GetByUrl(string url, string method, Dictionary<string, object> matchedVariables)
public AbstractEndpoint GetByUrl(string url, string method, Dictionary<string, object> matchedVariables)
{
foreach(var endpoint in _restEndpoints.Where(m => m.Method.Equals(method, StringComparison.OrdinalIgnoreCase)))
{
Expand Down Expand Up @@ -200,12 +200,12 @@ public Endpoint GetByUrl(string url, string method, Dictionary<string, object> m
return null;
}

public IEnumerable<Endpoint> GetScheduledEndpoints()
public IEnumerable<AbstractEndpoint> GetScheduledEndpoints()
{
return _scheduledEndpoints;
}

private bool IsMatch(Endpoint callback, string url, Dictionary<string, object> matchedVariables)
private bool IsMatch(AbstractEndpoint callback, string url, Dictionary<string, object> matchedVariables)
{
if (callback.Parts == null) return false;

Expand Down
10 changes: 5 additions & 5 deletions src/UniversalDashboard/Interfaces/IEndpointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace UniversalDashboard.Interfaces
{
public interface IEndpointService
{
Endpoint Get(string name, string sessionId);
AbstractEndpoint Get(string name, string sessionId);
void Unregister(string name, string sessionId);
Endpoint GetByUrl(string url, string method, Dictionary<string, object> matchedVariables);
IEnumerable<Endpoint> GetScheduledEndpoints();
void Register(Endpoint callback);
ConcurrentDictionary<string, Endpoint> Endpoints { get; }
AbstractEndpoint GetByUrl(string url, string method, Dictionary<string, object> matchedVariables);
IEnumerable<AbstractEndpoint> GetScheduledEndpoints();
void Register(AbstractEndpoint callback);
ConcurrentDictionary<string, AbstractEndpoint> Endpoints { get; }
ISessionManager SessionManager { get; }
}
}
4 changes: 2 additions & 2 deletions src/UniversalDashboard/Models/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class SessionState
public SessionState(string id)
{
Id = id;
Endpoints = new ConcurrentDictionary<string, Endpoint>();
Endpoints = new ConcurrentDictionary<string, AbstractEndpoint>();
SessionVariables = new ConcurrentDictionary<string, object>();
Connections = 1;
LastTouched = DateTime.UtcNow;
}

public string Id { get; set; }
public int Connections { get; set; }
public ConcurrentDictionary<string, Endpoint> Endpoints { get; set; }
public ConcurrentDictionary<string, AbstractEndpoint> Endpoints { get; set; }
public ConcurrentDictionary<string, object> SessionVariables { get; set; }
public DateTime LastTouched { get; set; }

Expand Down

0 comments on commit 55aca27

Please sign in to comment.