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

Pass variables to webschema's "script" #16

Open
beatcracker opened this issue Nov 1, 2015 · 3 comments
Open

Pass variables to webschema's "script" #16

beatcracker opened this issue Nov 1, 2015 · 3 comments

Comments

@beatcracker
Copy link
Contributor

We need some way to pass variables/objects to webschema's script.

Ideally, script should be passed and executed as an actual PowerShell scriptblock, with it's SessionState and so on. This way we could capture required variables with GetNewClosure or pass them to scriptblock as arguments.

Right now, if I understand it correctly, scriptblocks are used as text to build function that executed in nancy via PowerShell host:

string command = @"function RouteBody {{ param($Parameters, $Request) {0} }}";
@beatcracker beatcracker changed the title Pass variables to webschema's script Pass variables to webschema's "script" Nov 1, 2015
@toenuff
Copy link
Owner

toenuff commented Nov 1, 2015

I'd love to be able to do this. I'm not sure I can though - I will be actively pursuing a solution over this week while I'm at the MVP summit in Redmond.

@beatcracker
Copy link
Contributor Author

I'm not sure that we can pass an actual PS scriptblock, but as viable workaround we can create a new InitialSessionState, create Runspace using it, assign this Runspace to a PowerShell object, and then import current variables/modules into it. Unfortunately, while it's all can be done in PowerShell, I have no idea how to pass resulting Runspace to the Flancy. Probably C# code has to be extended with some method/property that would accept Runspace object.

References:

@beatcracker
Copy link
Contributor Author

More thoughts on a subject:

  • If we could pass a runspace to a Nancy's PS host, we could ditch string command = @"function RouteBody {{ param($Parameters, $Request) {0} }}"; line entirely and instead add this function to a Runspace beforehand in PS part of module.
  • If this Runspace object could be passed as some kind of "shared" object (by reference?), we could modify it on the fly and script could be reloaded (but not routes, though) without restarting PowerShell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants