-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDPack.cs
More file actions
56 lines (47 loc) · 1.43 KB
/
DPack.cs
File metadata and controls
56 lines (47 loc) · 1.43 KB
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
using Jering.Javascript.NodeJS;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using System.Threading.Tasks;
namespace DPack.NET
{
public class DPack
{
private ServiceCollection _servicesCollection;
private ServiceProvider _serviceProvider;
private string _DPackJs;
public DPack()
{
_servicesCollection = new ServiceCollection();
_servicesCollection.AddNodeJS();
_serviceProvider = _servicesCollection.BuildServiceProvider();
_DPackJs = File.ReadAllText(@"..\node_modules\dpack\dist\index.js");
}
public async Task<string> Serialize(string input)
{
string output;
try
{
output = await StaticNodeJSService.InvokeFromStringAsync<string>(_DPackJs, "serialize", args: new object[] { input });
}
catch (Exception ex)
{
output = ex.Message;
}
return output;
}
public async Task<string> Parse(string input)
{
string output;
try
{
output = await StaticNodeJSService.InvokeFromStringAsync<string>(_DPackJs, "parse", args: new object[] { input });
}
catch (Exception ex)
{
output = ex.Message;
}
return output;
}
}
}