BadScript 2
Loading...
Searching...
No Matches
BadRemoteConsoleSystem.cs
Go to the documentation of this file.
3using BadScript2.IO;
8
10
14public class BadRemoteConsoleSystem : BadConsoleSystem<BadRemoteConsoleSystemSettings>
15{
20 public BadRemoteConsoleSystem(BadRuntime runtime) : base(runtime) { }
21
23 public override string Name => "remote";
24
34
36 protected override Task<int> Run(BadRemoteConsoleSystemSettings settings)
37 {
38 Func<BadNetworkConsoleClient, IBadNetworkConsoleClientCommandParser> parser = settings.UseScriptCommands ? CreateScriptParser : BadNetworkConsoleClient.DefaultParserFactory;
39 BadNetworkConsoleClient client = new BadNetworkConsoleClient(settings.Host, settings.Port, parser);
40 client.Start();
41
42 return Task.FromResult(0);
43 }
44
49 {
54
58 private readonly BadRuntime m_Runtime;
59
64
71 {
72 m_Runtime = runtime;
73 m_Client = client;
74 }
75
76
78 public void ExecuteCommand(string command)
79 {
80 try
81 {
83 IEnumerable<BadExpression> parsed = BadRuntime.Parse(command);
84 foreach (BadObject _ in ctx.Execute(parsed))
85 {
86 //Do nothing
87 }
88 }
89 catch (Exception e)
90 {
91 BadConsole.WriteLine(e.ToString());
92 }
93 }
94
100 {
101 return m_Context ??= CreateContext();
102 }
103
109 {
111 BadExecutionContext ctx = new BadExecutionContext(context.Scope.CreateChild("ClientCommands", null, null));
112 BadTable table = ctx.Scope.GetTable();
113 table.SetFunction("disconnect", m_Client.Stop);
114 table.SetFunction("exit", m_Client.Stop);
115 table.SetFunction("clear", BadConsole.Clear);
116 table.SetFunction("list", () => BadConsole.WriteLine(table.ToSafeString()));
117 table.SetFunction("reset", () => { m_Context = CreateContext(); });
118
119 return ctx;
120 }
121 }
122}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
BadExecutionContext CreateContext(string workingDirectory)
Creates a new Context with the configured Options.
static IEnumerable< BadExpression > Parse(string source)
Parses the specified source.
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static void Clear()
Clears the console.
static void WriteLine(string str)
Writes a string to the console and appends a newline.
Definition BadConsole.cs:76
static IBadNetworkConsoleClientCommandParser DefaultParserFactory(BadNetworkConsoleClient client)
The Default Parser Factory.
Implements a Console System that uses a settings object of Type T.
BadScriptCommandParser(BadRuntime runtime, BadNetworkConsoleClient client)
Creates a new ScriptCommandParser instance.
IBadNetworkConsoleClientCommandParser CreateScriptParser(BadNetworkConsoleClient client)
Creates a new Script Command Parser.
override Task< int > Run(BadRemoteConsoleSystemSettings settings)
BadRemoteConsoleSystem(BadRuntime runtime)
Creates a new BadRemoteConsoleSystem instance.
Public interface for the filesystem abstraction of the BadScript Engine.
static IFileSystem Instance
File System implementation.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
Definition BadScope.cs:792
BadTable GetTable()
Returns the Variable Table of the current scope.
Definition BadScope.cs:778
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
override string ToSafeString(List< BadObject > done)
Definition BadTable.cs:240
string GetCurrentDirectory()
Returns the Current Directory.
Contains the Console Client Implementation for the Remote Console Abstraction over TCP.
Contains a Console Abstraction Layer to be able to Simulate Console Input/Output over the Network.
Definition BadConsole.cs:6
Contains the 'run' console command implementation.
Contains IO Implementation for the BadScript2 Runtime.
Contains the Expressions for the BadScript2 Language.
Contains the Extension Classes for Functions.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.