Skip to content

Commit

Permalink
full clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Dec 7, 2023
1 parent 7521b8a commit 061dd07
Show file tree
Hide file tree
Showing 63 changed files with 1,402 additions and 1,276 deletions.
19 changes: 10 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:suggestion

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
Expand All @@ -53,26 +53,26 @@ dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
dotnet_naming_style.static_prefix_style.required_prefix = s_
dotnet_naming_style.static_prefix_style.capitalization = camel_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
Expand Down Expand Up @@ -182,6 +182,7 @@ indent_size = 2
# Shell scripts
[*.sh]
end_of_line = lf

[*.{cmd,bat}]
end_of_line = crlf

32 changes: 16 additions & 16 deletions src/Fibonacci/Fibonacci.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>

<ItemGroup>
<None Update="dog.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="dog.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
23 changes: 12 additions & 11 deletions src/Fibonacci/Program.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);
var serviceCollection = builder.Services;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
IServiceCollection serviceCollection = builder.Services;
serviceCollection.AddSingleton<Fibonacci, Fibonacci>();
var app = builder.Build();
WebApplication app = builder.Build();


app.MapPost("/fibonacci", (
[FromServices]ILogger<Fibonacci> logger,
[FromServices] Fibonacci fibonacci,
[FromServices] ILogger<Fibonacci> logger,
[FromServices] Fibonacci fibonacci,
int input) =>
{
logger.LogDebug("Fibonacci Called");
return fibonacci.Run(input);
});

app.MapGet("/download", ([FromServices]ILogger<Fibonacci> logger) =>
app.MapGet("/download", ([FromServices] ILogger<Fibonacci> logger) =>
{
logger.LogDebug("Download Called");
var path = Path.Combine(Directory.GetCurrentDirectory(), "dog.png");
return Results.File(path, contentType: "image/png");
string path = Path.Combine(Directory.GetCurrentDirectory(), "dog.png");
return Results.File(path, "image/png");
});

app.MapGet("/hello/{name}", ([FromServices]ILogger<Fibonacci> logger, string name) =>
app.MapGet("/hello/{name}", ([FromServices] ILogger<Fibonacci> logger, string name) =>
{
logger.LogDebug("Hello Called");
return $"Hello {name}!";
});

app.Run();

class Fibonacci
internal class Fibonacci
{
public int Run(int i)
{
if (i <= 2)
{
return 1;
}

return Run(i - 1) + Run(i - 2);
}
}
}
66 changes: 33 additions & 33 deletions src/Fibonacci/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:34722",
"sslPort": 44347
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5165",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7008;http://localhost:5165",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:34722",
"sslPort": 44347
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5165",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7008;http://localhost:5165",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
}
10 changes: 5 additions & 5 deletions src/Fibonacci/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
}
14 changes: 7 additions & 7 deletions src/Fibonacci/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion src/SlimData/.editorconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
root=true
root = true
24 changes: 12 additions & 12 deletions src/SlimData/ClusterConfigurator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
using DotNext.Net.Cluster;
using System.Diagnostics;
using DotNext.Net.Cluster;
using DotNext.Net.Cluster.Consensus.Raft;
using System.Diagnostics;

namespace RaftNode;

internal sealed class ClusterConfigurator : IClusterMemberLifetime
{
public void OnStart(IRaftCluster cluster, IDictionary<string, string> metadata)
{
cluster.LeaderChanged += LeaderChanged;
}

public void OnStop(IRaftCluster cluster)
{
cluster.LeaderChanged -= LeaderChanged;
}

internal static void LeaderChanged(ICluster cluster, IClusterMember? leader)
{
Debug.Assert(cluster is IRaftCluster);
Expand All @@ -16,14 +26,4 @@ internal static void LeaderChanged(ICluster cluster, IClusterMember? leader)
: $"New cluster leader is elected. Leader address is {leader.EndPoint}");
Console.WriteLine($"Term of local cluster member is {term}. Election timeout {timeout}");
}

public void OnStart(IRaftCluster cluster, IDictionary<string, string> metadata)
{
cluster.LeaderChanged += LeaderChanged;
}

public void OnStop(IRaftCluster cluster)
{
cluster.LeaderChanged -= LeaderChanged;
}
}
13 changes: 6 additions & 7 deletions src/SlimData/Commands/AddHashSetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ public struct AddHashSetCommand : ISerializable<AddHashSetCommand>
get
{
// compute length of the serialized data, in bytes
long result = Encoding.UTF8.GetByteCount(Key);
long result = Encoding.UTF8.GetByteCount(Key);
result += sizeof(int); // 4 bytes for count
foreach (var keyValuePair in Value)
{
result += Encoding.UTF8.GetByteCount(keyValuePair.Key) + Encoding.UTF8.GetByteCount(keyValuePair.Value);
}
result += Encoding.UTF8.GetByteCount(keyValuePair.Key) + Encoding.UTF8.GetByteCount(keyValuePair.Value);
return result;
}
}
Expand All @@ -31,7 +29,8 @@ public async ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken t
where TWriter : notnull, IAsyncBinaryWriter
{
var command = this;
await writer.WriteStringAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false), LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.Plain, token);
// write the number of entries
await writer.WriteInt32Async(Value.Count, true, token);
// write the entries
Expand All @@ -49,7 +48,7 @@ public static async ValueTask<AddHashSetCommand> ReadFromAsync<TReader>(TReader
where TReader : notnull, IAsyncBinaryReader
{
var key = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token);

var count = await reader.ReadInt32Async(true, token);
var keysValues = new Dictionary<string, string>(count);
// deserialize entries
Expand All @@ -60,7 +59,7 @@ public static async ValueTask<AddHashSetCommand> ReadFromAsync<TReader>(TReader
var value = await reader.ReadStringAsync(LengthFormat.Plain, context, token);
keysValues.Add(key_, value);
}

return new AddHashSetCommand
{
Key = key,
Expand Down
8 changes: 5 additions & 3 deletions src/SlimData/Commands/AddKeyValueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public async ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken t
where TWriter : notnull, IAsyncBinaryWriter
{
var command = this;
await writer.WriteStringAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false), LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Value.AsMemory(), new EncodingContext(Encoding.UTF8, false), LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Value.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.Plain, token);
}

#pragma warning disable CA2252
Expand All @@ -30,7 +32,7 @@ public static async ValueTask<AddKeyValueCommand> ReadFromAsync<TReader>(TReader
return new AddKeyValueCommand
{
Key = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token),
Value = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token),
Value = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token)
};
}
}
8 changes: 5 additions & 3 deletions src/SlimData/Commands/ListLeftPushCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public async ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken t
where TWriter : notnull, IAsyncBinaryWriter
{
var command = this;
await writer.WriteStringAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false), LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Value.AsMemory(), new EncodingContext(Encoding.UTF8, false), LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.Plain, token);
await writer.WriteStringAsync(command.Value.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.Plain, token);
}

#pragma warning disable CA2252
Expand All @@ -30,7 +32,7 @@ public static async ValueTask<ListLeftPushCommand> ReadFromAsync<TReader>(TReade
return new ListLeftPushCommand
{
Key = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token),
Value = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token),
Value = await reader.ReadStringAsync(LengthFormat.Plain, new DecodingContext(Encoding.UTF8, false), token)
};
}
}
Loading

0 comments on commit 061dd07

Please sign in to comment.