1
+ using System ;
2
+ using System . IO ;
3
+ using System . Threading ;
4
+ using System . Threading . Tasks ;
5
+
6
+ using Jering . Javascript . NodeJS ;
7
+
8
+ namespace JavaScriptEngineSwitcher . Node
9
+ {
10
+ /// <summary>
11
+ /// Default Node JS service
12
+ /// </summary>
13
+ /// <remarks>
14
+ /// Wrapper around the <see cref="StaticNodeJSService"/> class.
15
+ /// </remarks>
16
+ public sealed class DefaultNodeJsService : INodeJSService
17
+ {
18
+ /// <summary>
19
+ /// Instance of default Node JS service
20
+ /// </summary>
21
+ private static readonly DefaultNodeJsService _instance = new DefaultNodeJsService ( ) ;
22
+
23
+ /// <summary>
24
+ /// Gets a instance of default Node JS service
25
+ /// </summary>
26
+ public static INodeJSService Instance
27
+ {
28
+ get { return _instance ; }
29
+ }
30
+
31
+
32
+ /// <summary>
33
+ /// Private constructor for implementation Singleton pattern
34
+ /// </summary>
35
+ private DefaultNodeJsService ( )
36
+ { }
37
+
38
+
39
+ #region INodeJSService implementation
40
+
41
+ public Task < T > InvokeFromFileAsync < T > ( string modulePath , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
42
+ {
43
+ return StaticNodeJSService . InvokeFromFileAsync < T > ( modulePath , exportName , args , cancellationToken ) ;
44
+ }
45
+
46
+ public Task InvokeFromFileAsync ( string modulePath , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
47
+ {
48
+ return StaticNodeJSService . InvokeFromFileAsync ( modulePath , exportName , args , cancellationToken ) ;
49
+ }
50
+
51
+ public Task < T > InvokeFromStringAsync < T > ( string moduleString , string newCacheIdentifier = null , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
52
+ {
53
+ return StaticNodeJSService . InvokeFromStringAsync < T > ( moduleString , newCacheIdentifier , exportName , args , cancellationToken ) ;
54
+ }
55
+
56
+ public Task InvokeFromStringAsync ( string moduleString , string newCacheIdentifier = null , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
57
+ {
58
+ return StaticNodeJSService . InvokeFromStringAsync ( moduleString , newCacheIdentifier , exportName , args , cancellationToken ) ;
59
+ }
60
+
61
+ public Task < T > InvokeFromStringAsync < T > ( Func < string > moduleFactory , string cacheIdentifier , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
62
+ {
63
+ return StaticNodeJSService . InvokeFromStringAsync < T > ( moduleFactory , cacheIdentifier , exportName , args , cancellationToken ) ;
64
+ }
65
+
66
+ public Task InvokeFromStringAsync ( Func < string > moduleFactory , string cacheIdentifier , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
67
+ {
68
+ return StaticNodeJSService . InvokeFromStringAsync ( moduleFactory , cacheIdentifier , exportName , args , cancellationToken ) ;
69
+ }
70
+
71
+ public Task < T > InvokeFromStreamAsync < T > ( Stream moduleStream , string newCacheIdentifier = null , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
72
+ {
73
+ return StaticNodeJSService . InvokeFromStreamAsync < T > ( moduleStream , newCacheIdentifier , exportName , args , cancellationToken ) ;
74
+ }
75
+
76
+ public Task InvokeFromStreamAsync ( Stream moduleStream , string newCacheIdentifier = null , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
77
+ {
78
+ return StaticNodeJSService . InvokeFromStreamAsync ( moduleStream , newCacheIdentifier , exportName , args , cancellationToken ) ;
79
+ }
80
+
81
+ public Task < T > InvokeFromStreamAsync < T > ( Func < Stream > moduleFactory , string cacheIdentifier , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
82
+ {
83
+ return StaticNodeJSService . InvokeFromStreamAsync < T > ( moduleFactory , cacheIdentifier , exportName , args , cancellationToken ) ;
84
+ }
85
+
86
+ public Task InvokeFromStreamAsync ( Func < Stream > moduleFactory , string cacheIdentifier , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
87
+ {
88
+ return StaticNodeJSService . InvokeFromStreamAsync ( moduleFactory , cacheIdentifier , exportName , args , cancellationToken ) ;
89
+ }
90
+
91
+ public Task < ( bool , T ) > TryInvokeFromCacheAsync < T > ( string moduleCacheIdentifier , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
92
+ {
93
+ return StaticNodeJSService . TryInvokeFromCacheAsync < T > ( moduleCacheIdentifier , exportName , args , cancellationToken ) ;
94
+ }
95
+
96
+ public Task < bool > TryInvokeFromCacheAsync ( string moduleCacheIdentifier , string exportName = null , object [ ] args = null , CancellationToken cancellationToken = default )
97
+ {
98
+ return StaticNodeJSService . TryInvokeFromCacheAsync ( moduleCacheIdentifier , exportName , args , cancellationToken ) ;
99
+ }
100
+
101
+ #region IDisposable implementation
102
+
103
+ public void Dispose ( )
104
+ {
105
+ throw new NotSupportedException ( ) ;
106
+ }
107
+
108
+ #endregion
109
+
110
+ #endregion
111
+ }
112
+ }
0 commit comments