Skip to content

Commit 38e518c

Browse files
author
Jani Giannoudis
committed
web server start: added environment parameters
refactored status update updated third party nugets first version 0.9.0-beta.1
1 parent e6c8ca4 commit 38e518c

25 files changed

+250
-124
lines changed

Core/Asset/BackendAsset.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ public override async Task UpdateStatusAsync(AssetContext context)
7575
}
7676

7777
/// <inheritdoc />
78-
public Task StartAsync()
78+
public async Task StartAsync(AssetContext context)
7979
{
80+
var environment = await context.SettingsService.GetEnvironmentSettingsAsync();
8081
OperatingSystem.StartWebserver(
8182
workingDirectory: Name,
8283
webserverExec: Parameters.WebserverExec,
8384
webserverUrl: WebserverConnection.ToUrl(),
84-
webserverName: Parameters.WebserverName);
85-
return Task.CompletedTask;
85+
webserverName: Parameters.WebserverName,
86+
environment: environment);
8687
}
8788

8889
/// <inheritdoc />

Core/Asset/FileAssetService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public async Task UpdateStatusAsync()
113113
await asset.UpdateStatusAsync(AssetContext);
114114
}
115115
}
116-
ValidStatus = true;
117116
}
118117

119118
#endregion

Core/Asset/IStartAsset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public interface IStartAsset
1111
/// Start the asset
1212
/// </summary>
1313
// ReSharper disable once UnusedMemberInSuper.Global
14-
Task StartAsync();
14+
Task StartAsync(AssetContext contextI);
1515
}

Core/Asset/WebAppAsset.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ public override async Task UpdateStatusAsync(AssetContext context)
5050
}
5151

5252
/// <inheritdoc />
53-
public Task StartAsync()
53+
public async Task StartAsync(AssetContext context)
5454
{
55+
var environment = await context.SettingsService.GetEnvironmentSettingsAsync();
5556
OperatingSystem.StartWebserver(
5657
workingDirectory: Name,
5758
webserverExec: Parameters.WebserverExec,
5859
webserverUrl: WebserverConnection.ToUrl(),
59-
webserverName: Parameters.WebserverName);
60-
return Task.CompletedTask;
60+
webserverName: Parameters.WebserverName,
61+
environment: environment);
6162
}
6263

6364
/// <inheritdoc />

Core/OperatingSystem.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Text.Json;
45
using System.Diagnostics;
@@ -14,12 +15,6 @@ public static class OperatingSystem
1415

1516
#region OS
1617

17-
/// <summary>
18-
/// Test for windows OS
19-
/// </summary>
20-
private static bool IsWindows() =>
21-
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
22-
2318
/// <summary>
2419
/// Test for linux OS
2520
/// </summary>
@@ -157,26 +152,30 @@ private static int ExecuteProcess(string fileName, string arguments,
157152
/// <param name="workingDirectory">Webserver path</param>
158153
/// <param name="webserverExec">Executable file name</param>
159154
/// <param name="webserverUrl">Target webserver url</param>
160-
/// <param name="webserverName">Server name</param>
155+
/// <param name="webserverName">Server name (currently not supported)</param>
156+
/// <param name="environment">Process environment</param>
161157
public static void StartWebserver(string workingDirectory, string webserverExec,
162-
string webserverUrl, string webserverName)
158+
// ReSharper disable once UnusedParameter.Global
159+
string webserverUrl, string webserverName,Dictionary<string, string> environment = null)
163160
{
164161
Directory.SetCurrentDirectory(workingDirectory);
165162

166-
var fileName = "dotnet.exe";
167163
var arguments = $"{webserverExec} --urls={webserverUrl}";
168-
if (IsWindows() && !string.IsNullOrWhiteSpace(webserverName))
169-
{
170-
fileName = "cmd.exe";
171-
arguments = $"/C START /MIN \"Payroll Engine - Backend Server\" dotnet {webserverExec} --urls={webserverUrl}";
172-
}
173-
var info = new ProcessStartInfo(fileName, arguments)
164+
var info = new ProcessStartInfo("dotnet.exe", arguments)
174165
{
175166

176167
WorkingDirectory = workingDirectory,
177-
UseShellExecute = !IsLinux(),
168+
UseShellExecute = false,
169+
//UseShellExecute = !IsLinux(),
178170
WindowStyle = ProcessWindowStyle.Minimized
179171
};
172+
if (environment != null)
173+
{
174+
foreach (var item in environment)
175+
{
176+
info.Environment.Add(item);
177+
}
178+
}
180179

181180
using var process = Process.Start(info);
182181
}

Core/PayrollEngine.AdminApp.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="9.0.1" />
12-
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.1" />
11+
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="9.0.2" />
12+
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.2" />
1313
</ItemGroup>
1414

1515
</Project>

Core/Setting/EnvironmentSettingsService.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
22
using System.Threading.Tasks;
3-
using PayrollEngine.AdminApp.Persistence;
3+
using System.Collections.Generic;
44
using PayrollEngine.AdminApp.Webserver;
5+
using PayrollEngine.AdminApp.Persistence;
56

67
namespace PayrollEngine.AdminApp.Setting;
78

@@ -11,6 +12,26 @@ namespace PayrollEngine.AdminApp.Setting;
1112
public class EnvironmentSettingsService : ISettingsService
1213
{
1314

15+
/// <inheritdoc />
16+
public Task<Dictionary<string, string>> GetEnvironmentSettingsAsync()
17+
{
18+
var environment = new Dictionary<string, string>();
19+
AddEnvironmentVariable(environment, Specification.PayrollDatabaseConnection);
20+
AddEnvironmentVariable(environment, Specification.PayrollApiKey);
21+
AddEnvironmentVariable(environment, Specification.PayrollApiConnection);
22+
AddEnvironmentVariable(environment, Specification.PayrollWebAppConnection);
23+
return Task.FromResult(environment);
24+
}
25+
26+
private static void AddEnvironmentVariable(Dictionary<string, string> environment, string variable)
27+
{
28+
var value = GetUserVariable(variable);
29+
if (!string.IsNullOrWhiteSpace(value))
30+
{
31+
environment.Add(variable, value);
32+
}
33+
}
34+
1435
#region Database
1536

1637
/// <inheritdoc />

Core/Setting/ISettingsService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
23
using PayrollEngine.AdminApp.Webserver;
34
using PayrollEngine.AdminApp.Persistence;
45

@@ -9,6 +10,11 @@ namespace PayrollEngine.AdminApp.Setting;
910
/// </summary>
1011
public interface ISettingsService
1112
{
13+
/// <summary>
14+
/// Get environment settings
15+
/// </summary>
16+
Task<Dictionary<string,string>> GetEnvironmentSettingsAsync();
17+
1218
/// <summary>
1319
/// Get the database connection string
1420
/// </summary>

Persistence.SqlServer/PayrollEngine.AdminApp.Persistence.SqlServer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
12-
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="172.52.0" />
11+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
12+
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="172.61.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

Presentation/Components/Assets/BackendAssetView.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<MudStack Spacing="2">
77
<MudStack Spacing="0" Row="true">
88
<MudText Typo="Typo.h5" Class="flex-grow-1">@Localizer.BackendLocalTitle</MudText>
9-
<MudText Color="Asset.BackendStatus.ToEditColor()">@Localizer.Enum(Asset.BackendStatus)</MudText>
9+
<MudText Color="Asset.BackendStatus.ToEditColor()">
10+
@(StatusUpdating ? string.Empty : Localizer.Enum(Asset.BackendStatus))
11+
</MudText>
1012
</MudStack>
1113

1214
@if (Asset.DatabaseStatus >= DatabaseStatus.EmptyDatabase)
@@ -43,6 +45,7 @@
4345
<MudTooltip Delay="1000" Text="@Localizer.Enum(Asset.WebserverStatus)" Placement="Placement.Left">
4446
<MudButton @onclick="@EditServerAsync"
4547
Class="ml-2"
48+
Disabled="@StatusUpdating"
4649
Color="@(Asset.WebserverStatus == WebserverStatus.UndefinedConnection ?
4750
Color.Success : Color.Primary)"
4851
Variant="@Globals.ButtonVariant"
@@ -57,6 +60,7 @@
5760
<MudTooltip Delay="1000" Text="@Localizer.OpenBackendHelp" Placement="Placement.Left">
5861
<MudButton @onclick="@BrowseServerAsync"
5962
Class="ml-2"
63+
Disabled="@StatusUpdating"
6064
Color="@Color.Primary"
6165
Variant="@Globals.ButtonVariant"
6266
EndIcon="@Icons.Material.Filled.Api"
@@ -70,6 +74,7 @@
7074
<MudTooltip Delay="1000" Text="@Localizer.StartHelp" Placement="Placement.Left">
7175
<MudButton @onclick="@StartServerAsync"
7276
Class="ml-2"
77+
Disabled="@StatusUpdating"
7378
Color="@Color.Success"
7479
Variant="@Globals.ButtonVariant"
7580
EndIcon="@Icons.Material.Filled.PlayCircleOutline"
@@ -117,6 +122,7 @@
117122
<MudTooltip Delay="1000" Text="@Localizer.Enum(Asset.DatabaseStatus)" Placement="Placement.Left">
118123
<MudButton @onclick="@EditConnectionAsync"
119124
Class="ml-2"
125+
Disabled="@StatusUpdating"
120126
Color="@(Asset.DatabaseStatus == DatabaseStatus.UndefinedConnection ?
121127
Color.Success : Color.Primary)"
122128
Variant="@Globals.ButtonVariant"
@@ -131,6 +137,7 @@
131137
<MudTooltip Delay="1000" Text="@Localizer.DatabaseUpdateHelp" Placement="Placement.Left">
132138
<MudButton @onclick="@SetupDatabaseAsync"
133139
Class="ml-2"
140+
Disabled="@StatusUpdating"
134141
Color="Color.Success"
135142
Variant="@Globals.ButtonVariant"
136143
EndIcon="@(Asset.DatabaseStatus.ReadyToUpdate() ?

0 commit comments

Comments
 (0)