Skip to content

Commit

Permalink
Fix #494: Moved from WASM to ServerSide (#497)
Browse files Browse the repository at this point in the history
* Fix #494: Moved from WASM to ServerSide

* test

* Rebase and dotsettings update
  • Loading branch information
antoineatstariongroup authored Feb 21, 2024
1 parent 0cc7091 commit 70c640c
Show file tree
Hide file tree
Showing 21 changed files with 489 additions and 228 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServiceCollectionExtensionsTestFixtures.cs" company="RHEA System S.A.">
// Copyright (c) 2024 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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 this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Tests.Extensions
{
using COMETwebapp.Extensions;

using Microsoft.Extensions.DependencyInjection;

using Moq;

using NUnit.Framework;

[TestFixture]
public class ServiceCollectionExtensionsTestFixtures
{
[Test]
public void VerifyRegistration()
{
var serviceCollection = new Mock<IServiceCollection>();

Assert.Multiple(() =>
{
Assert.That(() => serviceCollection.Object.RegisterServices(), Throws.Nothing);
Assert.That(() => serviceCollection.Object.RegisterViewModels(), Throws.Nothing);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void Setup()
this.versionService = new Mock<IVersionService>();
this.versionService.Setup(x => x.GetVersion()).Returns("1.1.2");
this.context.Services.AddSingleton(this.versionService.Object);
this.context.Services.AddSingleton(new Mock<IHttpClientFactory>().Object);
this.context.ConfigureDevExpressBlazor();
}

Expand Down
40 changes: 14 additions & 26 deletions COMETwebapp.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeAccessorOwnerBody/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AutoPropertyCanBeMadeGetOnly_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
Expand Down Expand Up @@ -251,38 +251,26 @@
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/QualifiedUsingAtNestedScope/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/EditorConfig/EnableStyleCopSupport/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/EditorConfig/ShowEditorConfigStatusBarIndicator/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">--------------------------------------------------------------------------------------------------------------------&#xD;
&lt;copyright file="${File.FileName}" company="RHEA System S.A."&gt;&#xD;
Copyright (c) ${CurrentDate.Year} RHEA System S.A.&#xD;
&#xD;
Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine&#xD;
&#xD;
This file is part of COMET WEB Community Edition&#xD;
The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.&#xD;
&#xD;
The COMET WEB Community Edition is free software; you can redistribute it and/or&#xD;
modify it under the terms of the GNU Affero General Public&#xD;
License as published by the Free Software Foundation; either&#xD;
version 3 of the License, or (at your option) any later version.&#xD;
&#xD;
The COMET WEB Community Edition is distributed in the hope that it will be useful,&#xD;
but WITHOUT ANY WARRANTY; without even the implied warranty of&#xD;
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&#xD;
Affero General Public License for more details.&#xD;
&#xD;
You should have received a copy of the GNU Affero General Public License&#xD;
along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.&#xD;
&lt;/copyright&gt;&#xD;
--------------------------------------------------------------------------------------------------------------------
</s:String>

<s:Boolean x:Key="/Default/CodeStyle/Generate/=Implementations/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Generate/=Implementations/Options/=Async/@EntryIndexedValue">False</s:String>
<s:String x:Key="/Default/CodeStyle/Generate/=Implementations/Options/=Mutable/@EntryIndexedValue">False</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/IsNotificationDisabled/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=4AB96A4D2627B246A5C2ECDB728C4A58/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=4AB96A4D2627B246A5C2ECDB728C4A58/AbsolutePath/@EntryValue">C:\CODE\COMET\COMET-WEB-Community-Edition\CommonLibrary.DotSettings</s:String>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=4AB96A4D2627B246A5C2ECDB728C4A58/RelativePath/@EntryValue">..\CommonLibrary.DotSettings</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=D550F7EA807C0A4C8F7E43AD856774F2/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=D550F7EA807C0A4C8F7E43AD856774F2/AbsolutePath/@EntryValue">C:\CODE\COMET\COMET-WEB-Community-Edition\WebAppHeader.DotSettings</s:String>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=D550F7EA807C0A4C8F7E43AD856774F2/RelativePath/@EntryValue">..\WebAppHeader.DotSettings</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File4AB96A4D2627B246A5C2ECDB728C4A58/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File4AB96A4D2627B246A5C2ECDB728C4A58/DisplayName/@EntryValue">CommonLibraryHeader</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File4AB96A4D2627B246A5C2ECDB728C4A58/IsOn/@EntryValue">False</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File4AB96A4D2627B246A5C2ECDB728C4A58/RelativePriority/@EntryValue">1</s:Double>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileD550F7EA807C0A4C8F7E43AD856774F2/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileD550F7EA807C0A4C8F7E43AD856774F2/RelativePriority/@EntryValue">2</s:Double>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
10 changes: 7 additions & 3 deletions COMETwebapp/COMETwebapp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -21,13 +21,17 @@
<PackageReference Include="BlazorStrap" Version="5.1.102.51923" />
<PackageReference Include="System.Drawing.Common" Version="8.0.2" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.16" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.16" PrivateAssets="all" />
<PackageReference Include="Z.Blazor.Diagrams" Version="2.1.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\COMET.Web.Common\COMET.Web.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
7 changes: 4 additions & 3 deletions COMETwebapp/Components/Shared/About.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public partial class About
private string license = string.Empty;

/// <summary>
/// The <see cref="HttpClient" />
/// The <see cref="IHttpClientFactory" />
/// </summary>
[Inject]
public HttpClient HttpClient { get; set; }
public IHttpClientFactory HttpClientFactory { get; set; }

/// <summary>
/// The <see cref="IVersionService" />
Expand All @@ -66,7 +66,8 @@ public partial class About
protected override async Task OnInitializedAsync()
{
this.cometWebVersion = this.VersionService.GetVersion();
this.license = await this.HttpClient.GetStringAsync(GitUrl);
var httpClient = this.HttpClientFactory.CreateClient("About");
this.license = await httpClient.GetStringAsync(GitUrl);
}
}
}
9 changes: 5 additions & 4 deletions COMETwebapp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ RUN dotnet build COMETwebapp -c Release -o /app/build --no-restore
FROM build AS publish
RUN dotnet publish COMETwebapp -c Release -o /app/publish

FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
COPY --from=publish /app/publish/wwwroot .
COPY COMETwebapp/nginx.conf /etc/nginx/nginx.conf
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "COMETwebapp.dll"]
89 changes: 89 additions & 0 deletions COMETwebapp/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServiceCollectionExtensions.cs" company="RHEA System S.A.">
// Copyright (c) 2024 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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 this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Extensions
{
using COMETwebapp.Model.Viewer;
using COMETwebapp.Services.Interoperability;
using COMETwebapp.Services.ShowHideDeprecatedThingsService;
using COMETwebapp.Services.SubscriptionService;
using COMETwebapp.Utilities;
using COMETwebapp.ViewModels.Components.BookEditor;
using COMETwebapp.ViewModels.Components.ModelDashboard;
using COMETwebapp.ViewModels.Components.ModelDashboard.ParameterValues;
using COMETwebapp.ViewModels.Components.ModelEditor;
using COMETwebapp.ViewModels.Components.ParameterEditor;
using COMETwebapp.ViewModels.Components.ReferenceData;
using COMETwebapp.ViewModels.Components.SubscriptionDashboard;
using COMETwebapp.ViewModels.Components.SystemRepresentation;
using COMETwebapp.ViewModels.Components.UserManagement;
using COMETwebapp.ViewModels.Components.Viewer;
using COMETwebapp.ViewModels.Shared.TopMenuEntry;

/// <summary>
/// Extension class for the <see cref="IServiceCollection" />
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Register all services required to run the application inside the <see cref="IServiceCollection" />
/// </summary>
/// <param name="serviceCollection">The <see cref="IServiceCollection" /></param>
public static void RegisterServices(this IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<ISubscriptionService, SubscriptionService>();
serviceCollection.AddScoped<IShowHideDeprecatedThingsService, ShowHideDeprecatedThingsService>();
serviceCollection.AddScoped<ISceneSettings, SceneSettings>();
serviceCollection.AddScoped<ISelectionMediator, SelectionMediator>();
serviceCollection.AddScoped<IDraggableElementService, DraggableElementService>();
serviceCollection.AddScoped<IBabylonInterop, BabylonInterop>();
serviceCollection.AddScoped<IDomDataService, DomDataService>();
serviceCollection.AddHttpClient();
serviceCollection.AddAntDesign();
}

/// <summary>
/// Register all view models required to run the application inside the <see cref="IServiceCollection" />
/// </summary>
/// <param name="serviceCollection">The <see cref="IServiceCollection" /></param>
public static void RegisterViewModels(this IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<IShowHideDeprecatedThingsViewModel, ShowHideDeprecatedThingsViewModel>();
serviceCollection.AddTransient<IParameterTableViewModel, ParameterTableViewModel>();
serviceCollection.AddTransient<IParameterDashboardViewModel, ParameterDashboardViewModel>();
serviceCollection.AddTransient<IModelDashboardBodyViewModel, ModelDashboardBodyViewModel>();
serviceCollection.AddTransient<ISubscriptionDashboardBodyViewModel, SubscriptionDashboardBodyViewModel>();
serviceCollection.AddTransient<ISubscribedTableViewModel, SubscribedTableViewModel>();
serviceCollection.AddTransient<IParameterEditorBodyViewModel, ParameterEditorBodyViewModel>();
serviceCollection.AddTransient<IViewerBodyViewModel, ViewerBodyViewModel>();
serviceCollection.AddTransient<IElementDefinitionDetailsViewModel, ElementDefinitionDetailsViewModel>();
serviceCollection.AddTransient<IParameterTypeTableViewModel, ParameterTypeTableViewModel>();
serviceCollection.AddTransient<IUserManagementTableViewModel, UserManagementTableViewModel>();
serviceCollection.AddTransient<ICategoriesTableViewModel, CategoriesTableViewModel>();
serviceCollection.AddTransient<ISystemRepresentationBodyViewModel, SystemRepresentationBodyViewModel>();
serviceCollection.AddTransient<IElementDefinitionTableViewModel, ElementDefinitionTableViewModel>();
serviceCollection.AddTransient<IBookEditorBodyViewModel, BookEditorBodyViewModel>();
}
}
}
50 changes: 50 additions & 0 deletions COMETwebapp/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@page
<!------------------------------------------------------------------------------
// Copyright (c) 2023 INNOVET LLC
//
// Authors: Sam Gerené, Antoine Théate, Jaime Bernar, Martin Risseeuw, Roberto Alves, João Rua
//
// This file is part of DMAP-CDAO application
// The DMAP-CDAO application is a Web Application implementation of ECSS-E-TM-10-25 for DMAP-CDAO.
------------------------------------------------------------------------------->
@model COMETwebapp.Pages.ErrorModel

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet"/>
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true"/>
</head>

<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (this.Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@(this.Model.RequestId)</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</div>
</body>

</html>
Loading

0 comments on commit 70c640c

Please sign in to comment.