From cec4c9ec3ae85d9e0f4f50d32b703f3200182b76 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Mon, 16 Dec 2019 08:07:47 -0700 Subject: [PATCH] Fixes #1369 --- .../Execution/SessionDriveProvider.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/UniversalDashboard/Execution/SessionDriveProvider.cs b/src/UniversalDashboard/Execution/SessionDriveProvider.cs index 803d304c..9e5c699c 100644 --- a/src/UniversalDashboard/Execution/SessionDriveProvider.cs +++ b/src/UniversalDashboard/Execution/SessionDriveProvider.cs @@ -57,6 +57,11 @@ private string SessionId private HostState HostState => Host.PrivateData.BaseObject as HostState; protected override void GetItem(string name) { + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { var value = HostState.EndpointService.SessionManager.GetSession(SessionId).GetVariableValue(name); @@ -69,6 +74,11 @@ protected override void GetItem(string name) protected override void NewItem(string path, string itemTypeName, object newItemValue) { + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { HostState.EndpointService.SessionManager.GetSession(SessionId).SetVariable(path, newItemValue); @@ -77,6 +87,11 @@ protected override void NewItem(string path, string itemTypeName, object newItem protected override void SetItem(string name, object value) { + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { HostState.EndpointService.SessionManager.GetSession(SessionId).SetVariable(name, value); @@ -85,6 +100,11 @@ protected override void SetItem(string name, object value) protected override bool ItemExists(string path) { + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { return HostState.EndpointService.SessionManager.GetSession(SessionId).SessionVariables.ContainsKey(path.ToLower()); @@ -99,6 +119,11 @@ protected override bool IsValidPath(string path) public void ClearContent(string path) { + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { HostState.EndpointService.SessionManager.GetSession(SessionId).RemoveVariable(path); @@ -114,6 +139,11 @@ public IContentReader GetContentReader(string path) { Logger.Debug($"GetContentReader - {path} "); + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { return new SessionStateReaderWriter(path.ToLower(), HostState.EndpointService.SessionManager.GetSession(SessionId)); @@ -131,6 +161,11 @@ public IContentWriter GetContentWriter(string path) { Logger.Debug($"GetContentWriter - {path} "); + if (HostState?.EndpointService?.SessionManager == null) + { + throw new Exception("You cannot call the $Session provider outside of an endpoint."); + } + if (HostState.EndpointService.SessionManager.SessionExists(SessionId)) { return new SessionStateReaderWriter(path.ToLower(), HostState.EndpointService.SessionManager.GetSession(SessionId));