Skip to content

Commit

Permalink
refactor: fix nrt/warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Jan 27, 2023
1 parent c115ad0 commit 9405dbf
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
Expand Up @@ -5,5 +5,5 @@ namespace Tbc.Core.Socket.Abstractions;

public interface IRemoteEndpoint
{
public Task<TResponse> SendRequest<TRequest, TResponse>(TRequest request, CancellationToken canceller = default);
public Task<TResponse?> SendRequest<TRequest, TResponse>(TRequest request, CancellationToken canceller = default);
}
4 changes: 2 additions & 2 deletions src/components/tbc.core/Socket/SocketServer.cs
Expand Up @@ -149,7 +149,7 @@ private async Task<ReceiveResult> ReceiveAndHandle(CancellationToken ct = defaul
}
}

public async Task<TResponse> SendRequest<TRequest, TResponse>(TRequest request, CancellationToken ct = default)
public async Task<TResponse?> SendRequest<TRequest, TResponse>(TRequest request, CancellationToken ct = default)
{
if (request == null) throw new ArgumentNullException(nameof(request));

Expand All @@ -158,7 +158,7 @@ private async Task<ReceiveResult> ReceiveAndHandle(CancellationToken ct = defaul
_log("ignoring attempt to send message on finished socket server, please find the caller " +
"who did this and prevent them from doing this >:)");

return default!;
return default;
}

var responseMessageId =
Expand Down
Expand Up @@ -93,6 +93,9 @@ private async Task TryLoadLoadContext()
var ctx = JsonConvert.DeserializeObject<PersistedContext>(
await File.ReadAllTextAsync($"{_loadContext}.json"));

if (ctx is null)
return;

foreach (var file in ctx.WatchedFiles.Select(x => new ChangedFile { Path = x, Contents = File.ReadAllText(x) }))
IncrementalCompiler.StageFile(file, silent: true);

Expand Down Expand Up @@ -122,6 +125,8 @@ public async Task SetupReferenceTracking()

var tempFilePath = FileSystem.Path.GetTempFileName();
var targetHello = await Client.Hello(new HostHello { SharedHostFilePath = tempFilePath });
if (targetHello is null)
throw new Exception("Remote disconnected");

var sharedFilesystem = targetHello.CanAccessSharedHostFile;
var existingReferences = new List<AssemblyReference>();
Expand Down Expand Up @@ -344,7 +349,7 @@ private async Task AddSharedFilesystemReference(TargetHello targetHello, List<As
var reference = new AssemblyReference
{
AssemblyLocation = f,
ModificationTime = FileSystem.FileInfo.FromFileName(f).LastWriteTime,
ModificationTime = FileSystem.FileInfo.New(f).LastWriteTime,
PeBytes = await FileSystem.File.ReadAllBytesAsync(f)
};

Expand Down
Expand Up @@ -76,7 +76,7 @@ source.Kind switch

var (search, mask) = GetFilePathAndMask(path);
var matches = _fileSystem.Directory.GetFiles(search, mask, SearchOption.AllDirectories)
.OrderByDescending(x => _fileSystem.FileInfo.FromFileName(x).LastWriteTime)
.OrderByDescending(x => _fileSystem.FileInfo.New(x).LastWriteTime)
.ToList();

var usings = matches
Expand Down
Expand Up @@ -244,13 +244,13 @@ public void WriteEmittedAssembly(EmittedAssembly emittedAssembly)
{
Logger.LogInformation("Writing emitted assembly {@Assembly}", emittedAssembly);

var peOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath, $"{emittedAssembly.AssemblyName}.dll");
var pdOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath, $"{emittedAssembly.AssemblyName}.pdb");
var peOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath!, $"{emittedAssembly.AssemblyName}.dll");
var pdOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath!, $"{emittedAssembly.AssemblyName}.pdb");

_fileSystem.File.WriteAllBytes(peOut, emittedAssembly.Pe);

if (_options.EmitDebugInformation)
_fileSystem.File.WriteAllBytes(pdOut, emittedAssembly.Pd);
if (_options.EmitDebugInformation && emittedAssembly.Pd is {} pdb)
_fileSystem.File.WriteAllBytes(pdOut, pdb);
}

public void AddMetadataReference(AssemblyReference asm)
Expand Down
Expand Up @@ -14,7 +14,7 @@ public interface ITargetClient : IDisposable
Task WaitForTerminalState();
IObservable<CanonicalChannelState> ClientChannelState { get; }

Task<TargetHello> Hello(HostHello hello);
Task<TargetHello?> Hello(HostHello hello);
Task<IAsyncEnumerable<AssemblyReference>> AssemblyReferences(List<AssemblyReference> existing);
Task<IAsyncEnumerable<ExecuteCommandRequest>> CommandRequests();
Task<Outcome> RequestClientExecAsync(ExecuteCommandRequest req);
Expand Down
Expand Up @@ -83,8 +83,8 @@ public async Task WaitForConnection()
}
}

public Task<TargetHello> Hello(HostHello hello) =>
Target!.SendRequest<HostHello, TargetHello>(hello);
public Task<TargetHello?> Hello(HostHello hello)
=> Target!.SendRequest<HostHello, TargetHello>(hello);

public Task<IAsyncEnumerable<AssemblyReference>> AssemblyReferences(List<AssemblyReference> assemblyReferences)
{
Expand All @@ -99,15 +99,18 @@ public Task<IAsyncEnumerable<AssemblyReference>> AssemblyReferences(List<Assembl
public Task<IAsyncEnumerable<ExecuteCommandRequest>> CommandRequests()
=> Task.FromResult(_incomingCommandRequests.ToAsyncEnumerable());

public Task<Outcome> RequestClientExecAsync(ExecuteCommandRequest req)
=> Target!.SendRequest<ExecuteCommandRequest, Outcome>(req);
public async Task<Outcome> RequestClientExecAsync(ExecuteCommandRequest req)
{
var result = await Target!.SendRequest<ExecuteCommandRequest, Outcome>(req);
return result ?? new Outcome { Success = false, Messages = new() { new() { Message = "Socket disconnected" } } };
}

public async Task<Outcome> RequestClientLoadAssemblyAsync(LoadDynamicAssemblyRequest req)
{
var sw = Stopwatch.StartNew();
var result = await Target!.SendRequest<LoadDynamicAssemblyRequest, Outcome>(req);
Logger.LogInformation("Round trip for LoadAssembly with primary type {PrimaryTypeName}, {Duration}ms", req.PrimaryTypeName, sw.ElapsedMilliseconds);
return result;
return result ?? new Outcome { Success = false, Messages = new() { new() { Message = "Socket disconnected" } } };
}

public Task WaitForTerminalState() =>
Expand Down

0 comments on commit 9405dbf

Please sign in to comment.