This code imports necessary modules, defines constants, and creates a.NET function using edge-js
to call a function from a C# assembly. The testEdge
function is then exported as a module to be used elsewhere.
npm run import -- "test edge.js"
const path = require('path')
const edge = require('edge-js');
//const dotnet = require('node-api-dotnet');
const { safeurl } = importer.import("domain cache tools")
const BUILD_DIRECTORY = path.join(__dirname, '../.build')
async function testEdge() {
const codeCell = importer.interpret('rosetta euler csharp 005')
const Euler = await importer.import("rosetta euler csharp 005")
let libName = safeurl(codeCell.questions[0])
let dynamicLib = path.join(BUILD_DIRECTORY, libName + '.dll')
const RunEuler = edge.func({
assemblyFile: dynamicLib,
typeName: 'Rosetta.Euler',
methodName: 'RunEuler' // Must be a static method
});
console.log(await new Promise(resolve => RunEuler("", function(arg1, arg2) {
resolve(arg2)
})))
//Euler.Main()
}
module.exports = testEdge
// Import required modules
const path = require('path');
const edge = require('edge-js');
const { safeurl } = require('domain-cache-tools');
// Constants
const BUILD_DIRECTORY = path.join(__dirname, '../.build');
// Function to execute edge function and return result
async function executeEdgeFunction(edgeFunc,...args) {
return new Promise((resolve, reject) => {
edgeFunc(...args, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
}
// Function to test edge functionality
async function testEdge() {
// Interpret and import C# code
const codeCell = await importCode('rosetta euler csharp 005');
const { RunEuler } = await importModule('rosetta euler csharp 005');
// Get library name and dynamic library path
const libName = safeurl(codeCell.questions[0]);
const dynamicLib = path.join(BUILD_DIRECTORY, libName + '.dll');
// Get edge function
const edgeFunc = edge.func({
assemblyFile: dynamicLib,
typeName: 'Rosetta.Euler',
methodName: 'RunEuler', // Must be a static method
});
// Execute edge function and return result
const result = await executeEdgeFunction(edgeFunc, "", (arg1, arg2) => arg2);
console.log(result);
}
// Function to import C# code
async function importCode(codeName) {
// TODO: Implement code interpretation logic
// For now, just return an empty object
return {};
}
// Function to import C# module
async function importModule(moduleName) {
// TODO: Implement module import logic
// For now, just return an empty object
return {};
}
// Export testEdge function
module.exports = testEdge;
Requires and Imports
const path = require('path')
: Imports the Node.js path
module for working with file paths.const edge = require('edge-js');
: Imports the edge-js
module, which allows calling.NET code from Node.js.const { safeurl } = importer.import('domain cache tools')
: Imports the safeurl
function from the domain cache tools
module.Constants
const BUILD_DIRECTORY = path.join(__dirname, '../.build')
: Defines a constant BUILD_DIRECTORY
as the path to the .build
directory in the parent directory.Function
async function testEdge()
: Defines an asynchronous function testEdge
.Function Body
Code Interpretation and Import
const codeCell = importer.interpret('rosetta euler csharp 005')
: Interprets code from a string.const Euler = await importer.import('rosetta euler csharp 005')
: Imports a module from a string.let libName = safeurl(codeCell.questions[0])
: Extracts the library name from the code cell.let dynamicLib = path.join(BUILD_DIRECTORY, libName + '.dll')
: Builds the path to the dynamic library.Creating a.NET Function
const RunEuler = edge.func({...})
: Creates a.NET function using edge-js
.dynamicLib
), a type name (Rosetta.Euler
), and a method name (RunEuler
).Calling the Function
console.log(await new Promise(resolve => RunEuler("", function(arg1, arg2) {... })))
: Calls the created function and logs the result.Export
module.exports = testEdge
: Exports the testEdge
function as a module.