Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryCordewener committed Nov 18, 2024
1 parent 884c147 commit ae2dcba
Show file tree
Hide file tree
Showing 25 changed files with 2,793 additions and 2,828 deletions.
14 changes: 7 additions & 7 deletions TelnetNegotiationCore.Functional/MSDPLibrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module MSDPLibrary =
| MSDP_ARRAY_CLOSE = 6uy

[<TailCall>]
let private MSDPScanTailRec (root: obj, array: seq<byte>, encoding: Encoding) =
let rec private MSDPScanTailRec (root: obj, array: byte seq, encoding: Encoding) =
let rec scan accRoot accArray =
if Seq.length accArray = 0 then (accRoot, accArray)
else
Expand All @@ -42,8 +42,8 @@ module MSDPLibrary =
(encoding.GetString(accArray |> Seq.takeWhile(fun x -> x > 6uy) |> Array.ofSeq), accArray |> Seq.skipWhile(fun x -> x > 6uy))
scan root array

let public MSDPScan(array: seq<byte>, encoding) =
let (result, _) = MSDPScanTailRec(Map<string,obj> [], array, encoding)
let public MSDPScan(array: byte seq, encoding) =
let result, _ = MSDPScanTailRec(Map<string,obj> [], array, encoding)
result

let parseJsonRoot (jsonRootNode: JsonNode, encoding: Encoding) =
Expand All @@ -55,16 +55,16 @@ module MSDPLibrary =
|> Seq.map (fun prop ->
let key = prop.Key
let value = parseJsonValue prop.Value
[(byte)Trigger.MSDP_VAR] @ (encoding.GetBytes(key) |> List.ofArray) @ [(byte)Trigger.MSDP_VAL] @ value
[byte Trigger.MSDP_VAR] @ (encoding.GetBytes(key) |> List.ofArray) @ [byte Trigger.MSDP_VAL] @ value
) |> List.concat
[(byte)Trigger.MSDP_TABLE_OPEN] @ parsedObj @ [(byte)Trigger.MSDP_TABLE_CLOSE]
[byte Trigger.MSDP_TABLE_OPEN] @ parsedObj @ [(byte)Trigger.MSDP_TABLE_CLOSE]
| JsonValueKind.Array ->
let parsedArr =
jsonNode.AsArray()
|> Seq.map (fun prop -> [(byte)Trigger.MSDP_VAL] @ parseJsonValue(prop))
|> Seq.map (fun prop -> [byte Trigger.MSDP_VAL] @ parseJsonValue(prop))
|> List.ofSeq
|> List.concat
[(byte)Trigger.MSDP_ARRAY_OPEN] @ parsedArr @ [(byte)Trigger.MSDP_ARRAY_CLOSE]
[byte Trigger.MSDP_ARRAY_OPEN] @ parsedArr @ [byte Trigger.MSDP_ARRAY_CLOSE]
| JsonValueKind.String -> encoding.GetBytes(jsonNode.AsValue().ToString()) |> List.ofArray
| JsonValueKind.Number -> encoding.GetBytes(jsonNode.AsValue().ToString()) |> List.ofArray
| JsonValueKind.True -> encoding.GetBytes("1") |> List.ofArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion TelnetNegotiationCore.UnitTests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TelnetNegotiationCore.UnitTests
{
public class BaseTest
{
static internal Microsoft.Extensions.Logging.ILogger logger;
internal static readonly Microsoft.Extensions.Logging.ILogger logger;

static BaseTest()
{
Expand Down
2 changes: 1 addition & 1 deletion TelnetNegotiationCore.UnitTests/CHARSETTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace TelnetNegotiationCore.UnitTests
{
[TestFixture]
public class CHARSETTests() : BaseTest
public class CharsetTests() : BaseTest
{
private byte[] _negotiationOutput;

Expand Down
107 changes: 53 additions & 54 deletions TelnetNegotiationCore.UnitTests/CreateDotGraph.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using NUnit.Framework;
using Stateless.Graph;
using System.Collections.Generic;
using System.IO;
Expand All @@ -8,62 +7,62 @@
using TelnetNegotiationCore.Interpreters;
using TelnetNegotiationCore.Models;

namespace TelnetNegotiationCore.UnitTests
namespace TelnetNegotiationCore.UnitTests;

[TestFixture(
Category = "Tool",
Description = "Creates the DotGraph files for Server and Client forms. Some of these are combined.")]
public class CreateDotGraph : BaseTest
{
[TestFixture(
Category = "Tool",
Description = "Creates the DotGraph files for Server and Client forms. Some of these are combined.")]
public class CreateDotGraph : BaseTest
{
[Test]
public async Task WriteClientDotGraph()
{
var telnet = await new TelnetInterpreter(TelnetInterpreter.TelnetMode.Client, logger)
{
CallbackOnSubmitAsync = WriteBack,
SignalOnGMCPAsync = WriteBackToGMCP,
CallbackNegotiationAsync = WriteToOutputStream,
SignalOnNAWSAsync = SignalNAWS,
CharsetOrder = new[] { Encoding.GetEncoding("utf-8"), Encoding.GetEncoding("iso-8859-1") }
}.BuildAsync();
[Test]
public async Task WriteClientDotGraph()
{
var telnet = await new TelnetInterpreter(TelnetInterpreter.TelnetMode.Client, logger)
{
CallbackOnSubmitAsync = WriteBack,
SignalOnGMCPAsync = WriteBackToGMCP,
CallbackNegotiationAsync = WriteToOutputStream,
SignalOnNAWSAsync = SignalNAWS,
CharsetOrder = [Encoding.GetEncoding("utf-8"), Encoding.GetEncoding("iso-8859-1")]
}.BuildAsync();

var dotGraph = UmlDotGraph.Format(telnet.TelnetStateMachine.GetInfo());
await File.WriteAllTextAsync(Path.Combine(Directory.GetCurrentDirectory(), "..", "ClientDotGraph.dot"), dotGraph);
}

var dotGraph = UmlDotGraph.Format(telnet.TelnetStateMachine.GetInfo());
File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "..", "ClientDotGraph.dot"), dotGraph);
}
[Test]
public async Task WriteServerDotGraph()
{
var telnet = await new TelnetInterpreter(TelnetInterpreter.TelnetMode.Server, logger)
{
CallbackOnSubmitAsync = WriteBack,
SignalOnGMCPAsync = WriteBackToGMCP,
CallbackNegotiationAsync = WriteToOutputStream,
SignalOnNAWSAsync = SignalNAWS,
CharsetOrder = [Encoding.GetEncoding("utf-8"), Encoding.GetEncoding("iso-8859-1")]
}
.RegisterMSSPConfig(() => new MSSPConfig
{
Name = "My Telnet Negotiated Server",
UTF_8 = true,
Gameplay = ["ABC", "DEF"],
Extended = new Dictionary<string, dynamic>
{
{ "Foo", "Bar" },
{ "Baz", (string[]) ["Moo", "Meow"] }
}
}).BuildAsync();

[Test]
public async Task WriteServerDotGraph()
{
var telnet = await new TelnetInterpreter(TelnetInterpreter.TelnetMode.Server, logger)
{
CallbackOnSubmitAsync = WriteBack,
SignalOnGMCPAsync = WriteBackToGMCP,
CallbackNegotiationAsync = WriteToOutputStream,
SignalOnNAWSAsync = SignalNAWS,
CharsetOrder = new[] { Encoding.GetEncoding("utf-8"), Encoding.GetEncoding("iso-8859-1") }
}
.RegisterMSSPConfig(() => new MSSPConfig
{
Name = "My Telnet Negotiated Server",
UTF_8 = true,
Gameplay = new[] { "ABC", "DEF" },
Extended = new Dictionary<string, dynamic>
{
{ "Foo", "Bar"},
{ "Baz", new [] {"Moo", "Meow" }}
}
}).BuildAsync();
var dotGraph = UmlDotGraph.Format(telnet.TelnetStateMachine.GetInfo());
await File.WriteAllTextAsync(Path.Combine(Directory.GetCurrentDirectory(), "..", "ServerDotGraph.dot"),
dotGraph);
}

var dotGraph = UmlDotGraph.Format(telnet.TelnetStateMachine.GetInfo());
File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "..", "ServerDotGraph.dot"), dotGraph);
}
private async Task WriteToOutputStream(byte[] arg) => await Task.CompletedTask;

private async Task WriteToOutputStream(byte[] arg) => await Task.CompletedTask;
private async Task SignalNAWS(int arg1, int arg2) => await Task.CompletedTask;

private async Task SignalNAWS(int arg1, int arg2) => await Task.CompletedTask;

private async Task WriteBack(byte[] arg1, Encoding encoding, TelnetInterpreter t) => await Task.CompletedTask;
private async Task WriteBack(byte[] arg1, Encoding encoding, TelnetInterpreter t) => await Task.CompletedTask;

private async Task WriteBackToGMCP((string module, string writeback) arg1) => await Task.CompletedTask;
}
}
private async Task WriteBackToGMCP((string module, string writeback) arg1) => await Task.CompletedTask;
}
Loading

0 comments on commit ae2dcba

Please sign in to comment.