├── .dockerignore ├── .gitattributes ├── .github └── workflows │ ├── cleanup.yml │ ├── pipeline.yml │ ├── space-game-deploy.yml │ └── updater.yml ├── .gitignore ├── Dockerfile ├── Readme.md ├── database ├── database.sqlproj └── dbo │ └── Tables │ ├── Achievements.sql │ ├── Profile.sql │ ├── ProfileAchievements.sql │ └── Scores.sql ├── e2e-tests ├── package-lock.json ├── package.json ├── playwright.config.ts └── tests │ ├── download-game.spec.ts │ ├── navigate-leaderboard.spec.ts │ └── view-screenshots.spec.ts ├── gulpfile.js ├── iac ├── bicepconfig.json ├── db.bicep ├── deploy.ipynb ├── loadtest.bicep ├── main.bicep ├── registry.bicep └── webapp.bicep ├── load-tests ├── filters.csv ├── home-page.jmx └── home-page.yaml ├── package-lock.json ├── package.json ├── space-game.sln ├── unit-tests ├── DocumentDBRepository_GetItemsAsyncShould.cs └── unit-tests.csproj └── web-app ├── Controllers └── HomeController.cs ├── IDocumentDBRepository.cs ├── LocalDocumentDBRepository.cs ├── Models ├── ErrorViewModel.cs ├── LeaderboardViewModel.cs ├── Model.cs ├── Profile.cs ├── ProfileViewModel.cs └── Score.cs ├── Program.cs ├── Properties └── launchSettings.json ├── SampleData ├── profiles.json └── scores.json ├── Startup.cs ├── Views ├── Home │ ├── Index.cshtml │ ├── Privacy.cshtml │ └── Profile.cshtml ├── Shared │ ├── Error.cshtml │ ├── _CookieConsentPartial.cshtml │ ├── _Layout.cshtml │ └── _ValidationScriptsPartial.cshtml ├── _ViewImports.cshtml └── _ViewStart.cshtml ├── appsettings.Development.json ├── appsettings.json ├── web-app.csproj └── wwwroot ├── css ├── site.css ├── site.css.map ├── site.min.css └── site.scss ├── favicon.ico ├── images ├── avatars │ └── default.svg ├── placeholder.svg ├── space-background.svg ├── space-foreground.svg ├── space-game-placeholder.svg └── space-game-title.svg ├── js ├── site.js └── site.min.js └── lib ├── bootstrap ├── .bower.json ├── LICENSE └── dist │ ├── css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap-theme.min.css.map │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ └── bootstrap.min.css.map │ ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 │ └── js │ ├── bootstrap.js │ ├── bootstrap.min.js │ └── npm.js ├── jquery-validation-unobtrusive ├── .bower.json ├── LICENSE.txt ├── jquery.validate.unobtrusive.js └── jquery.validate.unobtrusive.min.js ├── jquery-validation ├── .bower.json ├── LICENSE.md └── dist │ ├── additional-methods.js │ ├── additional-methods.min.js │ ├── jquery.validate.js │ └── jquery.validate.min.js └── jquery ├── .bower.json ├── LICENSE.txt └── dist ├── jquery.js ├── jquery.min.js └── jquery.min.map /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/cleanup.yml: -------------------------------------------------------------------------------- 1 | name: cleanup 2 | 3 | on: 4 | pull_request: 5 | types: [closed] 6 | env: 7 | APPNAME: spacegamevnext 8 | jobs: 9 | cleanup: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Azure authentication 13 | uses: azure/login@v1 14 | with: 15 | creds: ${{ secrets.AZURE_CREDENTIALS }} 16 | - name: get source branch name for app 17 | run: | 18 | echo "BRANCH_NAME=$(echo ${{ github.event.pull_request.head.ref }} | sed 's/\//_/g')" >> $GITHUB_ENV 19 | - name: Cleanup dev environment after PR is closed 20 | run: az webapp delete --name ${{ env.APPNAME }}-dev-${{ env.BRANCH_NAME }} --resource-group ${{ env.APPNAME }}-dev-rg 21 | -------------------------------------------------------------------------------- /.github/workflows/pipeline.yml: -------------------------------------------------------------------------------- 1 | name: pipeline 2 | on: 3 | pull_request: 4 | branches: 5 | - main 6 | workflow_dispatch: 7 | 8 | env: 9 | APPNAME: spacegamevnext # Name of app. Used for prefix in resource group, service plan, app service, container images, sql server and database. 10 | REGISTRYNAME: "marcusfellingspacegamevnextacr" # Registry that is shared across environments 11 | LOCATION: "WestUS" # Region for all Azure resources 12 | 13 | jobs: 14 | build-app: 15 | name: Build - App 16 | runs-on: ubuntu-22.04 17 | steps: 18 | - uses: actions/checkout@v3.1.0 19 | 20 | - name: Azure authentication 21 | uses: azure/login@v1 22 | with: 23 | creds: ${{ secrets.AZURE_CREDENTIALS }} 24 | 25 | - uses: actions/setup-dotnet@v3.0.3 26 | with: 27 | dotnet-version: '7.0.x' 28 | 29 | - name: Build app and run unit tests 30 | run: | 31 | dotnet restore web-app/web-app.csproj 32 | dotnet restore unit-tests/unit-tests.csproj 33 | dotnet build web-app/web-app.csproj --configuration Release 34 | dotnet build unit-tests/unit-tests.csproj --configuration Release 35 | dotnet test unit-tests/unit-tests.csproj 36 | 37 | - name: Create Azure container registry using Bicep 38 | run: > 39 | az deployment group create \ 40 | --resource-group '${{ env.APPNAME }}-ACR-rg' \ 41 | --template-file iac/registry.bicep \ 42 | --parameters registry='${{ env.REGISTRYNAME }}' 43 | 44 | - name: ACR authentication 45 | uses: azure/docker-login@v1 46 | with: 47 | login-server: ${{ env.REGISTRYNAME }}.azurecr.io 48 | username: ${{ secrets.ACR_USERNAME }} 49 | password: ${{ secrets.ACR_PASSWORD }} 50 | 51 | - name: Docker Build & Push to ACR 52 | run: | 53 | docker login ${{ env.REGISTRYNAME }}.azurecr.io --username ${{ secrets.ACR_USERNAME }} --password ${{ secrets.ACR_PASSWORD }} 54 | docker build "$GITHUB_WORKSPACE" -f "Dockerfile" -t ${{ env.REGISTRYNAME }}.azurecr.io/${{ env.APPNAME }}:${{ github.sha }} 55 | docker push ${{ env.REGISTRYNAME }}.azurecr.io/${{ env.APPNAME }}:${{ github.sha }} 56 | 57 | build-database: 58 | name: Build - Database 59 | runs-on: windows-2022 60 | steps: 61 | - uses: actions/checkout@v3.1.0 62 | 63 | - name: setup-msbuild 64 | uses: microsoft/setup-msbuild@v1 65 | 66 | - name: Use MSBuild to build db project 67 | run: MSBuild.exe database/database.sqlproj 68 | 69 | - name: Copy dacpac before artifact Upload 70 | run: Copy-Item "database/bin/Debug/database.dacpac" -Destination "database.dacpac" 71 | 72 | - name: Upload dacpac as artifact 73 | uses: actions/upload-artifact@v3.1.1 74 | with: 75 | name: dacpac 76 | path: database.dacpac 77 | 78 | build-iac: 79 | name: Build - Infrastructure 80 | runs-on: ubuntu-22.04 81 | steps: 82 | - uses: actions/checkout@v3.1.0 83 | 84 | - name: Azure authentication 85 | uses: azure/login@v1 86 | with: 87 | creds: ${{ secrets.AZURE_CREDENTIALS }} 88 | 89 | - name: Validate Bicep templates to ensure transpilation, linting, and preflight are successful 90 | working-directory: iac 91 | env: 92 | ENVIRONMENTNAME: dev 93 | DEVENV: true 94 | run: | 95 | az deployment sub validate \ 96 | --name 'spacegamedeploy-${{ env.ENVIRONMENTNAME }}' \ 97 | --location '${{ env.LOCATION }}' \ 98 | --template-file main.bicep \ 99 | --parameters appName='${{ env.APPNAME }}' \ 100 | environmentName=${{ env.ENVIRONMENTNAME }} \ 101 | registryName='${{ env.REGISTRYNAME }}' \ 102 | tag='${{ github.sha }}' \ 103 | dbUserName='${{ secrets.DBUSERNAME }}' \ 104 | dbPassword='${{ secrets.DBPASSWORD }}' \ 105 | devEnv='${{ env.DEVENV }}' 106 | 107 | deploy-dev: 108 | uses: ./.github/workflows/space-game-deploy.yml 109 | secrets: inherit 110 | with: 111 | environment: 'dev' 112 | devenv: true 113 | envurl: https://spacegamevnext-dev-${{ github.HEAD_REF }}.azurewebsites.net 114 | concurrency: 115 | group: dev 116 | cancel-in-progress: true 117 | needs: [build-app, build-database, build-iac] 118 | 119 | deploy-test: 120 | uses: ./.github/workflows/space-game-deploy.yml 121 | secrets: inherit 122 | with: 123 | environment: 'test' 124 | devenv: false 125 | envurl: https://spacegamevnext-test.azurewebsites.net 126 | concurrency: 127 | group: test 128 | cancel-in-progress: true 129 | needs: [deploy-dev] 130 | 131 | test-e2e: 132 | name: Run E2E Tests 133 | runs-on: ubuntu-22.04 134 | container: mcr.microsoft.com/playwright:v1.27.0-focal 135 | environment: 136 | name: test 137 | url: https://spacegamevnext-test.azurewebsites.net 138 | concurrency: 139 | group: test 140 | cancel-in-progress: true 141 | env: 142 | ENVIRONMENTNAME: test-e2e 143 | BASEURL: https://spacegamevnext-test.azurewebsites.net # Playwright tests use this env var 144 | defaults: 145 | run: 146 | working-directory: e2e-tests 147 | needs: [deploy-test] 148 | steps: 149 | - uses: actions/checkout@v3.1.0 150 | - uses: actions/setup-node@v3.5.1 151 | with: 152 | node-version: "14.x" 153 | 154 | - name: Install dependencies 155 | run: npm ci 156 | 157 | - name: Run Playwright Tests 158 | continue-on-error: false 159 | run: | 160 | HOME=/root npx playwright test 161 | 162 | - name: Create test summary 163 | uses: test-summary/action@v2.0 164 | if: always() 165 | with: 166 | paths: e2e-tests/results/junit.xml 167 | 168 | - uses: actions/upload-artifact@v3.1.1 169 | name: Upload HTML report 170 | if: always() 171 | with: 172 | name: e2e-tests-report 173 | path: e2e-tests/results/html 174 | 175 | test-load: 176 | name: Run Load Tests 177 | runs-on: ubuntu-22.04 178 | environment: 179 | name: test-load 180 | url: https://spacegamevnext-test.azurewebsites.net 181 | concurrency: 182 | group: test-load 183 | cancel-in-progress: true 184 | env: 185 | ENVIRONMENTNAME: test 186 | needs: [deploy-test, test-e2e] 187 | steps: 188 | - uses: actions/checkout@v3.1.0 189 | 190 | - name: Azure authentication 191 | uses: azure/login@v1 192 | with: 193 | creds: ${{ secrets.AZURE_CREDENTIALS }} 194 | 195 | - name: "Azure Load Testing - Home Page Test" 196 | uses: azure/load-testing@v1 197 | with: 198 | loadTestConfigFile: "load-tests/home-page.yaml" 199 | loadTestResource: ${{ env.APPNAME }}-loadtest 200 | resourceGroup: ${{ env.APPNAME }}-loadtest-rg 201 | env: | 202 | [ 203 | { 204 | "name": "HOMEPAGE_URL", 205 | "value": "spacegamevnext-test.azurewebsites.net" 206 | } 207 | ] 208 | 209 | deploy-prod: 210 | uses: ./.github/workflows/space-game-deploy.yml 211 | secrets: inherit 212 | with: 213 | environment: 'prod' 214 | devenv: false 215 | envurl: https://spacegamevnext-prod.azurewebsites.net 216 | concurrency: 217 | group: prod 218 | cancel-in-progress: true 219 | needs: [deploy-test, test-load, test-e2e] 220 | -------------------------------------------------------------------------------- /.github/workflows/space-game-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Resuable workflow for deployments 2 | 3 | # set env vars in template until this limitation is "fixed" https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations 4 | env: 5 | APPNAME: spacegamevnext # Name of app. Used for prefix in resource group, service plan, app service, container images, sql server and database. 6 | REGISTRYNAME: "marcusfellingspacegamevnextacr" # Registry that is shared across environments 7 | LOCATION: "WestUS" # Region for all Azure resources 8 | 9 | on: 10 | workflow_call: 11 | inputs: 12 | environment: 13 | required: true 14 | type: string 15 | devenv: # used for conditionals like deploy slots that don't exist in dev 16 | required: true 17 | type: string 18 | envurl: 19 | required: true 20 | type: string 21 | 22 | jobs: 23 | deploy: 24 | name: Deploy to ${{ inputs.environment }} 25 | environment: 26 | name: ${{ inputs.environment }} 27 | url: ${{ inputs.envurl }} 28 | runs-on: ubuntu-22.04 29 | steps: 30 | - uses: actions/checkout@v3.1.0 31 | 32 | - name: Dump GitHub context 33 | env: 34 | GITHUB_CONTEXT: ${{ toJSON(github) }} 35 | run: echo "$GITHUB_CONTEXT" 36 | 37 | - name: Azure authentication 38 | uses: azure/login@v1 39 | with: 40 | creds: ${{ secrets.AZURE_CREDENTIALS }} 41 | 42 | - name: Deploy infrastructure (dev) 43 | if: ${{ inputs.devenv == 'true' }} 44 | run: > 45 | az deployment sub create \ 46 | --name 'spacegamedeploy-${{ inputs.environment }}' \ 47 | --location '${{ env.LOCATION }}' \ 48 | --template-file iac/main.bicep \ 49 | --parameters appName='${{ env.APPNAME }}' \ 50 | environmentName=${{ inputs.environment }} \ 51 | branch='-${{ github.HEAD_REF }}' \ 52 | registryName='${{ env.REGISTRYNAME }}' \ 53 | tag='${{ github.sha }}' \ 54 | dbUserName='${{ secrets.DBUSERNAME }}' \ 55 | dbPassword='${{ secrets.DBPASSWORD }}' \ 56 | devEnv='${{ inputs.devenv }}' 57 | 58 | - name: Deploy infrastructure 59 | if: ${{ inputs.devenv == 'false' }} 60 | run: > 61 | az deployment sub create \ 62 | --name 'spacegamedeploy-${{ inputs.environment }}' \ 63 | --location '${{ env.LOCATION }}' \ 64 | --template-file iac/main.bicep \ 65 | --parameters appName='${{ env.APPNAME }}' \ 66 | environmentName=${{ inputs.environment }} \ 67 | registryName='${{ env.REGISTRYNAME }}' \ 68 | tag='${{ github.sha }}' \ 69 | dbUserName='${{ secrets.DBUSERNAME }}' \ 70 | dbPassword='${{ secrets.DBPASSWORD }}' \ 71 | devEnv='${{ inputs.devenv }}' 72 | 73 | - uses: actions/download-artifact@v3.0.1 74 | name: Download dacpac from build 75 | with: 76 | name: dacpac 77 | 78 | - name: Deploy Database using dacpac 79 | uses: docker://markhobson/sqlpackage:latest # Use container with sqlpackage.exe 80 | with: 81 | args: /SourceFile:"database.dacpac" /Action:Publish /TargetServerName:"${{ env.APPNAME }}-${{ inputs.environment }}-sql.database.windows.net" /TargetDatabaseName:"${{ env.APPNAME }}database" /TargetUser:"${{ secrets.DBUSERNAME }}" /TargetPassword:"${{ secrets.DBPASSWORD }}" 82 | 83 | - name: "Deploy to Azure Web App for Containers (dev)" 84 | if: ${{ inputs.devenv == 'true' }} 85 | uses: azure/webapps-deploy@v2 86 | with: 87 | app-name: "${{ env.APPNAME }}-${{ inputs.environment }}-${{ github.HEAD_REF }}" 88 | images: ${{ env.REGISTRYNAME }}.azurecr.io/${{ env.APPNAME }}:${{ github.sha }} 89 | 90 | - name: "Deploy to Azure Web App for Containers slot" 91 | if: ${{ inputs.devenv == 'false' }} 92 | uses: azure/webapps-deploy@v2 93 | with: 94 | app-name: "${{ env.APPNAME }}-${{ inputs.environment }}" 95 | slot-name: "swap" 96 | images: ${{ env.REGISTRYNAME }}.azurecr.io/${{ env.APPNAME }}:${{ github.sha }} 97 | 98 | - name: Swap slots for no downtime deploy 99 | if: ${{ inputs.devenv == 'false' }} 100 | run: | 101 | az webapp deployment slot swap -g '${{ env.APPNAME }}-${{ inputs.environment }}-rg' -n '${{ env.APPNAME }}-${{ inputs.environment }}' --slot 'swap' --target-slot 'production' 102 | -------------------------------------------------------------------------------- /.github/workflows/updater.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Actions Version Updater 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | # Automatically run on every Sunday 7 | - cron: '0 0 * * 0' 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3.1.0 13 | with: 14 | token: ${{ secrets.UPDATER_SECRET }} 15 | 16 | - name: Run GitHub Actions Version Updater 17 | uses: saadmk11/github-actions-version-updater@v0.7.1 18 | with: 19 | token: ${{ secrets.UPDATER_SECRET }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build 04results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # Playwright tests 5 | e2e-tests/results/ 6 | e2e-tests/test-results/ 7 | e2e-tests/playwright-report/ 8 | e2e-tests/playwright/.cache/ 9 | e2e-tests/storageState.json 10 | e2e-tests/.env 11 | 12 | 13 | # User-specific files 14 | *.suo 15 | *.user 16 | *.userosscache 17 | *.sln.docstates 18 | 19 | # User-specific files (MonoDevelop/Xamarin Studio) 20 | *.userprefs 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | 34 | # Visual Studio 2015 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # MSTest test Results 40 | [Tt]est[Rr]esult*/ 41 | [Bb]uild[Ll]og.* 42 | 43 | # NUNIT 44 | *.VisualState.xml 45 | TestResult.xml 46 | 47 | # Build Results of an ATL Project 48 | [Dd]ebugPS/ 49 | [Rr]eleasePS/ 50 | dlldata.c 51 | 52 | # DNX 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | *_i.c 58 | *_p.c 59 | *_i.h 60 | *.ilk 61 | *.meta 62 | *.obj 63 | *.pch 64 | *.pdb 65 | *.pgc 66 | *.pgd 67 | *.rsp 68 | *.sbr 69 | *.tlb 70 | *.tli 71 | *.tlh 72 | *.tmp 73 | *.tmp_proj 74 | *.log 75 | *.vspscc 76 | *.vssscc 77 | .builds 78 | *.pidb 79 | *.svclog 80 | *.scc 81 | 82 | # Chutzpah Test files 83 | _Chutzpah* 84 | 85 | # Visual C++ cache files 86 | ipch/ 87 | *.aps 88 | *.ncb 89 | *.opendb 90 | *.opensdf 91 | *.sdf 92 | *.cachefile 93 | *.VC.db 94 | *.VC.VC.opendb 95 | 96 | # Visual Studio profiler 97 | *.psess 98 | *.vsp 99 | *.vspx 100 | *.sap 101 | 102 | # TFS 2012 Local Workspace 103 | $tf/ 104 | 105 | # Guidance Automation Toolkit 106 | *.gpState 107 | 108 | # ReSharper is a .NET coding add-in 109 | _ReSharper*/ 110 | *.[Rr]e[Ss]harper 111 | *.DotSettings.user 112 | 113 | # JustCode is a .NET coding add-in 114 | .JustCode 115 | 116 | # TeamCity is a build add-in 117 | _TeamCity* 118 | 119 | # DotCover is a Code Coverage Tool 120 | *.dotCover 121 | 122 | # NCrunch 123 | _NCrunch_* 124 | .*crunch*.local.xml 125 | nCrunchTemp_* 126 | 127 | # MightyMoose 128 | *.mm.* 129 | AutoTest.Net/ 130 | 131 | # Web workbench (sass) 132 | .sass-cache/ 133 | 134 | # Installshield output folder 135 | [Ee]xpress/ 136 | 137 | # DocProject is a documentation generator add-in 138 | DocProject/buildhelp/ 139 | DocProject/Help/*.HxT 140 | DocProject/Help/*.HxC 141 | DocProject/Help/*.hhc 142 | DocProject/Help/*.hhk 143 | DocProject/Help/*.hhp 144 | DocProject/Help/Html2 145 | DocProject/Help/html 146 | 147 | # Click-Once directory 148 | publish/ 149 | 150 | # Publish Web Output 151 | *.[Pp]ublish.xml 152 | *.azurePubxml 153 | # TODO: Comment the next line if you want to checkin your web deploy settings 154 | # but database connection strings (with potential passwords) will be unencrypted 155 | #*.pubxml 156 | *.publishproj 157 | 158 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 159 | # checkin your Azure Web App publish settings, but sensitive information contained 160 | # in these scripts will be unencrypted 161 | PublishScripts/ 162 | 163 | # NuGet Packages 164 | *.nupkg 165 | # The packages folder can be ignored because of Package Restore 166 | **/packages/* 167 | # except build/, which is used as an MSBuild target. 168 | !**/packages/build/ 169 | # Uncomment if necessary however generally it will be regenerated when needed 170 | #!**/packages/repositories.config 171 | # NuGet v3's project.json files produces more ignoreable files 172 | *.nuget.props 173 | *.nuget.targets 174 | 175 | # Microsoft Azure Build Output 176 | csx/ 177 | *.build.csdef 178 | 179 | # Microsoft Azure Emulator 180 | ecf/ 181 | rcf/ 182 | 183 | # Windows Store app package directories and files 184 | AppPackages/ 185 | BundleArtifacts/ 186 | Package.StoreAssociation.xml 187 | _pkginfo.txt 188 | 189 | # Visual Studio cache files 190 | # files ending in .cache can be ignored 191 | *.[Cc]ache 192 | # but keep track of directories ending in .cache 193 | !*.[Cc]ache/ 194 | 195 | # Others 196 | ClientBin/ 197 | ~$* 198 | *~ 199 | *.dbmdl 200 | *.dbproj.schemaview 201 | *.jfm 202 | *.pfx 203 | *.publishsettings 204 | node_modules/ 205 | orleans.codegen.cs 206 | 207 | # Since there are multiple workflows, uncomment next line to ignore bower_components 208 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 209 | #bower_components/ 210 | 211 | # RIA/Silverlight projects 212 | Generated_Code/ 213 | 214 | # Backup & report files from converting an old project file 215 | # to a newer Visual Studio version. Backup files are not needed, 216 | # because we have git ;-) 217 | _UpgradeReport_Files/ 218 | Backup*/ 219 | UpgradeLog*.XML 220 | UpgradeLog*.htm 221 | 222 | # SQL Server files 223 | *.mdf 224 | *.ldf 225 | 226 | # Business Intelligence projects 227 | *.rdl.data 228 | *.bim.layout 229 | *.bim_*.settings 230 | 231 | # Microsoft Fakes 232 | FakesAssemblies/ 233 | 234 | # GhostDoc plugin setting file 235 | *.GhostDoc.xml 236 | 237 | # Node.js Tools for Visual Studio 238 | .ntvs_analysis.dat 239 | 240 | # Visual Studio 6 build log 241 | *.plg 242 | 243 | # Visual Studio 6 workspace options file 244 | *.opt 245 | 246 | # Visual Studio LightSwitch build output 247 | **/*.HTMLClient/GeneratedArtifacts 248 | **/*.DesktopClient/GeneratedArtifacts 249 | **/*.DesktopClient/ModelManifest.xml 250 | **/*.Server/GeneratedArtifacts 251 | **/*.Server/ModelManifest.xml 252 | _Pvt_Extensions 253 | 254 | # Paket dependency manager 255 | .paket/paket.exe 256 | paket-files/ 257 | 258 | # FAKE - F# Make 259 | .fake/ 260 | 261 | # JetBrains Rider 262 | .idea/ 263 | *.sln.iml 264 | 265 | # CodeRush 266 | .cr/ 267 | 268 | # Python Tools for Visual Studio (PTVS) 269 | __pycache__/ 270 | *.pyc 271 | 272 | # Generated ARM Templates 273 | IaC\main.json -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base 2 | WORKDIR /app 3 | EXPOSE 80 4 | EXPOSE 443 5 | 6 | FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build 7 | WORKDIR /src 8 | 9 | COPY ["web-app/web-app.csproj", "web-app/"] 10 | RUN dotnet restore "web-app/web-app.csproj" 11 | COPY . . 12 | WORKDIR "/src/web-app" 13 | RUN dotnet build "web-app.csproj" -c Release -o /app/build 14 | 15 | FROM build AS publish 16 | RUN dotnet publish "web-app.csproj" -c Release -o /app/publish 17 | 18 | FROM base AS final 19 | WORKDIR /app 20 | COPY --from=publish /app/publish . 21 | ENTRYPOINT ["dotnet", "web-app.dll"] -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # demo-space-game-vnext 2 | 3 | ![spaceGame](https://user-images.githubusercontent.com/6855361/111529516-3efed480-8730-11eb-9a73-a1f4727f3b21.PNG) 4 | 5 | The next iteration of [demo-space-game](https://github.com/MarcusFelling/Demo.SpaceGame), now using containers and GitHub Actions 🚀! 6 | 7 | The Space Game website is a .NET 7 web app that's deployed to ☁️ Azure Web App for Containers and Azure SQL ☁️. The infrastructure is deployed using [Azure Bicep](https://github.com/Azure/bicep) 💪, and the application is tested using [Playwright](https://playwright.dev/) for browser tests and [Azure Load Testing](https://azure.microsoft.com/services/load-testing/) for load tests. 8 | 9 | ## CI/CD Workflow 10 | 11 | The main branch is set up with a [branch protection rule](https://docs.github.com/en/github/administering-a-repository/managing-a-branch-protection-rule#:~:text=You%20can%20create%20a%20branch,merged%20into%20the%20protected%20branch.) that require all of the jobs in the [pipeline](https://github.com/MarcusFelling/demo-space-game-vnext/actions/workflows/pipeline.yml) succeed. This means the topic branch that is targeting main will need to make it through the entirety of the pipeline before the PR can be completed and merged into main. 12 | 13 | 1. The build stage of the pipeline ensures all projects successfully compile and unit tests pass. 14 | 1. The pipeline will provision a new website for your branch that can be used for exploratory testing or remote debugging. The URL of the new website will post to the Environments section of the PR. Click "View Deployment" to open the site: 15 | ![environment](https://user-images.githubusercontent.com/6855361/111533320-a61e8800-8734-11eb-93d4-b2f4883313b3.PNG) 16 | 1. Meanwhile, the pipeline will execute functional and load tests in a testing environment. 17 | 1. If all tests are successful, the pipeline will deploy to production. 18 | 1. After the PR is merged, a final [workflow](https://github.com/MarcusFelling/demo-space-game-vnext/blob/main/.github/workflows/cleanup.yml) will run to clean up the development environment. 19 | 20 | ![image](https://user-images.githubusercontent.com/6855361/162650030-869aea0c-b666-4454-9c02-35e0f0221408.png) 21 | -------------------------------------------------------------------------------- /database/database.sqlproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | database 7 | 2.0 8 | 4.1 9 | {8baa5c4e-f217-4e45-8473-1ebae2684bff} 10 | Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider 11 | Database 12 | 13 | 14 | Database 15 | Database 16 | 1033,CI 17 | BySchemaAndSchemaType 18 | True 19 | v4.8 20 | CS 21 | Properties 22 | False 23 | True 24 | True 25 | SQL_Latin1_General_CP1_CI_AS 26 | PRIMARY 27 | ReadOnly 28 | 29 | database 30 | 31 | 32 | bin\Release\ 33 | $(MSBuildProjectName).sql 34 | False 35 | pdbonly 36 | true 37 | false 38 | true 39 | prompt 40 | 4 41 | 42 | 43 | bin\Debug\ 44 | $(MSBuildProjectName).sql 45 | false 46 | true 47 | full 48 | false 49 | true 50 | true 51 | prompt 52 | 4 53 | 54 | 55 | 11.0 56 | 57 | True 58 | 11.0 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /database/dbo/Tables/Achievements.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Achievements] ( 2 | [id] INT NOT NULL, 3 | [description] NVARCHAR (50) NULL, 4 | PRIMARY KEY CLUSTERED ([id] ASC) 5 | ); -------------------------------------------------------------------------------- /database/dbo/Tables/Profile.sql: -------------------------------------------------------------------------------- 1 |  2 | CREATE TABLE [dbo].[Profiles] ( 3 | [id] INT NOT NULL, 4 | [userName] NVARCHAR (50) NOT NULL, 5 | [avatarUrl] NVARCHAR (50) NULL, 6 | PRIMARY KEY CLUSTERED ([id] ASC) 7 | ); -------------------------------------------------------------------------------- /database/dbo/Tables/ProfileAchievements.sql: -------------------------------------------------------------------------------- 1 |  2 | CREATE TABLE [dbo].[ProfileAchievements] ( 3 | [profileId] INT NOT NULL, 4 | [achievementId] INT NOT NULL, 5 | PRIMARY KEY CLUSTERED ([profileId], [achievementId]) 6 | ); 7 | 8 | GO 9 | 10 | ALTER TABLE [dbo].[ProfileAchievements] 11 | ADD CONSTRAINT [FK_ProfileAchievements_Profiles] FOREIGN KEY ([profileId]) REFERENCES [dbo].[Profiles] ([id]); 12 | GO 13 | ALTER TABLE [dbo].[ProfileAchievements] 14 | ADD CONSTRAINT [FK_ProfileAchievements_Achievements] FOREIGN KEY ([achievementId]) REFERENCES [dbo].[Achievements] ([id]); 15 | GO -------------------------------------------------------------------------------- /database/dbo/Tables/Scores.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[Scores] 2 | ( 3 | [id] INT NOT NULL PRIMARY KEY, 4 | [profileId] INT NOT NULL, 5 | [score] INT NULL, 6 | [gameMode] NVARCHAR(10) NULL, 7 | [gameRegion] NVARCHAR(50) NULL, 8 | CONSTRAINT [FK_Scores_Profiles] FOREIGN KEY ([profileId]) REFERENCES [Profiles]([id]) 9 | ) -------------------------------------------------------------------------------- /e2e-tests/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "e2e-tests", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": { 6 | "": { 7 | "dependencies": { 8 | "dotenv": "^16.0.3" 9 | }, 10 | "devDependencies": { 11 | "@playwright/test": "^1.27.0", 12 | "@types/node": "^18.11.0" 13 | } 14 | }, 15 | "node_modules/@playwright/test": { 16 | "version": "1.27.1", 17 | "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.27.1.tgz", 18 | "integrity": "sha512-mrL2q0an/7tVqniQQF6RBL2saskjljXzqNcCOVMUjRIgE6Y38nCNaP+Dc2FBW06bcpD3tqIws/HT9qiMHbNU0A==", 19 | "dev": true, 20 | "dependencies": { 21 | "@types/node": "*", 22 | "playwright-core": "1.27.1" 23 | }, 24 | "bin": { 25 | "playwright": "cli.js" 26 | }, 27 | "engines": { 28 | "node": ">=14" 29 | } 30 | }, 31 | "node_modules/@types/node": { 32 | "version": "18.11.0", 33 | "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.0.tgz", 34 | "integrity": "sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w==", 35 | "dev": true 36 | }, 37 | "node_modules/dotenv": { 38 | "version": "16.0.3", 39 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", 40 | "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", 41 | "engines": { 42 | "node": ">=12" 43 | } 44 | }, 45 | "node_modules/playwright-core": { 46 | "version": "1.27.1", 47 | "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.27.1.tgz", 48 | "integrity": "sha512-9EmeXDncC2Pmp/z+teoVYlvmPWUC6ejSSYZUln7YaP89Z6lpAaiaAnqroUt/BoLo8tn7WYShcfaCh+xofZa44Q==", 49 | "dev": true, 50 | "bin": { 51 | "playwright": "cli.js" 52 | }, 53 | "engines": { 54 | "node": ">=14" 55 | } 56 | } 57 | }, 58 | "dependencies": { 59 | "@playwright/test": { 60 | "version": "1.27.1", 61 | "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.27.1.tgz", 62 | "integrity": "sha512-mrL2q0an/7tVqniQQF6RBL2saskjljXzqNcCOVMUjRIgE6Y38nCNaP+Dc2FBW06bcpD3tqIws/HT9qiMHbNU0A==", 63 | "dev": true, 64 | "requires": { 65 | "@types/node": "*", 66 | "playwright-core": "1.27.1" 67 | } 68 | }, 69 | "@types/node": { 70 | "version": "18.11.0", 71 | "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.0.tgz", 72 | "integrity": "sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w==", 73 | "dev": true 74 | }, 75 | "dotenv": { 76 | "version": "16.0.3", 77 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", 78 | "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" 79 | }, 80 | "playwright-core": { 81 | "version": "1.27.1", 82 | "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.27.1.tgz", 83 | "integrity": "sha512-9EmeXDncC2Pmp/z+teoVYlvmPWUC6ejSSYZUln7YaP89Z6lpAaiaAnqroUt/BoLo8tn7WYShcfaCh+xofZa44Q==", 84 | "dev": true 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /e2e-tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@playwright/test": "^1.27.0", 4 | "@types/node": "^18.11.0" 5 | }, 6 | "dependencies": { 7 | "dotenv": "^16.0.3" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /e2e-tests/playwright.config.ts: -------------------------------------------------------------------------------- 1 | import type { PlaywrightTestConfig } from '@playwright/test'; 2 | import { devices } from '@playwright/test'; 3 | /** 4 | * Read environment variables from file for local development. 5 | * https://github.com/motdotla/dotenv 6 | */ 7 | require('dotenv').config(); 8 | 9 | // Reference: https://playwright.dev/docs/test-configuration 10 | const config: PlaywrightTestConfig = { 11 | testDir: 'tests', 12 | /* Maximum time one test can run for. */ 13 | timeout: 60 * 1000, 14 | expect: { 15 | /** 16 | * Maximum time expect() should wait for the condition to be met. 17 | * For example in `await expect(locator).toHaveText();` 18 | */ 19 | timeout: 5000, 20 | }, 21 | // If a test fails, retry it additional 2 times 22 | retries: 2, 23 | /* Reporter to use. See https://playwright.dev/docs/test-reporters */ 24 | reporter: [ 25 | ['list'], 26 | ['junit', { outputFile: './results/junit.xml' }], 27 | ['html', { outputFolder: './results/html' }], 28 | ], 29 | use: { 30 | // Run headless by default 31 | headless: true, 32 | // Use env var to set baseURL 33 | baseURL: process.env.BASEURL, 34 | // Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. 35 | // More information: https://playwright.dev/docs/trace-viewer 36 | trace: 'on', 37 | // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context 38 | contextOptions: { 39 | ignoreHTTPSErrors: true, 40 | }, 41 | 42 | acceptDownloads: true, 43 | }, 44 | projects: [ 45 | { 46 | name: 'Desktop Chrome', 47 | use: { 48 | ...devices['Desktop Chrome'], 49 | }, 50 | }, 51 | { 52 | name: 'Desktop Edge', 53 | use: { 54 | ...devices['Desktop Edge'], 55 | }, 56 | }, 57 | { 58 | name: 'Desktop Firefox', 59 | use: { 60 | ...devices['Desktop Firefox HiDPI'], 61 | }, 62 | }, 63 | // Test against mobile viewports. 64 | { 65 | name: 'Mobile Chrome', 66 | use: { 67 | ...devices['Pixel 5'], 68 | }, 69 | }, 70 | ], 71 | }; 72 | export default config; 73 | -------------------------------------------------------------------------------- /e2e-tests/tests/download-game.spec.ts: -------------------------------------------------------------------------------- 1 | import { test, expect } from '@playwright/test'; 2 | 3 | test.beforeEach(async ({ page }) => { 4 | await page.goto(''); 5 | }); 6 | 7 | test.skip('Download game', async ({ page }) => { 8 | // Go to download page 9 | await page.getByRole('link', { name: 'Download game' }).click(); 10 | // Click download button 11 | await page.getByRole('link', { name: 'Download APK (8 MB)' }).first().click(); 12 | // Wrap download click in promise to wait for download 13 | const [download] = await Promise.all([ 14 | // Start waiting for the download 15 | page.waitForEvent('download'), 16 | // Initiate the download 17 | page.getByRole('link', { name: 'Fake Game Collection 2.0.21\n(21) APK 8 MB Android 5.0+ nodpi' }).click() 18 | ]); 19 | // Save downloaded file 20 | await download.saveAs('/not/a/real/path/fake.apk'); 21 | }); 22 | -------------------------------------------------------------------------------- /e2e-tests/tests/navigate-leaderboard.spec.ts: -------------------------------------------------------------------------------- 1 | import { test, expect } from '@playwright/test'; 2 | 3 | test.beforeEach(async ({ page }) => { 4 | await page.goto(''); 5 | }); 6 | 7 | test('Navigate leadboard', async ({ page }) => { 8 | // Leaderboard section should have Space leaders header 9 | await expect(page.locator('section.leaderboard > div > h2')).toHaveText('Space leaders'); 10 | // Click #1 ranked profile 11 | await page.locator('[data-target="#profile-modal-1"]').click(); 12 | // Make sure profile is ranked #1 13 | await page.getByText('Rank #1').first().click(); 14 | // Make sure profile has at least 1 achievement 15 | const length = await page.$$eval('div.modal-body > div > div.col-sm-8 > div > ul', (items) => items.length); 16 | expect(length >= 1).toBeTruthy(); 17 | // Close profile modal 18 | await page.locator('[data-dismiss="modal"] >> nth=0').click(); 19 | // Paginate results 20 | await page.getByText('2', { exact: true }).click(); 21 | await page.getByText('3', { exact: true }).click(); 22 | await page.getByText('1', { exact: true }).click(); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e-tests/tests/view-screenshots.spec.ts: -------------------------------------------------------------------------------- 1 | import { test } from '@playwright/test'; 2 | 3 | test.beforeEach(async ({ page }) => { 4 | await page.goto(''); 5 | }); 6 | 7 | test('View game screenshot examples', async ({ page }) => { 8 | // Loop through each game screenshot example 9 | for (const screenshot of ['screenshot-1', 'screenshot-2', 'screenshot-3', 'screenshot-4']) { 10 | // Click each screenshot example using data-test-id 11 | await page.locator("data-test-id=" + screenshot).click(); 12 | // Close screenshot 13 | await page.locator('text=× Gamescreen example >> button.close').click(); 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /// 2 | "use strict"; 3 | 4 | const gulp = require("gulp"), 5 | rimraf = require("rimraf"), 6 | concat = require("gulp-concat"), 7 | cssmin = require("gulp-cssmin"), 8 | uglify = require("gulp-uglify"); 9 | 10 | const paths = { 11 | webroot: "./wwwroot/" 12 | }; 13 | 14 | paths.js = paths.webroot + "js/**/*.js"; 15 | paths.minJs = paths.webroot + "js/**/*.min.js"; 16 | paths.css = paths.webroot + "css/**/*.css"; 17 | paths.minCss = paths.webroot + "css/**/*.min.css"; 18 | paths.concatJsDest = paths.webroot + "js/site.min.js"; 19 | paths.concatCssDest = paths.webroot + "css/site.min.css"; 20 | 21 | gulp.task("clean:js", done => rimraf(paths.concatJsDest, done)); 22 | gulp.task("clean:css", done => rimraf(paths.concatCssDest, done)); 23 | gulp.task("clean", gulp.series(["clean:js", "clean:css"])); 24 | 25 | gulp.task("min:js", () => { 26 | return gulp.src([paths.js, "!" + paths.minJs], { base: "." }) 27 | .pipe(concat(paths.concatJsDest)) 28 | .pipe(uglify()) 29 | .pipe(gulp.dest(".")); 30 | }); 31 | 32 | gulp.task("min:css", () => { 33 | return gulp.src([paths.css, "!" + paths.minCss]) 34 | .pipe(concat(paths.concatCssDest)) 35 | .pipe(cssmin()) 36 | .pipe(gulp.dest(".")); 37 | }); 38 | 39 | gulp.task("min", gulp.series(["min:js", "min:css"])); 40 | 41 | // A 'default' task is required by Gulp v4 42 | gulp.task("default", gulp.series(["min"])); -------------------------------------------------------------------------------- /iac/bicepconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "analyzers": { 3 | "core": { 4 | "verbose": false, 5 | "enabled": true, 6 | "rules": { 7 | "no-hardcoded-env-urls": { 8 | "level": "error", 9 | "disallowedhosts": [ 10 | "management.core.windows.net", 11 | "gallery.azure.com", 12 | "management.core.windows.net", 13 | "management.azure.com", 14 | "database.windows.net", 15 | "core.windows.net", 16 | "login.microsoftonline.com", 17 | "graph.windows.net", 18 | "trafficmanager.net", 19 | "vault.azure.net", 20 | "datalake.azure.net", 21 | "azuredatalakestore.net", 22 | "azuredatalakeanalytics.net", 23 | "vault.azure.net", 24 | "api.loganalytics.io", 25 | "api.loganalytics.iov1", 26 | "asazure.windows.net", 27 | "region.asazure.windows.net", 28 | "api.loganalytics.iov1", 29 | "api.loganalytics.io", 30 | "asazure.windows.net", 31 | "region.asazure.windows.net", 32 | "batch.core.windows.net" 33 | ] 34 | }, 35 | "no-unused-params": { 36 | "level": "error" 37 | }, 38 | "no-unused-vars": { 39 | "level": "error" 40 | }, 41 | "prefer-interpolation":{ 42 | "level": "error" 43 | }, 44 | "secure-parameter-default":{ 45 | "level": "error" 46 | }, 47 | "simplify-interpolation":{ 48 | "level": "error" 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /iac/db.bicep: -------------------------------------------------------------------------------- 1 | // PARAMETERS 2 | @description('Name of SQL Server instance - default is %appName%-%environmentName%-sql') 3 | param sqlServerName string 4 | @description('Name of database - default is %appName%database') 5 | param dbName string 6 | @description('Database user name') 7 | param dbUserName string 8 | @description('Database password - passed in via GitHub secret') 9 | @secure() 10 | param dbPassword string 11 | @description('Primary location for resources') 12 | param location string = resourceGroup().location 13 | 14 | // RESOURCES 15 | resource sqlServer 'Microsoft.Sql/servers@2021-08-01-preview' = { 16 | name: sqlServerName 17 | location: location 18 | properties: { 19 | administratorLogin: dbUserName 20 | administratorLoginPassword: dbPassword 21 | version: '12.0' 22 | } 23 | 24 | resource database 'databases@2021-08-01-preview' = { 25 | name: dbName 26 | location: location 27 | sku: { 28 | name: 'GP_S_Gen5' 29 | tier: 'GeneralPurpose' 30 | family: 'Gen5' 31 | capacity: 1 32 | } 33 | properties: { 34 | collation: 'SQL_Latin1_General_CP1_CI_AS' 35 | catalogCollation: 'SQL_Latin1_General_CP1_CI_AS' 36 | zoneRedundant: false 37 | readScale: 'Disabled' 38 | autoPauseDelay: 60 39 | minCapacity: 1 40 | } 41 | } 42 | 43 | resource firewallAllowAllWindowsAzureIps 'firewallRules@2021-08-01-preview' = { 44 | name: 'AllowAllWindowsAzureIps' 45 | properties: { 46 | startIpAddress: '0.0.0.0' 47 | endIpAddress: '0.0.0.0' 48 | } 49 | } 50 | } 51 | 52 | // Use outputs for connection string in web app module 53 | output sqlServerFQDN string = sqlServer.properties.fullyQualifiedDomainName 54 | output databaseName string = sqlServer::database.name 55 | output userName string = sqlServer.properties.administratorLogin 56 | -------------------------------------------------------------------------------- /iac/deploy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Space Game Infrastructure\r\n", 8 | "\r\n", 9 | "This notebook deploys all of the required infrastructure for Space Game. It's intended use is for development purposes and should not be used in production.\r\n", 10 | "\r\n", 11 | "Requirements:\r\n", 12 | "- [VS Code](https://code.visualstudio.com/)\r\n", 13 | "- [Azure subcription](https://azure.microsoft.com/subcriptions/free)\r\n", 14 | "- [Azure CLI](https://aka.ms/getazcli)" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## Setup:\r\n", 22 | "- Navigate to local directory where repo is cloned\r\n", 23 | "- Login to Azure" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": { 30 | "dotnet_interactive": { 31 | "language": "pwsh" 32 | } 33 | }, 34 | "outputs": [ 35 | { 36 | "data": { 37 | "application/vnd.code.notebook.error": { 38 | "message": "System.OperationCanceledException: Command :SubmitCode: $WORKINGDIR = \"C:\\Git\\Demo.SpaceGamevNext\"\r\ncd $WO ... cancelled.", 39 | "name": "Error" 40 | } 41 | }, 42 | "output_type": "unknown" 43 | } 44 | ], 45 | "source": [ 46 | "\r\n", 47 | "$WORKINGDIR = \"C:\\Git\\Demo.SpaceGamevNext\"\r\n", 48 | "cd $WORKINGDIR\r\n", 49 | "az login" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "## Set parameters" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": { 63 | "dotnet_interactive": { 64 | "language": "pwsh" 65 | } 66 | }, 67 | "outputs": [], 68 | "source": [ 69 | "$APPNAME = \"spacegamevnext\" # Name of app. Used for prefix in resource group, service plan, app service, container images, sql server and database.\r\n", 70 | "$REGISTRYNAME = \"marcusfellingspacegamevnextacr\" # Registry that is shared across environments. Must be globally unique and lowercase.\r\n", 71 | "$LOCATION = \"WestUS\" # Region for all Azure resources without spaces. https://azure.microsoft.com/en-us/global-infrastructure/geographies/#geographies\r\n", 72 | "$ENVIRONMENTNAME = \"dev\" # Name of your environment that will contain it's own set of resources for web app and db e.g. dev, test, local, etc.\r\n", 73 | "$TAG = \"latest\" # Container image tag.\r\n", 74 | "$DBUSERNAME = \"notarealusername\" # Name of SQL Server user. In non-dev environments, should be passed using GitHub Secret.\r\n", 75 | "$DBPASSWORD = \"notarealpassword\" # Password for SQL Server user. In non-dev environments, should be passed using GitHub Secret." 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "## Preview\r\n", 83 | "Before deploying the Bicep template, you can preview the changes that will happen. The what-if operation doesn't make any changes to existing resources. Instead, it predicts the changes if the specified template is deployed." 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": { 90 | "dotnet_interactive": { 91 | "language": "pwsh" 92 | } 93 | }, 94 | "outputs": [], 95 | "source": [ 96 | "az deployment sub what-if \\\r\n", 97 | " --name \"spacegamedeploy-$ENVIRONMENTNAME\" \\\r\n", 98 | " --location $LOCATION \\\r\n", 99 | " --template-file IaC/main.bicep \\\r\n", 100 | " --parameters appName=$APPNAME \\\r\n", 101 | " environmentName=$ENVIRONMENTNAME \\\r\n", 102 | " registryName=$REGISTRYNAME \\\r\n", 103 | " tag=$TAG \\\r\n", 104 | " dbUserName=$DBUSERNAME \\\r\n", 105 | " dbPassword=$DBPASSWORD" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "## Deploy" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": null, 118 | "metadata": { 119 | "dotnet_interactive": { 120 | "language": "pwsh" 121 | } 122 | }, 123 | "outputs": [], 124 | "source": [ 125 | "az deployment sub create \\\r\n", 126 | " --name \"spacegamedeploy-$ENVIRONMENTNAME\" \\\r\n", 127 | " --location $LOCATION \\\r\n", 128 | " --template-file IaC/main.bicep \\\r\n", 129 | " --parameters appName=$APPNAME \\\r\n", 130 | " environmentName=$ENVIRONMENTNAME \\\r\n", 131 | " registryName=$REGISTRYNAME \\\r\n", 132 | " tag=$TAG \\\r\n", 133 | " dbUserName=$DBUSERNAME \\\r\n", 134 | " dbPassword=$DBPASSWORD" 135 | ] 136 | } 137 | ], 138 | "metadata": { 139 | "kernelspec": { 140 | "display_name": ".NET (C#)", 141 | "language": "C#", 142 | "name": ".net-csharp" 143 | }, 144 | "language_info": { 145 | "file_extension": ".cs", 146 | "mimetype": "text/x-csharp", 147 | "name": "C#", 148 | "pygments_lexer": "csharp", 149 | "version": "9.0" 150 | }, 151 | "metadata": { 152 | "interpreter": { 153 | "hash": "b32b3da54b9e43f292e3f9ba922e0e7e435140dd714ecaddad8b29bb9558fd56" 154 | } 155 | }, 156 | "orig_nbformat": 2 157 | }, 158 | "nbformat": 4, 159 | "nbformat_minor": 2 160 | } -------------------------------------------------------------------------------- /iac/loadtest.bicep: -------------------------------------------------------------------------------- 1 | @description('Application name - used as prefix for resource names') 2 | param appName string 3 | 4 | resource loadtest 'Microsoft.LoadTestService/loadTests@2021-12-01-preview' = { 5 | name: '${appName}-loadtest' 6 | location: 'EastUS' // public preview not available in WestUS 7 | properties: { 8 | description: 'Load test for ${appName}' 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /iac/main.bicep: -------------------------------------------------------------------------------- 1 | // Creates all infrastructure for Space Game 2 | targetScope = 'subscription' // switch to sub scope to create resource group 3 | 4 | // PARAMETERS 5 | @description('Application name - used as prefix for resource names') 6 | param appName string 7 | @description('Environment name') 8 | @allowed([ 9 | 'dev' 10 | 'test' 11 | 'prod' 12 | ]) 13 | param environmentName string 14 | @description('Source branch passed in via pipeline for dev environment') 15 | param branch string = '' 16 | @description('Primary location for all resources') 17 | param location string = deployment().location 18 | @description('Name of shared registry') 19 | param registryName string 20 | @description('Container image tag - uses commit SHA passed in via pipeline') 21 | param tag string 22 | @description('Database user name') 23 | param dbUserName string 24 | @description('Database password - passed in via GitHub secret') 25 | @secure() 26 | param dbPassword string 27 | @description('Boolean for Dev environments - Used in conditions for resources that are skipped in dev (deploy slots, app insights, etc)') 28 | param devEnv bool = false 29 | 30 | // RESOURCES 31 | // Create resource group for webapp and db 32 | resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { 33 | name: '${appName}-${environmentName}-rg' 34 | location: location 35 | } 36 | 37 | // Create resource group for ACR 38 | resource acrrg 'Microsoft.Resources/resourceGroups@2021-04-01' = { 39 | name: '${appName}-ACR-rg' 40 | location: location 41 | } 42 | 43 | // Create resource group for Azure Load Testing 44 | resource loadtestrg 'Microsoft.Resources/resourceGroups@2021-04-01' = { 45 | name: '${appName}-loadtest-rg' 46 | location: 'EastUS' // public preview not available in west US 47 | } 48 | 49 | // Create shared registry 50 | module registry 'registry.bicep' = { 51 | name: '${appName}-registry-${uniqueString(acrrg.name)}' 52 | scope: acrrg 53 | params: { 54 | registry: registryName 55 | registrySku: 'Standard' 56 | location: location 57 | } 58 | } 59 | 60 | // Create database infrastructure 61 | module db 'db.bicep' = { 62 | name: '${appName}-db-${environmentName}-${uniqueString(rg.name)}' 63 | scope: rg 64 | params: { 65 | sqlServerName: '${appName}-${environmentName}-sql' 66 | dbName: '${appName}database' 67 | dbUserName: dbUserName 68 | dbPassword: dbPassword 69 | location: location 70 | } 71 | } 72 | 73 | // Create web app infrastructure 74 | module webapp 'webapp.bicep' = { 75 | name: '${appName}-webapp-${environmentName}-${uniqueString(rg.name)}' 76 | scope: rg 77 | params: { 78 | environmentName: environmentName 79 | appName: appName 80 | branch: branch 81 | appSku: 'S2' 82 | registry: registry.outputs.acrName 83 | tag: tag 84 | devEnv: devEnv 85 | // Use output from db module to set connection string 86 | sqlServer: db.outputs.sqlServerFQDN 87 | dbName: db.outputs.databaseName 88 | dbUserName: db.outputs.userName 89 | dbPassword: dbPassword 90 | location: location 91 | } 92 | } 93 | 94 | // Create Azure Load Test infrastructure 95 | module loadtest 'loadtest.bicep' = { 96 | name: '${appName}-loadtest-${uniqueString(loadtestrg.name)}' 97 | scope: loadtestrg 98 | params: { 99 | appName: appName 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /iac/registry.bicep: -------------------------------------------------------------------------------- 1 | @description('Shared registry name') 2 | param registry string 3 | @description('Shared registry SKU') 4 | @allowed([ 5 | 'Basic' 6 | 'Standard' 7 | 'Premium' 8 | ]) 9 | param registrySku string = 'Standard' 10 | @description('Primary location for resources') 11 | param location string = resourceGroup().location 12 | 13 | resource acr 'Microsoft.ContainerRegistry/registries@2021-09-01' = { 14 | name: registry 15 | location: location 16 | sku: { 17 | name: registrySku 18 | } 19 | properties: { 20 | adminUserEnabled: true 21 | encryption: { 22 | status: 'disabled' 23 | } 24 | } 25 | } 26 | 27 | output acrName string = acr.name 28 | -------------------------------------------------------------------------------- /iac/webapp.bicep: -------------------------------------------------------------------------------- 1 | // PARAMETERS 2 | @description('Environment name') 3 | @allowed([ 4 | 'dev' 5 | 'test' 6 | 'prod' 7 | ]) 8 | param environmentName string 9 | @description('Primary location for resources') 10 | param location string = resourceGroup().location 11 | @description('Application name - used as prefix for resource names') 12 | param appName string 13 | @description('Source branch passed in via pipeline for dev environment') 14 | param branch string = '' 15 | @description('App Service Plan SKU') 16 | @allowed([ 17 | 'S1' 18 | 'S2' 19 | 'S3' 20 | ]) 21 | param appSku string 22 | @description('Name of shared registry') 23 | param registry string 24 | @description('Container image tag - uses commit SHA passed in via pipeline') 25 | param tag string 26 | @description('Name of SQL Server instance - default is %appName%-%environmentName%-sql') 27 | param sqlServer string 28 | @description('Name of database - default is %appName%database') 29 | param dbName string 30 | @description('Database user name') 31 | param dbUserName string 32 | @description('Database password - passed in via GitHub secret') 33 | @secure() 34 | param dbPassword string 35 | @description('Boolean for Dev environments - Used in conditions for resources that are skipped in dev (deploy slots, app insights, etc)') 36 | param devEnv bool = false 37 | 38 | // RESOURCES 39 | resource servicePlan 'Microsoft.Web/serverfarms@2021-03-01' = { 40 | kind: 'linux' 41 | name: '${appName}-${environmentName}-plan' 42 | location: location 43 | sku: { 44 | name: appSku 45 | } 46 | properties: { 47 | reserved: true 48 | } 49 | } 50 | 51 | // Reference existing ACR for docker app settings. 52 | // This resource will not be deployed by this file, but the declaration provides access to properties on the existing resource. 53 | resource acr 'Microsoft.ContainerRegistry/registries@2021-09-01' existing = { 54 | name: registry 55 | scope: resourceGroup('${appName}-ACR-rg') 56 | } 57 | 58 | resource appService 'Microsoft.Web/sites@2022-03-01' = { 59 | name: '${appName}-${environmentName}${branch}' 60 | location: location 61 | properties: { 62 | siteConfig: { 63 | appSettings: [ 64 | { 65 | name: 'DOCKER_REGISTRY_SERVER_URL' 66 | value: acr.properties.loginServer 67 | } 68 | { 69 | name: 'DOCKER_REGISTRY_SERVER_USERNAME' 70 | value: listCredentials(acr.id, acr.apiVersion).username 71 | } 72 | { 73 | name: 'DOCKER_REGISTRY_SERVER_PASSWORD' 74 | value: listCredentials(acr.id, acr.apiVersion).passwords[0].value 75 | } 76 | { 77 | name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE' 78 | value: 'false' 79 | } 80 | ] 81 | linuxFxVersion: 'DOCKER|${acr.properties.loginServer}/${appName}:${tag}' 82 | } 83 | serverFarmId: servicePlan.id 84 | } 85 | 86 | resource connectionString 'config@2022-03-01' = { 87 | name: 'connectionstrings' 88 | properties: { 89 | DefaultConnection: { 90 | value: 'Data Source=tcp:${sqlServer},1433;Initial Catalog=${dbName};User Id=${dbUserName}@${sqlServer};Password=${dbPassword};' 91 | type: 'SQLAzure' 92 | } 93 | } 94 | } 95 | 96 | // Create deployment slot if it's not a dev environment 97 | resource deploySlot 'slots@2022-03-01' = if (!devEnv) { 98 | name: 'swap' 99 | location: location 100 | kind: 'linux' 101 | properties: { 102 | enabled: true 103 | serverFarmId: servicePlan.id 104 | } 105 | } 106 | } 107 | 108 | // Creat app insights if it's not a dev environment 109 | resource appInsights 'Microsoft.Insights/components@2020-02-02' = if (!devEnv) { 110 | name: '${appService.name}-monitor' 111 | location: location 112 | tags: { 113 | 'hidden-link:${appService.id}': 'Resource' 114 | displayName: 'AppInsightsComponent' 115 | } 116 | kind: 'web' 117 | properties: { 118 | Application_Type: 'web' 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /load-tests/filters.csv: -------------------------------------------------------------------------------- 1 | Solo,Andromeda 2 | Duo,Pinwheel 3 | Trio,Milky%20Way 4 | Solo,Pinwheel 5 | Duo,Messier%2082 6 | Trio,Andromeda 7 | -------------------------------------------------------------------------------- /load-tests/home-page.jmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | false 7 | true 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | continue 17 | 18 | false 19 | -1 20 | 21 | 100 22 | 2 23 | true 24 | 120 25 | 5 26 | true 27 | 28 | 29 | 30 | 31 | 32 | 33 | ${HOMEPAGE_URL} 34 | 35 | https 36 | 37 | 38 | GET 39 | true 40 | false 41 | true 42 | false 43 | 44 | 45 | 46 | 47 | 48 | 49 | , 50 | 51 | filters.csv 52 | false 53 | false 54 | true 55 | shareMode.all 56 | false 57 | mode,region 58 | 59 | 60 | 61 | 62 | 63 | 64 | false 65 | ${mode} 66 | = 67 | true 68 | mode 69 | 70 | 71 | false 72 | ${region} 73 | = 74 | true 75 | region 76 | 77 | 78 | 79 | spacegamevnext-test.azurewebsites.net 80 | 81 | https 82 | 83 | 84 | GET 85 | true 86 | false 87 | true 88 | false 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 200 97 | 98 | 99 | Assertion.response_code 100 | false 101 | 8 102 | all 103 | 104 | 105 | 106 | 107 | 108 | 109 | HOMEPAGE_URL 110 | ${__BeanShell( System.getenv("HOMEPAGE_URL") )} 111 | = 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /load-tests/home-page.yaml: -------------------------------------------------------------------------------- 1 | version: v0.1 2 | testName: HomePage 3 | testPlan: home-page.jmx 4 | description: 'Home Page Load Test' 5 | engineInstances: 3 6 | configurationFiles: 7 | - filters.csv 8 | failureCriteria: 9 | - avg(response_time_ms) > 2400 10 | - percentage(error) > 1 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@playwright/test": "^1.27.1", 4 | "gulp": "^4.0.2", 5 | "gulp-concat": "2.6.1", 6 | "gulp-cssmin": "0.2.0", 7 | "gulp-uglify": "3.0.0", 8 | "node-sass": "^7.0.3", 9 | "rimraf": "2.6.1" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /space-game.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31410.414 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "database", "database\database.sqlproj", "{8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "unit-tests", "unit-tests\unit-tests.csproj", "{773BA444-0D67-4F37-8762-17E108CCD5F5}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "web-app", "web-app\web-app.csproj", "{A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 21 | {8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}.Release|Any CPU.Build.0 = Release|Any CPU 23 | {8BAA5C4E-F217-4E45-8473-1EBAE2684BFF}.Release|Any CPU.Deploy.0 = Release|Any CPU 24 | {773BA444-0D67-4F37-8762-17E108CCD5F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {773BA444-0D67-4F37-8762-17E108CCD5F5}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {773BA444-0D67-4F37-8762-17E108CCD5F5}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {773BA444-0D67-4F37-8762-17E108CCD5F5}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(ExtensibilityGlobals) = postSolution 37 | SolutionGuid = {CDECAE68-0820-4E4C-81C4-091BAC64F8ED} 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /unit-tests/DocumentDBRepository_GetItemsAsyncShould.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq.Expressions; 5 | using System.Threading.Tasks; 6 | using NUnit.Framework; 7 | using TailSpin.SpaceGame.Web; 8 | using TailSpin.SpaceGame.Web.Models; 9 | 10 | namespace Tests 11 | { 12 | public class DocumentDBRepository_GetItemsAsyncShould 13 | { 14 | private IDocumentDBRepository _scoreRepository; 15 | 16 | [SetUp] 17 | public void Setup() 18 | { 19 | using (Stream scoresData = typeof(IDocumentDBRepository) 20 | .Assembly 21 | .GetManifestResourceStream("web-app.SampleData.scores.json")) 22 | { 23 | _scoreRepository = new LocalDocumentDBRepository(scoresData); 24 | } 25 | } 26 | 27 | [TestCase("Milky Way")] 28 | [TestCase("Andromeda")] 29 | [TestCase("Pinwheel")] 30 | [TestCase("NGC 1300")] 31 | [TestCase("Messier 82")] 32 | public void FetchOnlyRequestedGameRegion(string gameRegion) 33 | { 34 | const int PAGE = 0; // take the first page of results 35 | const int MAX_RESULTS = 10; // sample up to 10 results 36 | 37 | // Form the query predicate. 38 | // This expression selects all scores for the provided game region. 39 | Expression> queryPredicate = score => (score.GameRegion == gameRegion); 40 | 41 | // Fetch the scores. 42 | Task> scoresTask = _scoreRepository.GetItemsAsync( 43 | queryPredicate, // the predicate defined above 44 | score => 1, // we don't care about the order 45 | PAGE, 46 | MAX_RESULTS 47 | ); 48 | IEnumerable scores = scoresTask.Result; 49 | 50 | // Verify that each score's game region matches the provided game region. 51 | Assert.That(scores, Is.All.Matches(score => score.GameRegion == gameRegion)); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /unit-tests/unit-tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | false 6 | {773BA444-0D67-4F37-8762-17E108CCD5F5} 7 | 8 | 9 | 10 | 11 | runtime; build; native; contentfiles; analyzers 12 | all 13 | 14 | 15 | 16 | all 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /web-app/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using TailSpin.SpaceGame.Web.Models; 9 | 10 | namespace TailSpin.SpaceGame.Web.Controllers 11 | { 12 | public class HomeController : Controller 13 | { 14 | // High score repository. 15 | private readonly IDocumentDBRepository _scoreRepository; 16 | // User profile repository. 17 | private readonly IDocumentDBRepository _profileRespository; 18 | 19 | public HomeController( 20 | IDocumentDBRepository scoreRepository, 21 | IDocumentDBRepository profileRespository 22 | ) 23 | { 24 | _scoreRepository = scoreRepository; 25 | _profileRespository = profileRespository; 26 | } 27 | 28 | public async Task Index( 29 | int page = 1, 30 | int pageSize = 10, 31 | string mode = "", 32 | string region = "" 33 | ) 34 | { 35 | // Create the view model with initial values we already know. 36 | var vm = new LeaderboardViewModel 37 | { 38 | Page = page, 39 | PageSize = pageSize, 40 | SelectedMode = mode, 41 | SelectedRegion = region, 42 | 43 | GameModes = new List() 44 | { 45 | "Solo", 46 | "Duo", 47 | "Trio" 48 | }, 49 | 50 | GameRegions = new List() 51 | { 52 | "Milky Way", 53 | "Andromeda", 54 | "Pinwheel", 55 | "NGC 1300", 56 | "Messier 82", 57 | } 58 | }; 59 | 60 | try 61 | { 62 | // Form the query predicate. 63 | // This expression selects all scores that match the provided game 64 | // mode and region (map). 65 | // Select the score if the game mode or region is empty. 66 | Expression> queryPredicate = score => 67 | (string.IsNullOrEmpty(mode) || score.GameMode == mode) && 68 | (string.IsNullOrEmpty(region) || score.GameRegion == region); 69 | 70 | // Fetch the total number of results in the background. 71 | var countItemsTask = _scoreRepository.CountItemsAsync(queryPredicate); 72 | 73 | // Fetch the scores that match the current filter. 74 | IEnumerable scores = await _scoreRepository.GetItemsAsync( 75 | queryPredicate, // the predicate defined above 76 | score => score.HighScore, // sort descending by high score 77 | page - 1, // subtract 1 to make the query 0-based 78 | pageSize 79 | ); 80 | 81 | // Wait for the total count. 82 | vm.TotalResults = await countItemsTask; 83 | 84 | // Set previous and next hyperlinks. 85 | if (page > 1) 86 | { 87 | vm.PrevLink = $"/?page={page - 1}&pageSize={pageSize}&mode={mode}®ion={region}#leaderboard"; 88 | } 89 | if (vm.TotalResults > page * pageSize) 90 | { 91 | vm.NextLink = $"/?page={page + 1}&pageSize={pageSize}&mode={mode}®ion={region}#leaderboard"; 92 | } 93 | 94 | // Fetch the user profile for each score. 95 | // This creates a list that's parallel with the scores collection. 96 | var profiles = new List>(); 97 | foreach (var score in scores) 98 | { 99 | profiles.Add(_profileRespository.GetItemAsync(score.ProfileId)); 100 | } 101 | Task.WaitAll(profiles.ToArray()); 102 | 103 | // Combine each score with its profile. 104 | vm.Scores = scores.Zip(profiles, (score, profile) => new ScoreProfile { Score = score, Profile = profile.Result }); 105 | 106 | return View(vm); 107 | } 108 | catch (Exception) 109 | { 110 | return View(vm); 111 | } 112 | } 113 | 114 | [Route("/profile/{id}")] 115 | public async Task Profile(string id, string rank="") 116 | { 117 | try 118 | { 119 | // Fetch the user profile with the given identifier. 120 | return View(new ProfileViewModel { Profile = await _profileRespository.GetItemAsync(id), Rank = rank }); 121 | } 122 | catch (Exception) 123 | { 124 | return RedirectToAction("/"); 125 | } 126 | } 127 | 128 | public IActionResult Privacy() 129 | { 130 | return View(); 131 | } 132 | 133 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 134 | public IActionResult Error() 135 | { 136 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /web-app/IDocumentDBRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Threading.Tasks; 5 | using TailSpin.SpaceGame.Web.Models; 6 | 7 | namespace TailSpin.SpaceGame.Web 8 | { 9 | public interface IDocumentDBRepository where T : Model 10 | { 11 | /// 12 | /// Retrieves the item from the store with the given identifier. 13 | /// 14 | /// 15 | /// A task that represents the asynchronous operation. 16 | /// The task result contains the retrieved item. 17 | /// 18 | /// The identifier of the item to retrieve. 19 | Task GetItemAsync(string id); 20 | 21 | /// 22 | /// Retrieves items from the store that match the given query predicate. 23 | /// Results are given in descending order by the given ordering predicate. 24 | /// 25 | /// 26 | /// A task that represents the asynchronous operation. 27 | /// The task result contains the collection of retrieved items. 28 | /// 29 | /// Predicate that specifies which items to select. 30 | /// Predicate that specifies how to sort the results in descending order. 31 | /// The 1-based page of results to return. 32 | /// The number of items on a page. 33 | Task> GetItemsAsync( 34 | Expression> queryPredicate, 35 | Expression> orderDescendingPredicate, 36 | int page = 1, 37 | int pageSize = 10 38 | ); 39 | 40 | /// 41 | /// Retrieves the number of items that match the given query predicate. 42 | /// 43 | /// 44 | /// A task that represents the asynchronous operation. 45 | /// The task result contains the number of items that match the query predicate. 46 | /// 47 | /// Predicate that specifies which items to select. 48 | Task CountItemsAsync(Expression> queryPredicate); 49 | } 50 | } -------------------------------------------------------------------------------- /web-app/LocalDocumentDBRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using System.Threading.Tasks; 7 | using Newtonsoft.Json; 8 | using TailSpin.SpaceGame.Web.Models; 9 | 10 | namespace TailSpin.SpaceGame.Web 11 | { 12 | public class LocalDocumentDBRepository : IDocumentDBRepository where T : Model 13 | { 14 | // An in-memory list of all items in the collection. 15 | private readonly List _items; 16 | 17 | public LocalDocumentDBRepository(string fileName) 18 | { 19 | // Serialize the items from the provided JSON document. 20 | _items = JsonConvert.DeserializeObject>(File.ReadAllText(fileName)); 21 | } 22 | 23 | public LocalDocumentDBRepository(Stream stream) 24 | { 25 | // Serialize the items from the provided JSON document. 26 | _items = JsonConvert.DeserializeObject>(new StreamReader(stream).ReadToEnd()); 27 | } 28 | 29 | /// 30 | /// Retrieves the item from the store with the given identifier. 31 | /// 32 | /// 33 | /// A task that represents the asynchronous operation. 34 | /// The task result contains the retrieved item. 35 | /// 36 | /// The identifier of the item to retrieve. 37 | public Task GetItemAsync(string id) 38 | { 39 | return Task.FromResult(_items.Single(item => item.Id == id)); 40 | } 41 | 42 | /// 43 | /// Retrieves items from the store that match the given query predicate. 44 | /// Results are given in descending order by the given ordering predicate. 45 | /// 46 | /// 47 | /// A task that represents the asynchronous operation. 48 | /// The task result contains the collection of retrieved items. 49 | /// 50 | /// Predicate that specifies which items to select. 51 | /// Predicate that specifies how to sort the results in descending order. 52 | /// The 1-based page of results to return. 53 | /// The number of items on a page. 54 | public Task> GetItemsAsync( 55 | Expression> queryPredicate, 56 | Expression> orderDescendingPredicate, 57 | int page = 1, int pageSize = 10 58 | ) 59 | { 60 | var result = _items.AsQueryable() 61 | .Where(queryPredicate) // filter 62 | .OrderByDescending(orderDescendingPredicate) // sort 63 | .Skip(page * pageSize) // find page 64 | .Take(pageSize) // take items 65 | .AsEnumerable(); // make enumeratable 66 | 67 | return Task>.FromResult(result); 68 | } 69 | 70 | /// 71 | /// Retrieves the number of items that match the given query predicate. 72 | /// 73 | /// 74 | /// A task that represents the asynchronous operation. 75 | /// The task result contains the number of items that match the query predicate. 76 | /// 77 | /// Predicate that specifies which items to select. 78 | public Task CountItemsAsync(Expression> queryPredicate) 79 | { 80 | var count = _items.AsQueryable() 81 | .Where(queryPredicate) // filter 82 | .Count(); // count 83 | 84 | return Task.FromResult(count); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /web-app/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace TailSpin.SpaceGame.Web.Models 2 | { 3 | public class ErrorViewModel 4 | { 5 | public string RequestId { get; set; } 6 | 7 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 8 | } 9 | } -------------------------------------------------------------------------------- /web-app/Models/LeaderboardViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TailSpin.SpaceGame.Web.Models 4 | { 5 | public class LeaderboardViewModel 6 | { 7 | // The game mode selected in the view. 8 | public string SelectedMode { get; set; } 9 | // The game region (map) selected in the view. 10 | public string SelectedRegion { get; set; } 11 | // The current page to be shown in the view. 12 | public int Page { get; set; } 13 | // The number of items to show per page in the view. 14 | public int PageSize { get; set; } 15 | 16 | // The scores to display in the view. 17 | public IEnumerable Scores { get; set; } 18 | // The game modes to display in the view. 19 | public IEnumerable GameModes { get; set; } 20 | // The game regions (maps) to display in the view. 21 | public IEnumerable GameRegions { get; set; } 22 | 23 | // Hyperlink to the previous page of results. 24 | // This is empty if this is the first page. 25 | public string PrevLink { get; set; } 26 | // Hyperlink to the next page of results. 27 | // This is empty if this is the last page. 28 | public string NextLink { get; set; } 29 | // The total number of results for the selected game mode and region in the view. 30 | public int TotalResults { get; set; } 31 | } 32 | 33 | /// 34 | /// Combines a score and a user profile. 35 | /// 36 | public struct ScoreProfile 37 | { 38 | // The player's score. 39 | public Score Score; 40 | // The player's profile. 41 | public Profile Profile; 42 | } 43 | } -------------------------------------------------------------------------------- /web-app/Models/Model.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TailSpin.SpaceGame.Web.Models 4 | { 5 | /// 6 | /// Base class for data models. 7 | /// 8 | public abstract class Model 9 | { 10 | // The value that uniquely identifies this object. 11 | [JsonProperty(PropertyName = "id")] 12 | public string Id { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /web-app/Models/Profile.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TailSpin.SpaceGame.Web.Models 4 | { 5 | public class Profile : Model 6 | { 7 | // The player's user name. 8 | [JsonProperty(PropertyName = "userName")] 9 | public string UserName { get; set; } 10 | 11 | // The URL of the player's avatar image. 12 | [JsonProperty(PropertyName = "avatarUrl")] 13 | public string AvatarUrl { get; set; } 14 | 15 | // The achievements the player earned. 16 | [JsonProperty(PropertyName = "achievements")] 17 | public string[] Achievements { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /web-app/Models/ProfileViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace TailSpin.SpaceGame.Web.Models 2 | { 3 | public class ProfileViewModel 4 | { 5 | // The player profile. 6 | public Profile Profile; 7 | // The player's rank according to the active filter. 8 | public string Rank; 9 | } 10 | } -------------------------------------------------------------------------------- /web-app/Models/Score.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TailSpin.SpaceGame.Web.Models 4 | { 5 | public class Score : Model 6 | { 7 | // The ID of the player profile associated with this score. 8 | [JsonProperty(PropertyName = "profileId")] 9 | public string ProfileId { get; set; } 10 | 11 | // The score value. 12 | [JsonProperty(PropertyName = "score")] 13 | public int HighScore { get; set; } 14 | 15 | // The game mode the score is associated with. 16 | [JsonProperty(PropertyName = "gameMode")] 17 | public string GameMode { get; set; } 18 | 19 | // The game region (map) the score is associated with. 20 | [JsonProperty(PropertyName = "gameRegion")] 21 | public string GameRegion { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /web-app/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore; 2 | using Microsoft.AspNetCore.Hosting; 3 | 4 | namespace TailSpin.SpaceGame.Web 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | CreateWebHostBuilder(args).Build().Run(); 11 | } 12 | 13 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 14 | WebHost.CreateDefaultBuilder(args) 15 | .UseStartup(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /web-app/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49769/", 7 | "sslPort": 44385 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Tailspin.SpaceGame.Web": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 25 | }, 26 | "Docker": { 27 | "commandName": "Docker", 28 | "launchBrowser": true, 29 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", 30 | "publishAllPorts": true, 31 | "useSSL": true 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /web-app/SampleData/profiles.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "1", 4 | "userName": "duality", 5 | "avatarUrl": "images\/avatars\/default.svg", 6 | "achievements": [ 7 | "Professor", 8 | "Space Race", 9 | "Photon Hunter", 10 | "Professor", 11 | "King of the Hill", 12 | "Faster than Light", 13 | "Cosmologist", 14 | "Cruiser", 15 | "Particle Accelerator" 16 | ] 17 | }, 18 | { 19 | "id": "2", 20 | "userName": "arrise", 21 | "avatarUrl": "images\/avatars\/default.svg", 22 | "achievements": [ 23 | "Cosmologist", 24 | "Professor", 25 | "Professor", 26 | "King of the Hill", 27 | "Faster than Light", 28 | "Space Race", 29 | "Atom Smasher", 30 | "Photon Hunter", 31 | "Cruiser" 32 | ] 33 | }, 34 | { 35 | "id": "3", 36 | "userName": "evergrid", 37 | "avatarUrl": "images\/avatars\/default.svg", 38 | "achievements": [ 39 | "Faster than Light", 40 | "Photon Hunter", 41 | "Particle Accelerator", 42 | "Master Pilot", 43 | "Cosmologist", 44 | "Professor" 45 | ] 46 | }, 47 | { 48 | "id": "4", 49 | "userName": "sodapop", 50 | "avatarUrl": "images\/avatars\/default.svg", 51 | "achievements": [ 52 | "Photon Hunter", 53 | "Cosmologist", 54 | "Master Pilot", 55 | "Particle Accelerator", 56 | "King of the Hill", 57 | "Space Race", 58 | "Atom Smasher", 59 | "Professor", 60 | "Faster than Light" 61 | ] 62 | }, 63 | { 64 | "id": "5", 65 | "userName": "shortitem78", 66 | "avatarUrl": "images\/avatars\/default.svg", 67 | "achievements": [ 68 | "Atom Smasher" 69 | ] 70 | }, 71 | { 72 | "id": "6", 73 | "userName": "captaingrocs", 74 | "avatarUrl": "images\/avatars\/default.svg", 75 | "achievements": [ 76 | "Cruiser", 77 | "Master Pilot", 78 | "Atom Smasher", 79 | "King of the Hill", 80 | "Faster than Light", 81 | "Professor" 82 | ] 83 | }, 84 | { 85 | "id": "7", 86 | "userName": "protr2", 87 | "avatarUrl": "images\/avatars\/default.svg", 88 | "achievements": [ 89 | "Cosmologist", 90 | "Professor", 91 | "Professor", 92 | "Master Pilot", 93 | "Cruiser", 94 | "Faster than Light" 95 | ] 96 | }, 97 | { 98 | "id": "8", 99 | "userName": "hydragon", 100 | "avatarUrl": "images\/avatars\/default.svg", 101 | "achievements": [ 102 | "Master Pilot", 103 | "Atom Smasher", 104 | "Photon Hunter", 105 | "Particle Accelerator", 106 | "Faster than Light", 107 | "Professor", 108 | "Cruiser", 109 | "Cosmologist" 110 | ] 111 | }, 112 | { 113 | "id": "9", 114 | "userName": "banant", 115 | "avatarUrl": "images\/avatars\/default.svg", 116 | "achievements": [ 117 | "Atom Smasher", 118 | "Cruiser", 119 | "Cosmologist", 120 | "Space Race", 121 | "Photon Hunter", 122 | "Faster than Light" 123 | ] 124 | }, 125 | { 126 | "id": "10", 127 | "userName": "microle", 128 | "avatarUrl": "images\/avatars\/default.svg", 129 | "achievements": [ 130 | "Master Pilot", 131 | "Particle Accelerator", 132 | "Professor", 133 | "Cruiser", 134 | "King of the Hill", 135 | "Atom Smasher", 136 | "Professor", 137 | "Photon Hunter", 138 | "Faster than Light" 139 | ] 140 | }, 141 | { 142 | "id": "11", 143 | "userName": "flowfish", 144 | "avatarUrl": "images\/avatars\/default.svg", 145 | "achievements": [ 146 | "Particle Accelerator", 147 | "Atom Smasher", 148 | "Professor", 149 | "Professor", 150 | "King of the Hill", 151 | "Photon Hunter", 152 | "Cruiser", 153 | "Master Pilot", 154 | "Faster than Light" 155 | ] 156 | }, 157 | { 158 | "id": "12", 159 | "userName": "easis", 160 | "avatarUrl": "images\/avatars\/default.svg", 161 | "achievements": [ 162 | "Atom Smasher", 163 | "Professor", 164 | "Photon Hunter", 165 | "Cosmologist", 166 | "Master Pilot" 167 | ] 168 | }, 169 | { 170 | "id": "13", 171 | "userName": "caspneti", 172 | "avatarUrl": "images\/avatars\/default.svg", 173 | "achievements": [ 174 | "Photon Hunter", 175 | "Particle Accelerator", 176 | "Faster than Light" 177 | ] 178 | }, 179 | { 180 | "id": "14", 181 | "userName": "banant", 182 | "avatarUrl": "images\/avatars\/default.svg", 183 | "achievements": [ 184 | "Cruiser", 185 | "Faster than Light", 186 | "Atom Smasher", 187 | "Master Pilot", 188 | "Photon Hunter", 189 | "Space Race", 190 | "Professor", 191 | "King of the Hill" 192 | ] 193 | }, 194 | { 195 | "id": "15", 196 | "userName": "moose", 197 | "avatarUrl": "images\/avatars\/default.svg", 198 | "achievements": [ 199 | "Faster than Light", 200 | "Space Race", 201 | "Cruiser", 202 | "King of the Hill", 203 | "Atom Smasher", 204 | "Photon Hunter", 205 | "Particle Accelerator", 206 | "Master Pilot" 207 | ] 208 | }, 209 | { 210 | "id": "16", 211 | "userName": "glishell", 212 | "avatarUrl": "images\/avatars\/default.svg", 213 | "achievements": [ 214 | "Cosmologist" 215 | ] 216 | }, 217 | { 218 | "id": "17", 219 | "userName": "scord123", 220 | "avatarUrl": "images\/avatars\/default.svg", 221 | "achievements": [ 222 | "Photon Hunter", 223 | "Particle Accelerator", 224 | "Space Race", 225 | "Cruiser", 226 | "King of the Hill", 227 | "Cosmologist", 228 | "Faster than Light" 229 | ] 230 | }, 231 | { 232 | "id": "18", 233 | "userName": "undlease12", 234 | "avatarUrl": "images\/avatars\/default.svg", 235 | "achievements": [ 236 | "Cosmologist", 237 | "Particle Accelerator", 238 | "Professor", 239 | "Atom Smasher", 240 | "King of the Hill", 241 | "Cruiser", 242 | "Space Race", 243 | "Professor", 244 | "Master Pilot", 245 | "Faster than Light" 246 | ] 247 | }, 248 | { 249 | "id": "19", 250 | "userName": "glishell", 251 | "avatarUrl": "images\/avatars\/default.svg", 252 | "achievements": [ 253 | "Photon Hunter", 254 | "Cruiser", 255 | "Professor", 256 | "Space Race", 257 | "Professor" 258 | ] 259 | }, 260 | { 261 | "id": "20", 262 | "userName": "vivagran", 263 | "avatarUrl": "images\/avatars\/default.svg", 264 | "achievements": [ 265 | "Photon Hunter", 266 | "Space Race", 267 | "King of the Hill" 268 | ] 269 | } 270 | ] -------------------------------------------------------------------------------- /web-app/SampleData/scores.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "1", 4 | "profileId": "1", 5 | "score": 999999, 6 | "gameMode": "Solo", 7 | "gameRegion": "Milky Way" 8 | }, 9 | { 10 | "id": "2", 11 | "profileId": "2", 12 | "score": 999998, 13 | "gameMode": "Solo", 14 | "gameRegion": "NGC 1300" 15 | }, 16 | { 17 | "id": "3", 18 | "profileId": "3", 19 | "score": 856999, 20 | "gameMode": "Duo", 21 | "gameRegion": "Ring Nebula" 22 | }, 23 | { 24 | "id": "4", 25 | "profileId": "4", 26 | "score": 766979, 27 | "gameMode": "Solo", 28 | "gameRegion": "Milky Way" 29 | }, 30 | { 31 | "id": "5", 32 | "profileId": "5", 33 | "score": 669939, 34 | "gameMode": "Solo", 35 | "gameRegion": "Messier 82" 36 | }, 37 | { 38 | "id": "6", 39 | "profileId": "6", 40 | "score": 666555, 41 | "gameMode": "Duo", 42 | "gameRegion": "Ring Nebula" 43 | }, 44 | { 45 | "id": "7", 46 | "profileId": "7", 47 | "score": 665554, 48 | "gameMode": "Trio", 49 | "gameRegion": "Milky Way" 50 | }, 51 | { 52 | "id": "8", 53 | "profileId": "8", 54 | "score": 566525, 55 | "gameMode": "Solo", 56 | "gameRegion": "Messier 82" 57 | }, 58 | { 59 | "id": "9", 60 | "profileId": "9", 61 | "score": 411515, 62 | "gameMode": "Trio", 63 | "gameRegion": "NGC 1300" 64 | }, 65 | { 66 | "id": "10", 67 | "profileId": "10", 68 | "score": 311515, 69 | "gameMode": "Trio", 70 | "gameRegion": "Milky Way" 71 | }, 72 | { 73 | "id": "11", 74 | "profileId": "11", 75 | "score": 213315, 76 | "gameMode": "Solo", 77 | "gameRegion": "Andromeda" 78 | }, 79 | { 80 | "id": "12", 81 | "profileId": "12", 82 | "score": 111525, 83 | "gameMode": "Trio", 84 | "gameRegion": "NGC 1300" 85 | }, 86 | { 87 | "id": "13", 88 | "profileId": "13", 89 | "score": 268821, 90 | "gameMode": "Solo", 91 | "gameRegion": "Pinwheel" 92 | }, 93 | { 94 | "id": "14", 95 | "profileId": "14", 96 | "score": 91525, 97 | "gameMode": "Solo", 98 | "gameRegion": "Ring Nebula" 99 | }, 100 | { 101 | "id": "15", 102 | "profileId": "15", 103 | "score": 91524, 104 | "gameMode": "Duo", 105 | "gameRegion": "Messier 82" 106 | }, 107 | { 108 | "id": "16", 109 | "profileId": "16", 110 | "score": 91523, 111 | "gameMode": "Solo", 112 | "gameRegion": "Pinwheel" 113 | }, 114 | { 115 | "id": "17", 116 | "profileId": "17", 117 | "score": 91425, 118 | "gameMode": "Solo", 119 | "gameRegion": "Milky Way" 120 | }, 121 | { 122 | "id": "18", 123 | "profileId": "18", 124 | "score": 81525, 125 | "gameMode": "Duo", 126 | "gameRegion": "Pinwheel" 127 | }, 128 | { 129 | "id": "19", 130 | "profileId": "19", 131 | "score": 71525, 132 | "gameMode": "Trio", 133 | "gameRegion": "Andromeda" 134 | }, 135 | { 136 | "id": "20", 137 | "profileId": "20", 138 | "score": 61525, 139 | "gameMode": "Solo", 140 | "gameRegion": "Milky Way" 141 | }, 142 | { 143 | "id": "21", 144 | "profileId": "1", 145 | "score": 51525, 146 | "gameMode": "Duo", 147 | "gameRegion": "NGC 1300" 148 | }, 149 | { 150 | "id": "22", 151 | "profileId": "2", 152 | "score": 41525, 153 | "gameMode": "Trio", 154 | "gameRegion": "Messier 82" 155 | }, 156 | { 157 | "id": "23", 158 | "profileId": "3", 159 | "score": 31525, 160 | "gameMode": "Solo", 161 | "gameRegion": "Andromeda" 162 | }, 163 | { 164 | "id": "24", 165 | "profileId": "4", 166 | "score": 21525, 167 | "gameMode": "Trio", 168 | "gameRegion": "NGC 1300" 169 | }, 170 | { 171 | "id": "25", 172 | "profileId": "5", 173 | "score": 11525, 174 | "gameMode": "Duo", 175 | "gameRegion": "Ring Nebula" 176 | } 177 | ] 178 | -------------------------------------------------------------------------------- /web-app/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Hosting; 8 | using TailSpin.SpaceGame.Web.Models; 9 | 10 | namespace TailSpin.SpaceGame.Web 11 | { 12 | public class Startup 13 | { 14 | public Startup(IConfiguration configuration) 15 | { 16 | Configuration = configuration; 17 | } 18 | 19 | public IConfiguration Configuration { get; } 20 | 21 | // This method gets called by the runtime. Use this method to add services to the container. 22 | [System.Obsolete] 23 | public void ConfigureServices(IServiceCollection services) 24 | { 25 | services.Configure(options => 26 | { 27 | // This lambda determines whether user consent for non-essential cookies is needed for a given request. 28 | options.CheckConsentNeeded = context => true; 29 | options.MinimumSameSitePolicy = SameSiteMode.None; 30 | }); 31 | 32 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); 33 | services.AddMvc(option => option.EnableEndpointRouting = false); 34 | 35 | // Add document stores. These are passed to the HomeController constructor. 36 | services.AddSingleton>(new LocalDocumentDBRepository(@"SampleData/scores.json")); 37 | services.AddSingleton>(new LocalDocumentDBRepository(@"SampleData/profiles.json")); 38 | } 39 | 40 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 41 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 42 | { 43 | if (env.IsDevelopment()) 44 | { 45 | app.UseDeveloperExceptionPage(); 46 | } 47 | else 48 | { 49 | app.UseExceptionHandler("/Home/Error"); 50 | app.UseHsts(); 51 | } 52 | 53 | app.UseHttpsRedirection(); 54 | app.UseStaticFiles(); 55 | app.UseCookiePolicy(); 56 | 57 | app.UseMvc(routes => 58 | { 59 | routes.MapRoute( 60 | name: "default", 61 | template: "{controller=Home}/{action=Index}/{id?}"); 62 | }); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /web-app/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model TailSpin.SpaceGame.Web.Models.LeaderboardViewModel 2 | @{ 3 | ViewData["Title"] = "Home Page"; 4 | } 5 |
6 |
7 | Space Game 8 |

An example site for Marcus' Demos

9 |
10 |
11 |
12 |
13 |
14 | Download game 15 |
16 |
17 | 18 | 19 |
20 |
21 |
    22 |
  • 23 |
  • 24 |
  • 25 |
  • 26 |
27 |
28 |
29 | 30 | 31 |
32 |
33 | 34 |

Space leaders

35 | 36 |
37 |
38 | 55 | 56 | @{ 57 | if (Model.Scores.Count() == 0) 58 | { 59 |
No scores match your selection.
60 | } 61 | 62 | int rank = ((Model.Page - 1) * Model.PageSize) + 1; 63 | foreach (var score in Model.Scores) 64 | { 65 |
66 |
67 | @(rank++). 68 |
69 | 80 |
81 | @score.Score.GameMode 82 |
83 |
84 | @score.Score.GameRegion 85 |
86 |
87 | @score.Score.HighScore.ToString("N0") 88 |
89 |
90 | } 91 | } 92 | 129 |
130 | 131 |
132 | 190 |
191 |
192 | 193 |
194 |
195 | 196 | 197 |
198 |

More about Space Game

199 |

Space Game is an example website for Demos.

200 |
201 | 213 | 214 | 215 | 216 | 225 | 226 | 227 | 240 | 241 | 242 | 254 | 255 | 256 | -------------------------------------------------------------------------------- /web-app/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

-------------------------------------------------------------------------------- /web-app/Views/Home/Profile.cshtml: -------------------------------------------------------------------------------- 1 | @model TailSpin.SpaceGame.Web.Models.ProfileViewModel 2 | @{ 3 | ViewData["Title"] = "@Model.Profile.UserName Profile"; 4 | } 5 | -------------------------------------------------------------------------------- /web-app/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 22 |

23 | -------------------------------------------------------------------------------- /web-app/Views/Shared/_CookieConsentPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Http.Features 2 | 3 | @{ 4 | var consentFeature = Context.Features.Get 5 | (); 6 | var showBanner = !consentFeature?.CanTrack ?? false; 7 | var cookieString = consentFeature?.CreateConsentCookie(); 8 | } 9 | 10 | @if (showBanner) 11 | { 12 | 34 | 42 | } 43 | -------------------------------------------------------------------------------- /web-app/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - TailSpin SpaceGame 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 | @RenderBody() 25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 40 | 46 | 47 | 48 | 49 | @RenderSection("Scripts", required: false) 50 | 51 | 52 | -------------------------------------------------------------------------------- /web-app/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /web-app/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using TailSpin.SpaceGame.Web 2 | @using TailSpin.SpaceGame.Web.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /web-app/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /web-app/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /web-app/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /web-app/web-app.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46} 6 | b8c51918-b2c8-483a-8785-da54b228450e 7 | Linux 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Always 27 | 28 | 29 | Always 30 | 31 | 32 | 33 | 34 | PreserveNewest 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /web-app/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: black; 3 | --link: #064EC0; } 4 | 5 | a { 6 | color: var(--link); } 7 | 8 | h2 { 9 | font-size: 2.5rem; 10 | margin-bottom: 2rem; } 11 | 12 | section { 13 | text-align: center; 14 | padding: 6rem 0; 15 | border-bottom: 3px solid black; } 16 | 17 | .intro { 18 | height: 350px; 19 | background-color: #666; 20 | background-image: url("/images/space-background.svg"); 21 | background-size: 1440px; 22 | background-position: center top; 23 | background-repeat: no-repeat; 24 | background-attachment: fixed; } 25 | .intro .title { 26 | width: 20rem; 27 | margin-top: 2rem; } 28 | .intro p { 29 | color: white; 30 | font-weight: 600; 31 | font-size: 1.6rem; 32 | text-shadow: 0 0 2px black; 33 | margin-top: 2rem; } 34 | 35 | .download .image-cap { 36 | height: 180px; 37 | background-size: 800px; 38 | margin-top: -240px; 39 | background-image: url("/images/space-foreground.svg"); 40 | background-repeat: no-repeat; 41 | background-position: center top; } 42 | 43 | .download .btn { 44 | margin-top: 5rem; 45 | border: 3px solid black; 46 | font-weight: bold; } 47 | 48 | .screens { 49 | background: #666; } 50 | .screens ul { 51 | padding: 0; } 52 | .screens ul li { 53 | display: inline-block; 54 | width: 160px; 55 | height: 100px; 56 | background: #eee; 57 | margin: .25rem; 58 | margin-top: .75rem; } 59 | .screens ul li a { 60 | display: block; 61 | width: 100%; 62 | height: 100%; } 63 | .screens ul li img { 64 | width: 100%; } 65 | 66 | .pic .modal-body p { 67 | margin-top: 25px; } 68 | 69 | .leaderboard h2 { 70 | margin-bottom: 4rem; } 71 | 72 | .leaderboard ul { 73 | list-style: none; 74 | padding: 0; } 75 | 76 | .leaderboard .leader-nav .nav-buttons { 77 | border: 1px solid #999; 78 | border-radius: 10px; 79 | margin: 1rem; 80 | margin-top: 0; } 81 | .leaderboard .leader-nav .nav-buttons h4 { 82 | background: #333; 83 | color: white; 84 | padding: 1rem; 85 | margin: 0; 86 | border-top-left-radius: 10px; 87 | border-top-right-radius: 10px; } 88 | .leaderboard .leader-nav .nav-buttons li { 89 | padding: .5rem; } 90 | 91 | .leaderboard .leader-scores .high-score:nth-child(1) { 92 | background: #333; 93 | color: white; 94 | border-top-right-radius: 1rem; 95 | border-top-left-radius: 1rem; 96 | padding: 1rem 0; 97 | border: none; } 98 | 99 | .leaderboard .leader-scores .high-score:nth-last-child(2) { 100 | border-bottom-left-radius: 1rem; 101 | border-bottom-right-radius: 1rem; } 102 | 103 | .leaderboard .leader-scores .pagination { 104 | margin-top: 1rem; } 105 | .leaderboard .leader-scores .pagination > li > a { 106 | border-color: #999; 107 | color: var(--link); } 108 | .leaderboard .leader-scores .pagination > .active > a { 109 | background-color: var(--link); 110 | color: white; } 111 | 112 | .leaderboard .high-score { 113 | border: 1px solid #999; 114 | border-top-color: transparent; 115 | padding: 2rem 0 .5rem; } 116 | 117 | .leaderboard .avatar { 118 | width: 2rem; 119 | height: 2rem; 120 | overflow: hidden; 121 | background: gray; 122 | border-radius: 99px; 123 | display: inline-block; 124 | margin-right: .5rem; } 125 | 126 | .leaderboard .score-data a { 127 | display: inline-flex; 128 | align-items: center; } 129 | 130 | @media only screen and (max-width: 765px) { 131 | .leader-scores .high-score { 132 | padding: 2rem; } } 133 | 134 | .profile .avatar { 135 | border-radius: 999px; 136 | background-color: #ccc; 137 | background-size: cover; 138 | width: 200px; 139 | height: 200px; 140 | margin: 1rem; 141 | overflow: hidden; } 142 | .profile .avatar div { 143 | background-size: cover; 144 | width: 100%; 145 | height: 100%; } 146 | 147 | .profile .content { 148 | padding: 0 4rem; } 149 | .profile .content h2 { 150 | font-size: 2rem; } 151 | .profile .content ul { 152 | list-style: none; 153 | padding: 0; } 154 | 155 | .about { 156 | background: #eee; } 157 | .about h2 { 158 | margin-top: 0; } 159 | .about p { 160 | max-width: 600px; 161 | margin: 0 auto; 162 | padding: 0 1rem; } 163 | 164 | .social .share { 165 | display: inline-flex; 166 | align-items: center; } 167 | .social .share ul { 168 | display: flex; 169 | list-style: none; 170 | padding: 0; } 171 | .social .share a { 172 | display: block; 173 | width: 3rem; 174 | height: 3rem; 175 | margin: .75rem; } 176 | .social .share img { 177 | width: 3rem; 178 | height: 100%; } 179 | -------------------------------------------------------------------------------- /web-app/wwwroot/css/site.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sourceRoot":"","sources":["site.scss"],"names":[],"mappings":"AACA;EACI;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;;;AAIJ;EACI;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;;;AAKJ;EACI;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;;;AAIR;EACI;;AAEA;EACI;;AAEA;EACI;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;EACA;EACA;;AAGJ;EACI;;;AAMhB;EACI;;;AAIA;EACI;;AAGJ;EACI;EACA;;AAIA;EAUI;EACA;EACA;EACA;;AAZA;EACI;EACA;EACA;EACA;EACA;EACA;;AAQJ;EACI;;AAMR;EACI;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;;AAEA;EACI;EACA;;AAGJ;EACI;EACA;;AAKZ;EACI;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAIA;EACI;EACA;;;AAKZ;EACI;IACI;;;AAKJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;EACA;EACA;;AAIR;EACI;;AAEA;EACI;;AAGJ;EACI;EACA;;;AAMZ;EACI;;AAEA;EACI;;AAGJ;EACI;EACA;EACA;;;AAKJ;EACI;EACA;;AAEA;EACI;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;;AAGJ;EACI;EACA","file":"site.css"} -------------------------------------------------------------------------------- /web-app/wwwroot/css/site.min.css: -------------------------------------------------------------------------------- 1 | .download .image-cap,.intro{background-position:center top}body{color:#000;--link:#064EC0}a{color:var(--link)}h2{font-size:2.5rem;margin-bottom:2rem}section{text-align:center;padding:6rem 0;border-bottom:3px solid #000}.intro{height:350px;background-color:#666;background-image:url(/images/space-background.svg);background-size:1440px;background-repeat:no-repeat;background-attachment:fixed}.intro .title{width:20rem;margin-top:2rem}.intro p{color:#fff;font-weight:600;font-size:1.6rem;text-shadow:0 0 2px #000;margin-top:2rem}.download .image-cap{height:180px;background-size:800px;margin-top:-240px;background-image:url(/images/space-foreground.svg);background-repeat:no-repeat}.download .btn{margin-top:5rem;border:3px solid #000;font-weight:700}.screens{background:#666}.screens ul{padding:0}.screens ul li{display:inline-block;width:160px;height:100px;background:#eee;margin:.75rem .25rem .25rem}.screens ul li a{display:block;width:100%;height:100%}.screens ul li img{width:100%}.pic .modal-body p{margin-top:25px}.leaderboard h2{margin-bottom:4rem}.leaderboard ul{list-style:none;padding:0}.leaderboard .leader-nav .nav-buttons{border:1px solid #999;border-radius:10px;margin:0 1rem 1rem}.leaderboard .leader-nav .nav-buttons h4{background:#333;color:#fff;padding:1rem;margin:0;border-top-left-radius:10px;border-top-right-radius:10px}.leaderboard .leader-nav .nav-buttons li{padding:.5rem}.leaderboard .leader-scores .high-score:nth-child(1){background:#333;color:#fff;border-top-right-radius:1rem;border-top-left-radius:1rem;padding:1rem 0;border:none}.leaderboard .leader-scores .high-score:nth-last-child(2){border-bottom-left-radius:1rem;border-bottom-right-radius:1rem}.leaderboard .leader-scores .pagination{margin-top:1rem}.leaderboard .leader-scores .pagination>li>a{border-color:#999;color:var(--link)}.leaderboard .leader-scores .pagination>.active>a{background-color:var(--link);color:#fff}.leaderboard .high-score{border:1px solid #999;border-top-color:transparent;padding:2rem 0 .5rem}.leaderboard .avatar{width:2rem;height:2rem;overflow:hidden;background:gray;border-radius:99px;display:inline-block;margin-right:.5rem}.leaderboard .score-data a{display:inline-flex;align-items:center}@media only screen and (max-width:765px){.leader-scores .high-score{padding:2rem}}.profile .avatar{border-radius:999px;background-color:#ccc;background-size:cover;width:200px;height:200px;margin:1rem;overflow:hidden}.profile .avatar div{background-size:cover;width:100%;height:100%}.profile .content{padding:0 4rem}.profile .content h2{font-size:2rem}.profile .content ul{list-style:none;padding:0}.about{background:#eee}.about h2{margin-top:0}.about p{max-width:600px;margin:0 auto;padding:0 1rem}.social .share{display:inline-flex;align-items:center}.social .share ul{display:flex;list-style:none;padding:0}.social .share a{display:block;width:3rem;height:3rem;margin:.75rem}.social .share img{width:3rem;height:100%} -------------------------------------------------------------------------------- /web-app/wwwroot/css/site.scss: -------------------------------------------------------------------------------- 1 | // Page 2 | body { 3 | color: black; 4 | --link: #064EC0; 5 | } 6 | 7 | a { 8 | color: var(--link); 9 | } 10 | 11 | h2 { 12 | font-size: 2.5rem; 13 | margin-bottom: 2rem; 14 | } 15 | 16 | // Sections 17 | section { 18 | text-align: center; 19 | padding: 6rem 0; 20 | border-bottom: 3px solid black; 21 | } 22 | 23 | .intro { 24 | height: 350px; 25 | background-color: #666; 26 | background-image: url('/images/space-background.svg'); 27 | background-size: 1440px; 28 | background-position: center top; 29 | background-repeat: no-repeat; 30 | background-attachment: fixed; 31 | 32 | .title { 33 | width: 20rem; 34 | margin-top: 2rem; 35 | } 36 | 37 | p { 38 | color: white; 39 | font-weight: 600; 40 | font-size: 1.6rem; 41 | text-shadow: 0 0 2px black; 42 | margin-top: 2rem; 43 | } 44 | } 45 | 46 | .download { 47 | .image-cap { 48 | height: 180px; 49 | background-size: 800px; 50 | margin-top: -240px; 51 | background-image: url('/images/space-foreground.svg'); 52 | background-repeat: no-repeat; 53 | background-position: center top; 54 | } 55 | 56 | .btn { 57 | margin-top: 5rem; 58 | border: 3px solid black; 59 | font-weight: bold; 60 | } 61 | } 62 | 63 | .screens { 64 | background: #666; 65 | 66 | ul { 67 | padding: 0; 68 | 69 | li { 70 | display: inline-block; 71 | width: 160px; 72 | height: 100px; 73 | background: #eee; 74 | margin: .25rem; 75 | margin-top: .75rem; 76 | 77 | a { 78 | display: block; 79 | width: 100%; 80 | height: 100%; 81 | } 82 | 83 | img { 84 | width: 100%; 85 | } 86 | } 87 | } 88 | } 89 | 90 | .pic .modal-body p { 91 | margin-top: 25px; 92 | } 93 | 94 | .leaderboard { 95 | h2 { 96 | margin-bottom: 4rem; 97 | } 98 | 99 | ul { 100 | list-style: none; 101 | padding: 0; 102 | } 103 | 104 | .leader-nav { 105 | .nav-buttons { 106 | h4 { 107 | background: #333; 108 | color: white; 109 | padding: 1rem; 110 | margin: 0; 111 | border-top-left-radius: 10px; 112 | border-top-right-radius: 10px; 113 | } 114 | 115 | border: 1px solid #999; 116 | border-radius: 10px; 117 | margin: 1rem; 118 | margin-top: 0; 119 | 120 | li { 121 | padding: .5rem; 122 | } 123 | } 124 | } 125 | 126 | .leader-scores { 127 | .high-score:nth-child(1) { 128 | background: #333; 129 | color: white; 130 | border-top-right-radius: 1rem; 131 | border-top-left-radius: 1rem; 132 | padding: 1rem 0; 133 | border: none; 134 | } 135 | 136 | .high-score:nth-last-child(2) { 137 | border-bottom-left-radius: 1rem; 138 | border-bottom-right-radius: 1rem; 139 | } 140 | 141 | .pagination { 142 | margin-top: 1rem; 143 | 144 | > li > a { 145 | border-color: #999; 146 | color: var(--link); 147 | } 148 | 149 | > .active > a { 150 | background-color: var(--link); 151 | color: white; 152 | } 153 | } 154 | } 155 | 156 | .high-score { 157 | border: 1px solid #999; 158 | border-top-color: transparent; 159 | padding: 2rem 0 .5rem; 160 | } 161 | 162 | .avatar { 163 | width: 2rem; 164 | height: 2rem; 165 | overflow: hidden; 166 | background: gray; 167 | border-radius: 99px; 168 | display: inline-block; 169 | margin-right: .5rem; 170 | } 171 | 172 | .score-data { 173 | a { 174 | display: inline-flex; 175 | align-items: center; 176 | } 177 | } 178 | } 179 | 180 | @media only screen and (max-width: 765px) { 181 | .leader-scores .high-score { 182 | padding: 2rem; 183 | } 184 | } 185 | 186 | .profile { 187 | .avatar { 188 | border-radius: 999px; 189 | background-color: #ccc; 190 | background-size: cover; 191 | width: 200px; 192 | height: 200px; 193 | margin: 1rem; 194 | overflow: hidden; 195 | 196 | div { 197 | background-size: cover; 198 | width: 100%; 199 | height: 100%; 200 | } 201 | } 202 | 203 | .content { 204 | padding: 0 4rem; 205 | 206 | h2 { 207 | font-size: 2rem; 208 | } 209 | 210 | ul { 211 | list-style: none; 212 | padding: 0; 213 | } 214 | } 215 | } 216 | 217 | 218 | .about { 219 | background: #eee; 220 | 221 | h2 { 222 | margin-top: 0; 223 | } 224 | 225 | p { 226 | max-width: 600px; 227 | margin: 0 auto; 228 | padding: 0 1rem; 229 | } 230 | } 231 | 232 | .social { 233 | .share { 234 | display: inline-flex; 235 | align-items: center; 236 | 237 | ul { 238 | display: flex; 239 | list-style: none; 240 | padding: 0; 241 | } 242 | 243 | a { 244 | display: block; 245 | width: 3rem; 246 | height: 3rem; 247 | margin: .75rem; 248 | } 249 | 250 | img { 251 | width: 3rem; 252 | height: 100%; 253 | } 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /web-app/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcusFelling/demo-space-game-vnext/5c74507e2505db8c1bc60a0205218b692093c155/web-app/wwwroot/favicon.ico -------------------------------------------------------------------------------- /web-app/wwwroot/images/avatars/default.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /web-app/wwwroot/images/placeholder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /web-app/wwwroot/images/space-foreground.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 16 | 17 | 18 | 37 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 59 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 73 | 74 | 75 | 92 | 95 | 101 | 104 | 106 | 109 | 112 | 115 | 118 | 120 | 122 | 124 | 125 | 126 | 128 | 129 | -------------------------------------------------------------------------------- /web-app/wwwroot/images/space-game-placeholder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /web-app/wwwroot/images/space-game-title.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 16 | 18 | 22 | 23 | 27 | 29 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /web-app/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /web-app/wwwroot/js/site.min.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcusFelling/demo-space-game-vnext/5c74507e2505db8c1bc60a0205218b692093c155/web-app/wwwroot/js/site.min.js -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap", 3 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", 4 | "keywords": [ 5 | "css", 6 | "js", 7 | "less", 8 | "mobile-first", 9 | "responsive", 10 | "front-end", 11 | "framework", 12 | "web" 13 | ], 14 | "homepage": "http://getbootstrap.com", 15 | "license": "MIT", 16 | "moduleType": "globals", 17 | "main": [ 18 | "less/bootstrap.less", 19 | "dist/js/bootstrap.js" 20 | ], 21 | "ignore": [ 22 | "/.*", 23 | "_config.yml", 24 | "CNAME", 25 | "composer.json", 26 | "CONTRIBUTING.md", 27 | "docs", 28 | "js/tests", 29 | "test-infra" 30 | ], 31 | "dependencies": { 32 | "jquery": "1.9.1 - 3" 33 | }, 34 | "version": "3.3.7", 35 | "_release": "3.3.7", 36 | "_resolution": { 37 | "type": "version", 38 | "tag": "v3.3.7", 39 | "commit": "0b9c4a4007c44201dce9a6cc1a38407005c26c86" 40 | }, 41 | "_source": "https://github.com/twbs/bootstrap.git", 42 | "_target": "v3.3.7", 43 | "_originalSource": "bootstrap", 44 | "_direct": true 45 | } -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2016 Twitter, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcusFelling/demo-space-game-vnext/5c74507e2505db8c1bc60a0205218b692093c155/web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcusFelling/demo-space-game-vnext/5c74507e2505db8c1bc60a0205218b692093c155/web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcusFelling/demo-space-game-vnext/5c74507e2505db8c1bc60a0205218b692093c155/web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarcusFelling/demo-space-game-vnext/5c74507e2505db8c1bc60a0205218b692093c155/web-app/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /web-app/wwwroot/lib/bootstrap/dist/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation-unobtrusive/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation-unobtrusive", 3 | "homepage": "https://github.com/aspnet/jquery-validation-unobtrusive", 4 | "version": "3.2.9", 5 | "_release": "3.2.9", 6 | "_resolution": { 7 | "type": "version", 8 | "tag": "v3.2.9", 9 | "commit": "a91f5401898e125f10771c5f5f0909d8c4c82396" 10 | }, 11 | "_source": "https://github.com/aspnet/jquery-validation-unobtrusive.git", 12 | "_target": "^3.2.9", 13 | "_originalSource": "jquery-validation-unobtrusive", 14 | "_direct": true 15 | } -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (C) Microsoft Corporation. All rights reserved. 3 | // @version v3.2.9 4 | 5 | /*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */ 6 | /*global document: false, jQuery: false */ 7 | 8 | (function (factory) { 9 | if (typeof define === 'function' && define.amd) { 10 | // AMD. Register as an anonymous module. 11 | define("jquery.validate.unobtrusive", ['jquery.validation'], factory); 12 | } else if (typeof module === 'object' && module.exports) { 13 | // CommonJS-like environments that support module.exports 14 | module.exports = factory(require('jquery-validation')); 15 | } else { 16 | // Browser global 17 | jQuery.validator.unobtrusive = factory(jQuery); 18 | } 19 | }(function ($) { 20 | var $jQval = $.validator, 21 | adapters, 22 | data_validation = "unobtrusiveValidation"; 23 | 24 | function setValidationValues(options, ruleName, value) { 25 | options.rules[ruleName] = value; 26 | if (options.message) { 27 | options.messages[ruleName] = options.message; 28 | } 29 | } 30 | 31 | function splitAndTrim(value) { 32 | return value.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/g); 33 | } 34 | 35 | function escapeAttributeValue(value) { 36 | // As mentioned on http://api.jquery.com/category/selectors/ 37 | return value.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1"); 38 | } 39 | 40 | function getModelPrefix(fieldName) { 41 | return fieldName.substr(0, fieldName.lastIndexOf(".") + 1); 42 | } 43 | 44 | function appendModelPrefix(value, prefix) { 45 | if (value.indexOf("*.") === 0) { 46 | value = value.replace("*.", prefix); 47 | } 48 | return value; 49 | } 50 | 51 | function onError(error, inputElement) { // 'this' is the form element 52 | var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"), 53 | replaceAttrValue = container.attr("data-valmsg-replace"), 54 | replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) !== false : null; 55 | 56 | container.removeClass("field-validation-valid").addClass("field-validation-error"); 57 | error.data("unobtrusiveContainer", container); 58 | 59 | if (replace) { 60 | container.empty(); 61 | error.removeClass("input-validation-error").appendTo(container); 62 | } 63 | else { 64 | error.hide(); 65 | } 66 | } 67 | 68 | function onErrors(event, validator) { // 'this' is the form element 69 | var container = $(this).find("[data-valmsg-summary=true]"), 70 | list = container.find("ul"); 71 | 72 | if (list && list.length && validator.errorList.length) { 73 | list.empty(); 74 | container.addClass("validation-summary-errors").removeClass("validation-summary-valid"); 75 | 76 | $.each(validator.errorList, function () { 77 | $("
  • ").html(this.message).appendTo(list); 78 | }); 79 | } 80 | } 81 | 82 | function onSuccess(error) { // 'this' is the form element 83 | var container = error.data("unobtrusiveContainer"); 84 | 85 | if (container) { 86 | var replaceAttrValue = container.attr("data-valmsg-replace"), 87 | replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) : null; 88 | 89 | container.addClass("field-validation-valid").removeClass("field-validation-error"); 90 | error.removeData("unobtrusiveContainer"); 91 | 92 | if (replace) { 93 | container.empty(); 94 | } 95 | } 96 | } 97 | 98 | function onReset(event) { // 'this' is the form element 99 | var $form = $(this), 100 | key = '__jquery_unobtrusive_validation_form_reset'; 101 | if ($form.data(key)) { 102 | return; 103 | } 104 | // Set a flag that indicates we're currently resetting the form. 105 | $form.data(key, true); 106 | try { 107 | $form.data("validator").resetForm(); 108 | } finally { 109 | $form.removeData(key); 110 | } 111 | 112 | $form.find(".validation-summary-errors") 113 | .addClass("validation-summary-valid") 114 | .removeClass("validation-summary-errors"); 115 | $form.find(".field-validation-error") 116 | .addClass("field-validation-valid") 117 | .removeClass("field-validation-error") 118 | .removeData("unobtrusiveContainer") 119 | .find(">*") // If we were using valmsg-replace, get the underlying error 120 | .removeData("unobtrusiveContainer"); 121 | } 122 | 123 | function validationInfo(form) { 124 | var $form = $(form), 125 | result = $form.data(data_validation), 126 | onResetProxy = $.proxy(onReset, form), 127 | defaultOptions = $jQval.unobtrusive.options || {}, 128 | execInContext = function (name, args) { 129 | var func = defaultOptions[name]; 130 | func && $.isFunction(func) && func.apply(form, args); 131 | }; 132 | 133 | if (!result) { 134 | result = { 135 | options: { // options structure passed to jQuery Validate's validate() method 136 | errorClass: defaultOptions.errorClass || "input-validation-error", 137 | errorElement: defaultOptions.errorElement || "span", 138 | errorPlacement: function () { 139 | onError.apply(form, arguments); 140 | execInContext("errorPlacement", arguments); 141 | }, 142 | invalidHandler: function () { 143 | onErrors.apply(form, arguments); 144 | execInContext("invalidHandler", arguments); 145 | }, 146 | messages: {}, 147 | rules: {}, 148 | success: function () { 149 | onSuccess.apply(form, arguments); 150 | execInContext("success", arguments); 151 | } 152 | }, 153 | attachValidation: function () { 154 | $form 155 | .off("reset." + data_validation, onResetProxy) 156 | .on("reset." + data_validation, onResetProxy) 157 | .validate(this.options); 158 | }, 159 | validate: function () { // a validation function that is called by unobtrusive Ajax 160 | $form.validate(); 161 | return $form.valid(); 162 | } 163 | }; 164 | $form.data(data_validation, result); 165 | } 166 | 167 | return result; 168 | } 169 | 170 | $jQval.unobtrusive = { 171 | adapters: [], 172 | 173 | parseElement: function (element, skipAttach) { 174 | /// 175 | /// Parses a single HTML element for unobtrusive validation attributes. 176 | /// 177 | /// The HTML element to be parsed. 178 | /// [Optional] true to skip attaching the 179 | /// validation to the form. If parsing just this single element, you should specify true. 180 | /// If parsing several elements, you should specify false, and manually attach the validation 181 | /// to the form when you are finished. The default is false. 182 | var $element = $(element), 183 | form = $element.parents("form")[0], 184 | valInfo, rules, messages; 185 | 186 | if (!form) { // Cannot do client-side validation without a form 187 | return; 188 | } 189 | 190 | valInfo = validationInfo(form); 191 | valInfo.options.rules[element.name] = rules = {}; 192 | valInfo.options.messages[element.name] = messages = {}; 193 | 194 | $.each(this.adapters, function () { 195 | var prefix = "data-val-" + this.name, 196 | message = $element.attr(prefix), 197 | paramValues = {}; 198 | 199 | if (message !== undefined) { // Compare against undefined, because an empty message is legal (and falsy) 200 | prefix += "-"; 201 | 202 | $.each(this.params, function () { 203 | paramValues[this] = $element.attr(prefix + this); 204 | }); 205 | 206 | this.adapt({ 207 | element: element, 208 | form: form, 209 | message: message, 210 | params: paramValues, 211 | rules: rules, 212 | messages: messages 213 | }); 214 | } 215 | }); 216 | 217 | $.extend(rules, { "__dummy__": true }); 218 | 219 | if (!skipAttach) { 220 | valInfo.attachValidation(); 221 | } 222 | }, 223 | 224 | parse: function (selector) { 225 | /// 226 | /// Parses all the HTML elements in the specified selector. It looks for input elements decorated 227 | /// with the [data-val=true] attribute value and enables validation according to the data-val-* 228 | /// attribute values. 229 | /// 230 | /// Any valid jQuery selector. 231 | 232 | // $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one 233 | // element with data-val=true 234 | var $selector = $(selector), 235 | $forms = $selector.parents() 236 | .addBack() 237 | .filter("form") 238 | .add($selector.find("form")) 239 | .has("[data-val=true]"); 240 | 241 | $selector.find("[data-val=true]").each(function () { 242 | $jQval.unobtrusive.parseElement(this, true); 243 | }); 244 | 245 | $forms.each(function () { 246 | var info = validationInfo(this); 247 | if (info) { 248 | info.attachValidation(); 249 | } 250 | }); 251 | } 252 | }; 253 | 254 | adapters = $jQval.unobtrusive.adapters; 255 | 256 | adapters.add = function (adapterName, params, fn) { 257 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation. 258 | /// The name of the adapter to be added. This matches the name used 259 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 260 | /// [Optional] An array of parameter names (strings) that will 261 | /// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and 262 | /// mmmm is the parameter name). 263 | /// The function to call, which adapts the values from the HTML 264 | /// attributes into jQuery Validate rules and/or messages. 265 | /// 266 | if (!fn) { // Called with no params, just a function 267 | fn = params; 268 | params = []; 269 | } 270 | this.push({ name: adapterName, params: params, adapt: fn }); 271 | return this; 272 | }; 273 | 274 | adapters.addBool = function (adapterName, ruleName) { 275 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 276 | /// the jQuery Validate validation rule has no parameter values. 277 | /// The name of the adapter to be added. This matches the name used 278 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 279 | /// [Optional] The name of the jQuery Validate rule. If not provided, the value 280 | /// of adapterName will be used instead. 281 | /// 282 | return this.add(adapterName, function (options) { 283 | setValidationValues(options, ruleName || adapterName, true); 284 | }); 285 | }; 286 | 287 | adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) { 288 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 289 | /// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and 290 | /// one for min-and-max). The HTML parameters are expected to be named -min and -max. 291 | /// The name of the adapter to be added. This matches the name used 292 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 293 | /// The name of the jQuery Validate rule to be used when you only 294 | /// have a minimum value. 295 | /// The name of the jQuery Validate rule to be used when you only 296 | /// have a maximum value. 297 | /// The name of the jQuery Validate rule to be used when you 298 | /// have both a minimum and maximum value. 299 | /// [Optional] The name of the HTML attribute that 300 | /// contains the minimum value. The default is "min". 301 | /// [Optional] The name of the HTML attribute that 302 | /// contains the maximum value. The default is "max". 303 | /// 304 | return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) { 305 | var min = options.params.min, 306 | max = options.params.max; 307 | 308 | if (min && max) { 309 | setValidationValues(options, minMaxRuleName, [min, max]); 310 | } 311 | else if (min) { 312 | setValidationValues(options, minRuleName, min); 313 | } 314 | else if (max) { 315 | setValidationValues(options, maxRuleName, max); 316 | } 317 | }); 318 | }; 319 | 320 | adapters.addSingleVal = function (adapterName, attribute, ruleName) { 321 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 322 | /// the jQuery Validate validation rule has a single value. 323 | /// The name of the adapter to be added. This matches the name used 324 | /// in the data-val-nnnn HTML attribute(where nnnn is the adapter name). 325 | /// [Optional] The name of the HTML attribute that contains the value. 326 | /// The default is "val". 327 | /// [Optional] The name of the jQuery Validate rule. If not provided, the value 328 | /// of adapterName will be used instead. 329 | /// 330 | return this.add(adapterName, [attribute || "val"], function (options) { 331 | setValidationValues(options, ruleName || adapterName, options.params[attribute]); 332 | }); 333 | }; 334 | 335 | $jQval.addMethod("__dummy__", function (value, element, params) { 336 | return true; 337 | }); 338 | 339 | $jQval.addMethod("regex", function (value, element, params) { 340 | var match; 341 | if (this.optional(element)) { 342 | return true; 343 | } 344 | 345 | match = new RegExp(params).exec(value); 346 | return (match && (match.index === 0) && (match[0].length === value.length)); 347 | }); 348 | 349 | $jQval.addMethod("nonalphamin", function (value, element, nonalphamin) { 350 | var match; 351 | if (nonalphamin) { 352 | match = value.match(/\W/g); 353 | match = match && match.length >= nonalphamin; 354 | } 355 | return match; 356 | }); 357 | 358 | if ($jQval.methods.extension) { 359 | adapters.addSingleVal("accept", "mimtype"); 360 | adapters.addSingleVal("extension", "extension"); 361 | } else { 362 | // for backward compatibility, when the 'extension' validation method does not exist, such as with versions 363 | // of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for 364 | // validating the extension, and ignore mime-type validations as they are not supported. 365 | adapters.addSingleVal("extension", "extension", "accept"); 366 | } 367 | 368 | adapters.addSingleVal("regex", "pattern"); 369 | adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"); 370 | adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range"); 371 | adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength"); 372 | adapters.add("equalto", ["other"], function (options) { 373 | var prefix = getModelPrefix(options.element.name), 374 | other = options.params.other, 375 | fullOtherName = appendModelPrefix(other, prefix), 376 | element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0]; 377 | 378 | setValidationValues(options, "equalTo", element); 379 | }); 380 | adapters.add("required", function (options) { 381 | // jQuery Validate equates "required" with "mandatory" for checkbox elements 382 | if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") { 383 | setValidationValues(options, "required", true); 384 | } 385 | }); 386 | adapters.add("remote", ["url", "type", "additionalfields"], function (options) { 387 | var value = { 388 | url: options.params.url, 389 | type: options.params.type || "GET", 390 | data: {} 391 | }, 392 | prefix = getModelPrefix(options.element.name); 393 | 394 | $.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) { 395 | var paramName = appendModelPrefix(fieldName, prefix); 396 | value.data[paramName] = function () { 397 | var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']"); 398 | // For checkboxes and radio buttons, only pick up values from checked fields. 399 | if (field.is(":checkbox")) { 400 | return field.filter(":checked").val() || field.filter(":hidden").val() || ''; 401 | } 402 | else if (field.is(":radio")) { 403 | return field.filter(":checked").val() || ''; 404 | } 405 | return field.val(); 406 | }; 407 | }); 408 | 409 | setValidationValues(options, "remote", value); 410 | }); 411 | adapters.add("password", ["min", "nonalphamin", "regex"], function (options) { 412 | if (options.params.min) { 413 | setValidationValues(options, "minlength", options.params.min); 414 | } 415 | if (options.params.nonalphamin) { 416 | setValidationValues(options, "nonalphamin", options.params.nonalphamin); 417 | } 418 | if (options.params.regex) { 419 | setValidationValues(options, "regex", options.params.regex); 420 | } 421 | }); 422 | adapters.add("fileextensions", ["extensions"], function (options) { 423 | setValidationValues(options, "extension", options.params.extensions); 424 | }); 425 | 426 | $(function () { 427 | $jQval.unobtrusive.parse(document); 428 | }); 429 | 430 | return $jQval.unobtrusive; 431 | })); -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (C) Microsoft Corporation. All rights reserved. 3 | // @version v3.2.9 4 | !function(a){"function"==typeof define&&define.amd?define("jquery.validate.unobtrusive",["jquery.validation"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery-validation")):jQuery.validator.unobtrusive=a(jQuery)}(function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function u(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=f.unobtrusive.options||{},u=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),u("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),u("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),u("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var m,f=a.validator,v="unobtrusiveValidation";return f.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=u(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){f.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=u(this);a&&a.attachValidation()})}},m=f.unobtrusive.adapters,m.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},m.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},m.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},m.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},f.addMethod("__dummy__",function(a,e,n){return!0}),f.addMethod("regex",function(a,e,n){var t;return!!this.optional(e)||(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),f.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),f.methods.extension?(m.addSingleVal("accept","mimtype"),m.addSingleVal("extension","extension")):m.addSingleVal("extension","extension","accept"),m.addSingleVal("regex","pattern"),m.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),m.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),m.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),m.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),m.add("required",function(a){"INPUT"===a.element.tagName.toUpperCase()&&"CHECKBOX"===a.element.type.toUpperCase()||e(a,"required",!0)}),m.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),m.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),m.add("fileextensions",["extensions"],function(a){e(a,"extension",a.params.extensions)}),a(function(){f.unobtrusive.parse(document)}),f.unobtrusive}); -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation", 3 | "homepage": "https://jqueryvalidation.org/", 4 | "repository": { 5 | "type": "git", 6 | "url": "git://github.com/jquery-validation/jquery-validation.git" 7 | }, 8 | "authors": [ 9 | "Jörn Zaefferer " 10 | ], 11 | "description": "Form validation made easy", 12 | "main": "dist/jquery.validate.js", 13 | "keywords": [ 14 | "forms", 15 | "validation", 16 | "validate" 17 | ], 18 | "license": "MIT", 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "demo", 25 | "lib" 26 | ], 27 | "dependencies": { 28 | "jquery": ">= 1.7.2" 29 | }, 30 | "version": "1.17.0", 31 | "_release": "1.17.0", 32 | "_resolution": { 33 | "type": "version", 34 | "tag": "1.17.0", 35 | "commit": "fc9b12d3bfaa2d0c04605855b896edb2934c0772" 36 | }, 37 | "_source": "https://github.com/jzaefferer/jquery-validation.git", 38 | "_target": "^1.17.0", 39 | "_originalSource": "jquery-validation", 40 | "_direct": true 41 | } -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /web-app/wwwroot/lib/jquery-validation/dist/additional-methods.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery Validation Plugin - v1.17.0 - 7/29/2017 2 | * https://jqueryvalidation.org/ 3 | * Copyright (c) 2017 Jörn Zaefferer; Licensed MIT */ 4 | !function(a){"function"==typeof define&&define.amd?define(["jquery","./jquery.validate.min"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){return function(){function b(a){return a.replace(/<.[^<>]*?>/g," ").replace(/ | /gi," ").replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g,"")}a.validator.addMethod("maxWords",function(a,c,d){return this.optional(c)||b(a).match(/\b\w+\b/g).length<=d},a.validator.format("Please enter {0} words or less.")),a.validator.addMethod("minWords",function(a,c,d){return this.optional(c)||b(a).match(/\b\w+\b/g).length>=d},a.validator.format("Please enter at least {0} words.")),a.validator.addMethod("rangeWords",function(a,c,d){var e=b(a),f=/\b\w+\b/g;return this.optional(c)||e.match(f).length>=d[0]&&e.match(f).length<=d[1]},a.validator.format("Please enter between {0} and {1} words."))}(),a.validator.addMethod("accept",function(b,c,d){var e,f,g,h="string"==typeof d?d.replace(/\s/g,""):"image/*",i=this.optional(c);if(i)return i;if("file"===a(c).attr("type")&&(h=h.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g,"\\$&").replace(/,/g,"|").replace(/\/\*/g,"/.*"),c.files&&c.files.length))for(g=new RegExp(".?("+h+")$","i"),e=0;e9?"0":f,g="JABCDEFGHI".substr(f,1).toString(),i.match(/[ABEH]/)?k===f:i.match(/[KPQS]/)?k===g:k===f||k===g},"Please specify a valid CIF number."),a.validator.addMethod("cpfBR",function(a){if(a=a.replace(/([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g,""),11!==a.length)return!1;var b,c,d,e,f=0;if(b=parseInt(a.substring(9,10),10),c=parseInt(a.substring(10,11),10),d=function(a,b){var c=10*a%11;return 10!==c&&11!==c||(c=0),c===b},""===a||"00000000000"===a||"11111111111"===a||"22222222222"===a||"33333333333"===a||"44444444444"===a||"55555555555"===a||"66666666666"===a||"77777777777"===a||"88888888888"===a||"99999999999"===a)return!1;for(e=1;e<=9;e++)f+=parseInt(a.substring(e-1,e),10)*(11-e);if(d(f,b)){for(f=0,e=1;e<=10;e++)f+=parseInt(a.substring(e-1,e),10)*(12-e);return d(f,c)}return!1},"Please specify a valid CPF number"),a.validator.addMethod("creditcard",function(a,b){if(this.optional(b))return"dependency-mismatch";if(/[^0-9 \-]+/.test(a))return!1;var c,d,e=0,f=0,g=!1;if(a=a.replace(/\D/g,""),a.length<13||a.length>19)return!1;for(c=a.length-1;c>=0;c--)d=a.charAt(c),f=parseInt(d,10),g&&(f*=2)>9&&(f-=9),e+=f,g=!g;return e%10===0},"Please enter a valid credit card number."),a.validator.addMethod("creditcardtypes",function(a,b,c){if(/[^0-9\-]+/.test(a))return!1;a=a.replace(/\D/g,"");var d=0;return c.mastercard&&(d|=1),c.visa&&(d|=2),c.amex&&(d|=4),c.dinersclub&&(d|=8),c.enroute&&(d|=16),c.discover&&(d|=32),c.jcb&&(d|=64),c.unknown&&(d|=128),c.all&&(d=255),1&d&&/^(5[12345])/.test(a)?16===a.length:2&d&&/^(4)/.test(a)?16===a.length:4&d&&/^(3[47])/.test(a)?15===a.length:8&d&&/^(3(0[012345]|[68]))/.test(a)?14===a.length:16&d&&/^(2(014|149))/.test(a)?15===a.length:32&d&&/^(6011)/.test(a)?16===a.length:64&d&&/^(3)/.test(a)?16===a.length:64&d&&/^(2131|1800)/.test(a)?15===a.length:!!(128&d)},"Please enter a valid credit card number."),a.validator.addMethod("currency",function(a,b,c){var d,e="string"==typeof c,f=e?c:c[0],g=!!e||c[1];return f=f.replace(/,/g,""),f=g?f+"]":f+"]?",d="^["+f+"([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$",d=new RegExp(d),this.optional(b)||d.test(a)},"Please specify a valid currency"),a.validator.addMethod("dateFA",function(a,b){return this.optional(b)||/^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test(a)},a.validator.messages.date),a.validator.addMethod("dateITA",function(a,b){var c,d,e,f,g,h=!1,i=/^\d{1,2}\/\d{1,2}\/\d{4}$/;return i.test(a)?(c=a.split("/"),d=parseInt(c[0],10),e=parseInt(c[1],10),f=parseInt(c[2],10),g=new Date(Date.UTC(f,e-1,d,12,0,0,0)),h=g.getUTCFullYear()===f&&g.getUTCMonth()===e-1&&g.getUTCDate()===d):h=!1,this.optional(b)||h},a.validator.messages.date),a.validator.addMethod("dateNL",function(a,b){return this.optional(b)||/^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(a)},a.validator.messages.date),a.validator.addMethod("extension",function(a,b,c){return c="string"==typeof c?c.replace(/,/g,"|"):"png|jpe?g|gif",this.optional(b)||a.match(new RegExp("\\.("+c+")$","i"))},a.validator.format("Please enter a value with a valid extension.")),a.validator.addMethod("giroaccountNL",function(a,b){return this.optional(b)||/^[0-9]{1,7}$/.test(a)},"Please specify a valid giro account number"),a.validator.addMethod("iban",function(a,b){if(this.optional(b))return!0;var c,d,e,f,g,h,i,j,k,l=a.replace(/ /g,"").toUpperCase(),m="",n=!0,o="",p="",q=5;if(l.length9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/)},"Please specify a valid mobile number"),a.validator.addMethod("netmask",function(a,b){return this.optional(b)||/^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/i.test(a)},"Please enter a valid netmask."),a.validator.addMethod("nieES",function(a,b){"use strict";if(this.optional(b))return!0;var c,d=new RegExp(/^[MXYZ]{1}[0-9]{7,8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/gi),e="TRWAGMYFPDXBNJZSQVHLCKET",f=a.substr(a.length-1).toUpperCase();return a=a.toString().toUpperCase(),!(a.length>10||a.length<9||!d.test(a))&&(a=a.replace(/^[X]/,"0").replace(/^[Y]/,"1").replace(/^[Z]/,"2"),c=9===a.length?a.substr(0,8):a.substr(0,9),e.charAt(parseInt(c,10)%23)===f)},"Please specify a valid NIE number."),a.validator.addMethod("nifES",function(a,b){"use strict";return!!this.optional(b)||(a=a.toUpperCase(),!!a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)")&&(/^[0-9]{8}[A-Z]{1}$/.test(a)?"TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.substring(8,0)%23)===a.charAt(8):!!/^[KLM]{1}/.test(a)&&a[8]==="TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.substring(8,1)%23)))},"Please specify a valid NIF number."),a.validator.addMethod("nipPL",function(a){"use strict";if(a=a.replace(/[^0-9]/g,""),10!==a.length)return!1;for(var b=[6,5,7,2,3,4,5,6,7],c=0,d=0;d<9;d++)c+=b[d]*a[d];var e=c%11,f=10===e?0:e;return f===parseInt(a[9],10)},"Please specify a valid NIP number."),a.validator.addMethod("notEqualTo",function(b,c,d){return this.optional(c)||!a.validator.methods.equalTo.call(this,b,c,d)},"Please enter a different value, values must not be the same."),a.validator.addMethod("nowhitespace",function(a,b){return this.optional(b)||/^\S+$/i.test(a)},"No white space please"),a.validator.addMethod("pattern",function(a,b,c){return!!this.optional(b)||("string"==typeof c&&(c=new RegExp("^(?:"+c+")$")),c.test(a))},"Invalid format."),a.validator.addMethod("phoneNL",function(a,b){return this.optional(b)||/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test(a)},"Please specify a valid phone number."),a.validator.addMethod("phonesUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/)},"Please specify a valid uk phone number"),a.validator.addMethod("phoneUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/)},"Please specify a valid phone number"),a.validator.addMethod("phoneUS",function(a,b){return a=a.replace(/\s+/g,""),this.optional(b)||a.length>9&&a.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/)},"Please specify a valid phone number"),a.validator.addMethod("postalcodeBR",function(a,b){return this.optional(b)||/^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test(a)},"Informe um CEP válido."),a.validator.addMethod("postalCodeCA",function(a,b){return this.optional(b)||/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeIT",function(a,b){return this.optional(b)||/^\d{5}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeNL",function(a,b){return this.optional(b)||/^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postcodeUK",function(a,b){return this.optional(b)||/^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(a)},"Please specify a valid UK postcode"),a.validator.addMethod("require_from_group",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_req_grp")?f.data("valid_req_grp"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length>=d[0];return f.data("valid_req_grp",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),h},a.validator.format("Please fill at least {0} of these fields.")),a.validator.addMethod("skip_or_fill_minimum",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_skip")?f.data("valid_skip"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length,i=0===h||h>=d[0];return f.data("valid_skip",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),i},a.validator.format("Please either skip these fields or fill at least {0} of them.")),a.validator.addMethod("stateUS",function(a,b,c){var d,e="undefined"==typeof c,f=!e&&"undefined"!=typeof c.caseSensitive&&c.caseSensitive,g=!e&&"undefined"!=typeof c.includeTerritories&&c.includeTerritories,h=!e&&"undefined"!=typeof c.includeMilitary&&c.includeMilitary;return d=g||h?g&&h?"^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":g?"^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":"^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$":"^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$",d=f?new RegExp(d):new RegExp(d,"i"),this.optional(b)||d.test(a)},"Please specify a valid state"),a.validator.addMethod("strippedminlength",function(b,c,d){return a(b).text().length>=d},a.validator.format("Please enter at least {0} characters")),a.validator.addMethod("time",function(a,b){return this.optional(b)||/^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test(a)},"Please enter a valid time, between 00:00 and 23:59"),a.validator.addMethod("time12h",function(a,b){return this.optional(b)||/^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(a)},"Please enter a valid time in 12-hour am/pm format"),a.validator.addMethod("url2",function(a,b){return this.optional(b)||/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(a)},a.validator.messages.url),a.validator.addMethod("vinUS",function(a){if(17!==a.length)return!1;var b,c,d,e,f,g,h=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"],i=[1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9],j=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2],k=0;for(b=0;b<17;b++){if(e=j[b],d=a.slice(b,b+1),8===b&&(g=d),isNaN(d)){for(c=0;c