Skip to content

Commit

Permalink
Fix #494: Moved from WASM to ServerSide
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatrhea committed Jan 3, 2024
1 parent fa14eca commit 9cfc0b9
Show file tree
Hide file tree
Showing 20 changed files with 437 additions and 226 deletions.
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
37 changes: 13 additions & 24 deletions COMETwebapp.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -251,37 +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="$FILENAME$" company="RHEA System S.A."&gt;&#xD;
Copyright (c) $CURRENT_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/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.100" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.4" 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>
58 changes: 58 additions & 0 deletions COMETwebapp/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Error.cshtml.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.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Pages
{
using System.Diagnostics;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

/// <summary>
/// Data model that provide information about request when an error occurs
/// </summary>
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
/// <summary>
/// Gets or sets the request id
/// </summary>
public string RequestId { get; set; }

/// <summary>
/// Gets the assert the the <see cref="RequestId" /> should be shown
/// </summary>
public bool ShowRequestId => !string.IsNullOrEmpty(this.RequestId);

/// <summary>
/// Sets the <see cref="RequestId" /> based on context
/// </summary>
public void OnGet()
{
this.RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier;
}
}
}
2 changes: 1 addition & 1 deletion COMETwebapp/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
------------------------------------------------------------------------------->
@page "/"
<IndexComponent Redirect="@this.Redirect"/>
<IndexComponent Redirect="@this.Redirect"/>
Loading

0 comments on commit 9cfc0b9

Please sign in to comment.