Skip to content

Commit

Permalink
Fix warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Apr 25, 2023
1 parent ce46988 commit f341631
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Nexus.Sources.Remote/DataSourceTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public RemoteException(string message, Exception? innerException = default)

internal class JsonElementConverter : Newtonsoft.Json.JsonConverter
{
internal static JsonSerializerOptions _serializerOptions = new JsonSerializerOptions()
internal static JsonSerializerOptions _serializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
Expand Down
2 changes: 1 addition & 1 deletion src/Nexus.Sources.Remote/PropertiesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class PropertiesExtensions

if (properties.TryGetValue(pathSegments[0], out var element))
{
pathSegments = pathSegments.Slice(1);
pathSegments = pathSegments[1..];

if (pathSegments.Length == 0)
{
Expand Down
16 changes: 9 additions & 7 deletions src/Nexus.Sources.Remote/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace Nexus.Sources
"Provides access to remote databases",
"https://github.com/malstroem-labs/nexus-sources-remote",
"https://github.com/malstroem-labs/nexus-sources-remote")]
public class Remote : IDataSource, IDisposable
public partial class Remote : IDataSource, IDisposable
{
#region Fields

private ReadDataHandler? _readData;
private static int API_LEVEL = 1;
private static readonly int API_LEVEL = 1;
private RemoteCommunicator _communicator = default!;
private IJsonRpcServer _rpcServer = default!;

Expand Down Expand Up @@ -91,8 +91,7 @@ public async Task SetContextAsync(
if (requestConfiguration.TryGetValue("environment-variables", out var propertyValue) &&
propertyValue.ValueKind == JsonValueKind.Object)
{
var environmentVariablesRaw = JsonSerializer
.Deserialize<Dictionary<string, JsonElement>>(propertyValue);
var environmentVariablesRaw = propertyValue .Deserialize<Dictionary<string, JsonElement>>();

if (environmentVariablesRaw is not null)
environmentVariables = environmentVariablesRaw
Expand All @@ -119,7 +118,7 @@ public async Task SetContextAsync(

var apiVersion = (await _rpcServer.GetApiVersionAsync(timeoutTokenSource.Token)).ApiVersion;

if (apiVersion < 1 || apiVersion > Remote.API_LEVEL)
if (apiVersion < 1 || apiVersion > API_LEVEL)
throw new Exception($"The API level '{apiVersion}' is not supported.");

logger.LogTrace("Set context to remote client");
Expand Down Expand Up @@ -233,7 +232,7 @@ private string BuildCommand(string templateId)
if (template is null)
throw new Exception($"The template {templateId} does not exist.");

var command = Regex.Replace(template, "{(.*?)}", match =>
var command = CommandRegex().Replace(template, match =>
{
var parameterKey = match.Groups[1].Value;
var parameterValue = Context.SourceConfiguration?.GetStringValue(parameterKey);
Expand Down Expand Up @@ -261,7 +260,7 @@ private async Task HandleReadDataAsync(string resourcePath, DateTime begin, Date
await _communicator.WriteRawAsync(byteData, timeoutTokenSource.Token);
}

private CancellationTokenSource GetTimeoutTokenSource(TimeSpan timeout)
private static CancellationTokenSource GetTimeoutTokenSource(TimeSpan timeout)
{
var timeoutToken = new CancellationTokenSource();
timeoutToken.CancelAfter(timeout);
Expand Down Expand Up @@ -294,6 +293,9 @@ public void Dispose()
GC.SuppressFinalize(this);
}

[GeneratedRegex("{(.*?)}")]
private static partial Regex CommandRegex();

#endregion
}
}
10 changes: 5 additions & 5 deletions src/Nexus.Sources.Remote/RemoteCommunicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public async Task<IJsonRpcServer> ConnectAsync(CancellationToken cancellationTok
_process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
_logger.LogDebug(e.Data);
_logger.LogDebug("{Message}", e.Data);
};

_process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
_logger.LogWarning(e.Data);
_logger.LogWarning("{Message}", e.Data);
};

_process.BeginOutputReadLine();
Expand Down Expand Up @@ -149,7 +149,7 @@ public async Task<IJsonRpcServer> ConnectAsync(CancellationToken cancellationTok

jsonRpc.AddLocalRpcMethod("log", new Action<LogLevel, string>((logLevel, message) =>
{
_logger.Log(logLevel, message);
_logger.Log(logLevel, "{Message}", message);
}));

jsonRpc.AddLocalRpcMethod("readData", _readData);
Expand All @@ -159,7 +159,7 @@ public async Task<IJsonRpcServer> ConnectAsync(CancellationToken cancellationTok
{
MethodNameTransform = pascalCaseAsyncName =>
{
return char.ToLower(pascalCaseAsyncName[0]) + pascalCaseAsyncName.Substring(1).Replace("Async", string.Empty);
return char.ToLower(pascalCaseAsyncName[0]) + pascalCaseAsyncName[1..].Replace("Async", string.Empty);
}
});

Expand Down Expand Up @@ -198,7 +198,7 @@ private static async Task InternalReadRawAsync(Memory<byte> buffer, Stream sourc
if (readCount == 0)
throw new Exception("The TCP connection closed early.");

buffer = buffer.Slice(readCount);
buffer = buffer[readCount..];
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Nexus.Sources.Remote.Tests/RemoteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void GenerateData(DateTimeOffset dateTime)
.ToArray();

var offset = (int)(dateTime - begin).TotalSeconds;
data.CopyTo(expectedData.AsSpan().Slice(offset));
data.CopyTo(expectedData.AsSpan()[offset..]);
expectedStatus.AsSpan().Slice(offset, 600).Fill(1);
}

Expand Down

0 comments on commit f341631

Please sign in to comment.