diff --git a/src/.vscode/launch.json b/src/.vscode/launch.json new file mode 100644 index 00000000..f3af5295 --- /dev/null +++ b/src/.vscode/launch.json @@ -0,0 +1,52 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "PowerShell Launch Current File", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "args": [], + "cwd": "${file}" + }, + { + "name": "PowerShell Launch Current File in Temporary Console", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "args": [], + "cwd": "${file}", + "createTemporaryIntegratedConsole": true + }, + { + "name": "PowerShell Launch Current File w/Args Prompt", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "args": [ + "${command:SpecifyScriptArgs}" + ], + "cwd": "${file}" + }, + { + "name": "PowerShell Attach to Host Process", + "type": "PowerShell", + "request": "attach" + }, + { + "name": "PowerShell Interactive Session", + "type": "PowerShell", + "request": "launch", + "cwd": "" + }, + { + "name": "PowerShell Attach Interactive Session Runspace", + "type": "PowerShell", + "request": "attach", + "processId": "current" + } + ] +} \ No newline at end of file diff --git a/src/UniversalDashboard.Materialize/Scripts/grid.ps1 b/src/UniversalDashboard.Materialize/Scripts/grid.ps1 index e7a4a0a9..eafcf089 100644 --- a/src/UniversalDashboard.Materialize/Scripts/grid.ps1 +++ b/src/UniversalDashboard.Materialize/Scripts/grid.ps1 @@ -45,7 +45,7 @@ function New-UDGrid { if ($null -ne $Endpoint) { if ($Endpoint -is [scriptblock]) { - $Endpoint = New-UDEndpoint -Endpoint $Endpoint -Id $Id + $Endpoint = New-UDEndpoint -Endpoint $Endpoint -Id $Id -ArgumentList $ArgumentList } elseif ($Endpoint -isnot [UniversalDashboard.Models.Endpoint]) { throw "Endpoint must be a script block or UDEndpoint" diff --git a/src/UniversalDashboard/Cmdlets/NewEndpointCommand.cs b/src/UniversalDashboard/Cmdlets/NewEndpointCommand.cs index 2629115b..019d81f0 100644 --- a/src/UniversalDashboard/Cmdlets/NewEndpointCommand.cs +++ b/src/UniversalDashboard/Cmdlets/NewEndpointCommand.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Management.Automation; +using System.Management.Automation.Language; using System.Text.RegularExpressions; using UniversalDashboard.Models; using UniversalDashboard.Services; +using System.Linq; namespace UniversalDashboard.Cmdlets { @@ -44,11 +46,34 @@ protected override void EndProcessing() ArgumentList = ArgumentList }; + callback.Variables = new Dictionary(); + + try + { + var variables = Endpoint.Ast.FindAll(x => x is VariableExpressionAst, true).Cast().Select(m => m.VariablePath.ToString()); + + foreach (var variableName in variables) + { + var variable = SessionState.InvokeCommand.InvokeScript($"Get-Variable -Name '{variableName}' -ErrorAction SilentlyContinue").Select(m => m.BaseObject).OfType().FirstOrDefault(); + if (variable != null && !variable.Options.HasFlag(ScopedItemOptions.Constant) && !variable.Options.HasFlag(ScopedItemOptions.ReadOnly)) + { + if (!callback.Variables.ContainsKey(variable.Name)) + callback.Variables.Add(variable.Name, SessionState.PSVariable.GetValue(variable.Name)); + } + } + } + catch (Exception ex) + { + WriteWarning(ex.Message); + } + + if (EvaluateUrlAsRegex) { callback.UrlRegEx = new Regex(Url); } callback.SessionId = SessionState.PSVariable.Get(Constants.SessionId)?.Value as string; + callback.Page = SessionState.PSVariable.Get(Constants.UDPage)?.Value as Page; if (callback.Schedule == null) { diff --git a/src/client/package-lock.json b/src/client/package-lock.json index cb1abd45..7168315b 100644 --- a/src/client/package-lock.json +++ b/src/client/package-lock.json @@ -1490,7 +1490,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -2561,7 +2561,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -3193,7 +3193,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -3700,7 +3700,7 @@ "dependencies": { "core-js": { "version": "1.2.7", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", + "resolved": "http://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=" } } @@ -3846,7 +3846,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -3962,7 +3962,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -4237,7 +4237,6 @@ "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4433,8 +4432,7 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -4577,8 +4575,7 @@ }, "yallist": { "version": "3.0.2", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -4719,7 +4716,7 @@ "dependencies": { "pify": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true } @@ -4941,7 +4938,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -6454,7 +6451,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -6873,7 +6870,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -7047,7 +7044,7 @@ "dependencies": { "async": { "version": "1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "resolved": "http://registry.npmjs.org/async/-/async-1.5.2.tgz", "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", "dev": true } @@ -8564,7 +8561,7 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "requires": { "lcid": "^1.0.0" @@ -9249,7 +9246,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -9295,7 +9292,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -9356,7 +9353,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -9569,7 +9566,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": {