mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Initial state
This commit is contained in:
38
Microsoft.AspNet.NodeServices/NodeInstance.cs
Normal file
38
Microsoft.AspNet.NodeServices/NodeInstance.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.NodeServices {
|
||||
public class NodeInstance : IDisposable {
|
||||
private readonly NodeHost _nodeHost;
|
||||
|
||||
public NodeInstance(NodeHostingModel hostingModel = NodeHostingModel.Http) {
|
||||
switch (hostingModel) {
|
||||
case NodeHostingModel.Http:
|
||||
this._nodeHost = new HttpNodeHost();
|
||||
break;
|
||||
case NodeHostingModel.InputOutputStream:
|
||||
this._nodeHost = new InputOutputStreamNodeHost();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unknown hosting model: " + hostingModel.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public Task<string> Invoke(string moduleName, params object[] args) {
|
||||
return this.InvokeExport(moduleName, null, args);
|
||||
}
|
||||
|
||||
public async Task<string> InvokeExport(string moduleName, string exportedFunctionName, params object[] args) {
|
||||
return await this._nodeHost.Invoke(new NodeInvocationInfo {
|
||||
ModuleName = moduleName,
|
||||
ExportedFunctionName = exportedFunctionName,
|
||||
Args = args
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this._nodeHost.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user