-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.cs
More file actions
130 lines (108 loc) · 4.98 KB
/
Copy pathProgram.cs
File metadata and controls
130 lines (108 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// -------------------------------------------------------------------------------------------------
// <copyright file="Program.cs" company="Starion Group S.A.">
//
// Copyright 2022-2026 Starion Group S.A.
//
// 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 SysML2.NET.Viewer
{
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using BlazorStrap;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Radzen;
using ReactiveUI.Builder;
using Serilog;
using SySML2.NET.REST;
using SysML2.NET.Serializer.Json;
using SysML2.NET.Viewer.Services.Authentication;
/// <summary>
/// The purpose of the <see cref="Program"/> class is to provide the
/// main entry point of te application
/// </summary>
public static class Program
{
/// <summary>
/// Main entry point of the application
/// </summary>
/// <param name="args">Command line arguments</param>
/// <returns>
/// an awaitable <see cref="Task"/>
/// </returns>
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();
builder.Services.AddLogging(loggingBuilder =>
loggingBuilder.AddSerilog(dispose: true));
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
AddServices(builder);
AddViewModels(builder);
RxAppBuilder.CreateReactiveUIBuilder()
.WithCoreServices()
.BuildApp();
await builder.Build().RunAsync();
}
/// <summary>
/// Register all services into the <see cref="WebAssemblyHostBuilder.Services" />
/// </summary>
/// <param name="builder">The <see cref="WebAssemblyHostBuilder" /></param>
private static void AddServices(WebAssemblyHostBuilder builder)
{
builder.Services.AddSessionStorageServices();
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<DialogService>();
builder.Services.AddScoped<NotificationService>();
builder.Services.AddScoped<TooltipService>();
builder.Services.AddScoped<ContextMenuService>();
builder.Services.AddBlazorStrap();
builder.Services.AddScoped(sp => new HttpClient());
builder.Services.AddScoped<AuthenticationStateProvider, AnonymousAuthenticationStateProvider>();
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>();
builder.Services.AddScoped<IRestClient, RestClient>();
builder.Services.AddScoped<IDeSerializer, DeSerializer>();
builder.Services.AddScoped<ISerializer, Serializer>();
}
/// <summary>
/// Register all ViewModels into the <see cref="WebAssemblyHostBuilder" />
/// </summary>
/// <param name="builder">The <see cref="WebAssemblyHostBuilder" /></param>
private static void AddViewModels(WebAssemblyHostBuilder builder)
{
var viewModelInterfaces = Assembly.GetCallingAssembly().GetExportedTypes()
.Where(x => x.IsInterface && x.Name.EndsWith("ViewModel")).ToList();
foreach (var viewModelInterface in viewModelInterfaces)
{
var viewModel = Assembly.GetCallingAssembly().GetExportedTypes()
.FirstOrDefault(x => x.IsClass
&& x.Name == viewModelInterface.Name.Remove(0, 1)
&& x.GetInterface(viewModelInterface.Name) == viewModelInterface);
if (viewModel != null)
{
builder.Services.AddTransient(viewModelInterface, viewModel);
}
}
}
}
}