Skip to content

Commit

Permalink
Merge pull request #17 from cortside/issue-16
Browse files Browse the repository at this point in the history
[ISSUE-16] add support for multiple resultsets from report procs
  • Loading branch information
cYCL157 authored Dec 16, 2022
2 parents 7c76e35 + e98c4f9 commit b49945e
Show file tree
Hide file tree
Showing 181 changed files with 3,863 additions and 2,170 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,8 @@ coverage.opencover.xml
*.zip
.vscode/*

*.ncrunchproject
*.local.json
.refsignored

# don't set trigger on outbox table
src/sql/trigger/trOutbox.trigger.sql
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# cortside.webapistarter
# cortside.sqlreport

SqlReport is an RESTful api service that exposes presetup stored procedures as minimalistic reports that can be viewed or exported. Reports can be tied to permissons through authorization service so that users can only see what is granted.

# Pre-Requisites
* .NET 3.1 SDK
* Visual Studio 2019
* .NET 6.0 SDK
* Visual Studio 2022


5 changes: 4 additions & 1 deletion add-migration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ param(
[parameter(Mandatory=$true)][string]$migration
)

$repo = "Acme.WebApiStarter"
$repo = "Cortside.SqlReportApi"
$project = "src/$repo.Data"
$startup = "src/$repo.WebApi"
$context = "DatabaseContext"

echo "creating new migration $migration for $context context in project $project"
dotnet tool update --global dotnet-ef

dotnet ef migrations add $migration --project "$project" --startup-project "$startup" --context "$context"

dotnet build ./src

.\generate-sql.ps1
.\generate-sqltriggers.ps1
.\update-database.ps1

echo "done"
77 changes: 59 additions & 18 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,37 @@ version: 1.0.{build}
configuration:
- Debug

#platform: Any CPU
platform: Any CPU

pull_requests:
do_not_increment_build_number: true

environment:
# Don't report back to the mothership
DOTNET_CLI_TELEMETRY_OPTOUT: 1
JAVA_HOME: C:\Program Files\Java\jdk15
SONAR_TOKEN:
secure: fNmV/P8zSNwd3LWpzw2nnm807oe1Hr0gr11hTItGCXmnVQ0tHN1ESPUjLYjsXmpG
SONAR_PROJECT: cortside_cortside.sqlreportapi
RESTRICTED_WORDS:
secure: y2oCk9wYmgBAzk4m1tsSFUOlcEePEjozzMCfC0p6NQI=

init:
- ps: $Env:LABEL = "CI" + $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0")
- ps: Get-ChildItem "Env:"

assembly_info:
patch: true
file: '**\Assembly*Info.*'
file: '**\AssemblyInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'

dotnet_csproj:
patch: true
file: '**\*.csproj'
version: '{version}'
assembly_version: '{version}'
file_version: '{version}'

before_build:
- appveyor-retry dotnet restore src/Cortside.SqlReportApi.sln -v Minimal
- set DNX_BUILD_VERSION=%APPVEYOR_BUILD_NUMBER%
- appveyor-retry dotnet restore src -v Minimal
- set DNX_BUILD_VERSION=%APPVEYOR_BUILD_NUMBER%
- dotnet --info
- ps: ./prebuild.ps1

build:
publish_nuget: true
Expand All @@ -38,28 +43,64 @@ build:
verbosity: minimal

build_script:
- ps: ./build.ps1
- ps: >-
$version = $env:APPVEYOR_BUILD_VERSION;
$analysisArgs = "";
if (-not (Test-Path env:APPVEYOR_PULL_REQUEST_NUMBER)) {
$branch = $Env:APPVEYOR_REPO_BRANCH;
$analysisArgs = "/d:sonar.branch.name=""$branch""";
if ($branch -ne "master") {
$target = "develop";
if ($branch -eq "develop" -or $branch -like "release/*" -or $branch -like "hotfix/*") {
$target = "master";
}
$analysisArgs += " /d:sonar.newCode.referenceBranch=""$target""";
}
} else {
$branch = $Env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH;
$target = $Env:APPVEYOR_REPO_BRANCH;
$commit = $Env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT;
$pullRequestId = $Env:APPVEYOR_PULL_REQUEST_NUMBER;
$analysisArgs = "/d:sonar.scm.revision=""$commit"" /d:sonar.pullrequest.key=""$pullRequestId"" /d:sonar.pullrequest.base=""$target"" /d:sonar.pullrequest.branch=""$branch""";
}
$env:SOURCE_BRANCH="$branch";
$env:TARGET_BRANCH="$target";
$env:SONAR_ARGUMENTS="$analysisArgs";
echo "building version $version from branch $branch targeting $target with analysis arguments of $analysisArgs";
- dotnet tool install --global dotnet-sonarscanner
- echo "%SONAR_TOKEN%"
- dotnet sonarscanner begin /o:"cortside" /k:"%SONAR_PROJECT%" /v:"%APPVEYOR_BUILD_VERSION%" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="%SONAR_TOKEN%" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" %SONAR_ARGUMENTS%
- dotnet build src --no-restore --configuration %Configuration% /property:"Version=%APPVEYOR_BUILD_VERSION%"
- dotnet test src --no-restore --no-build --collect:"XPlat Code Coverage" --settings ./src/coverlet.runsettings.xml /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%"

after_build:
- ps: >-
$branch = $ENV:APPVEYOR_REPO_BRANCH;
$fileVersion = $env:APPVEYOR_BUILD_VERSION;
if($branch -ne 'master') {
$fileVersion = "${fileVersion}-${branch}";
}
$fileVersion = $fileVersion.replace("release/", "");
$fileVersion = $fileVersion.replace("feature/", "");
$fileVersion = $fileVersion.replace("bugfix/", "");
dotnet pack src --include-symbols -p:SymbolPackageFormat=snupkg --configuration $env:configuration -o ((get-location).Path + '\artifacts') /property:Version=$fileVersion
dotnet publish -r win-x64 -c Debug /p:PublishSingleFile=true /p:PublishTrimmed=true --output publish/win-x64 .\src\Cortside.SqlReportApi.WebApi;
dotnet publish -r linux-x64 -c Debug /p:PublishSingleFile=true /p:PublishTrimmed=true --output publish/linux-x64 .\src\Cortside.SqlReportApi.WebApi;
dotnet publish -r linux-musl-x64 -c Debug /p:PublishSingleFile=true /p:PublishTrimmed=true --output publish/linux-musl-x64 .\src\Cortside.SqlReportApi.WebApi;
#docker build -t cortside/sqlreport-api:1.0 .;
#- docker push cortside/healthmonitor:1.0;
- cmd: 7z a sqlreport-api.zip -r src/sql/* %APPVEYOR_BUILD_FOLDER%\publish\*
- cmd: appveyor PushArtifact sqlreport-api.zip


cache:
- '%USERPROFILE%\.nuget\packages'

nuget:
disable_publish_on_pr: true
# account_feed: true
# project_feed: true

test:
assemblies:
# - '**\Cortside.SqlReportApi.Test.dll'

artifacts:
- path: sqlreport-api.zip
name: deploy
Expand Down
12 changes: 6 additions & 6 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ if ($suffix){
}

# copy generated build.json to needed applications
cp .\src\build.json .\src\Cortside.SqlReportApi.WebApi\build.json -force
#cp .\src\build.json .\src\Cortside.SqlReportApi.WebApi\build.json -force

# build
$args = "clean $PSScriptRoot\src\Cortside.SqlReportApi.sln"
$args = "clean $PSScriptRoot\src"
Invoke-Exe -cmd dotnet -args $args
$args = "restore $PSScriptRoot\src\Cortside.SqlReportApi.sln --packages $PSScriptRoot\src\packages"
$args = "restore $PSScriptRoot\src --packages $PSScriptRoot\src\packages"
Invoke-Exe -cmd dotnet -args $args
$args = "build $PSScriptRoot\src\Cortside.SqlReportApi.sln --no-restore --configuration $msbuildconfig /p:Version=$BuildNumber"
$args = "build $PSScriptRoot\src --no-restore --configuration $msbuildconfig /p:Version=$BuildNumber"
Invoke-Exe -cmd dotnet -args $args
$args = "publish $PSScriptRoot\src\Cortside.SqlReportApi.WebApi\Cortside.SqlReportApi.WebApi.csproj --no-restore /p:Version=$BuildNumber"
Invoke-Exe -cmd dotnet -args $args
#$args = "publish $PSScriptRoot\src\Cortside.SqlReportApi.WebApi\Cortside.SqlReportApi.WebApi.csproj --no-restore /p:Version=$BuildNumber"
#Invoke-Exe -cmd dotnet -args $args
62 changes: 37 additions & 25 deletions clean.ps1
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
[cmdletBinding()]
param(
[switch]$quiet
)

Function remove {
param([string]$item)
If (Test-Path $item){
Write-Host "Removing $item"
if (-not $quiet.IsPresent) {
Write-Host "Removing $item"
}
Remove-Item $item -Force -Recurse
}
}

Function Invoke-Cleanup {
Write-Host "---------------------"
Write-Host "Invoke-Cleanup"
Write-Host "---------------------"
# clean package, bin and obj folders
Get-ChildItem .\ -include packages,bin,obj,node_modules -Recurse | Where-Object {$_.FullName -NotMatch "BuildScripts"} | foreach ($_) { Write-Host "Removing " + $_.fullname; remove-item $_.fullname -Force -Recurse }

#Find nunit files
Get-ChildItem -include *.nunit -Recurse |
ForEach-Object{
Write-Host $_

$results = $_.BaseName + ".xml"
If (Test-Path $results){
Write-Host "Removing $results"
Remove-Item $results
}
}

remove "TestResults"
remove "OpenCover"
remove "Publish"
remove "TestBin"

#return $true
if (-not $quiet.IsPresent) {
Write-Host "---------------------"
Write-Host "Invoke-Cleanup"
Write-Host "---------------------"
}

# clean package, bin and obj folders
Get-ChildItem .\ -include packages,bin,obj,node_modules -Recurse | Where-Object {$_.FullName -NotMatch "BuildScripts"} | foreach ($_) { Write-Host "Removing " + $_.fullname; remove-item $_.fullname -Force -Recurse }

#Find nunit files
Get-ChildItem -include *.nunit -Recurse |
ForEach-Object{
if (-not $quiet.IsPresent) {
Write-Host $_
}

$results = $_.BaseName + ".xml"
If (Test-Path $results){
if (-not $quiet.IsPresent) {
Write-Host "Removing $results"
}
Remove-Item $results
}
}

remove "TestResults"
remove "OpenCover"
remove "Publish"
remove "TestBin"
}

# stop extraneous processes
Expand Down
2 changes: 1 addition & 1 deletion convert-encoding.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Param(
)

Write-Output "===== USAGE EXAMPLE ====="
Write-Output 'PS C:\work\Acme.WebApiStarter> .\convert-encoding.ps1 -filePaths ((gci *.trigger.sql -Recurse) | % { $_.FullName })'
Write-Output 'PS C:\work\Cortside.SqlReportApi> .\convert-encoding.ps1 -filePaths ((gci *.trigger.sql -Recurse) | % { $_.FullName })'
Write-Output "========================="


Expand Down
2 changes: 1 addition & 1 deletion create-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if ($exists.Length -eq 0) {
git checkout develop
git merge $branch
./update-version.ps1
git commit -m "update version" .\src\version.json
git commit -m "update version" ./src/version.json
git push
} else {
echo "release branch already exists"
Expand Down
8 changes: 8 additions & 0 deletions export-seeddata.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$tables = @("Subject", "Widget")

foreach ($table in $tables) {
echo "exporting $table..."
$sql = "SELECT * FROM SqlReportApi.dbo.$table"
$filename = "src\\Cortside.SqlReportApi.WebApi.IntegrationTests\\SeedData\\$table.csv"
Invoke-Sqlcmd -Query $sql -HostName localhost | Export-Csv -Path $filename -NoTypeInformation
}
28 changes: 28 additions & 0 deletions find-projects-not-in-solutions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Function Global:Get-ProjectInSolution {
[CmdletBinding()] param (
[Parameter()][string]$Solution
)
$SolutionPath = Join-Path (Get-Location) $Solution
$SolutionFile = Get-Item $SolutionPath
$SolutionFolder = $SolutionFile.Directory.FullName

Get-Content $Solution |
Select-String 'Project\(' |
ForEach-Object {
$projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') }
[PSCustomObject]@{
File = $projectParts[2]
Guid = $projectParts[3]
Name = $projectParts[1]
}
} |
Where-Object File -match "csproj$" |
ForEach-Object {
Add-Member -InputObject $_ -NotePropertyName FullName -NotePropertyValue (Join-Path $SolutionFolder $_.File) -PassThru
}
}

Get-ProjectInSolution ./src/Cortside.SqlReportApi.sln | select-object Fullname | sort > projects.txt

gci *.csproj -r | select-object fullname | %{ $in = Select-String -Path .\projects.txt -SimpleMatch $_.FullName; if ($in -eq $null) { echo $_ } }

10 changes: 10 additions & 0 deletions fix-encoding.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
./clean.ps1

./convert-encoding.ps1 -filePaths ((gci *.ps1 -Recurse) | % { $_.FullName })
./convert-encoding.ps1 -filePaths ((gci *.cs -Recurse) | % { $_.FullName })
./convert-encoding.ps1 -filePaths ((gci *.csproj -Recurse) | % { $_.FullName })
./convert-encoding.ps1 -filePaths ((gci *.json -Recurse) | % { $_.FullName })
./convert-encoding.ps1 -filePaths ((gci *.sln -Recurse) | % { $_.FullName })
./convert-encoding.ps1 -filePaths ((gci *.sql -Recurse) | % { $_.FullName })

git status
2 changes: 1 addition & 1 deletion format.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Format code to match editorconfig settings
# Format code to match editorconfig settings
dotnet format --verbosity normal .\src
2 changes: 1 addition & 1 deletion generate-changelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $currentVersion = $a.version

# TODO: find current version in file if it exists and truncate to the end

$commits = (git --no-pager log --pretty=format:'| %h | <span style="white-space:nowrap;">%ad</span> | <span style="white-space:nowrap;">%aN</span> | %d %s' --date=short master.. | tac)
$commits = (git --no-pager log --pretty=format:'| %h | <span style="white-space:nowrap;">%ad</span> | <span style="white-space:nowrap;">%aN</span> | %d %s' --date=short master.. --reverse)

"" | Out-File CHANGELOG.md -Encoding utf8 -Append
"# Release $currentVersion" | Out-File CHANGELOG.md -Encoding utf8 -Append
Expand Down
2 changes: 1 addition & 1 deletion generate-sql.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$repo = "Acme.WebApiStarter"
$repo = "Cortside.SqlReportApi"
$project = "src/$repo.Data"
$startup = "src/$repo.WebApi"
$context = "DatabaseContext"
Expand Down
2 changes: 1 addition & 1 deletion generate-sqltriggers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Write-Output @("
start-sleep -Seconds 3

if ($PSScriptRoot.Contains(' ')) {
throw "Your working directory has a space in the path, which is not supported. Wise up and move to C:\work\Cortside.Template.api! And have a wonderful work day!"
throw "Your working directory has a space in the path, which is not supported. Wise up and move to C:\work\Cortside.SqlReportApi! And have a wonderful work day!"
exit
}

Expand Down
24 changes: 24 additions & 0 deletions git-prune.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Param
(
[Parameter(Mandatory = $false)][switch]$remote
)

# garbage collect
git gc --aggressive

# update local list of pruned branches on the remote to local:
git fetch --prune

if ($remote.IsPresent) {
# delete branches on remote origin that have been merge to master
git branch --merged remotes/origin/master -r | %{$_.trim().replace('origin/', '')} | ?{$_ -notmatch 'master'} | ?{$_ -notmatch 'develop'} | ?{$_ -notmatch 'release/*'} | %{ "delete remote $_"; git push --delete origin $_ }
} else {
# delete local branches that have been merged to master
git branch --merged remotes/origin/master | %{$_.trim()} | ?{$_ -notmatch 'master'} | ?{$_ -notmatch 'develop'} | ?{$_ -notmatch 'release/*'} | %{ "delete local $_"; git branch -d $_ }
}

# remove stale refs (local refs to branches that are gone on the remote)
git remote prune origin

# garbage collect
git gc --aggressive
16 changes: 16 additions & 0 deletions prebuild.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$fail = $false

#$env:RESTRICTED_WORDS="comma,separated,list"
$words =$($env:RESTRICTED_WORDS).Split(",")
$words |%{
& grep -R -i "$_" * |% { $_; $fail = $true }
}

$textFiles = git grep -Il .
git ls-files | where { $textFiles -notcontains $_ } | % { $_; $fail = $true }

if ($fail) {
throw "Found restricted words or unexpected binary files"
}

echo "prebuild check succeeded"
Loading

0 comments on commit b49945e

Please sign in to comment.