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 =
40 BadNetworkConsoleClient client = new BadNetworkConsoleClient(settings.Host, settings.Port, parser);
41 client.Start();
42
43 return Task.FromResult(0);
44 }
45
46#region Nested type: BadScriptCommandParser
47
52 {
57
61 private readonly BadRuntime m_Runtime;
62
67
74 {
75 m_Runtime = runtime;
76 m_Client = client;
77 }
78
79#region IBadNetworkConsoleClientCommandParser Members
80
82 public void ExecuteCommand(string command)
83 {
84 try
85 {
87 IEnumerable<BadExpression> parsed = BadRuntime.Parse(command);
88
89 foreach (BadObject _ in ctx.Execute(parsed))
90 {
91 //Do nothing
92 }
93 }
94 catch (Exception e)
95 {
96 BadConsole.WriteLine(e.ToString());
97 }
98 }
99
100#endregion
101
107 {
108 return m_Context ??= CreateContext();
109 }
110
116 {
118 BadExecutionContext ctx = new BadExecutionContext(context.Scope.CreateChild("ClientCommands", null, null));
119 BadTable table = ctx.Scope.GetTable();
120 table.SetFunction("disconnect", m_Client.Stop);
121 table.SetFunction("exit", m_Client.Stop);
122 table.SetFunction("clear", BadConsole.Clear);
123 table.SetFunction("list", () => BadConsole.WriteLine(table.ToSafeString()));
124 table.SetFunction("reset", () => { m_Context = CreateContext(); });
125
126 return ctx;
127 }
128 }
129
130#endregion
131}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:30
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:78
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:597
BadTable GetTable()
Returns the Variable Table of the current scope.
Definition BadScope.cs:583
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:262
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.