11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Reflection ;
45using Jering . Javascript . NodeJS ;
56using Newtonsoft . Json ;
@@ -22,27 +23,27 @@ private NodeJsEngine(INodeJSService nodeJSService)
2223 private string WrapAsModule ( string code ) => $@ "
2324let wrappedCode = () => vm.runInThisContext({ JsonConvert . SerializeObject ( code , _settings ) } );
2425
25- module.exports = function(callback, message ) {{
26- callback(null, wrappedCode());
26+ module.exports = function(callback, ...args ) {{
27+ callback(null, wrappedCode(args ));
2728}}" ;
2829
2930 public static INodeJsEngine CreateEngine ( INodeJSService nodeJSService )
3031 {
3132 return new NodeJsEngine ( nodeJSService ) ;
3233 }
3334
34- public string Name => throw new NotImplementedException ( ) ;
35+ public string Name => nameof ( NodeJsEngine ) ;
3536
36- public string Version => throw new NotImplementedException ( ) ;
37+ public string Version => "0.0.1" ;
3738
3839 public T CallFunctionReturningJson < T > ( string function , object [ ] args )
3940 {
40- throw new NotImplementedException ( ) ;
41+ return _nodeJSService . InvokeFromStringAsync < T > ( WrapAsModule ( function ) , args : args ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
4142 }
4243
4344 public void Dispose ( )
4445 {
45- throw new NotImplementedException ( ) ;
46+ _nodeJSService . Dispose ( ) ;
4647 }
4748
4849 public T Evaluate < T > ( string code )
@@ -67,7 +68,13 @@ public void ExecuteFile(IFileSystem fileSystem, string path)
6768
6869 public void ExecuteResource ( string resourceName , Assembly assembly )
6970 {
70- throw new NotImplementedException ( ) ;
71+ string result ;
72+ using ( Stream stream = assembly . GetManifestResourceStream ( resourceName ) )
73+ using ( StreamReader reader = new StreamReader ( stream ) )
74+ {
75+ result = reader . ReadToEnd ( ) ;
76+ }
77+ Execute ( result ) ;
7178 }
7279
7380 public bool HasVariable ( string key )
0 commit comments