forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptPackSession.cs
More file actions
77 lines (58 loc) · 2.06 KB
/
ScriptPackSession.cs
File metadata and controls
77 lines (58 loc) · 2.06 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections.Generic;
using System.Linq;
namespace ScriptCs.Contracts
{
public class ScriptPackSession : IScriptPackSession
{
private readonly IEnumerable<IScriptPack> _scriptPacks;
private readonly string[] _scriptArgs;
private readonly IEnumerable<IScriptPackContext> _contexts;
private readonly IDictionary<string, object> _state;
private readonly IList<string> _references;
private readonly IList<string> _namespaces;
public ScriptPackSession(IEnumerable<IScriptPack> scriptPacks, string[] scriptArgs)
{
_scriptPacks = scriptPacks;
_scriptArgs = scriptArgs;
_contexts = _scriptPacks.Select(s => s.GetContext()).Where(c => c != null);
_references = new List<string>();
_namespaces = new List<string>();
_state = new Dictionary<string, object>();
AddScriptContextNamespace();
}
private void AddScriptContextNamespace()
{
foreach (var context in _contexts)
{
_namespaces.Add(context.GetType().Namespace);
}
}
public virtual IEnumerable<IScriptPackContext> Contexts => _contexts;
public IEnumerable<string> References => _references;
public IEnumerable<string> Namespaces => _namespaces;
public void InitializePacks()
{
foreach (var s in _scriptPacks)
{
s.Initialize(this);
}
}
public void TerminatePacks()
{
foreach (var s in _scriptPacks)
{
s.Terminate();
}
}
public IDictionary<string, object> State => _state;
public string[] ScriptArgs => _scriptArgs;
void IScriptPackSession.AddReference(string assemblyDisplayNameOrPath)
{
_references.Add(assemblyDisplayNameOrPath);
}
void IScriptPackSession.ImportNamespace(string @namespace)
{
_namespaces.Add(@namespace);
}
}
}