Skip to content

Commit a5303d6

Browse files
committed
update AddLogicalService.ps1 in Example to Modern.CSharp.Templates version 2.0.0: adds automatic endpoint registration
1 parent a1365e1 commit a5303d6

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1-
Param(
1+
Param(
22
[Parameter(Mandatory, HelpMessage="The name (without 'Service' suffix) of the logical service to add to the CoreTeam multiservice solution in the current directory; used in the name of the new service project and in new namespaces + classes in the Apis and Contracts projects")]
33
[string]
44
$Name
55
)
6-
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes
6+
7+
# Function to update the Program.cs file to add a new parameter to the RegisterEndpoints method
8+
function Update-RegisterEndpoints {
9+
$newParameter = "`n typeof(Applicita.eShop.Apis.${Name}Api.${Name}Endpoints)`n"
10+
$apisDirectory = Join-Path -Path $PWD -ChildPath "Apis"
11+
$programFile = Get-ChildItem -Path $apisDirectory -Recurse -Filter "Program.cs" -ErrorAction SilentlyContinue | Select-Object -First 1
12+
13+
if ($programFile -ne $null) {
14+
$programContent = Get-Content -Path $programFile.FullName -Raw
15+
$pattern = "(?s)(app\s*\.RegisterEndpoints\s*\(.+?\))\s*\)"
16+
$modifiedContent = $programContent -replace $pattern, "`$1,$newParameter)"
17+
18+
if ($modifiedContent -ne $programContent) {
19+
Set-Content -Path $programFile.FullName -Value $modifiedContent
20+
Write-Output "Successfully added new parameter to RegisterEndpoints call in $($programFile.FullName):$newParameter"
21+
return
22+
}
23+
}
24+
25+
Write-Warning "Could not automatically add below parameter to the RegisterEndpoints(...) call; please add it manually:$newParameter"
26+
}
27+
28+
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes
29+
30+
Update-RegisterEndpoints
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1-
Param(
1+
Param(
22
[Parameter(Mandatory, HelpMessage="The name (without 'Service' suffix) of the logical service to add to the CoreTeam multiservice solution in the current directory; used in the name of the new service project and in new namespaces + classes in the Apis and Contracts projects")]
33
[string]
44
$Name
55
)
6-
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes
6+
7+
# Function to update the Program.cs file to add a new parameter to the RegisterEndpoints method
8+
function Update-RegisterEndpoints {
9+
$newParameter = "`n typeof(Applicita.eShop.Apis.${Name}Api.${Name}Endpoints)`n"
10+
$apisDirectory = Join-Path -Path $PWD -ChildPath "Apis"
11+
$programFile = Get-ChildItem -Path $apisDirectory -Recurse -Filter "Program.cs" -ErrorAction SilentlyContinue | Select-Object -First 1
12+
13+
if ($programFile -ne $null) {
14+
$programContent = Get-Content -Path $programFile.FullName -Raw
15+
$pattern = "(?s)(app\s*\.RegisterEndpoints\s*\(.+?\))\s*\)"
16+
$modifiedContent = $programContent -replace $pattern, "`$1,$newParameter)"
17+
18+
if ($modifiedContent -ne $programContent) {
19+
Set-Content -Path $programFile.FullName -Value $modifiedContent
20+
Write-Output "Successfully added new parameter to RegisterEndpoints call in $($programFile.FullName):$newParameter"
21+
return
22+
}
23+
}
24+
25+
Write-Warning "Could not automatically add below parameter to the RegisterEndpoints(...) call; please add it manually:$newParameter"
26+
}
27+
28+
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes
29+
30+
Update-RegisterEndpoints
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1-
Param(
1+
Param(
22
[Parameter(Mandatory, HelpMessage="The name (without 'Service' suffix) of the logical service to add to the CoreTeam multiservice solution in the current directory; used in the name of the new service project and in new namespaces + classes in the Apis and Contracts projects")]
33
[string]
44
$Name
55
)
6-
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes
6+
7+
# Function to update the Program.cs file to add a new parameter to the RegisterEndpoints method
8+
function Update-RegisterEndpoints {
9+
$newParameter = "`n typeof(Applicita.eShop.Apis.${Name}Api.${Name}Endpoints)`n"
10+
$apisDirectory = Join-Path -Path $PWD -ChildPath "Apis"
11+
$programFile = Get-ChildItem -Path $apisDirectory -Recurse -Filter "Program.cs" -ErrorAction SilentlyContinue | Select-Object -First 1
12+
13+
if ($programFile -ne $null) {
14+
$programContent = Get-Content -Path $programFile.FullName -Raw
15+
$pattern = "(?s)(app\s*\.RegisterEndpoints\s*\(.+?\))\s*\)"
16+
$modifiedContent = $programContent -replace $pattern, "`$1,$newParameter)"
17+
18+
if ($modifiedContent -ne $programContent) {
19+
Set-Content -Path $programFile.FullName -Value $modifiedContent
20+
Write-Output "Successfully added new parameter to RegisterEndpoints call in $($programFile.FullName):$newParameter"
21+
return
22+
}
23+
}
24+
25+
Write-Warning "Could not automatically add below parameter to the RegisterEndpoints(...) call; please add it manually:$newParameter"
26+
}
27+
28+
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes
29+
30+
Update-RegisterEndpoints

0 commit comments

Comments
 (0)