Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added calling Excel and passing payloads #50

Closed
wants to merge 1 commit into from

3 participants

@dfinke

No description provided.

@tjanczuk tjanczuk commented on the diff
README.md
((42 lines not shown))
+ "StDev": 29.011491975882016,
+ "Var": 841.66666666666663
+}
+```
+
+## How to: marshal data between PowerShell and node.js
+
+Edge.js can marshal any JSON-serializable value between .NET and node.js. Edge also supports marshaling between node.js `Buffer` instance and a .NET `byte[]` array to help you efficiently pass binary data.
+
+You can call .NET from node.js and pass in a complex JavaScript object as follows:
+
+```javascript
+var edge = require('edge');
+
+var powershellFunction = edge.func('ps', function () {/*
+@"
@tjanczuk Owner
tjanczuk added a note

Why does this need to be enclosed in quotes?

@dfinke
dfinke added a note

@" "@ is a PowerShell here-string. I'm using it to print text and execute the subexpression $().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tjanczuk tjanczuk commented on the diff
README.md
((81 lines not shown))
+ console.log(result[0]);
+});
+```
+
+```
+anInteger=1
+aNumber=3.1415
+aString=foo
+aBoolean=True
+aBuffer=0 0 0 0 0 0 0 0 0 0
+anArray=1 foo
+anObject.a=foo
+anObject.b=12
+```
+
+You can go from PowerShell to node.js. Here we advantage of PowerShell evaluating commands.
@tjanczuk Owner
tjanczuk added a note

we advantage -> we take advantage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tjanczuk tjanczuk commented on the diff
README.md
((32 lines not shown))
+
+ if(error) throw error;
+
+ console.log(result[0]);
+});
+```
+
+```
+{
+ "Median": 50.5,
+ "StDev": 29.011491975882016,
+ "Var": 841.66666666666663
+}
+```
+
+## How to: marshal data between PowerShell and node.js
@tjanczuk Owner
tjanczuk added a note

I wonder if it would make sense to keep that level of detail on the README.md of edge-ps and just link it from here. That way you will have the documentation close to code in case you rev the module.

+1, this is all super cool, but how much is the rest of the content in the README being diluted by adding a huge PS + Excel section? Maybe this belongs in a docs folder instead?

@tjanczuk Owner
tjanczuk added a note

I was hoping to highlight attractive use cases of PS in the context of edge.js, similarly to the few ideas at http://tjanczuk.github.io/edge/#/26. Perhaps the Excel code/sample could be moved out to wiki or some such and just linked from here?

@dfinke
dfinke added a note

Agreed. I need think through how to word it so I can talk about the cool aspect without an example that demos it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tjanczuk
Owner

As discussed this is a Wiki material as opposed to README.

@tjanczuk tjanczuk closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 5, 2013
  1. @dfinke
This page is out of date. Refresh to see the latest.
Showing with 142 additions and 0 deletions.
  1. +142 −0 README.md
View
142 README.md
@@ -629,7 +629,149 @@ helloPython('Node.js', function(error, result){
});
});
```
+## How to: interact with Excel from PowerShell in node.js
+PowerShell makes it really easy to work with a live instance of Microsoft Excel. Plus, Excel is more then just worksheets.
+This example calls three Excel Worksheet functions, in Excel 2010 there 348. From JavaScript, an array having 100 items numbered 1 to 100, is pass to the PowerShell script, Excel is launched and the worksheet functions *Median*, *StDev* and *Var* invoked. These results are returned and Excel is terminated.
+```javascript
+var edge = require('edge');
+
+var excelPS = edge.func('ps', function () {/*
+
+ $data = $inputFromJS | Invoke-Expression
+
+ $xl = New-Object -ComObject Excel.Application
+ $wf = $xl.WorksheetFunction
+
+ New-Object PSObject -Property @{
+ Median = $wf.Median($data)
+ StDev = $wf.StDev($data)
+ Var = $wf.Var($data)
+ } | ConvertTo-Json
+
+ $xlProcess = Get-Process excel
+ $xlProcess.kill()
+*/});
+
+// Invoke PowerShell, it start Excel, gets a WorksheetFunction and then calls
+// Medianm StDev and Var on the array of data passed in.
+// Here we are passing an array of 1 to 100
+excelPS('1..100', function(error, result){
+
+ if(error) throw error;
+
+ console.log(result[0]);
+});
+```
+
+```
+{
+ "Median": 50.5,
+ "StDev": 29.011491975882016,
+ "Var": 841.66666666666663
+}
+```
+
+## How to: marshal data between PowerShell and node.js
@tjanczuk Owner
tjanczuk added a note

I wonder if it would make sense to keep that level of detail on the README.md of edge-ps and just link it from here. That way you will have the documentation close to code in case you rev the module.

+1, this is all super cool, but how much is the rest of the content in the README being diluted by adding a huge PS + Excel section? Maybe this belongs in a docs folder instead?

@tjanczuk Owner
tjanczuk added a note

I was hoping to highlight attractive use cases of PS in the context of edge.js, similarly to the few ideas at http://tjanczuk.github.io/edge/#/26. Perhaps the Excel code/sample could be moved out to wiki or some such and just linked from here?

@dfinke
dfinke added a note

Agreed. I need think through how to word it so I can talk about the cool aspect without an example that demos it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+Edge.js can marshal any JSON-serializable value between .NET and node.js. Edge also supports marshaling between node.js `Buffer` instance and a .NET `byte[]` array to help you efficiently pass binary data.
+
+You can call .NET from node.js and pass in a complex JavaScript object as follows:
+
+```javascript
+var edge = require('edge');
+
+var powershellFunction = edge.func('ps', function () {/*
+@"
@tjanczuk Owner
tjanczuk added a note

Why does this need to be enclosed in quotes?

@dfinke
dfinke added a note

@" "@ is a PowerShell here-string. I'm using it to print text and execute the subexpression $().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+anInteger=$($inputFromJS.anInteger)
+aNumber=$($inputFromJS.aNumber)
+aString=$($inputFromJS.aString)
+aBoolean=$($inputFromJS.aBoolean)
+aBuffer=$($inputFromJS.aBuffer)
+anArray=$($inputFromJS.anArray)
+anObject.a=$($inputFromJS.anObject.a)
+anObject.b=$($inputFromJS.anObject.b)
+"@
+*/});
+
+var payload = {
+ anInteger: 1,
+ aNumber: 3.1415,
+ aString: 'foo',
+ aBoolean: true,
+ aBuffer: new Buffer(10),
+ anArray: [ 1, 'foo' ],
+ anObject: { a: 'foo', b: 12 }
+};
+
+powershellFunction(payload, function(error, result){
+ if(error) throw error;
+ console.log(result[0]);
+});
+```
+
+```
+anInteger=1
+aNumber=3.1415
+aString=foo
+aBoolean=True
+aBuffer=0 0 0 0 0 0 0 0 0 0
+anArray=1 foo
+anObject.a=foo
+anObject.b=12
+```
+
+You can go from PowerShell to node.js. Here we advantage of PowerShell evaluating commands.
@tjanczuk Owner
tjanczuk added a note

we advantage -> we take advantage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+```javascript
+var edge = require('edge');
+
+var getPSData = edge.func('ps', function () {/*
+[PSCustomObject] @{
+ anInterger=1
+ aNumber=3.1415
+ aString ='foo'
+ aBoolean = $true
+ anArray = 1, 'foo'
+ aHashtable = @{ a='foo'; b=12 }
+ anObject = [PSCustomObject]@{ c='bar'; GetChildItem=(ls *.js).name }
+ aCalculation = 1+1
+ aBuffer = New-Object byte[] 20
+} | ConvertTo-Json
+*/});
+
+getPSData('', function(error, result){
+ if(error) throw error;
+ console.log(result[0]);
+});
+```
+
+```
+PS C:\> node marshalFromPS
+{
+ "anInterger": 1,
+ "aNumber": 3.1415,
+ "aString": "foo",
+ "aBoolean": true,
+ "anArray": [
+ 1,
+ "foo"
+ ],
+ "aHashtable": {
+ "a": "foo",
+ "b": 12
+ },
+ "anObject": {
+ "c": "bar",
+ "GetChildItem": [ "marshalFromPS.js", "server.js" ]
+ },
+ "aCalculation": 2,
+ "aBuffer": {
+ "value": [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ],
+ "Count": 20
+ }
+}
+```
## How to: support for other CLR languages
Something went wrong with that request. Please try again.