Skip to content

Commit

Permalink
Merge pull request #4 from romanett/clean_architecture
Browse files Browse the repository at this point in the history
Switch to Clean architecture
  • Loading branch information
romanett authored Nov 15, 2023
2 parents 60aeec1 + baaa680 commit c2215dd
Show file tree
Hide file tree
Showing 45 changed files with 864 additions and 1,430 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Runtime.Serialization;
using GDSwithREST.Domain.Entities;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json.Serialization;

namespace GDSwithREST.Data.Models.ApiModels
namespace GDSwithREST.Domain.ApiModels
{
/// <summary>
/// A GDS registered Application
/// </summary>
public class ApplicationApiModel
public sealed class ApplicationApiModel
{
/// <summary>
/// The Guid identifying the Application
Expand All @@ -26,17 +27,17 @@ public class ApplicationApiModel
/// <summary>
/// The gds signed certificate of the Application
/// </summary>
public X509CertificateApiModel? Certificate { get;set; }
public X509CertificateApiModel? Certificate { get; set; }

public ApplicationApiModel(Applications application)

public ApplicationApiModel(Application application)
{
ApplicationId = application.ApplicationId;
ApplicationUri = application.ApplicationUri;
ApplicationName = application.ApplicationName;
ProductUri = application.ProductUri;
ApplicationType = (ApplicationType)application.ApplicationType;
if(application.Certificate.Length > 0)
if (application.Certificate.Length > 0)
Certificate = new X509CertificateApiModel(new X509Certificate2(application.Certificate));
}
[JsonConstructor]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using Opc.Ua.Gds.Server;
using Opc.Ua;
using System.Security.Cryptography.X509Certificates;
using System.Configuration;
using GDSwithREST.Services.GdsBackgroundService.Databases;
using System.Security.Cryptography.X509Certificates;
using System.Runtime.Serialization;
using Opc.Ua.Gds.Server;

namespace GDSwithREST.Data.Models.ApiModels
namespace GDSwithREST.Domain.ApiModels
{
/// <summary>
/// Certificate Group of the GDS
/// </summary>
public class CertificateGroupApiModel
public sealed class CertificateGroupApiModel
{
public CertificateGroupApiModel(CertificateGroup certificateGroup)
public CertificateGroupApiModel(ICertificateGroup certificateGroup)
{
try
{
Expand All @@ -39,9 +36,9 @@ public CertificateGroupApiModel(uint id, X509Certificate2 certificate, bool upda

public CertificateGroupType Id { get; set; }
public bool UpdateRequired { get; set; }
public X509CertificateApiModel? Ceritificate { get; set; }
public X509CertificateApiModel? Ceritificate { get; set; }
}

/// <summary>
/// Type of the Certificate Group
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Newtonsoft.Json;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.X509Certificates;

namespace GDSwithREST.Data.Models.ApiModels
namespace GDSwithREST.Domain.ApiModels
{
/// <summary>
/// A X509 Certificate
/// </summary>
public class X509CertificateApiModel
public sealed class X509CertificateApiModel
{
public string Subject { get; set; }
public string Thumbprint { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace GDSwithREST.Data.Models
namespace GDSwithREST.Domain.Entities
{
public partial class Applications
public sealed class Application
{
public Applications()
public Application()
{
ApplicationNames = new HashSet<ApplicationNames>();
CertificateRequests = new HashSet<CertificateRequests>();
ServerEndpoints = new HashSet<ServerEndpoints>();
ApplicationNames = new HashSet<ApplicationName>();
CertificateRequests = new HashSet<CertificateRequest>();
ServerEndpoints = new HashSet<ServerEndpoint>();
}

public int Id { get; set; }
Expand All @@ -21,10 +21,10 @@ public Applications()
public int? TrustListId { get; set; }
public int? HttpsTrustListId { get; set; }

public CertificateStores HttpsTrustList { get; set; } = null!;
public CertificateStores TrustList { get; set; } = null!;
public ICollection<ApplicationNames> ApplicationNames { get; set; }
public ICollection<CertificateRequests> CertificateRequests { get; set; }
public ICollection<ServerEndpoints> ServerEndpoints { get; set; }
public CertificateStore HttpsTrustList { get; set; } = null!;
public CertificateStore TrustList { get; set; } = null!;
public ICollection<ApplicationName> ApplicationNames { get; set; }
public ICollection<CertificateRequest> CertificateRequests { get; set; }
public ICollection<ServerEndpoint> ServerEndpoints { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace GDSwithREST.Data.Models
namespace GDSwithREST.Domain.Entities
{
public partial class ApplicationNames
public sealed class ApplicationName
{
public int Id { get; set; }
public int ApplicationId { get; set; }
public string Locale { get; set; } = null!;
public string? Text { get; set; }

public Applications Application { get; set; } = null!;
public Application Application { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace GDSwithREST.Data.Models
namespace GDSwithREST.Domain.Entities
{
public partial class CertificateRequests
public sealed class CertificateRequest
{
public int Id { get; set; }
public Guid RequestId { get; set; }
Expand All @@ -15,6 +15,6 @@ public partial class CertificateRequests
public string? PrivateKeyPassword { get; set; } = null!;
public string AuthorityId { get; set; } = null!;

public Applications Application { get; set; } = null!;
public Application Application { get; set; } = null!;
}
}
18 changes: 18 additions & 0 deletions GDSwithREST.Domain/Entities/CertificateStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace GDSwithREST.Domain.Entities
{
public sealed class CertificateStore
{
public CertificateStore()
{
ApplicationsHttpsTrustList = new HashSet<Application>();
ApplicationsTrustList = new HashSet<Application>();
}

public int Id { get; set; }
public string Path { get; set; } = null!;
public string AuthorityId { get; set; } = null!;

public ICollection<Application> ApplicationsHttpsTrustList { get; set; }
public ICollection<Application> ApplicationsTrustList { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace GDSwithREST.Data.Models
namespace GDSwithREST.Domain.Entities
{
public partial class ServerEndpoints
public sealed class ServerEndpoint
{
public int Id { get; set; }
public int ApplicationId { get; set; }
public string DiscoveryUrl { get; set; } = null!;

public Applications Application { get; set; } = null!;
public Application Application { get; set; } = null!;
}
}
14 changes: 14 additions & 0 deletions GDSwithREST.Domain/GDSwithREST.Domain.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Gds.Server.Common" Version="1.4.372.76" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions GDSwithREST.Domain/Repositories/IApplicationNameRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using GDSwithREST.Domain.Entities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GDSwithREST.Domain.Repositories
{
public interface IApplicationNameRepository
{
public Task<IEnumerable<ApplicationName>> GetAllApplicationNames();
public Task<IEnumerable<ApplicationName>> GetApplicationNamesByApplicationId(int id);
public void RemoveApplicationNames(ApplicationName[] applicationNames);
public ApplicationName AddApplicationName(ApplicationName applicationName);
}
}
18 changes: 18 additions & 0 deletions GDSwithREST.Domain/Repositories/IApplicationRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using GDSwithREST.Domain.Entities;

namespace GDSwithREST.Domain.Repositories
{
public interface IApplicationRepository
{
public Task<IEnumerable<Application>> GetAllApplications();
public Task<Application?> GetApplicationById(Guid id);
public IQueryable<Application> GetApplicationsByUri(string ApplicationUri);
public void RemoveApplication(Application application);
public Application AddApplication(Application application);

/// <summary>
/// persists the changes made to an Application instance
/// </summary>
public void SaveChanges();
}
}
16 changes: 16 additions & 0 deletions GDSwithREST.Domain/Repositories/ICertificateRequestRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using GDSwithREST.Domain.Entities;

namespace GDSwithREST.Domain.Repositories
{
public interface ICertificateRequestRepository
{
public void RemoveCertificateRequests(CertificateRequest[] certificateRequests);

public Task<CertificateRequest?> GetCertificateRequestById(Guid id);

/// <summary>
/// persists the changes made to an CeritificateRequest instance
/// </summary>
public void SaveChanges();
}
}
14 changes: 14 additions & 0 deletions GDSwithREST.Domain/Repositories/ICertificateStoreRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using GDSwithREST.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GDSwithREST.Domain.Repositories
{
public interface ICertificateStoreRepository
{
public Task<CertificateStore?> GetCertificateStoreByPath(string path);
}
}
13 changes: 13 additions & 0 deletions GDSwithREST.Domain/Repositories/IPersistencyRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GDSwithREST.Domain.Repositories
{
public interface IPersistencyRepository
{
public Task MigrateDatabaseAsync();
}
}
18 changes: 18 additions & 0 deletions GDSwithREST.Domain/Repositories/IServerEndpointRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using GDSwithREST.Domain.Entities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GDSwithREST.Domain.Repositories
{
public interface IServerEndpointRepository
{
public Task<IEnumerable<ServerEndpoint>> GetAllServerEndpoints();
public Task<IEnumerable<ServerEndpoint>> GetServerEndpointsByApplicationId(int id);
public void RemoveServerEndpoints(ServerEndpoint[] serverEndpoints);
public ServerEndpoint AddServerEndpoint(ServerEndpoint serverEndpoint);
}
}
Loading

0 comments on commit c2215dd

Please sign in to comment.