Skip to content

Commit 7cee35f

Browse files
Add files via upload
1 parent 9990c4e commit 7cee35f

4 files changed

Lines changed: 94 additions & 23 deletions

File tree

src/Contexts/InitContext.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// AzimuthConsole/Contexts/InitContext.cs
2-
using AzimuthConsole.Commands;
3-
4-
namespace AzimuthConsole.Contexts
5-
{
6-
public class InitContext : ICommandContext
7-
{
8-
private readonly Action<string> _log;
9-
10-
public string SourceId => "init";
11-
12-
public InitContext(Action<string> log)
13-
{
14-
_log = log;
15-
}
16-
17-
public Task SendResponseAsync(string cmdId, CommandResult result)
18-
{
19-
_log($"[init] {cmdId},{result}");
20-
return Task.CompletedTask;
21-
}
22-
}
23-
}
1+
// AzimuthConsole/Contexts/InitContext.cs
2+
using AzimuthConsole.Commands;
3+
4+
namespace AzimuthConsole.Contexts
5+
{
6+
public class InitContext : ICommandContext
7+
{
8+
private readonly Action<string> _log;
9+
10+
public string SourceId => "init";
11+
12+
public InitContext(Action<string> log)
13+
{
14+
_log = log;
15+
}
16+
17+
public Task SendResponseAsync(string cmdId, CommandResult result)
18+
{
19+
_log($"[init] {cmdId},{result}");
20+
return Task.CompletedTask;
21+
}
22+
}
23+
}

src/Contexts/TerminalContext.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// AzimuthConsole/Contexts/TerminalContext.cs
2+
using AzimuthConsole.Commands;
3+
4+
namespace AzimuthConsole.Contexts
5+
{
6+
public class TerminalContext : ICommandContext
7+
{
8+
public string SourceId => "terminal";
9+
10+
public Task SendResponseAsync(string cmdId, CommandResult result)
11+
{
12+
Console.WriteLine($"{cmdId},{result}");
13+
return Task.CompletedTask;
14+
}
15+
}
16+
}

src/Contexts/UdpRctrlContext.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// AzimuthConsole/Contexts/UdpRctrlContext.cs
2+
using System.Net;
3+
using System.Net.Sockets;
4+
using System.Text;
5+
using AzimuthConsole.Commands;
6+
7+
namespace AzimuthConsole.Contexts
8+
{
9+
public class UdpRctrlContext : ICommandContext
10+
{
11+
private readonly UdpClient _udp;
12+
private readonly IPEndPoint _remote;
13+
14+
public string SourceId => "rctrl";
15+
16+
public UdpRctrlContext(UdpClient udp, IPEndPoint remote)
17+
{
18+
_udp = udp;
19+
_remote = remote;
20+
}
21+
22+
public async Task SendResponseAsync(string cmdId, CommandResult result)
23+
{
24+
var line = $"{cmdId},{result}";
25+
var data = Encoding.ASCII.GetBytes(line);
26+
await _udp.SendAsync(data, data.Length, _remote);
27+
}
28+
}
29+
}

src/Contexts/WebContext.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// AzimuthConsole/Contexts/WebContext.cs
2+
using System.Net.WebSockets;
3+
using System.Text;
4+
using AzimuthConsole.Commands;
5+
6+
namespace AzimuthConsole.Contexts
7+
{
8+
public class WebContext : ICommandContext
9+
{
10+
private readonly WebSocket _socket;
11+
12+
public string SourceId => "web";
13+
14+
public WebContext(WebSocket socket)
15+
{
16+
_socket = socket;
17+
}
18+
19+
public async Task SendResponseAsync(string cmdId, CommandResult result)
20+
{
21+
var line = $"{cmdId},{result}";
22+
var data = Encoding.UTF8.GetBytes(line);
23+
await _socket.SendAsync(data, WebSocketMessageType.Text, true, CancellationToken.None);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)