Skip to content

Commit

Permalink
Merge pull request #84 from Etherna/improve/BHM-152-dotnet-9
Browse files Browse the repository at this point in the history
migrate to dotnet 9
  • Loading branch information
tmm360 authored Nov 22, 2024
2 parents e9372cb + 5c675cd commit cda2d4d
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 112 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ dotnet_diagnostic.CA1054.severity = none # Asp.Net Core uses strings natively
# CA1308: Normalize strings to uppercase
dotnet_diagnostic.CA1308.severity = none # I choose if use upper or lower case

# CA1515: Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)
dotnet_diagnostic.CA1515.severity = none # Rises a lot of false positives

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = none # I like underscores into constants name

Expand Down
3 changes: 2 additions & 1 deletion BeehiveManager.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with BeehiveManager.
If not, see &lt;https://www.gnu.org/licenses/&gt;.</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=etherna/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "BeehiveManager.sln"
Expand Down
6 changes: 4 additions & 2 deletions src/BeehiveManager.Domain/BeehiveManager.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Etherna.BeehiveManager.Domain</RootNamespace>

<Authors>Etherna SA</Authors>
Expand All @@ -10,11 +10,13 @@
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>

<NoWarn>NU1903</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Etherna.DomainEvents" Version="1.4.0" />
<PackageReference Include="MongODM.Core" Version="0.24.0" />
<PackageReference Include="MongODM.Core" Version="0.25.0-alpha.6" />
<PackageReference Include="Nethereum.Web3" Version="4.26.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Etherna.BeehiveManager.Persistence</RootNamespace>

<Authors>Etherna SA</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,32 @@

namespace Etherna.BeehiveManager.Persistence
{
public class BeehiveDbContext : DbContext, IBeehiveDbContext, IEventDispatcherDbContext
public class BeehiveManagerDbContext(
IEventDispatcher eventDispatcher,
IEnumerable<BeeNode>? seedDbBeeNodes)
: DbContext, IBeehiveDbContext, IEventDispatcherDbContext
{
// Consts.
private const string SerializersNamespace = "Etherna.BeehiveManager.Persistence.ModelMaps";

// Fields.
private readonly IEnumerable<BeeNode>? seedDbBeeNodes;

// Constructor.
public BeehiveDbContext(
IEventDispatcher eventDispatcher,
IEnumerable<BeeNode>? seedDbBeeNodes)
{
EventDispatcher = eventDispatcher;
this.seedDbBeeNodes = seedDbBeeNodes;
}

// Properties.
//repositories
public IRepository<BeeNode, string> BeeNodes { get; } = new DomainRepository<BeeNode, string>(
new RepositoryOptions<BeeNode>("beeNodes")
{
IndexBuilders = new[]
{
IndexBuilders =
[
(Builders<BeeNode>.IndexKeys.Ascending(n => n.GatewayPort)
.Ascending(n => n.Hostname), new CreateIndexOptions<BeeNode> { Unique = true })
}
]
});

//other properties
public IEventDispatcher EventDispatcher { get; }
public IEventDispatcher EventDispatcher { get; } = eventDispatcher;

// Protected properties.
protected override IEnumerable<IModelMapsCollector> ModelMapsCollectors =>
from t in typeof(BeehiveDbContext).GetTypeInfo().Assembly.GetTypes()
from t in typeof(BeehiveManagerDbContext).GetTypeInfo().Assembly.GetTypes()
where t.IsClass && t.Namespace == SerializersNamespace
where t.GetInterfaces().Contains(typeof(IModelMapsCollector))
select Activator.CreateInstance(t) as IModelMapsCollector;
Expand All @@ -72,8 +63,7 @@ where t.GetInterfaces().Contains(typeof(IModelMapsCollector))
public override async Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
// Dispatch events.
foreach (var model in ChangedModelsList.Where(m => m is EntityModelBase)
.Select(m => (EntityModelBase)m))
foreach (var model in ChangedModelsList.OfType<EntityModelBase>())
{
await EventDispatcher.DispatchAsync(model.Events);
model.ClearEvents();
Expand Down
8 changes: 5 additions & 3 deletions src/BeehiveManager.Services/BeehiveManager.Services.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Etherna.BeehiveManager.Services</RootNamespace>

<Authors>Etherna SA</Authors>
Expand All @@ -10,12 +10,14 @@
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>

<NoWarn>NU1902;NU1903</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bee.Net.Client" Version="0.4.0-alpha.58" />
<PackageReference Include="Bee.Net.Client" Version="0.4.0-alpha.65" />
<PackageReference Include="Etherna.DomainEvents.AspNetCore" Version="1.4.0" />
<PackageReference Include="MongODM.Hangfire" Version="0.24.0" />
<PackageReference Include="MongODM.Hangfire" Version="0.25.0-alpha.6" />
<PackageReference Include="Nethereum.JsonRpc.WebSocketClient" Version="4.26.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,9 @@

namespace Etherna.BeehiveManager.Services.EventHandlers
{
internal sealed class OnBeeNodeCreatedThenAddNodeStatusHandler : EventHandlerBase<EntityCreatedEvent<BeeNode>>
internal sealed class OnBeeNodeCreatedThenAddNodeStatusHandler(IBeeNodeLiveManager beeNodeLiveManager)
: EventHandlerBase<EntityCreatedEvent<BeeNode>>
{
// Fields.
private readonly IBeeNodeLiveManager beeNodeLiveManager;

// Constructor.
public OnBeeNodeCreatedThenAddNodeStatusHandler(
IBeeNodeLiveManager beeNodeLiveManager)
{
this.beeNodeLiveManager = beeNodeLiveManager;
}

// Methods.
public override async Task HandleAsync(EntityCreatedEvent<BeeNode> @event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,9 @@

namespace Etherna.BeehiveManager.Services.EventHandlers
{
internal sealed class OnBeeNodeDeletedThenRemoveNodeStatusHandler : EventHandlerBase<EntityDeletedEvent<BeeNode>>
internal sealed class OnBeeNodeDeletedThenRemoveNodeStatusHandler(IBeeNodeLiveManager beeNodeLiveManager)
: EventHandlerBase<EntityDeletedEvent<BeeNode>>
{
// Fields.
private readonly IBeeNodeLiveManager beeNodeLiveManager;

// Constructor.
public OnBeeNodeDeletedThenRemoveNodeStatusHandler(
IBeeNodeLiveManager beeNodeLiveManager)
{
this.beeNodeLiveManager = beeNodeLiveManager;
}

// Methods.
public override Task HandleAsync(EntityDeletedEvent<BeeNode> @event)
{
Expand Down
25 changes: 6 additions & 19 deletions src/BeehiveManager.Services/Tasks/CashoutAllNodesChequesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,24 @@
using Etherna.BeeNet.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Nethereum.Web3;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace Etherna.BeehiveManager.Services.Tasks
{
public class CashoutAllNodesChequesTask : ICashoutAllNodesChequesTask
public class CashoutAllNodesChequesTask(
IBeeNodeLiveManager liveManager,
ILogger<CashoutAllNodesChequesTask> logger,
IOptions<CashoutAllNodesChequesSettings> options)
: ICashoutAllNodesChequesTask
{
// Consts.
public const string TaskId = "cashoutAllNodesTask";

// Fields.
private readonly IBeeNodeLiveManager liveManager;
private readonly ILogger<CashoutAllNodesChequesTask> logger;
private readonly CashoutAllNodesChequesSettings options;

// Constructors.
public CashoutAllNodesChequesTask(
IBeeNodeLiveManager liveManager,
ILogger<CashoutAllNodesChequesTask> logger,
IOptions<CashoutAllNodesChequesSettings> options)
{
ArgumentNullException.ThrowIfNull(options, nameof(options));

this.liveManager = liveManager;
this.logger = logger;
this.options = options.Value;
}
private readonly CashoutAllNodesChequesSettings options = options.Value;

// Methods.
public async Task RunAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Etherna.BeehiveManager.Services.Tasks
{
/// <summary>
/// Cashout all cheques from other nodes in the Swarm network, when total cheques with it pass over a limit.
/// Cash out all cheques from other nodes in the Swarm network, when total cheques with it pass over a limit.
/// </summary>
public interface ICashoutAllNodesChequesTask
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using Etherna.BeehiveManager.Services.Utilities.Models;
using Etherna.BeeNet.Exceptions;
using Etherna.BeeNet.Models;
using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal BeeNodeLiveInstance(
BeeNode beeNode)
{
Id = beeNode.Id;
Client = new BeeClient(beeNode.BaseUrl.AbsoluteUri, beeNode.GatewayPort);
Client = new BeeClient(beeNode.GatewayUrl);
IsBatchCreationEnabled = beeNode.IsBatchCreationEnabled;
Status = new BeeNodeStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Etherna.BeehiveManager.Services.Utilities;
using Etherna.BeeNet.Exceptions;
using Etherna.BeeNet.Models;
using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using Etherna.MongODM.Core.Extensions;
using Microsoft.Extensions.Logging;
using System;
Expand All @@ -30,7 +30,7 @@

namespace Etherna.BeehiveManager.Areas.Api.Services
{
public class NodesControllerService(
internal sealed class NodesControllerService(
IBeehiveDbContext beehiveDbContext,
IBeeNodeLiveManager beeNodeLiveManager,
ILogger<NodesControllerService> logger)
Expand Down Expand Up @@ -61,7 +61,6 @@ public async Task<BeeNodeDto> AddBeeNodeAsync(BeeNodeInput input)
public async Task<bool> CheckResourceAvailabilityFromNodeAsync(string id, SwarmHash hash)
{
ArgumentNullException.ThrowIfNull(id, nameof(id));
ArgumentNullException.ThrowIfNull(hash, nameof(hash));

var beeNodeInstance = await beeNodeLiveManager.GetBeeNodeLiveInstanceAsync(id);
return await beeNodeInstance.Client.IsContentRetrievableAsync(hash);
Expand Down Expand Up @@ -156,7 +155,6 @@ public async Task RemoveBeeNodeAsync(string id)
public async Task ReuploadResourceToNetworkFromNodeAsync(string id, SwarmHash hash)
{
ArgumentNullException.ThrowIfNull(id, nameof(id));
ArgumentNullException.ThrowIfNull(hash, nameof(hash));

var beeNodeInstance = await beeNodeLiveManager.GetBeeNodeLiveInstanceAsync(id);
await beeNodeInstance.Client.ReuploadContentAsync(hash);
Expand Down
10 changes: 5 additions & 5 deletions src/BeehiveManager/BeehiveManager.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Etherna.BeehiveManager</RootNamespace>

<Authors>Etherna SA</Authors>
Expand All @@ -17,18 +17,18 @@

<ItemGroup>
<PackageReference Include="EthernaACR" Version="0.3.10" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PackageReference Include="GitVersion.MsBuild" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
<PackageReference Include="MongODM" Version="0.24.0" />
<PackageReference Include="MongODM.AspNetCore.UI" Version="0.24.0" />
<PackageReference Include="MongODM" Version="0.25.0-alpha.6" />
<PackageReference Include="MongODM.AspNetCore.UI" Version="0.25.0-alpha.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BeehiveManager/Configs/CommonConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Etherna.BeehiveManager.Configs
{
public static class CommonConsts
internal static class CommonConsts
{
public const string DatabaseAdminPath = "/admin/db";
public const string HangfireAdminPath = "/admin/hangfire";
Expand Down
4 changes: 3 additions & 1 deletion src/BeehiveManager/Configs/SystemStore/XmlRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace Etherna.BeehiveManager.Configs.SystemStore
{
public class XmlRepository : IXmlRepository
internal sealed class XmlRepository : IXmlRepository
{
// Consts.
public const string CollectionName = "dataProtectionKeys";
Expand All @@ -39,7 +39,9 @@ public XmlRepository(DbContextOptions options)
ArgumentNullException.ThrowIfNull(options, nameof(options));

// Initialize MongoDB driver.
#pragma warning disable CA2000 // Dispose objects before losing scope
var client = new MongoClient(options.ConnectionString);
#pragma warning restore CA2000 // Dispose objects before losing scope
var database = client.GetDatabase(options.DbName);
collection = database.GetCollection<BsonDocument>(CollectionName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Etherna.BeehiveManager.Exceptions
{
public class ServiceConfigurationException : Exception
internal sealed class ServiceConfigurationException : Exception
{
public ServiceConfigurationException()
{ }
Expand Down
4 changes: 2 additions & 2 deletions src/BeehiveManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ private static void ConfigureServices(WebApplicationBuilder builder)
}
};
})
.AddDbContext<IBeehiveDbContext, BeehiveDbContext>(sp =>
.AddDbContext<IBeehiveDbContext, BeehiveManagerDbContext>(sp =>
{
var eventDispatcher = sp.GetRequiredService<IEventDispatcher>();
var seedDbSettings = sp.GetRequiredService<IOptions<SeedDbSettings>>().Value;
return new BeehiveDbContext(
return new BeehiveManagerDbContext(
eventDispatcher,
seedDbSettings.BeeNodes.Where(n => n is not null)
.Select(n => new BeeNode(n.Scheme, n.GatewayPort, n.Hostname, n.EnableBatchCreation)));
Expand Down
4 changes: 2 additions & 2 deletions src/BeehiveManager/Settings/SeedDbSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace Etherna.BeehiveManager.Settings
{
#pragma warning disable CA1034 // Nested types should not be visible
#pragma warning disable CA1819 // Properties should not return arrays
public class SeedDbSettings
internal sealed class SeedDbSettings
{
// Internal classes.
public class BeeNode
internal sealed class BeeNode
{
public bool EnableBatchCreation { get; set; } = true;
public int GatewayPort { get; set; } = 1633;
Expand Down
Loading

0 comments on commit cda2d4d

Please sign in to comment.