├── Tailspin.SpaceGame.Web ├── wwwroot │ ├── js │ │ ├── site.min.js │ │ └── site.js │ ├── favicon.ico │ ├── lib │ │ ├── bootstrap │ │ │ ├── dist │ │ │ │ ├── fonts │ │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ │ └── js │ │ │ │ │ └── npm.js │ │ │ ├── LICENSE │ │ │ └── .bower.json │ │ ├── jquery-validation-unobtrusive │ │ │ ├── .bower.json │ │ │ ├── LICENSE.txt │ │ │ ├── jquery.validate.unobtrusive.min.js │ │ │ └── jquery.validate.unobtrusive.js │ │ ├── jquery │ │ │ ├── .bower.json │ │ │ └── LICENSE.txt │ │ └── jquery-validation │ │ │ ├── .bower.json │ │ │ ├── LICENSE.md │ │ │ └── dist │ │ │ └── additional-methods.min.js │ ├── images │ │ ├── space-game-placeholder.svg │ │ ├── placeholder.svg │ │ ├── avatars │ │ │ └── default.svg │ │ ├── space-game-title.svg │ │ └── space-foreground.svg │ └── css │ │ ├── site.css.map │ │ ├── site.min.css │ │ ├── site.css │ │ └── site.scss ├── Views │ ├── _ViewStart.cshtml │ ├── _ViewImports.cshtml │ ├── Home │ │ ├── Privacy.cshtml │ │ ├── Profile.cshtml │ │ └── Index.cshtml │ └── Shared │ │ ├── Error.cshtml │ │ ├── _ValidationScriptsPartial.cshtml │ │ ├── _CookieConsentPartial.cshtml │ │ └── _Layout.cshtml ├── appsettings.json ├── appsettings.Development.json ├── Models │ ├── ErrorViewModel.cs │ ├── ProfileViewModel.cs │ ├── Model.cs │ ├── Profile.cs │ ├── Score.cs │ └── LeaderboardViewModel.cs ├── Tailspin.SpaceGame.Web.csproj ├── Program.cs ├── IDocumentDBRepository.cs ├── Startup.cs ├── LocalDocumentDBRepository.cs ├── SampleData │ ├── scores.json │ └── profiles.json └── Controllers │ └── HomeController.cs ├── azure-pipelines.yml ├── .agent-tools ├── readme.md ├── build-tools.sh └── build-agent.sh ├── package.json ├── .devcontainer ├── library-scripts │ ├── start.sh │ └── common-debian.sh ├── devcontainer.json └── Dockerfile ├── Tailspin.SpaceGame.Web.sln ├── LICENSE-CODE ├── gulpfile.js ├── .vscode ├── tasks.json └── launch.json ├── SECURITY.md ├── README.md ├── .gitignore └── LICENSE /Tailspin.SpaceGame.Web/wwwroot/js/site.min.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | pool: MyAgentPool 2 | steps: 3 | - bash: echo hello world -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /.agent-tools/readme.md: -------------------------------------------------------------------------------- 1 | This folder contains scripts used in the "Host your own build agent in Azure Pipelines" 2 | training module -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidacm/mslearn-tailspin-spacegame-web/main/Tailspin.SpaceGame.Web/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using TailSpin.SpaceGame.Web 2 | @using TailSpin.SpaceGame.Web.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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.

-------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidacm/mslearn-tailspin-spacegame-web/main/Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidacm/mslearn-tailspin-spacegame-web/main/Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidacm/mslearn-tailspin-spacegame-web/main/Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "gulp": "^4.0.2", 4 | "gulp-clean-css": "^4.2.0", 5 | "gulp-concat": "2.6.1", 6 | "gulp-uglify": "3.0.0", 7 | "node-sass": "^7.0.1", 8 | "rimraf": "2.6.1" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidacm/mslearn-tailspin-spacegame-web/main/Tailspin.SpaceGame.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46} 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Models/Model.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 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 | [JsonPropertyName("id")] 12 | public string Id { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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') -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/images/space-game-placeholder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Models/Profile.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace TailSpin.SpaceGame.Web.Models 4 | { 5 | public class Profile : Model 6 | { 7 | // The player's user name. 8 | [JsonPropertyName("userName")] 9 | public string UserName { get; set; } 10 | 11 | // The URL of the player's avatar image. 12 | [JsonPropertyName("avatarUrl")] 13 | public string AvatarUrl { get; set; } 14 | 15 | // The achievements the player earned. 16 | [JsonPropertyName("achievements")] 17 | public string[] Achievements { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/lib/jquery/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "main": "dist/jquery.js", 4 | "license": "MIT", 5 | "ignore": [ 6 | "package.json" 7 | ], 8 | "keywords": [ 9 | "jquery", 10 | "javascript", 11 | "browser", 12 | "library" 13 | ], 14 | "homepage": "https://github.com/jquery/jquery-dist", 15 | "version": "3.3.1", 16 | "_release": "3.3.1", 17 | "_resolution": { 18 | "type": "version", 19 | "tag": "3.3.1", 20 | "commit": "9e8ec3d10fad04748176144f108d7355662ae75e" 21 | }, 22 | "_source": "https://github.com/jquery/jquery-dist.git", 23 | "_target": "^3.3.1", 24 | "_originalSource": "jquery", 25 | "_direct": true 26 | } -------------------------------------------------------------------------------- /.agent-tools/build-tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Select a default .NET version if one is not specified 5 | if [ -z "$DOTNET_VERSION" ]; then 6 | DOTNET_VERSION=6.0.300 7 | fi 8 | 9 | # Add the Node.js PPA so that we can install the latest version 10 | curl -sL https://deb.nodesource.com/setup_16.x | bash - 11 | 12 | # Install Node.js and jq 13 | apt-get install -y nodejs 14 | 15 | apt-get install -y jq 16 | 17 | # Install gulp 18 | npm install -g gulp 19 | 20 | # Change ownership of the .npm directory to the sudo (non-root) user 21 | chown -R $SUDO_USER ~/.npm 22 | 23 | # Install .NET as the sudo (non-root) user 24 | sudo -i -u $SUDO_USER bash << EOF 25 | curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c LTS -v $DOTNET_VERSION 26 | EOF 27 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Models/Score.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 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 | [JsonPropertyName("profileId")] 9 | public string ProfileId { get; set; } 10 | 11 | // The score value. 12 | [JsonPropertyName("score")] 13 | public int HighScore { get; set; } 14 | 15 | // The game mode the score is associated with. 16 | [JsonPropertyName("gameMode")] 17 | public string GameMode { get; set; } 18 | 19 | // The game region (map) the score is associated with. 20 | [JsonPropertyName("gameRegion")] 21 | public string GameRegion { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /.devcontainer/library-scripts/start.sh: -------------------------------------------------------------------------------- 1 | #start.sh 2 | #!/bin/bash 3 | 4 | #Script modified from https://github.com/Pwd9000-ML/GitHub-Codespaces-Lab/tree/master/.devcontainer/codespaceADOagent 5 | 6 | #GitHub Codespace secrets 7 | ADO_ORG=$ADO_ORG 8 | ADO_PAT=$ADO_PAT 9 | ADO_POOL_NAME=$ADO_POOL_NAME 10 | 11 | # Derived environment variables 12 | HOSTNAME=$(hostname) 13 | AGENT_SUFFIX="ADO-agent" 14 | AGENT_NAME="${HOSTNAME}-${AGENT_SUFFIX}" 15 | ADO_URL="https://dev.azure.com/${ADO_ORG}" 16 | 17 | export VSO_AGENT_IGNORE=ADO_PAT,GH_TOKEN,GITHUB_CODESPACE_TOKEN,GITHUB_TOKEN 18 | 19 | /home/vscode/azure-pipelines/config.sh --unattended \ 20 | --agent "${AGENT_NAME}" \ 21 | --url "${ADO_URL}" \ 22 | --auth PAT \ 23 | --token "${ADO_PAT}" \ 24 | --pool "${ADO_POOL_NAME:-Default}" \ 25 | --replace \ 26 | --acceptTeeEula 27 | 28 | /home/vscode/azure-pipelines/run.sh -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/images/placeholder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tailspin.SpaceGame.Web", "Tailspin.SpaceGame.Web\Tailspin.SpaceGame.Web.csproj", "{A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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"} -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /LICENSE-CODE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) Microsoft Corporation 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial 11 | portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 15 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 16 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 17 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /// 2 | "use strict"; 3 | 4 | const gulp = require("gulp"), 5 | rimraf = require("rimraf"), 6 | concat = require("gulp-concat"), 7 | cleanCSS = require("gulp-clean-css"), 8 | uglify = require("gulp-uglify"); 9 | 10 | const paths = { 11 | webroot: "./Tailspin.SpaceGame.Web/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(cleanCSS()) 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"])); -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/images/avatars/default.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AzurePipelines", 3 | "dockerFile": "Dockerfile", 4 | 5 | // Configure tool-specific properties. 6 | "customizations": { 7 | // Configure properties specific to VS Code. 8 | "vscode": { 9 | // Add the IDs of extensions you want installed when the container is created. 10 | "extensions": [ 11 | "ms-vscode.azurecli", 12 | "ms-vscode.powershell", 13 | "hashicorp.terraform", 14 | "esbenp.prettier-vscode", 15 | "tfsec.tfsec" 16 | ] 17 | } 18 | }, 19 | 20 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 21 | // "forwardPorts": [], 22 | 23 | // Use 'postStartCommand' to run commands each time the container is successfully started.. 24 | "postStartCommand": "/home/vscode/azure-pipelines/start.sh", 25 | 26 | // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 27 | "remoteUser": "vscode", 28 | // Amend Azure Pipelines agent version and arch type with 'ARCH' and 'AGENT_VERSION'. https://github.com/microsoft/azure-pipelines-agent/releases. 29 | "build": { 30 | "args": { 31 | "UPGRADE_PACKAGES": "true", 32 | "ARCH": "x64", 33 | "AGENT_VERSION": "2.206.1" 34 | } 35 | }, 36 | "features": { 37 | "terraform": "latest", 38 | "azure-cli": "latest", 39 | "git-lfs": "latest", 40 | "github-cli": "latest", 41 | "powershell": "latest" 42 | } 43 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | // Use IntelliSense to find out which attributes exist for C# debugging 6 | // Use hover for the description of the existing attributes 7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 8 | "name": ".NET Core Launch (web)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/Tailspin.SpaceGame.Web/bin/Debug/net5.0/Tailspin.SpaceGame.Web.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/Tailspin.SpaceGame.Web", 16 | "stopAtEntry": false, 17 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser 18 | "serverReadyAction": { 19 | "action": "openExternally", 20 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 21 | }, 22 | "env": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "sourceFileMap": { 26 | "/Views": "${workspaceFolder}/Views" 27 | } 28 | }, 29 | { 30 | "name": ".NET Core Attach", 31 | "type": "coreclr", 32 | "request": "attach", 33 | "processId": "${command:pickProcess}" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Views/Home/Profile.cshtml: -------------------------------------------------------------------------------- 1 | @model TailSpin.SpaceGame.Web.Models.ProfileViewModel 2 | @{ 3 | ViewData["Title"] = "@Model.Profile.UserName Profile"; 4 | } 5 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/lib/jquery/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright JS Foundation and other contributors, https://js.foundation/ 2 | 3 | This software consists of voluntary contributions made by many 4 | individuals. For exact contribution history, see the revision history 5 | available at https://github.com/jquery/jquery 6 | 7 | The following license applies to all parts of this software except as 8 | documented below: 9 | 10 | ==== 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the 14 | "Software"), to deal in the Software without restriction, including 15 | without limitation the rights to use, copy, modify, merge, publish, 16 | distribute, sublicense, and/or sell copies of the Software, and to 17 | permit persons to whom the Software is furnished to do so, subject to 18 | the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be 21 | included in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | 31 | ==== 32 | 33 | All files located in the node_modules and external directories are 34 | externally maintained libraries used by this software which have their 35 | own licenses; we recommend you read them, as their terms may differ from 36 | the terms above. 37 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/devcontainers/dotnet:6.0 2 | 3 | # Install NodeJS 4 | # [Choice] Node.js version: none, lts/*, 18, 16, 14 5 | ARG NODE_VERSION="16" 6 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 7 | 8 | # Install Gulp 9 | RUN npm install --global gulp-cli 10 | 11 | RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash 12 | 13 | # [Optional] Install zsh 14 | ARG INSTALL_ZSH="true" 15 | # [Optional] Upgrade OS packages to their latest versions 16 | ARG UPGRADE_PACKAGES="false" 17 | 18 | # Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. 19 | ARG USERNAME=vscode 20 | ARG USER_UID=1000 21 | ARG USER_GID=$USER_UID 22 | COPY library-scripts/*.sh /tmp/library-scripts/ 23 | RUN bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" 24 | 25 | # cd into the user directory, download and unzip the Azure DevOps agent 26 | RUN cd /home/vscode && mkdir azure-pipelines && cd azure-pipelines 27 | 28 | # input Azure DevOps agent arguments 29 | ARG ARCH="x64" 30 | ARG AGENT_VERSION="2.206.1" 31 | 32 | RUN cd /home/vscode/azure-pipelines \ 33 | && curl -O -L https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/vsts-agent-linux-${ARCH}-${AGENT_VERSION}.tar.gz \ 34 | && tar xzf /home/vscode/azure-pipelines/vsts-agent-linux-${ARCH}-${AGENT_VERSION}.tar.gz \ 35 | && /home/vscode/azure-pipelines/bin/installdependencies.sh 36 | 37 | # copy over the start.sh script 38 | COPY library-scripts/start.sh /home/vscode/azure-pipelines/start.sh 39 | 40 | # Apply ownership of home folder 41 | RUN chown -R vscode ~vscode 42 | 43 | # make the script executable 44 | RUN chmod +x /home/vscode/azure-pipelines/start.sh 45 | 46 | # Clean up 47 | RUN rm -rf /var/lib/apt/lists/* /tmp/library-scripts -------------------------------------------------------------------------------- /.agent-tools/build-agent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Select a default agent version if one is not specified 5 | if [ -z "$AZP_AGENT_VERSION" ]; then 6 | AZP_AGENT_VERSION=2.187.2 7 | fi 8 | 9 | # Verify Azure Pipelines token is set 10 | if [ -z "$AZP_TOKEN" ]; then 11 | echo 1>&2 "error: missing AZP_TOKEN environment variable" 12 | exit 1 13 | fi 14 | 15 | # Verify Azure DevOps URL is set 16 | if [ -z "$AZP_URL" ]; then 17 | echo 1>&2 "error: missing AZP_URL environment variable" 18 | exit 1 19 | fi 20 | 21 | # If a working directory was specified, create that directory 22 | if [ -n "$AZP_WORK" ]; then 23 | mkdir -p "$AZP_WORK" 24 | fi 25 | 26 | # Create the Downloads directory under the user's home directory 27 | if [ -n "$HOME/Downloads" ]; then 28 | mkdir -p "$HOME/Downloads" 29 | fi 30 | 31 | # Download the agent package 32 | curl https://vstsagentpackage.azureedge.net/agent/$AZP_AGENT_VERSION/vsts-agent-linux-x64-$AZP_AGENT_VERSION.tar.gz > $HOME/Downloads/vsts-agent-linux-x64-$AZP_AGENT_VERSION.tar.gz 33 | 34 | # Create the working directory for the agent service to run jobs under 35 | if [ -n "$AZP_WORK" ]; then 36 | mkdir -p "$AZP_WORK" 37 | fi 38 | 39 | # Create a working directory to extract the agent package to 40 | mkdir -p $HOME/azp/agent 41 | 42 | # Move to the working directory 43 | cd $HOME/azp/agent 44 | 45 | # Extract the agent package to the working directory 46 | tar zxvf $HOME/Downloads/vsts-agent-linux-x64-$AZP_AGENT_VERSION.tar.gz 47 | 48 | # Install the agent software 49 | ./bin/installdependencies.sh 50 | 51 | # Configure the agent as the sudo (non-root) user 52 | chown $SUDO_USER $HOME/azp/agent 53 | sudo -u $SUDO_USER ./config.sh --unattended \ 54 | --agent "${AZP_AGENT_NAME:-$(hostname)}" \ 55 | --url "$AZP_URL" \ 56 | --auth PAT \ 57 | --token "$AZP_TOKEN" \ 58 | --pool "${AZP_POOL:-Default}" \ 59 | --work "${AZP_WORK:-_work}" \ 60 | --replace \ 61 | --acceptTeeEula 62 | 63 | # Install and start the agent service 64 | ./svc.sh install 65 | ./svc.sh start -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/IDocumentDBRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 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 | Func queryPredicate, 35 | Func 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(Func queryPredicate); 49 | } 50 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.HttpsPolicy; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Hosting; 11 | using TailSpin.SpaceGame.Web.Models; 12 | using Microsoft.AspNetCore.Http; 13 | 14 | 15 | namespace TailSpin.SpaceGame.Web 16 | { 17 | public class Startup 18 | { 19 | public Startup(IConfiguration configuration) 20 | { 21 | Configuration = configuration; 22 | } 23 | 24 | public IConfiguration Configuration { get; } 25 | 26 | // This method gets called by the runtime. Use this method to add services to the container. 27 | public void ConfigureServices(IServiceCollection services) 28 | { 29 | services.AddControllersWithViews(); 30 | services.Configure(options => 31 | { 32 | // This lambda determines whether user consent for non-essential cookies is needed for a given request. 33 | options.CheckConsentNeeded = context => true; 34 | options.MinimumSameSitePolicy = SameSiteMode.None; 35 | }); 36 | 37 | // Add document stores. These are passed to the HomeController constructor. 38 | services.AddSingleton>(new LocalDocumentDBRepository(@"SampleData/scores.json")); 39 | services.AddSingleton>(new LocalDocumentDBRepository(@"SampleData/profiles.json")); 40 | } 41 | 42 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 43 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 44 | { 45 | if (env.IsDevelopment()) 46 | { 47 | app.UseDeveloperExceptionPage(); 48 | } 49 | else 50 | { 51 | app.UseExceptionHandler("/Home/Error"); 52 | app.UseHsts(); 53 | } 54 | 55 | app.UseHttpsRedirection(); 56 | app.UseStaticFiles(); 57 | 58 | app.UseRouting(); 59 | 60 | app.UseAuthorization(); 61 | 62 | app.UseEndpoints(endpoints => 63 | { 64 | endpoints.MapControllerRoute( 65 | name: "default", 66 | pattern: "{controller=Home}/{action=Index}/{id?}"); 67 | }); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/css/site.min.css: -------------------------------------------------------------------------------- 1 | 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-position:center top;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;background-position:center top}.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:.25rem;margin-top:.75rem}.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:1rem;margin-top:0}.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%}.no-border{border:none} -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/wwwroot/images/space-game-title.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 16 | 18 | 22 | 23 | 27 | 29 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/LocalDocumentDBRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using System.Text.Json; 7 | using TailSpin.SpaceGame.Web.Models; 8 | 9 | namespace TailSpin.SpaceGame.Web 10 | { 11 | public class LocalDocumentDBRepository : IDocumentDBRepository where T : Model 12 | { 13 | // An in-memory list of all items in the collection. 14 | private readonly List _items; 15 | 16 | public LocalDocumentDBRepository(string fileName) 17 | { 18 | // Serialize the items from the provided JSON document. 19 | _items = JsonSerializer.Deserialize>(File.ReadAllText(fileName)); 20 | } 21 | 22 | /// 23 | /// Retrieves the item from the store with the given identifier. 24 | /// 25 | /// 26 | /// A task that represents the asynchronous operation. 27 | /// The task result contains the retrieved item. 28 | /// 29 | /// The identifier of the item to retrieve. 30 | public Task GetItemAsync(string id) 31 | { 32 | return Task.FromResult(_items.Single(item => item.Id == id)); 33 | } 34 | 35 | /// 36 | /// Retrieves items from the store that match the given query predicate. 37 | /// Results are given in descending order by the given ordering predicate. 38 | /// 39 | /// 40 | /// A task that represents the asynchronous operation. 41 | /// The task result contains the collection of retrieved items. 42 | /// 43 | /// Predicate that specifies which items to select. 44 | /// Predicate that specifies how to sort the results in descending order. 45 | /// The 1-based page of results to return. 46 | /// The number of items on a page. 47 | public Task> GetItemsAsync( 48 | Func queryPredicate, 49 | Func orderDescendingPredicate, 50 | int page = 1, int pageSize = 10 51 | ) 52 | { 53 | var result = _items 54 | .Where(queryPredicate) // filter 55 | .OrderByDescending(orderDescendingPredicate) // sort 56 | .Skip(page * pageSize) // find page 57 | .Take(pageSize); // take items 58 | 59 | return Task>.FromResult(result); 60 | } 61 | 62 | /// 63 | /// Retrieves the number of items that match the given query predicate. 64 | /// 65 | /// 66 | /// A task that represents the asynchronous operation. 67 | /// The task result contains the number of items that match the query predicate. 68 | /// 69 | /// Predicate that specifies which items to select. 70 | public Task CountItemsAsync(Func queryPredicate) 71 | { 72 | var count = _items 73 | .Where(queryPredicate) // filter 74 | .Count(); // count 75 | 76 | return Task.FromResult(count); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributing 3 | 4 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 5 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 6 | the rights to use your contribution. For details, visit https://cla.microsoft.com. 7 | 8 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide 9 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions 10 | provided by the bot. You will only need to do this once across all repos using our CLA. 11 | 12 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 13 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 14 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 15 | 16 | ## For maintainers: Updating feature branches 17 | 18 | This repository uses feature branches to associate code with specific modules on Microsoft Learn. Any changes you make to the default branch will likely need to be propagated to each feature branch in this repo. A common example is when we need to update Node packages in `package.json`. 19 | 20 | Here's one way to update the remote feature branches when you make a change to the default branch. Note that this process deletes all local branches except for `main`. 21 | 22 | ```bash 23 | # Synchronize with the remote main branch 24 | git checkout main 25 | git pull origin main 26 | # Delete all local branches except for main 27 | git branch | grep -ve "main" | xargs git branch -D 28 | # List all remote branches except for main 29 | branches=$(git branch -r 2> /dev/null | grep -ve "main" | cut -d "/" -f 2) 30 | # Synchronize each branch with main and push the result 31 | while IFS= read -r branch; do 32 | # Fetch and switch to feature branch 33 | git fetch origin $branch 34 | git checkout $branch 35 | # Ensure local environment is free of extra files 36 | git clean -xdf 37 | # Merge down main 38 | git merge --no-ff main 39 | # Break out if merge failed 40 | if [ $? -ne 0 ]; then 41 | break 42 | fi 43 | # Push update 44 | git push origin $branch 45 | done <<< "$branches" 46 | # Switch back to main 47 | git checkout main 48 | ``` 49 | 50 | # Legal Notices 51 | 52 | Microsoft and any contributors grant you a license to the Microsoft documentation and other content 53 | in this repository under the [Creative Commons Attribution 4.0 International Public License](https://creativecommons.org/licenses/by/4.0/legalcode), 54 | see the [LICENSE](LICENSE) file, and grant you a license to any code in the repository under the [MIT License](https://opensource.org/licenses/MIT), see the 55 | [LICENSE-CODE](LICENSE-CODE) file. 56 | 57 | Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation 58 | may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. 59 | The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. 60 | Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653. 61 | 62 | Privacy information can be found at https://privacy.microsoft.com/en-us/ 63 | 64 | Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, 65 | or trademarks, whether by implication, estoppel or otherwise. 66 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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": 111111, 13 | "gameMode": "Solo", 14 | "gameRegion": "NGC 1300" 15 | }, 16 | { 17 | "id": "3", 18 | "profileId": "3", 19 | "score": 221220, 20 | "gameMode": "Duo", 21 | "gameRegion": "Ring Nebula" 22 | }, 23 | { 24 | "id": "4", 25 | "profileId": "4", 26 | "score": 672918, 27 | "gameMode": "Solo", 28 | "gameRegion": "Milky Way" 29 | }, 30 | { 31 | "id": "5", 32 | "profileId": "5", 33 | "score": 777666, 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": 324561, 48 | "gameMode": "Trio", 49 | "gameRegion": "Milky Way" 50 | }, 51 | { 52 | "id": "8", 53 | "profileId": "8", 54 | "score": 123456, 55 | "gameMode": "Solo", 56 | "gameRegion": "Messier 82" 57 | }, 58 | { 59 | "id": "9", 60 | "profileId": "9", 61 | "score": 999998, 62 | "gameMode": "Trio", 63 | "gameRegion": "NGC 1300" 64 | }, 65 | { 66 | "id": "10", 67 | "profileId": "10", 68 | "score": 900000, 69 | "gameMode": "Trio", 70 | "gameRegion": "Milky Way" 71 | }, 72 | { 73 | "id": "11", 74 | "profileId": "11", 75 | "score": 654321, 76 | "gameMode": "Solo", 77 | "gameRegion": "Andromeda" 78 | }, 79 | { 80 | "id": "12", 81 | "profileId": "12", 82 | "score": 999997, 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": 311980, 97 | "gameMode": "Solo", 98 | "gameRegion": "Ring Nebula" 99 | }, 100 | { 101 | "id": "15", 102 | "profileId": "15", 103 | "score": 996671, 104 | "gameMode": "Duo", 105 | "gameRegion": "Messier 82" 106 | }, 107 | { 108 | "id": "16", 109 | "profileId": "16", 110 | "score": 824179, 111 | "gameMode": "Solo", 112 | "gameRegion": "Pinwheel" 113 | }, 114 | { 115 | "id": "17", 116 | "profileId": "17", 117 | "score": 528673, 118 | "gameMode": "Solo", 119 | "gameRegion": "Milky Way" 120 | }, 121 | { 122 | "id": "18", 123 | "profileId": "18", 124 | "score": 221088, 125 | "gameMode": "Duo", 126 | "gameRegion": "Pinwheel" 127 | }, 128 | { 129 | "id": "19", 130 | "profileId": "19", 131 | "score": 613790, 132 | "gameMode": "Trio", 133 | "gameRegion": "Andromeda" 134 | }, 135 | { 136 | "id": "20", 137 | "profileId": "20", 138 | "score": 714207, 139 | "gameMode": "Solo", 140 | "gameRegion": "Milky Way" 141 | }, 142 | { 143 | "id": "21", 144 | "profileId": "1", 145 | "score": 128377, 146 | "gameMode": "Duo", 147 | "gameRegion": "NGC 1300" 148 | }, 149 | { 150 | "id": "22", 151 | "profileId": "2", 152 | "score": 100085, 153 | "gameMode": "Trio", 154 | "gameRegion": "Messier 82" 155 | }, 156 | { 157 | "id": "23", 158 | "profileId": "3", 159 | "score": 321419, 160 | "gameMode": "Solo", 161 | "gameRegion": "Andromeda" 162 | }, 163 | { 164 | "id": "24", 165 | "profileId": "4", 166 | "score": 342045, 167 | "gameMode": "Trio", 168 | "gameRegion": "NGC 1300" 169 | }, 170 | { 171 | "id": "25", 172 | "profileId": "5", 173 | "score": 104041, 174 | "gameMode": "Duo", 175 | "gameRegion": "Ring Nebula" 176 | } 177 | ] 178 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | 180 | .no-border { 181 | border: none; } 182 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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}); -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using TailSpin.SpaceGame.Web.Models; 8 | 9 | namespace TailSpin.SpaceGame.Web.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | // High score repository. 14 | private readonly IDocumentDBRepository _scoreRepository; 15 | // User profile repository. 16 | private readonly IDocumentDBRepository _profileRespository; 17 | 18 | public HomeController( 19 | IDocumentDBRepository scoreRepository, 20 | IDocumentDBRepository profileRespository 21 | ) 22 | { 23 | _scoreRepository = scoreRepository; 24 | _profileRespository = profileRespository; 25 | } 26 | 27 | public async Task Index( 28 | int page = 1, 29 | int pageSize = 10, 30 | string mode = "", 31 | string region = "" 32 | ) 33 | { 34 | // Create the view model with initial values we already know. 35 | var vm = new LeaderboardViewModel 36 | { 37 | Page = page, 38 | PageSize = pageSize, 39 | SelectedMode = mode, 40 | SelectedRegion = region, 41 | 42 | GameModes = new List() 43 | { 44 | "Solo", 45 | "Duo", 46 | "Trio" 47 | }, 48 | 49 | GameRegions = new List() 50 | { 51 | "Milky Way", 52 | "Andromeda", 53 | "Pinwheel", 54 | "NGC 1300", 55 | "Messier 82", 56 | } 57 | }; 58 | 59 | try 60 | { 61 | // Form the query predicate. 62 | // Select all scores that match the provided game mode and region (map). 63 | // Select the score if the game mode or region is empty. 64 | Func queryPredicate = score => 65 | (string.IsNullOrEmpty(mode) || score.GameMode == mode) && 66 | (string.IsNullOrEmpty(region) || score.GameRegion == region); 67 | 68 | // Fetch the total number of results in the background. 69 | var countItemsTask = _scoreRepository.CountItemsAsync(queryPredicate); 70 | 71 | // Fetch the scores that match the current filter. 72 | IEnumerable scores = await _scoreRepository.GetItemsAsync( 73 | queryPredicate, // the predicate defined above 74 | score => score.HighScore, // sort descending by high score 75 | page - 1, // subtract 1 to make the query 0-based 76 | pageSize 77 | ); 78 | 79 | // Wait for the total count. 80 | vm.TotalResults = await countItemsTask; 81 | 82 | // Set previous and next hyperlinks. 83 | if (page > 1) 84 | { 85 | vm.PrevLink = $"/?page={page - 1}&pageSize={pageSize}&mode={mode}®ion={region}#leaderboard"; 86 | } 87 | if (vm.TotalResults > page * pageSize) 88 | { 89 | vm.NextLink = $"/?page={page + 1}&pageSize={pageSize}&mode={mode}®ion={region}#leaderboard"; 90 | } 91 | 92 | // Fetch the user profile for each score. 93 | // This creates a list that's parallel with the scores collection. 94 | var profiles = new List>(); 95 | foreach (var score in scores) 96 | { 97 | profiles.Add(_profileRespository.GetItemAsync(score.ProfileId)); 98 | } 99 | Task.WaitAll(profiles.ToArray()); 100 | 101 | // Combine each score with its profile. 102 | vm.Scores = scores.Zip(profiles, (score, profile) => new ScoreProfile { Score = score, Profile = profile.Result }); 103 | 104 | return View(vm); 105 | } 106 | catch (Exception) 107 | { 108 | return View(vm); 109 | } 110 | } 111 | 112 | [Route("/profile/{id}")] 113 | public async Task Profile(string id, string rank="") 114 | { 115 | try 116 | { 117 | // Fetch the user profile with the given identifier. 118 | return View(new ProfileViewModel { Profile = await _profileRespository.GetItemAsync(id), Rank = rank }); 119 | } 120 | catch (Exception) 121 | { 122 | return RedirectToAction("/"); 123 | } 124 | } 125 | 126 | public IActionResult Privacy() 127 | { 128 | return View(); 129 | } 130 | 131 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 132 | public IActionResult Error() 133 | { 134 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | 257 | .no-border { 258 | border: none; 259 | } -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | ] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | ## Ignore Visual Studio temporary files, build results, and 4 | ## files generated by popular Visual Studio add-ons. 5 | ## 6 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 7 | 8 | # User-specific files 9 | *.suo 10 | *.user 11 | *.userosscache 12 | *.sln.docstates 13 | 14 | # User-specific files (MonoDevelop/Xamarin Studio) 15 | *.userprefs 16 | 17 | # Build results 18 | [Dd]ebug/ 19 | [Dd]ebugPublic/ 20 | [Rr]elease/ 21 | [Rr]eleases/ 22 | x64/ 23 | x86/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | [Ll]og/ 28 | 29 | # Visual Studio 2015/2017 cache/options directory 30 | .vs/ 31 | # Uncomment if you have tasks that create the project's static files in wwwroot 32 | #wwwroot/ 33 | 34 | # Visual Studio 2017 auto generated files 35 | Generated\ Files/ 36 | 37 | # MSTest test Results 38 | [Tt]est[Rr]esult*/ 39 | [Bb]uild[Ll]og.* 40 | 41 | # NUNIT 42 | *.VisualState.xml 43 | TestResult.xml 44 | 45 | # Build Results of an ATL Project 46 | [Dd]ebugPS/ 47 | [Rr]eleasePS/ 48 | dlldata.c 49 | 50 | # Benchmark Results 51 | BenchmarkDotNet.Artifacts/ 52 | 53 | # .NET Core 54 | project.lock.json 55 | project.fragment.lock.json 56 | artifacts/ 57 | **/Properties/launchSettings.json 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_i.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *.log 83 | *.vspscc 84 | *.vssscc 85 | .builds 86 | *.pidb 87 | *.svclog 88 | *.scc 89 | 90 | # Chutzpah Test files 91 | _Chutzpah* 92 | 93 | # Visual C++ cache files 94 | ipch/ 95 | *.aps 96 | *.ncb 97 | *.opendb 98 | *.opensdf 99 | *.sdf 100 | *.cachefile 101 | *.VC.db 102 | *.VC.VC.opendb 103 | 104 | # Visual Studio profiler 105 | *.psess 106 | *.vsp 107 | *.vspx 108 | *.sap 109 | 110 | # Visual Studio Trace Files 111 | *.e2e 112 | 113 | # TFS 2012 Local Workspace 114 | $tf/ 115 | 116 | # Guidance Automation Toolkit 117 | *.gpState 118 | 119 | # ReSharper is a .NET coding add-in 120 | _ReSharper*/ 121 | *.[Rr]e[Ss]harper 122 | *.DotSettings.user 123 | 124 | # JustCode is a .NET coding add-in 125 | .JustCode 126 | 127 | # TeamCity is a build add-in 128 | _TeamCity* 129 | 130 | # DotCover is a Code Coverage Tool 131 | *.dotCover 132 | 133 | # AxoCover is a Code Coverage Tool 134 | .axoCover/* 135 | !.axoCover/settings.json 136 | 137 | # Visual Studio code coverage results 138 | *.coverage 139 | *.coveragexml 140 | 141 | # NCrunch 142 | _NCrunch_* 143 | .*crunch*.local.xml 144 | nCrunchTemp_* 145 | 146 | # MightyMoose 147 | *.mm.* 148 | AutoTest.Net/ 149 | 150 | # Web workbench (sass) 151 | .sass-cache/ 152 | 153 | # Installshield output folder 154 | [Ee]xpress/ 155 | 156 | # DocProject is a documentation generator add-in 157 | DocProject/buildhelp/ 158 | DocProject/Help/*.HxT 159 | DocProject/Help/*.HxC 160 | DocProject/Help/*.hhc 161 | DocProject/Help/*.hhk 162 | DocProject/Help/*.hhp 163 | DocProject/Help/Html2 164 | DocProject/Help/html 165 | 166 | # Click-Once directory 167 | publish/ 168 | 169 | # Publish Web Output 170 | *.[Pp]ublish.xml 171 | *.azurePubxml 172 | # Note: Comment the next line if you want to checkin your web deploy settings, 173 | # but database connection strings (with potential passwords) will be unencrypted 174 | *.pubxml 175 | *.publishproj 176 | 177 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 178 | # checkin your Azure Web App publish settings, but sensitive information contained 179 | # in these scripts will be unencrypted 180 | PublishScripts/ 181 | 182 | # NuGet Packages 183 | *.nupkg 184 | # The packages folder can be ignored because of Package Restore 185 | **/[Pp]ackages/* 186 | # except build/, which is used as an MSBuild target. 187 | !**/[Pp]ackages/build/ 188 | # Uncomment if necessary however generally it will be regenerated when needed 189 | #!**/[Pp]ackages/repositories.config 190 | # NuGet v3's project.json files produces more ignorable files 191 | *.nuget.props 192 | *.nuget.targets 193 | 194 | # Microsoft Azure Build Output 195 | csx/ 196 | *.build.csdef 197 | 198 | # Microsoft Azure Emulator 199 | ecf/ 200 | rcf/ 201 | 202 | # Windows Store app package directories and files 203 | AppPackages/ 204 | BundleArtifacts/ 205 | Package.StoreAssociation.xml 206 | _pkginfo.txt 207 | *.appx 208 | 209 | # Visual Studio cache files 210 | # files ending in .cache can be ignored 211 | *.[Cc]ache 212 | # but keep track of directories ending in .cache 213 | !*.[Cc]ache/ 214 | 215 | # Others 216 | ClientBin/ 217 | ~$* 218 | *~ 219 | *.dbmdl 220 | *.dbproj.schemaview 221 | *.jfm 222 | *.pfx 223 | *.publishsettings 224 | orleans.codegen.cs 225 | 226 | # Including strong name files can present a security risk 227 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 228 | #*.snk 229 | 230 | # Since there are multiple workflows, uncomment next line to ignore bower_components 231 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 232 | #bower_components/ 233 | 234 | # RIA/Silverlight projects 235 | Generated_Code/ 236 | 237 | # Backup & report files from converting an old project file 238 | # to a newer Visual Studio version. Backup files are not needed, 239 | # because we have git ;-) 240 | _UpgradeReport_Files/ 241 | Backup*/ 242 | UpgradeLog*.XML 243 | UpgradeLog*.htm 244 | ServiceFabricBackup/ 245 | *.rptproj.bak 246 | 247 | # SQL Server files 248 | *.mdf 249 | *.ldf 250 | *.ndf 251 | 252 | # Business Intelligence projects 253 | *.rdl.data 254 | *.bim.layout 255 | *.bim_*.settings 256 | *.rptproj.rsuser 257 | 258 | # Microsoft Fakes 259 | FakesAssemblies/ 260 | 261 | # GhostDoc plugin setting file 262 | *.GhostDoc.xml 263 | 264 | # Node.js Tools for Visual Studio 265 | .ntvs_analysis.dat 266 | node_modules/ 267 | 268 | # Visual Studio 6 build log 269 | *.plg 270 | 271 | # Visual Studio 6 workspace options file 272 | *.opt 273 | 274 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 275 | *.vbw 276 | 277 | # Visual Studio LightSwitch build output 278 | **/*.HTMLClient/GeneratedArtifacts 279 | **/*.DesktopClient/GeneratedArtifacts 280 | **/*.DesktopClient/ModelManifest.xml 281 | **/*.Server/GeneratedArtifacts 282 | **/*.Server/ModelManifest.xml 283 | _Pvt_Extensions 284 | 285 | # Paket dependency manager 286 | .paket/paket.exe 287 | paket-files/ 288 | 289 | # FAKE - F# Make 290 | .fake/ 291 | 292 | # JetBrains Rider 293 | .idea/ 294 | *.sln.iml 295 | 296 | # CodeRush 297 | .cr/ 298 | 299 | # Python Tools for Visual Studio (PTVS) 300 | __pycache__/ 301 | *.pyc 302 | 303 | # Cake - Uncomment if you are using it 304 | # tools/** 305 | # !tools/packages.config 306 | 307 | # Tabs Studio 308 | *.tss 309 | 310 | # Telerik's JustMock configuration file 311 | *.jmconfig 312 | 313 | # BizTalk build output 314 | *.btp.cs 315 | *.btm.cs 316 | *.odx.cs 317 | *.xsd.cs 318 | 319 | # OpenCover UI analysis results 320 | OpenCover/ 321 | 322 | # Azure Stream Analytics local run output 323 | ASALocalRun/ 324 | 325 | # MSBuild Binary and Structured Log 326 | *.binlog 327 | 328 | # NVidia Nsight GPU debugger configuration file 329 | *.nvuser 330 | 331 | # MFractors (Xamarin productivity tool) working folder 332 | .mfractor/ 333 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 learning

    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 learning purposes. Check out Microsoft Learn to find out more.

    200 |
    201 | 213 | 214 | 215 | 216 | 228 | 229 | 230 | 243 | 244 | 245 | 257 | 258 | 259 | -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 /etc/profile.d/00-restore-env.sh 32 | chmod +x /etc/profile.d/00-restore-env.sh 33 | 34 | # If in automatic mode, determine if a user already exists, if not use vscode 35 | if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then 36 | USERNAME="" 37 | POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") 38 | for CURRENT_USER in ${POSSIBLE_USERS[@]}; do 39 | if id -u ${CURRENT_USER} > /dev/null 2>&1; then 40 | USERNAME=${CURRENT_USER} 41 | break 42 | fi 43 | done 44 | if [ "${USERNAME}" = "" ]; then 45 | USERNAME=vscode 46 | fi 47 | elif [ "${USERNAME}" = "none" ]; then 48 | USERNAME=root 49 | USER_UID=0 50 | USER_GID=0 51 | fi 52 | 53 | # Load markers to see which steps have already run 54 | if [ -f "${MARKER_FILE}" ]; then 55 | echo "Marker file found:" 56 | cat "${MARKER_FILE}" 57 | source "${MARKER_FILE}" 58 | fi 59 | 60 | # Ensure apt is in non-interactive to avoid prompts 61 | export DEBIAN_FRONTEND=noninteractive 62 | 63 | # Function to call apt-get if needed 64 | apt_get_update_if_needed() 65 | { 66 | if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then 67 | echo "Running apt-get update..." 68 | apt-get update 69 | else 70 | echo "Skipping apt-get update." 71 | fi 72 | } 73 | 74 | # Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies 75 | if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then 76 | 77 | package_list="apt-utils \ 78 | openssh-client \ 79 | gnupg2 \ 80 | dirmngr \ 81 | iproute2 \ 82 | procps \ 83 | lsof \ 84 | htop \ 85 | net-tools \ 86 | psmisc \ 87 | curl \ 88 | wget \ 89 | rsync \ 90 | ca-certificates \ 91 | unzip \ 92 | zip \ 93 | nano \ 94 | vim-tiny \ 95 | less \ 96 | jq \ 97 | lsb-release \ 98 | apt-transport-https \ 99 | dialog \ 100 | libc6 \ 101 | libgcc1 \ 102 | libkrb5-3 \ 103 | libgssapi-krb5-2 \ 104 | libicu[0-9][0-9] \ 105 | liblttng-ust[0-9] \ 106 | libstdc++6 \ 107 | zlib1g \ 108 | locales \ 109 | sudo \ 110 | ncdu \ 111 | man-db \ 112 | strace \ 113 | manpages \ 114 | manpages-dev \ 115 | init-system-helpers" 116 | 117 | # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian 118 | if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then 119 | # Bring in variables from /etc/os-release like VERSION_CODENAME 120 | . /etc/os-release 121 | sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list 122 | sed -i -E "s/deb-src http:\/\/(deb|httredir)\.debian\.org\/debian ${VERSION_CODENAME} main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME} main contrib non-free/" /etc/apt/sources.list 123 | sed -i -E "s/deb http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list 124 | sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list 125 | sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list 126 | sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list 127 | sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list 128 | sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list 129 | # Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html 130 | sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list 131 | sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list 132 | echo "Running apt-get update..." 133 | apt-get update 134 | package_list="${package_list} manpages-posix manpages-posix-dev" 135 | else 136 | apt_get_update_if_needed 137 | fi 138 | 139 | # Install libssl1.1 if available 140 | if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then 141 | package_list="${package_list} libssl1.1" 142 | fi 143 | 144 | # Install appropriate version of libssl1.0.x if available 145 | libssl_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') 146 | if [ "$(echo "$LIlibssl_packageBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then 147 | if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then 148 | # Debian 9 149 | package_list="${package_list} libssl1.0.2" 150 | elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then 151 | # Ubuntu 18.04, 16.04, earlier 152 | package_list="${package_list} libssl1.0.0" 153 | fi 154 | fi 155 | 156 | echo "Packages to verify are installed: ${package_list}" 157 | apt-get -y install --no-install-recommends ${package_list} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 ) 158 | 159 | # Install git if not already installed (may be more recent than distro version) 160 | if ! type git > /dev/null 2>&1; then 161 | apt-get -y install --no-install-recommends git 162 | fi 163 | 164 | PACKAGES_ALREADY_INSTALLED="true" 165 | fi 166 | 167 | # Get to latest versions of all packages 168 | if [ "${UPGRADE_PACKAGES}" = "true" ]; then 169 | apt_get_update_if_needed 170 | apt-get -y upgrade --no-install-recommends 171 | apt-get autoremove -y 172 | fi 173 | 174 | # Ensure at least the en_US.UTF-8 UTF-8 locale is available. 175 | # Common need for both applications and things like the agnoster ZSH theme. 176 | if [ "${LOCALE_ALREADY_SET}" != "true" ] && ! grep -o -E '^\s*en_US.UTF-8\s+UTF-8' /etc/locale.gen > /dev/null; then 177 | echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen 178 | locale-gen 179 | LOCALE_ALREADY_SET="true" 180 | fi 181 | 182 | # Create or update a non-root user to match UID/GID. 183 | group_name="${USERNAME}" 184 | if id -u ${USERNAME} > /dev/null 2>&1; then 185 | # User exists, update if needed 186 | if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then 187 | group_name="$(id -gn $USERNAME)" 188 | groupmod --gid $USER_GID ${group_name} 189 | usermod --gid $USER_GID $USERNAME 190 | fi 191 | if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then 192 | usermod --uid $USER_UID $USERNAME 193 | fi 194 | else 195 | # Create user 196 | if [ "${USER_GID}" = "automatic" ]; then 197 | groupadd $USERNAME 198 | else 199 | groupadd --gid $USER_GID $USERNAME 200 | fi 201 | if [ "${USER_UID}" = "automatic" ]; then 202 | useradd -s /bin/bash --gid $USERNAME -m $USERNAME 203 | else 204 | useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME 205 | fi 206 | fi 207 | 208 | # Add add sudo support for non-root user 209 | if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then 210 | echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME 211 | chmod 0440 /etc/sudoers.d/$USERNAME 212 | EXISTING_NON_ROOT_USER="${USERNAME}" 213 | fi 214 | 215 | # ** Shell customization section ** 216 | if [ "${USERNAME}" = "root" ]; then 217 | user_rc_path="/root" 218 | else 219 | user_rc_path="/home/${USERNAME}" 220 | fi 221 | 222 | # Restore user .bashrc defaults from skeleton file if it doesn't exist or is empty 223 | if [ ! -f "${user_rc_path}/.bashrc" ] || [ ! -s "${user_rc_path}/.bashrc" ] ; then 224 | cp /etc/skel/.bashrc "${user_rc_path}/.bashrc" 225 | fi 226 | 227 | # Restore user .profile defaults from skeleton file if it doesn't exist or is empty 228 | if [ ! -f "${user_rc_path}/.profile" ] || [ ! -s "${user_rc_path}/.profile" ] ; then 229 | cp /etc/skel/.profile "${user_rc_path}/.profile" 230 | fi 231 | 232 | # .bashrc/.zshrc snippet 233 | rc_snippet="$(cat << 'EOF' 234 | 235 | if [ -z "${USER}" ]; then export USER=$(whoami); fi 236 | if [[ "${PATH}" != *"$HOME/.local/bin"* ]]; then export PATH="${PATH}:$HOME/.local/bin"; fi 237 | 238 | # Display optional first run image specific notice if configured and terminal is interactive 239 | if [ -t 1 ] && [[ "${TERM_PROGRAM}" = "vscode" || "${TERM_PROGRAM}" = "codespaces" ]] && [ ! -f "$HOME/.config/vscode-dev-containers/first-run-notice-already-displayed" ]; then 240 | if [ -f "/usr/local/etc/vscode-dev-containers/first-run-notice.txt" ]; then 241 | cat "/usr/local/etc/vscode-dev-containers/first-run-notice.txt" 242 | elif [ -f "/workspaces/.codespaces/shared/first-run-notice.txt" ]; then 243 | cat "/workspaces/.codespaces/shared/first-run-notice.txt" 244 | fi 245 | mkdir -p "$HOME/.config/vscode-dev-containers" 246 | # Mark first run notice as displayed after 10s to avoid problems with fast terminal refreshes hiding it 247 | ((sleep 10s; touch "$HOME/.config/vscode-dev-containers/first-run-notice-already-displayed") &) 248 | fi 249 | 250 | # Set the default git editor if not already set 251 | if [ -z "$(git config --get core.editor)" ] && [ -z "${GIT_EDITOR}" ]; then 252 | if [ "${TERM_PROGRAM}" = "vscode" ]; then 253 | if [[ -n $(command -v code-insiders) && -z $(command -v code) ]]; then 254 | export GIT_EDITOR="code-insiders --wait" 255 | else 256 | export GIT_EDITOR="code --wait" 257 | fi 258 | fi 259 | fi 260 | 261 | EOF 262 | )" 263 | 264 | # code shim, it fallbacks to code-insiders if code is not available 265 | cat << 'EOF' > /usr/local/bin/code 266 | #!/bin/sh 267 | 268 | get_in_path_except_current() { 269 | which -a "$1" | grep -A1 "$0" | grep -v "$0" 270 | } 271 | 272 | code="$(get_in_path_except_current code)" 273 | 274 | if [ -n "$code" ]; then 275 | exec "$code" "$@" 276 | elif [ "$(command -v code-insiders)" ]; then 277 | exec code-insiders "$@" 278 | else 279 | echo "code or code-insiders is not installed" >&2 280 | exit 127 281 | fi 282 | EOF 283 | chmod +x /usr/local/bin/code 284 | 285 | # systemctl shim - tells people to use 'service' if systemd is not running 286 | cat << 'EOF' > /usr/local/bin/systemctl 287 | #!/bin/sh 288 | set -e 289 | if [ -d "/run/systemd/system" ]; then 290 | exec /bin/systemctl/systemctl "$@" 291 | else 292 | echo '\n"systemd" is not running in this container due to its overhead.\nUse the "service" command to start services instead. e.g.: \n\nservice --status-all' 293 | fi 294 | EOF 295 | chmod +x /usr/local/bin/systemctl 296 | 297 | # Codespaces bash and OMZ themes - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme 298 | codespaces_bash="$(cat \ 299 | <<'EOF' 300 | 301 | # Codespaces bash prompt theme 302 | __bash_prompt() { 303 | local userpart='`export XIT=$? \ 304 | && [ ! -z "${GITHUB_USER}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER} " || echo -n "\[\033[0;32m\]\u " \ 305 | && [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`' 306 | local gitbranch='`\ 307 | if [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \ 308 | export BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null); \ 309 | if [ "${BRANCH}" != "" ]; then \ 310 | echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH}" \ 311 | && if git ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \ 312 | echo -n " \[\033[1;33m\]✗"; \ 313 | fi \ 314 | && echo -n "\[\033[0;36m\]) "; \ 315 | fi; \ 316 | fi`' 317 | local lightblue='\[\033[1;34m\]' 318 | local removecolor='\[\033[0m\]' 319 | PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ " 320 | unset -f __bash_prompt 321 | } 322 | __bash_prompt 323 | 324 | EOF 325 | )" 326 | 327 | codespaces_zsh="$(cat \ 328 | <<'EOF' 329 | # Codespaces zsh prompt theme 330 | __zsh_prompt() { 331 | local prompt_username 332 | if [ ! -z "${GITHUB_USER}" ]; then 333 | prompt_username="@${GITHUB_USER}" 334 | else 335 | prompt_username="%n" 336 | fi 337 | PROMPT="%{$fg[green]%}${prompt_username} %(?:%{$reset_color%}➜ :%{$fg_bold[red]%}➜ )" # User/exit code arrow 338 | PROMPT+='%{$fg_bold[blue]%}%(5~|%-1~/…/%3~|%4~)%{$reset_color%} ' # cwd 339 | PROMPT+='$([ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ] && git_prompt_info)' # Git status 340 | PROMPT+='%{$fg[white]%}$ %{$reset_color%}' 341 | unset -f __zsh_prompt 342 | } 343 | ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[cyan]%}(%{$fg_bold[red]%}" 344 | ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " 345 | ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg_bold[yellow]%}✗%{$fg_bold[cyan]%})" 346 | ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[cyan]%})" 347 | __zsh_prompt 348 | 349 | EOF 350 | )" 351 | 352 | # Add RC snippet and custom bash prompt 353 | if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then 354 | echo "${rc_snippet}" >> /etc/bash.bashrc 355 | echo "${codespaces_bash}" >> "${user_rc_path}/.bashrc" 356 | echo 'export PROMPT_DIRTRIM=4' >> "${user_rc_path}/.bashrc" 357 | if [ "${USERNAME}" != "root" ]; then 358 | echo "${codespaces_bash}" >> "/root/.bashrc" 359 | echo 'export PROMPT_DIRTRIM=4' >> "/root/.bashrc" 360 | fi 361 | chown ${USERNAME}:${group_name} "${user_rc_path}/.bashrc" 362 | RC_SNIPPET_ALREADY_ADDED="true" 363 | fi 364 | 365 | # Optionally install and configure zsh and Oh My Zsh! 366 | if [ "${INSTALL_ZSH}" = "true" ]; then 367 | if ! type zsh > /dev/null 2>&1; then 368 | apt_get_update_if_needed 369 | apt-get install -y zsh 370 | fi 371 | if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then 372 | echo "${rc_snippet}" >> /etc/zsh/zshrc 373 | ZSH_ALREADY_INSTALLED="true" 374 | fi 375 | 376 | # Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. 377 | # See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script. 378 | oh_my_install_dir="${user_rc_path}/.oh-my-zsh" 379 | if [ ! -d "${oh_my_install_dir}" ] && [ "${INSTALL_OH_MYS}" = "true" ]; then 380 | template_path="${oh_my_install_dir}/templates/zshrc.zsh-template" 381 | user_rc_file="${user_rc_path}/.zshrc" 382 | umask g-w,o-w 383 | mkdir -p ${oh_my_install_dir} 384 | git clone --depth=1 \ 385 | -c core.eol=lf \ 386 | -c core.autocrlf=false \ 387 | -c fsck.zeroPaddedFilemode=ignore \ 388 | -c fetch.fsck.zeroPaddedFilemode=ignore \ 389 | -c receive.fsck.zeroPaddedFilemode=ignore \ 390 | "https://github.com/ohmyzsh/ohmyzsh" "${oh_my_install_dir}" 2>&1 391 | echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${user_rc_file} 392 | sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="codespaces"/g' ${user_rc_file} 393 | 394 | mkdir -p ${oh_my_install_dir}/custom/themes 395 | echo "${codespaces_zsh}" > "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme" 396 | # Shrink git while still enabling updates 397 | cd "${oh_my_install_dir}" 398 | git repack -a -d -f --depth=1 --window=1 399 | # Copy to non-root user if one is specified 400 | if [ "${USERNAME}" != "root" ]; then 401 | cp -rf "${user_rc_file}" "${oh_my_install_dir}" /root 402 | chown -R ${USERNAME}:${group_name} "${user_rc_path}" 403 | fi 404 | fi 405 | fi 406 | 407 | # Persist image metadata info, script if meta.env found in same directory 408 | meta_info_script="$(cat << 'EOF' 409 | #!/bin/sh 410 | . /usr/local/etc/vscode-dev-containers/meta.env 411 | 412 | # Minimal output 413 | if [ "$1" = "version" ] || [ "$1" = "image-version" ]; then 414 | echo "${VERSION}" 415 | exit 0 416 | elif [ "$1" = "release" ]; then 417 | echo "${GIT_REPOSITORY_RELEASE}" 418 | exit 0 419 | elif [ "$1" = "content" ] || [ "$1" = "content-url" ] || [ "$1" = "contents" ] || [ "$1" = "contents-url" ]; then 420 | echo "${CONTENTS_URL}" 421 | exit 0 422 | fi 423 | 424 | #Full output 425 | echo 426 | echo "Development container image information" 427 | echo 428 | if [ ! -z "${VERSION}" ]; then echo "- Image version: ${VERSION}"; fi 429 | if [ ! -z "${DEFINITION_ID}" ]; then echo "- Definition ID: ${DEFINITION_ID}"; fi 430 | if [ ! -z "${VARIANT}" ]; then echo "- Variant: ${VARIANT}"; fi 431 | if [ ! -z "${GIT_REPOSITORY}" ]; then echo "- Source code repository: ${GIT_REPOSITORY}"; fi 432 | if [ ! -z "${GIT_REPOSITORY_RELEASE}" ]; then echo "- Source code release/branch: ${GIT_REPOSITORY_RELEASE}"; fi 433 | if [ ! -z "${BUILD_TIMESTAMP}" ]; then echo "- Timestamp: ${BUILD_TIMESTAMP}"; fi 434 | if [ ! -z "${CONTENTS_URL}" ]; then echo && echo "More info: ${CONTENTS_URL}"; fi 435 | echo 436 | EOF 437 | )" 438 | if [ -f "${SCRIPT_DIR}/meta.env" ]; then 439 | mkdir -p /usr/local/etc/vscode-dev-containers/ 440 | cp -f "${SCRIPT_DIR}/meta.env" /usr/local/etc/vscode-dev-containers/meta.env 441 | echo "${meta_info_script}" > /usr/local/bin/devcontainer-info 442 | chmod +x /usr/local/bin/devcontainer-info 443 | fi 444 | 445 | # Write marker file 446 | mkdir -p "$(dirname "${MARKER_FILE}")" 447 | echo -e "\ 448 | PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ 449 | LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ 450 | EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ 451 | RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ 452 | ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" 453 | 454 | echo "Done!" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public 379 | licenses. Notwithstanding, Creative Commons may elect to apply one of 380 | its public licenses to material it publishes and in those instances 381 | will be considered the “Licensor.” The text of the Creative Commons 382 | public licenses is dedicated to the public domain under the CC0 Public 383 | Domain Dedication. Except for the limited purpose of indicating that 384 | material is shared under a Creative Commons public license or as 385 | otherwise permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the 393 | public licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /Tailspin.SpaceGame.Web/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 | })); --------------------------------------------------------------------------------