forked from agracio/edge-js-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-fn.js
83 lines (66 loc) · 2.56 KB
/
main-fn.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
const path = require('path');
exports.runNetLibrary = () => {
var version = 'core';
var namespace = 'QuickStart.' + version.charAt(0).toUpperCase() + version.substr(1);
if (version === 'core') version = 'coreapp';
const baseNetAppPath = path.join(__dirname, '/src/' + namespace + '/bin/Debug/net' + version + '2.0');
//to solve error: CoreClrEmbedding::Initialize - Could not resolve CoreCLR path. edge.initializeClrFunc is not a function
//should match directory name in C:\Program Files\dotnet\shared\Microsoft.NETCore.App\
//it works for sure with major versions from 2 to 5, but not for 6
process.env.CORECLR_VERSION = '5.0.17';
process.env.EDGE_USE_CORECLR = 1;
if (version !== 'standard')
process.env.EDGE_APP_ROOT = baseNetAppPath;
var edge = require('edge-js');
var baseDll = path.join(baseNetAppPath, namespace + '.dll');
var localTypeName = namespace + '.LocalMethods';
var externalTypeName = namespace + '.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 getPerson = edge.func({
assemblyFile: baseDll,
typeName: externalTypeName,
methodName: 'GetPersonInfo'
});
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('Node.Js', function (error, result) {
if (error) throw error;
console.log(localTypeName + '.UseDynamicInput');
console.log(result);
console.log();
});
console.log();
console.log('### Calling external library methods using ' + namespace + '.dll wrapper');
console.log();
getPerson('', function (error, result) {
if (error) throw error;
console.log(externalTypeName + '.GetPersonInfo');
console.log(result);
});
}