-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.js
154 lines (129 loc) · 4.11 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const path = require('path');
var net = process.argv[2];
var framework = net.charAt(0).toUpperCase() + net.substr(1);
var namespace = 'QuickStart.' + framework;
if(net === 'core') net = '';
var version = net == 'standard' ? '2.0' : '8.0'
const baseNetAppPath = path.join(__dirname, '/src/'+ namespace +'/bin/Debug/net'+ net + version);
//const baseNetAppPath = path.join(__dirname, '/src/QuickStart.Core/bin/Release/net8.0/win-x64/publish');
process.env.EDGE_USE_CORECLR = 1;
if(net !== 'standard')
process.env.EDGE_APP_ROOT = baseNetAppPath;
var edge = require('edge-js');
var baseDll = path.join(baseNetAppPath, namespace + '.dll');
console.log('### Application base path: '+ baseNetAppPath);
console.log('### Application dll: '+ baseDll);
console.log();
console.log();
var localTypeName = 'QuickStart.LocalMethods';
var externalTypeName = 'QuickStart.ExternalMethods';
var getAppDomainDirectory = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: 'GetAppDomainDirectory'
});
var getCurrentTime = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: 'GetCurrentTime'
});
var useDynamicInput = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: 'UseDynamicInput'
});
var handleException = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: 'ThrowException'
});
var getPerson = edge.func({
assemblyFile: baseDll,
typeName: externalTypeName,
methodName: 'GetPersonInfo'
});
var listCertificates = edge.func({
assemblyFile: baseDll,
typeName: localTypeName,
methodName: 'ListCertificates'
});
var getInlinePerson = edge.func({
source: function () {/*
using System.Threading.Tasks;
using System;
public class Person
{
public Person(string name, string email, int age)
{
Id = Guid.NewGuid();
Name = name;
Email = email;
Age = age;
}
public Guid Id {get;}
public string Name {get;set;}
public string Email {get;set;}
public int Age {get;set;}
}
public class Startup
{
public async Task<object> Invoke(dynamic input)
{
return new Person(input.name, input.email, input.age);
}
}
*/}
});
console.log('### Calling inline c# code with multiple parameters')
console.log();
getInlinePerson({name: 'Peter Smith', email: 'peter.smith@edge-js-quick-start.com', age: 30}, function(error, result) {
if (error) throw error;
console.log(result);
console.log();
});
console.log();
console.log('### Calling local methods from ' + namespace +'.dll')
console.log();
getAppDomainDirectory('', function(error, result) {
if (error) throw error;
console.log(localTypeName + '.GetAppDomainDirectory');
console.log(result);
console.log();
});
getCurrentTime('', function(error, result) {
if (error) throw error;
console.log(localTypeName + '.GetCurrentTime');
console.log(result);
console.log();
});
useDynamicInput({framework: framework, node: 'Node.Js'}, function(error, result) {
if (error) throw error;
console.log(localTypeName + '.UseDynamicInput');
console.log(result);
console.log();
});
if(process.platform !== 'linux'){
listCertificates({ storeName: 'My', storeLocation: 'LocalMachine' }, function(error, result) {
if (error) throw error;
console.log(localTypeName + '.ListCertificates');
console.log(result);
console.log();
});
}
console.log();
console.log('### Handling exception');
console.log();
try{
handleException('', function(error, result) {
});
}catch(e){
console.log('.NET Exception: ' + e.Message);
}
console.log();
console.log('### Calling external library methods using '+ namespace +'.dll wrapper');
console.log();
getPerson({name: 'John Smith', email: 'john.smith@edge-js-quick-start.com', age: 35}, function(error, result) {
if (error) throw error;
console.log(externalTypeName + '.GetPersonInfo');
console.log(result);
});