Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1369 #1386

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/UniversalDashboard/Execution/SessionDriveProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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));
Expand Down