Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add abstraction over grpc-core request models and target cl…
…ient
- Loading branch information
Showing
21 changed files
with
384 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Tbc.Core.Models; | ||
|
||
public record ConnectRequest | ||
{ | ||
public HostInfo HostInfo { get; set; } | ||
} | ||
|
||
public record ConnectResponse | ||
{ | ||
public string AssemblyName { get; set; } | ||
} | ||
|
||
public record LoadDynamicAssemblyRequest | ||
{ | ||
public byte[] PeBytes { get; set; } | ||
public byte[] PdbBytes { get; set; } | ||
public string AssemblyName { get; set; } | ||
public string PrimaryTypeName { get; set; } | ||
} | ||
|
||
public record Outcome | ||
{ | ||
public bool Success { get; set; } | ||
public List<OutcomeMessage> Messages { get; set; } = new(); | ||
} | ||
|
||
public record OutcomeMessage | ||
{ | ||
public string Message { get; set; } | ||
} | ||
|
||
public record HostInfo | ||
{ | ||
public string Address { get; set; } | ||
public int Port { get; set; } | ||
} | ||
|
||
public record ExecuteCommandRequest | ||
{ | ||
public string Command { get; set; } | ||
public List<string> Args { get; set; } = new(); | ||
} | ||
|
||
public record CachedAssemblyState | ||
{ | ||
public List<CachedAssembly> CachedAssemblies { get; set; } = new(); | ||
} | ||
|
||
public record CachedAssembly | ||
{ | ||
public string AssemblyName { get; set; } = default!; | ||
public DateTimeOffset ModificationTime { get; set; } | ||
} | ||
|
||
public record AssemblyReference | ||
{ | ||
public string AssemblyName { get; set; } = default!; | ||
public string AssemblyLocation { get; set; } = default!; | ||
public DateTimeOffset ModificationTime { get; set; } = default!; | ||
public byte[] PeBytes { get; set; } = default!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ponents/FileEnvironment/Models/IClient.cs → ...ronment/Models/IRemoteClientDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Tbc.Host.Components.FileEnvironment.Models | ||
{ | ||
public interface IClient | ||
public interface IRemoteClientDefinition | ||
{ | ||
public string Address { get; set; } | ||
public int Port { get; set; } | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/components/tbc.host/Components/FileEnvironment/Models/RemoteClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/components/tbc.host/Components/TargetClient/CanonicalChannelState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public enum CanonicalChannelState | ||
{ | ||
/// <summary> | ||
/// Channel is idle | ||
/// </summary> | ||
Idle, | ||
|
||
/// <summary> | ||
/// Channel is connecting | ||
/// </summary> | ||
Connecting, | ||
|
||
/// <summary> | ||
/// Channel is ready for work | ||
/// </summary> | ||
Ready, | ||
|
||
/// <summary> | ||
/// Channel has seen a failure but expects to recover | ||
/// </summary> | ||
TransientFailure, | ||
|
||
/// <summary> | ||
/// Channel has seen a failure that it cannot recover from | ||
/// </summary> | ||
Shutdown | ||
} |
47 changes: 47 additions & 0 deletions
47
src/components/tbc.host/Components/TargetClient/GrpcCore/GrpcCoreMappingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Linq; | ||
using Google.Protobuf; | ||
using Tbc.Core.Models; | ||
using AssemblyReference = Tbc.Protocol.AssemblyReference; | ||
using ExecuteCommandRequest = Tbc.Protocol.ExecuteCommandRequest; | ||
using LoadDynamicAssemblyRequest = Tbc.Protocol.LoadDynamicAssemblyRequest; | ||
using Outcome = Tbc.Protocol.Outcome; | ||
|
||
namespace Tbc.Host.Components.TargetClient.GrpcCore; | ||
|
||
public static class GrpcCoreMappingExtensions | ||
{ | ||
public static Tbc.Core.Models.Outcome ToCanonical(this Outcome o) | ||
=> new() { | ||
Success = o.Success, | ||
Messages = o.Messages.Select(x => new OutcomeMessage { Message = x.Message_ }).ToList() | ||
}; | ||
|
||
public static Tbc.Core.Models.ExecuteCommandRequest ToCanonical(this ExecuteCommandRequest x) | ||
=> new() { Command = x.Command, Args = x.Args.ToList() }; | ||
|
||
public static Tbc.Core.Models.AssemblyReference ToCanonical(this AssemblyReference x) | ||
=> new() | ||
{ | ||
AssemblyName = x.AssemblyName, | ||
ModificationTime = DateTimeOffset.FromUnixTimeSeconds((long)x.ModificationTime), | ||
AssemblyLocation = x.AssemblyLocation, | ||
PeBytes = x.PeBytes.ToByteArray() | ||
}; | ||
|
||
public static LoadDynamicAssemblyRequest ToCore(this Tbc.Core.Models.LoadDynamicAssemblyRequest req) | ||
=> new() | ||
{ | ||
AssemblyName = req.AssemblyName, | ||
PeBytes = ByteString.CopyFrom(req.PeBytes), | ||
PdbBytes = ByteString.CopyFrom(req.PdbBytes), | ||
PrimaryTypeName = req.PrimaryTypeName | ||
}; | ||
|
||
public static ExecuteCommandRequest ToCore(this Tbc.Core.Models.ExecuteCommandRequest req) | ||
=> new() | ||
{ | ||
Command = req.Command, | ||
Args = { req.Args } | ||
}; | ||
} |
Oops, something went wrong.