├── .appveyor.yml ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .vsts-pipelines └── builds │ ├── ci-internal.yml │ └── ci-public.yml ├── CONTRIBUTING.md ├── Directory.Build.props ├── Directory.Build.targets ├── DotNetTools.sln ├── LICENSE.txt ├── NuGet.config ├── NuGetPackageVerifier.json ├── README.md ├── build.cmd ├── build.sh ├── build ├── Key.snk ├── VSIX.props ├── VSIX.targets ├── dependencies.props ├── repo.props ├── repo.targets └── sources.props ├── korebuild-lock.txt ├── korebuild.json ├── run.cmd ├── run.ps1 ├── run.sh ├── samples └── dotnet-watch │ ├── Directory.Build.props │ ├── Directory.Build.targets │ ├── LaunchAnyCommand │ ├── LaunchAnyCommand.csproj │ ├── README.md │ ├── package.json │ └── say-hello.js │ ├── README.md │ ├── WatchJavascriptFiles │ ├── Program.cs │ ├── README.md │ ├── WatchJavascriptFiles.csproj │ └── wwwroot │ │ └── app.js │ └── WatchMultipleProjects │ ├── README.md │ ├── Test │ ├── Test.csproj │ └── UnitTest1.cs │ ├── Web │ ├── Program.cs │ └── Web.csproj │ └── watch.csproj ├── shared ├── CliContext.cs ├── CommandLineApplicationExtensions.cs ├── ConsoleReporter.cs ├── DebugHelper.cs ├── Ensure.cs ├── IConsole.cs ├── IReporter.cs ├── NullReporter.cs └── PhysicalConsole.cs ├── src ├── Directory.Build.props ├── Directory.Build.targets ├── Microsoft.AspNetCore.DeveloperCertificates.XPlat │ ├── CertificateGenerator.cs │ └── Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj ├── Microsoft.HttpRepl │ ├── AggregateDirectoryStructure.cs │ ├── Commands │ │ ├── BaseHttpCommand.cs │ │ ├── ChangeDirectoryCommand.cs │ │ ├── ClearCommand.cs │ │ ├── ConfigCommand.cs │ │ ├── DeleteCommand.cs │ │ ├── EchoCommand.cs │ │ ├── ExitCommand.cs │ │ ├── Formatter.cs │ │ ├── GetCommand.cs │ │ ├── HeadCommand.cs │ │ ├── HelpCommand.cs │ │ ├── ListCommand.cs │ │ ├── OptionsCommand.cs │ │ ├── PatchCommand.cs │ │ ├── PostCommand.cs │ │ ├── PrefCommand.cs │ │ ├── PutCommand.cs │ │ ├── RunCommand.cs │ │ ├── SetBaseCommand.cs │ │ ├── SetDiagCommand.cs │ │ ├── SetHeaderCommand.cs │ │ ├── SetSwaggerCommand.cs │ │ ├── TreeNode.cs │ │ └── UICommand.cs │ ├── Diagnostics │ │ ├── ConfigItem.cs │ │ ├── DiagEndpoint.cs │ │ ├── DiagEndpointMetadata.cs │ │ ├── DiagItem.cs │ │ └── DiagnosticsState.cs │ ├── DirectoryStructure.cs │ ├── DirectoryStructureExtensions.cs │ ├── Formatting │ │ └── JsonVisitor.cs │ ├── HttpState.cs │ ├── IDirectoryStructure.cs │ ├── IRequestInfo.cs │ ├── Microsoft.HttpRepl.csproj │ ├── OpenApi │ │ ├── Either.cs │ │ ├── EitherConverter.cs │ │ ├── EndpointMetadata.cs │ │ ├── EndpointMetadataReader.cs │ │ ├── IEndpointMetadataReader.cs │ │ ├── OpenApiV3EndpointMetadataReader.cs │ │ ├── Parameter.cs │ │ ├── PointerUtil.cs │ │ ├── Schema.cs │ │ ├── SwaggerV1EndpointMetadataReader.cs │ │ └── SwaggerV2EndpointMetadataReader.cs │ ├── Preferences │ │ ├── IJsonConfig.cs │ │ ├── JsonConfig.cs │ │ ├── RequestConfig.cs │ │ ├── RequestOrResponseConfig.cs │ │ ├── ResponseConfig.cs │ │ └── WellKnownPreference.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ └── Suggestions │ │ ├── HeaderCompletion.cs │ │ └── ServerPathCompletion.cs ├── Microsoft.Repl │ ├── Commanding │ │ ├── CommandHistory.cs │ │ ├── CommandInputLocation.cs │ │ ├── CommandInputProcessingIssue.cs │ │ ├── CommandInputProcessingIssueKind.cs │ │ ├── CommandInputSpecification.cs │ │ ├── CommandInputSpecificationBuilder.cs │ │ ├── CommandOptionSpecification.cs │ │ ├── CommandWithStructuredInputBase.cs │ │ ├── DefaultCommandDispatcher.cs │ │ ├── DefaultCommandInput.cs │ │ ├── ICommand.cs │ │ ├── ICommandDispatcher.cs │ │ ├── ICommandHistory.cs │ │ └── InputElement.cs │ ├── ConsoleHandling │ │ ├── AllowedColors.cs │ │ ├── AnsiColorExtensions.cs │ │ ├── AnsiConsole.cs │ │ ├── ConsoleManager.cs │ │ ├── IConsoleManager.cs │ │ ├── IWritable.cs │ │ ├── Point.cs │ │ ├── Reporter.cs │ │ └── Writable.cs │ ├── Disposable.cs │ ├── IShellState.cs │ ├── Input │ │ ├── AsyncKeyPressHandler.cs │ │ ├── IInputManager.cs │ │ ├── InputManager.cs │ │ └── KeyHandlers.cs │ ├── Microsoft.Repl.csproj │ ├── Parsing │ │ ├── CoreParseResult.cs │ │ ├── CoreParser.cs │ │ ├── ICoreParseResult.cs │ │ └── IParser.cs │ ├── Scripting │ │ ├── IScriptExecutor.cs │ │ └── ScriptExecutor.cs │ ├── Shell.cs │ ├── ShellState.cs │ ├── Suggestions │ │ ├── FileSystemCompletion.cs │ │ ├── ISuggestionManager.cs │ │ └── SuggestionManager.cs │ └── Utils.cs ├── dotnet-dev-certs │ ├── Program.cs │ ├── README.md │ └── dotnet-dev-certs.csproj ├── dotnet-sql-cache │ ├── Program.cs │ ├── README.md │ ├── SqlQueries.cs │ └── dotnet-sql-cache.csproj ├── dotnet-user-secrets │ ├── CommandLineOptions.cs │ ├── Internal │ │ ├── ClearCommand.cs │ │ ├── CommandContext.cs │ │ ├── ICommand.cs │ │ ├── InitCommand.cs │ │ ├── ListCommand.cs │ │ ├── MsBuildProjectFinder.cs │ │ ├── ProjectIdResolver.cs │ │ ├── ReadableJsonConfigurationSource.cs │ │ ├── RemoveCommand.cs │ │ ├── SecretsStore.cs │ │ └── SetCommand.cs │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Resources.Designer.cs │ ├── README.md │ ├── Resources.resx │ ├── assets │ │ └── SecretManager.targets │ └── dotnet-user-secrets.csproj └── dotnet-watch │ ├── CommandLineOptions.cs │ ├── DotNetWatcher.cs │ ├── IFileSet.cs │ ├── IFileSetFactory.cs │ ├── Internal │ ├── FileSet.cs │ ├── FileSetWatcher.cs │ ├── FileWatcher.cs │ ├── FileWatcher │ │ ├── DotnetFileWatcher.cs │ │ ├── FileWatcherFactory.cs │ │ ├── IFileSystemWatcher.cs │ │ └── PollingFileWatcher.cs │ ├── MsBuildFileSetFactory.cs │ ├── MsBuildProjectFinder.cs │ ├── OutputCapture.cs │ ├── OutputSink.cs │ └── ProcessRunner.cs │ ├── PrefixConsoleReporter.cs │ ├── ProcessSpec.cs │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ └── Resources.Designer.cs │ ├── README.md │ ├── Resources.resx │ ├── assets │ └── DotNetWatch.targets │ └── dotnet-watch.csproj ├── test ├── Directory.Build.props ├── Microsoft.HttpRepl.Tests │ ├── JsonVisitorTests.cs │ └── Microsoft.HttpRepl.Tests.csproj ├── Microsoft.Repl.Tests │ ├── Microsoft.Repl.Tests.csproj │ └── ParserTests.cs ├── Shared │ ├── TestConsole.cs │ └── TestReporter.cs ├── dotnet-user-secrets.Tests │ ├── InitCommandTest.cs │ ├── MsBuildProjectFinderTest.cs │ ├── SecretManagerTests.cs │ ├── SetCommandTest.cs │ ├── TemporaryFileProvider.cs │ ├── UserSecretsTestFixture.cs │ └── dotnet-user-secrets.Tests.csproj ├── dotnet-watch.FunctionalTests │ ├── AppWithDepsTests.cs │ ├── AwaitableProcess.cs │ ├── DotNetWatcherTests.cs │ ├── FileWatcherTests.cs │ ├── GlobbingAppTests.cs │ ├── NoDepsAppTests.cs │ ├── Scenario │ │ ├── ProjectToolScenario.cs │ │ └── WatchableApp.cs │ ├── TestProjects │ │ ├── AppWithDeps │ │ │ ├── AppWithDeps.csproj │ │ │ └── Program.cs │ │ ├── Dependency │ │ │ ├── Dependency.csproj │ │ │ └── Foo.cs │ │ ├── GlobbingApp │ │ │ ├── GlobbingApp.csproj │ │ │ ├── Program.cs │ │ │ ├── exclude │ │ │ │ └── Baz.cs │ │ │ └── include │ │ │ │ └── Foo.cs │ │ ├── KitchenSink │ │ │ ├── KitchenSink.csproj │ │ │ └── Program.cs │ │ └── NoDepsApp │ │ │ ├── NoDepsApp.csproj │ │ │ └── Program.cs │ └── dotnet-watch.FunctionalTests.csproj └── dotnet-watch.Tests │ ├── AssertEx.cs │ ├── CommandLineOptionsTests.cs │ ├── ConsoleReporterTests.cs │ ├── MsBuildFileSetFactoryTest.cs │ ├── ProgramTests.cs │ ├── Utilities │ ├── TemporaryCSharpProject.cs │ ├── TemporaryDirectory.cs │ └── TestProjectGraph.cs │ └── dotnet-watch.Tests.csproj ├── tooling ├── Microsoft.VisualStudio.SecretManager.TestExtension │ ├── Key.snk │ ├── Microsoft.VisualStudio.SecretManager.TestExtension.csproj │ ├── NotifyPropertyChanged.cs │ ├── ProjectViewModel.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RelayCommand.cs │ ├── Resources │ │ ├── SecretManagerTestCommand.png │ │ └── SecretManagerTestPackage.ico │ ├── SecretManagerTestCommand.cs │ ├── SecretManagerTestControl.xaml │ ├── SecretManagerTestControl.xaml.cs │ ├── SecretManagerTestPackage.cs │ ├── SecretManagerTestPackage.vsct │ ├── SecretManagerTestWindow.cs │ ├── SecretManagerViewModel.cs │ ├── VSPackage.resx │ ├── app.config │ └── source.extension.vsixmanifest └── Microsoft.VisualStudio.SecretManager │ ├── Microsoft.VisualStudio.SecretManager.csproj │ ├── ProjectLocalSecretsManager.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── SecretManagerFactory.cs │ ├── SecretStore.cs │ ├── Sources │ ├── ConfigurationPath.cs │ ├── JsonConfigurationFileParser.cs │ └── PathHelper.cs │ └── source.extension.vsixmanifest └── version.props /.appveyor.yml: -------------------------------------------------------------------------------- 1 | init: 2 | - git config --global core.autocrlf true 3 | branches: 4 | only: 5 | - master 6 | - /^release\/.*$/ 7 | - /^(.*\/)?ci-.*$/ 8 | build_script: 9 | - ps: .\run.ps1 default-build 10 | clone_depth: 1 11 | environment: 12 | global: 13 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 14 | DOTNET_CLI_TELEMETRY_OPTOUT: 1 15 | test: 'off' 16 | deploy: 'off' 17 | os: Visual Studio 2017 18 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome:http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.cs] 13 | indent_size = 4 14 | dotnet_sort_system_directives_first = true:warning 15 | 16 | # Xml files 17 | [*.{csproj,config,props,targets,ruleset,config,resx,xml}] 18 | indent_size = 2 19 | 20 | [*.{json, yml}] 21 | indent_size = 2 22 | 23 | [*.{ps1,sh}] 24 | indent_size = 4 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.rb text=auto 26 | *.java text=auto 27 | *.html text=auto 28 | *.htm text=auto 29 | *.css text=auto 30 | *.scss text=auto 31 | *.sass text=auto 32 | *.less text=auto 33 | *.js text=auto 34 | *.lisp text=auto 35 | *.clj text=auto 36 | *.sql text=auto 37 | *.php text=auto 38 | *.lua text=auto 39 | *.m text=auto 40 | *.asm text=auto 41 | *.erl text=auto 42 | *.fs text=auto 43 | *.fsx text=auto 44 | *.hs text=auto 45 | 46 | *.csproj text=auto 47 | *.vbproj text=auto 48 | *.fsproj text=auto 49 | *.dbproj text=auto 50 | *.sln text=auto eol=crlf 51 | 52 | *.sh eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Oo]bj/ 2 | [Bb]in/ 3 | TestResults/ 4 | .nuget/ 5 | _ReSharper.*/ 6 | packages/ 7 | artifacts/ 8 | PublishProfiles/ 9 | *.user 10 | *.suo 11 | *.cache 12 | *.docstates 13 | _ReSharper.* 14 | nuget.exe 15 | *net45.csproj 16 | *net451.csproj 17 | *k10.csproj 18 | *.psess 19 | *.vsp 20 | *.pidb 21 | *.userprefs 22 | *DS_Store 23 | *.ncrunchsolution 24 | *.*sdf 25 | *.ipch 26 | *.sln.ide 27 | project.lock.json 28 | .testPublish/ 29 | .build/ 30 | /.vs/ 31 | .vscode/ 32 | *.nuget.props 33 | *.nuget.targets 34 | .idea/ 35 | .dotnet/ 36 | global.json 37 | *.binlog 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | sudo: false 3 | dist: trusty 4 | env: 5 | global: 6 | - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 7 | - DOTNET_CLI_TELEMETRY_OPTOUT: 1 8 | mono: none 9 | os: 10 | - linux 11 | - osx 12 | osx_image: xcode8.2 13 | addons: 14 | apt: 15 | packages: 16 | - libunwind8 17 | branches: 18 | only: 19 | - master 20 | - /^release\/.*$/ 21 | - /^(.*\/)?ci-.*$/ 22 | before_install: 23 | - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s 24 | /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib 25 | /usr/local/lib/; fi 26 | script: 27 | - ./build.sh 28 | -------------------------------------------------------------------------------- /.vsts-pipelines/builds/ci-internal.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | - release/* 4 | 5 | resources: 6 | repositories: 7 | - repository: buildtools 8 | type: git 9 | name: aspnet-BuildTools 10 | ref: refs/heads/master 11 | 12 | phases: 13 | - template: .vsts-pipelines/templates/project-ci.yml@buildtools 14 | -------------------------------------------------------------------------------- /.vsts-pipelines/builds/ci-public.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | - release/* 4 | 5 | # See https://github.com/aspnet/BuildTools 6 | resources: 7 | repositories: 8 | - repository: buildtools 9 | type: github 10 | endpoint: DotNet-Bot GitHub Connection 11 | name: aspnet/BuildTools 12 | ref: refs/heads/master 13 | 14 | phases: 15 | - template: .vsts-pipelines/templates/project-ci.yml@buildtools 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ====== 3 | 4 | Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo. 5 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Microsoft .NET 12 | https://github.com/aspnet/DotNetTools 13 | git 14 | $(MSBuildThisFileDirectory) 15 | $(MSBuildThisFileDirectory)build\Key.snk 16 | true 17 | true 18 | 19 | 20 | false 21 | $(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\ 22 | $(MSBuildThisFileDirectory)bin\$(MSBuildProjectName)\ 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(MicrosoftNETCoreApp30PackageVersion) 4 | $(NETStandardLibrary20PackageVersion) 5 | 6 | 99.9 7 | 8 | 9 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NuGetPackageVerifier.json: -------------------------------------------------------------------------------- 1 | { 2 | "adx": { 3 | "rules": [ 4 | "AdxVerificationCompositeRule" 5 | ], 6 | "packages": { 7 | "dotnet-watch": { 8 | "packageTypes": [ 9 | "DotnetTool" 10 | ] 11 | }, 12 | "dotnet-sql-cache": { 13 | "packageTypes": [ 14 | "DotnetTool" 15 | ] 16 | }, 17 | "dotnet-user-secrets": { 18 | "packageTypes": [ 19 | "DotnetTool" 20 | ] 21 | }, 22 | "dotnet-dev-certs": { 23 | "packageTypes": [ 24 | "DotnetTool" 25 | ] 26 | }, 27 | "Microsoft.AspNetCore.DeveloperCertificates.XPlat": { 28 | "Exclusions": { 29 | "DOC_MISSING": { 30 | "lib/netcoreapp3.0/Microsoft.AspNetCore.DeveloperCertificates.XPlat.dll": "Docs not required to shipoob package" 31 | } 32 | } 33 | } 34 | } 35 | }, 36 | "Default": { 37 | "rules": [ 38 | "DefaultCompositeRule" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DotNetTools [Archived] 2 | ====================== 3 | 4 | **This GitHub project has been archived.** Ongoing development on this project can be found in . 5 | 6 | This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at . 7 | 8 | ## Projects 9 | 10 | The repository contains command-line tools for ASP.NET Core that are bundled* in the [.NET Core CLI](https://github.com/dotnet/cli). 11 | Follow the links below for more details on each tool. 12 | 13 | - [dotnet-watch](src/dotnet-watch/README.md) 14 | - [dotnet-user-secrets](src/dotnet-user-secrets/README.md) 15 | - [dotnet-sql-cache](src/dotnet-sql-cache/README.md) 16 | - [dotnet-dev-certs](src/dotnet-dev-certs/README.md) 17 | 18 | *\*This applies to .NET Core CLI 2.1.300-preview2 and up. For earlier versions of the CLI, these tools must be installed separately.* 19 | 20 | *For 2.0 CLI and earlier, see for details.* 21 | 22 | *For 2.1.300-preview1 CLI, see for details.* 23 | 24 | ## Usage 25 | 26 | The command line tools can be invoked as a subcommand of `dotnet`. 27 | 28 | ```sh 29 | dotnet watch 30 | dotnet user-secrets 31 | dotnet sql-cache 32 | dotnet dev-certs 33 | ``` 34 | 35 | Add `--help` to see more details. For example, 36 | 37 | ``` 38 | dotnet watch --help 39 | ``` 40 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE" 3 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | 6 | # Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs) 7 | chmod +x "$DIR/run.sh"; sync 8 | "$DIR/run.sh" default-build "$@" 9 | -------------------------------------------------------------------------------- /build/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/DotNetTools/da47b81a162ae6c9e3787752adb8bcd4a6c1cbe1/build/Key.snk -------------------------------------------------------------------------------- /build/VSIX.props: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /build/dependencies.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 4 | 5 | 6 | 3.0.0-alpha1-20181026.5 7 | 3.0.0-alpha1-10657 8 | 3.0.0-alpha1-10657 9 | 3.0.0-alpha1-10657 10 | 3.0.0-alpha1-10664 11 | 3.0.0-alpha1-10657 12 | 3.0.0-preview1-26907-05 13 | 15.9.0 14 | 5.2.6 15 | 2.0.3 16 | 11.0.2 17 | 4.6.0-preview1-26907-04 18 | 4.6.0-preview1-26907-04 19 | 9.0.1 20 | 2.4.0 21 | 2.4.0 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /build/repo.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Internal.AspNetCore.Universe.Lineup 11 | https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /build/repo.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Configuration=$(Configuration)NoVSIX 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /build/sources.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $(DotNetRestoreSources) 6 | 7 | $(RestoreSources); 8 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json; 9 | https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; 10 | https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json; 11 | https://vside.myget.org/F/vssdk/api/v3/index.json; 12 | https://vside.myget.org/F/devcore/api/v3/index.json 13 | 14 | 15 | $(RestoreSources); 16 | https://api.nuget.org/v3/index.json; 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /korebuild-lock.txt: -------------------------------------------------------------------------------- 1 | version:3.0.0-alpha1-20181026.5 2 | commithash:0c0410ef8b17d5177a05b50cb66f9ad89ce15e32 3 | -------------------------------------------------------------------------------- /korebuild.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json", 3 | "channel": "master", 4 | "toolsets": { 5 | "visualstudio": { 6 | "required": [ 7 | "windows" 8 | ], 9 | "includePrerelease": true, 10 | "versionRange": "[15.0.26730.03, 16.0)", 11 | "requiredWorkloads": [ 12 | "Microsoft.VisualStudio.Component.VSSDK" 13 | ] 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /run.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE" 3 | -------------------------------------------------------------------------------- /samples/dotnet-watch/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /samples/dotnet-watch/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /samples/dotnet-watch/LaunchAnyCommand/LaunchAnyCommand.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/dotnet-watch/LaunchAnyCommand/README.md: -------------------------------------------------------------------------------- 1 | Launch any command with dotnet-watch 2 | ==================================== 3 | 4 | ## Prerequisites 5 | 6 | 1. Install .NET Core command line. 7 | 2. Install NodeJS. 8 | 9 | ## Usage 10 | 11 | Open a terminal to the directory containing this project. 12 | 13 | ``` 14 | dotnet watch msbuild /t:RunMyNpmCommand 15 | ``` 16 | 17 | Changing the .csproj file, or the say-hello.js file will cause dotnet-watch to re-run the 'RunMyNpmCommand' target in MyApp.csproj. 18 | -------------------------------------------------------------------------------- /samples/dotnet-watch/LaunchAnyCommand/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "any-command", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "custom": "node say-hello.js" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/dotnet-watch/LaunchAnyCommand/say-hello.js: -------------------------------------------------------------------------------- 1 | console.log("Hello from Javascript"); 2 | -------------------------------------------------------------------------------- /samples/dotnet-watch/README.md: -------------------------------------------------------------------------------- 1 | dotnet-watch samples 2 | ==================== 3 | 4 | The samples in this folder show some ways to customize dotnet-watch. For full details on 5 | available settings and configuration, see the [README for the dotnet-watch](../../src/dotnet-watch/README.md) project. 6 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchJavascriptFiles/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | 9 | namespace WatchJavascriptFiles 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | var host = new WebHostBuilder() 16 | .UseKestrel() 17 | .UseContentRoot(Directory.GetCurrentDirectory()) 18 | .Configure(app => 19 | app.Run(async (context) => 20 | { 21 | await context.Response.WriteAsync("Hello World!"); 22 | })) 23 | .Build(); 24 | 25 | host.Run(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchJavascriptFiles/README.md: -------------------------------------------------------------------------------- 1 | Watch JavaScript files with dotnet-watch 2 | ======================================== 3 | 4 | ## Prerequisites 5 | 6 | Install .NET Core command line. 7 | 8 | ## Usage 9 | 10 | Open a terminal to the directory containing this project. 11 | 12 | ``` 13 | dotnet watch run 14 | ``` 15 | 16 | Changing the .csproj file, or \*.js file in wwwroot, or any \*.cs file will cause dotnet-watch to restart the website. 17 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchJavascriptFiles/WatchJavascriptFiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchJavascriptFiles/wwwroot/app.js: -------------------------------------------------------------------------------- 1 | document.title = "My awesome website"; 2 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchMultipleProjects/README.md: -------------------------------------------------------------------------------- 1 | Watch multiple projects with dotnet-watch 2 | ========================================= 3 | 4 | ## Prerequisites 5 | 6 | Install .NET Core command line. 7 | 8 | ## Usage 9 | 10 | Open a terminal to the directory containing this project. 11 | 12 | ``` 13 | dotnet watch msbuild /t:TestAndRun 14 | ``` 15 | 16 | The "TestAndRun" target in watch.proj will execute "dotnet test" on Test.csproj and then launch the website by calling "dotnet run" on Web.csproj. 17 | 18 | Changing any \*.cs file in Test/ or Web/, any \*.csproj file, or watch.proj, will cause dotnet-watch to relaunch the "TestAndRun" target from watch.proj. 19 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchMultipleProjects/Test/Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchMultipleProjects/Test/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Xunit; 6 | 7 | namespace Test 8 | { 9 | public class UnitTest1 10 | { 11 | [Fact] 12 | public void Test1() 13 | { 14 | Assert.True(true); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchMultipleProjects/Web/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | 9 | namespace Web 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | var host = new WebHostBuilder() 16 | .UseKestrel() 17 | .UseContentRoot(Directory.GetCurrentDirectory()) 18 | .Configure(app => 19 | app.Run(async (context) => 20 | { 21 | await context.Response.WriteAsync("Hello World!"); 22 | })) 23 | .Build(); 24 | 25 | host.Run(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchMultipleProjects/Web/Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /samples/dotnet-watch/WatchMultipleProjects/watch.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.0 4 | false 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /shared/CliContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.Tools.Internal 7 | { 8 | public static class CliContext 9 | { 10 | /// 11 | /// dotnet -d|--diagnostics subcommand 12 | /// 13 | /// 14 | public static bool IsGlobalVerbose() 15 | { 16 | bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_CLI_CONTEXT_VERBOSE"), out bool globalVerbose); 17 | return globalVerbose; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /shared/CommandLineApplicationExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Reflection; 6 | 7 | namespace Microsoft.Extensions.CommandLineUtils 8 | { 9 | internal static class CommandLineApplicationExtensions 10 | { 11 | public static CommandOption HelpOption(this CommandLineApplication app) 12 | => app.HelpOption("-?|-h|--help"); 13 | 14 | public static CommandOption VerboseOption(this CommandLineApplication app) 15 | => app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue, inherited: true); 16 | 17 | public static void OnExecute(this CommandLineApplication app, Action action) 18 | => app.OnExecute(() => 19 | { 20 | action(); 21 | return 0; 22 | }); 23 | 24 | public static void VersionOptionFromAssemblyAttributes(this CommandLineApplication app, Assembly assembly) 25 | => app.VersionOption("--version", GetInformationalVersion(assembly)); 26 | 27 | private static string GetInformationalVersion(Assembly assembly) 28 | { 29 | var attribute = assembly.GetCustomAttribute(); 30 | 31 | var versionAttribute = attribute == null 32 | ? assembly.GetName().Version.ToString() 33 | : attribute.InformationalVersion; 34 | 35 | return versionAttribute; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /shared/ConsoleReporter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | 7 | namespace Microsoft.Extensions.Tools.Internal 8 | { 9 | public class ConsoleReporter : IReporter 10 | { 11 | private object _writeLock = new object(); 12 | 13 | public ConsoleReporter(IConsole console) 14 | : this(console, verbose: false, quiet: false) 15 | { } 16 | 17 | public ConsoleReporter(IConsole console, bool verbose, bool quiet) 18 | { 19 | Ensure.NotNull(console, nameof(console)); 20 | 21 | Console = console; 22 | IsVerbose = verbose; 23 | IsQuiet = quiet; 24 | } 25 | 26 | protected IConsole Console { get; } 27 | public bool IsVerbose { get; set; } 28 | public bool IsQuiet { get; set; } 29 | 30 | protected virtual void WriteLine(TextWriter writer, string message, ConsoleColor? color) 31 | { 32 | lock (_writeLock) 33 | { 34 | if (color.HasValue) 35 | { 36 | Console.ForegroundColor = color.Value; 37 | } 38 | 39 | writer.WriteLine(message); 40 | 41 | if (color.HasValue) 42 | { 43 | Console.ResetColor(); 44 | } 45 | } 46 | } 47 | 48 | public virtual void Error(string message) 49 | => WriteLine(Console.Error, message, ConsoleColor.Red); 50 | public virtual void Warn(string message) 51 | => WriteLine(Console.Out, message, ConsoleColor.Yellow); 52 | 53 | public virtual void Output(string message) 54 | { 55 | if (IsQuiet) 56 | { 57 | return; 58 | } 59 | WriteLine(Console.Out, message, color: null); 60 | } 61 | 62 | public virtual void Verbose(string message) 63 | { 64 | if (!IsVerbose) 65 | { 66 | return; 67 | } 68 | 69 | WriteLine(Console.Out, message, ConsoleColor.DarkGray); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /shared/DebugHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | 8 | namespace Microsoft.Extensions.Tools.Internal 9 | { 10 | public static class DebugHelper 11 | { 12 | [Conditional("DEBUG")] 13 | public static void HandleDebugSwitch(ref string[] args) 14 | { 15 | if (args.Length > 0 && string.Equals("--debug", args[0], StringComparison.OrdinalIgnoreCase)) 16 | { 17 | args = args.Skip(1).ToArray(); 18 | Console.WriteLine("Waiting for debugger to attach. Press ENTER to continue"); 19 | Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}"); 20 | Console.ReadLine(); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /shared/Ensure.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.Tools.Internal 7 | { 8 | internal static class Ensure 9 | { 10 | public static T NotNull(T obj, string paramName) 11 | where T : class 12 | { 13 | if (obj == null) 14 | { 15 | throw new ArgumentNullException(paramName); 16 | } 17 | return obj; 18 | } 19 | 20 | public static string NotNullOrEmpty(string obj, string paramName) 21 | { 22 | if (string.IsNullOrEmpty(obj)) 23 | { 24 | throw new ArgumentException("Value cannot be null or an empty string.", paramName); 25 | } 26 | return obj; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /shared/IConsole.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | 7 | namespace Microsoft.Extensions.Tools.Internal 8 | { 9 | public interface IConsole 10 | { 11 | event ConsoleCancelEventHandler CancelKeyPress; 12 | TextWriter Out { get; } 13 | TextWriter Error { get; } 14 | TextReader In { get; } 15 | bool IsInputRedirected { get; } 16 | bool IsOutputRedirected { get; } 17 | bool IsErrorRedirected { get; } 18 | ConsoleColor ForegroundColor { get; set; } 19 | void ResetColor(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /shared/IReporter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.Tools.Internal 5 | { 6 | public interface IReporter 7 | { 8 | void Verbose(string message); 9 | void Output(string message); 10 | void Warn(string message); 11 | void Error(string message); 12 | } 13 | } -------------------------------------------------------------------------------- /shared/NullReporter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.Tools.Internal 5 | { 6 | public class NullReporter : IReporter 7 | { 8 | private NullReporter() 9 | { } 10 | 11 | public static IReporter Singleton { get; } = new NullReporter(); 12 | 13 | public void Verbose(string message) 14 | { } 15 | 16 | public void Output(string message) 17 | { } 18 | 19 | public void Warn(string message) 20 | { } 21 | 22 | public void Error(string message) 23 | { } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /shared/PhysicalConsole.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | 7 | namespace Microsoft.Extensions.Tools.Internal 8 | { 9 | public class PhysicalConsole : IConsole 10 | { 11 | private PhysicalConsole() 12 | { 13 | Console.CancelKeyPress += (o, e) => 14 | { 15 | CancelKeyPress?.Invoke(o, e); 16 | }; 17 | } 18 | 19 | public static IConsole Singleton { get; } = new PhysicalConsole(); 20 | 21 | public event ConsoleCancelEventHandler CancelKeyPress; 22 | public TextWriter Error => Console.Error; 23 | public TextReader In => Console.In; 24 | public TextWriter Out => Console.Out; 25 | public bool IsInputRedirected => Console.IsInputRedirected; 26 | public bool IsOutputRedirected => Console.IsOutputRedirected; 27 | public bool IsErrorRedirected => Console.IsErrorRedirected; 28 | public ConsoleColor ForegroundColor 29 | { 30 | get => Console.ForegroundColor; 31 | set => Console.ForegroundColor = value; 32 | } 33 | 34 | public void ResetColor() => Console.ResetColor(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.DeveloperCertificates.XPlat/CertificateGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Certificates.Generation; 3 | 4 | namespace Microsoft.AspNetCore.DeveloperCertificates.XPlat 5 | { 6 | public static class CertificateGenerator 7 | { 8 | public static void GenerateAspNetHttpsCertificate() 9 | { 10 | var manager = new CertificateManager(); 11 | var now = DateTimeOffset.Now; 12 | manager.EnsureAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.DeveloperCertificates.XPlat/Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | Package for the CLI first run experience. 6 | $(DefineConstants);XPLAT 7 | aspnet;cli 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/AggregateDirectoryStructure.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | namespace Microsoft.HttpRepl 9 | { 10 | public class AggregateDirectoryStructure : IDirectoryStructure 11 | { 12 | private readonly IDirectoryStructure _first; 13 | private readonly IDirectoryStructure _second; 14 | 15 | public AggregateDirectoryStructure(IDirectoryStructure first, IDirectoryStructure second) 16 | { 17 | _first = first; 18 | _second = second; 19 | } 20 | 21 | public IEnumerable DirectoryNames 22 | { 23 | get 24 | { 25 | HashSet values = new HashSet(StringComparer.OrdinalIgnoreCase); 26 | values.UnionWith(_first.DirectoryNames); 27 | values.UnionWith(_second.DirectoryNames); 28 | return values.OrderBy(x => x, StringComparer.OrdinalIgnoreCase); 29 | } 30 | } 31 | 32 | public IDirectoryStructure Parent => _first.Parent ?? _second.Parent; 33 | 34 | public IDirectoryStructure GetChildDirectory(string name) 35 | { 36 | return new AggregateDirectoryStructure(_first.GetChildDirectory(name), _second.GetChildDirectory(name)); 37 | } 38 | 39 | public IRequestInfo RequestInfo => _first.RequestInfo ?? _second.RequestInfo; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/ClearCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.Repl; 9 | using Microsoft.Repl.Commanding; 10 | using Microsoft.Repl.Parsing; 11 | 12 | namespace Microsoft.HttpRepl.Commands 13 | { 14 | public class ClearCommand : ICommand 15 | { 16 | private static readonly string Name = "clear"; 17 | private static readonly string AlternateName = "cls"; 18 | 19 | public bool? CanHandle(IShellState shellState, object programState, ICoreParseResult parseResult) 20 | { 21 | return parseResult.Sections.Count == 1 && (string.Equals(parseResult.Sections[0], Name, StringComparison.OrdinalIgnoreCase) || string.Equals(parseResult.Sections[0], AlternateName, StringComparison.OrdinalIgnoreCase)) 22 | ? (bool?) true 23 | : null; 24 | } 25 | 26 | public Task ExecuteAsync(IShellState shellState, object programState, ICoreParseResult parseResult, CancellationToken cancellationToken) 27 | { 28 | shellState.ConsoleManager.Clear(); 29 | shellState.CommandDispatcher.OnReady(shellState); 30 | return Task.CompletedTask; 31 | } 32 | 33 | public string GetHelpDetails(IShellState shellState, object programState, ICoreParseResult parseResult) 34 | { 35 | if (parseResult.Sections.Count == 1 && (string.Equals(parseResult.Sections[0], Name, StringComparison.OrdinalIgnoreCase) || string.Equals(parseResult.Sections[0], AlternateName, StringComparison.OrdinalIgnoreCase))) 36 | { 37 | return "Clears the shell"; 38 | } 39 | 40 | return null; 41 | } 42 | 43 | public string GetHelpSummary(IShellState shellState, object programState) 44 | { 45 | return "clear - Clears the shell"; 46 | } 47 | 48 | public IEnumerable Suggest(IShellState shellState, object programState, ICoreParseResult parseResult) 49 | { 50 | if (parseResult.SelectedSection == 0 && 51 | (string.IsNullOrEmpty(parseResult.Sections[parseResult.SelectedSection]) || Name.StartsWith(parseResult.Sections[0].Substring(0, parseResult.CaretPositionWithinSelectedSection), StringComparison.OrdinalIgnoreCase))) 52 | { 53 | return new[] { Name }; 54 | } 55 | 56 | if (parseResult.SelectedSection == 0 && 57 | (string.IsNullOrEmpty(parseResult.Sections[parseResult.SelectedSection]) || AlternateName.StartsWith(parseResult.Sections[0].Substring(0, parseResult.CaretPositionWithinSelectedSection), StringComparison.OrdinalIgnoreCase))) 58 | { 59 | return new[] { Name }; 60 | } 61 | 62 | return null; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/DeleteCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class DeleteCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "delete"; 9 | 10 | protected override bool RequiresBody => false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/ExitCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Microsoft.Repl; 8 | using Microsoft.Repl.Commanding; 9 | using Microsoft.Repl.ConsoleHandling; 10 | using Microsoft.Repl.Parsing; 11 | 12 | namespace Microsoft.HttpRepl.Commands 13 | { 14 | public class ExitCommand : CommandWithStructuredInputBase 15 | { 16 | protected override Task ExecuteAsync(IShellState shellState, object programState, DefaultCommandInput commandInput, ICoreParseResult parseResult, CancellationToken cancellationToken) 17 | { 18 | shellState.IsExiting = true; 19 | return Task.CompletedTask; 20 | } 21 | 22 | public override CommandInputSpecification InputSpec { get; } = CommandInputSpecification.Create("exit").ExactArgCount(0).Finish(); 23 | 24 | protected override string GetHelpDetails(IShellState shellState, object programState, DefaultCommandInput commandInput, ICoreParseResult parseResult) 25 | { 26 | var helpText = new StringBuilder(); 27 | helpText.Append("Usage: ".Bold()); 28 | helpText.AppendLine($"exit"); 29 | helpText.AppendLine(); 30 | helpText.AppendLine($"Exits the shell"); 31 | return helpText.ToString(); 32 | } 33 | 34 | public override string GetHelpSummary(IShellState shellState, object programState) 35 | { 36 | return "exit - Exits the shell"; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/Formatter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class Formatter 7 | { 8 | private int _prefix; 9 | private int _maxDepth; 10 | 11 | public void RegisterEntry(int prefixLength, int depth) 12 | { 13 | if (depth > _maxDepth) 14 | { 15 | _maxDepth = depth; 16 | } 17 | 18 | if (prefixLength > _prefix) 19 | { 20 | _prefix = prefixLength; 21 | } 22 | } 23 | 24 | public string Format(string prefix, string entry, int level) 25 | { 26 | string indent = "".PadRight(level * 4); 27 | return (indent + prefix).PadRight(_prefix + 3 + _maxDepth * 4) + entry; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/GetCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class GetCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "get"; 9 | 10 | protected override bool RequiresBody => false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/HeadCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class HeadCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "head"; 9 | 10 | protected override bool RequiresBody => false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/OptionsCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class OptionsCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "options"; 9 | 10 | protected override bool RequiresBody => false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/PatchCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class PatchCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "patch"; 9 | 10 | protected override bool RequiresBody => true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/PostCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class PostCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "post"; 9 | 10 | protected override bool RequiresBody => true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/PutCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Commands 5 | { 6 | public class PutCommand : BaseHttpCommand 7 | { 8 | protected override string Verb => "put"; 9 | 10 | protected override bool RequiresBody => true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Commands/TreeNode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.HttpRepl.Commands 8 | { 9 | public class TreeNode 10 | { 11 | private readonly int _depth; 12 | private readonly Formatter _formatter; 13 | private readonly string _prefix; 14 | private readonly string _entry; 15 | private readonly List _children = new List(); 16 | 17 | public TreeNode(Formatter formatter, string prefix, string entry) 18 | : this(formatter, prefix, entry, 0) 19 | { 20 | } 21 | 22 | private TreeNode(Formatter formatter, string prefix, string entry, int depth) 23 | { 24 | _formatter = formatter; 25 | formatter.RegisterEntry(prefix.Length, depth); 26 | _prefix = prefix; 27 | _entry = entry; 28 | _depth = depth; 29 | } 30 | 31 | public TreeNode AddChild(string prefix, string entry) 32 | { 33 | TreeNode child = new TreeNode(_formatter, prefix, entry, _depth + 1); 34 | _children.Add(child); 35 | return child; 36 | } 37 | 38 | public override string ToString() 39 | { 40 | string self = _formatter.Format(_prefix, _entry, _depth); 41 | 42 | if (_children.Count == 0) 43 | { 44 | return self; 45 | } 46 | 47 | return self + Environment.NewLine + string.Join(Environment.NewLine, _children); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Diagnostics/ConfigItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Diagnostics 5 | { 6 | public class ConfigItem 7 | { 8 | public string Key { get; set; } 9 | 10 | public string Value { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Diagnostics/DiagEndpoint.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Diagnostics 5 | { 6 | public class DiagEndpoint 7 | { 8 | public string DisplayName { get; set; } 9 | public string Url { get; set; } 10 | public DiagEndpointMetadata[] Metadata { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Diagnostics/DiagEndpointMetadata.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Diagnostics 5 | { 6 | public class DiagEndpointMetadata 7 | { 8 | public object Item { get; set; } 9 | public string Type { get; set; } 10 | public string[] Interfaces { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Diagnostics/DiagItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.Diagnostics 5 | { 6 | public class DiagItem 7 | { 8 | public string DisplayName { get; set; } 9 | 10 | public string Description { get; set; } 11 | 12 | public string Url { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Diagnostics/DiagnosticsState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.HttpRepl.Diagnostics 7 | { 8 | public class DiagnosticsState 9 | { 10 | public string DiagnosticsEndpoint { get; set; } 11 | 12 | public IReadOnlyList DiagnosticItems { get; internal set; } 13 | 14 | public IDirectoryStructure DiagEndpointsStructure { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/DirectoryStructureExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace Microsoft.HttpRepl 8 | { 9 | public static class DirectoryStructureExtensions 10 | { 11 | public static IEnumerable GetDirectoryListingAtPath(this IDirectoryStructure structure, string path) 12 | { 13 | return structure.TraverseTo(path).DirectoryNames; 14 | } 15 | 16 | public static IDirectoryStructure TraverseTo(this IDirectoryStructure structure, string path) 17 | { 18 | string[] parts = path.Replace('\\', '/').Split('/'); 19 | return structure.TraverseTo(parts); 20 | } 21 | 22 | public static IDirectoryStructure TraverseTo(this IDirectoryStructure structure, IEnumerable pathParts) 23 | { 24 | IDirectoryStructure s = structure; 25 | IReadOnlyList parts = pathParts.ToList(); 26 | 27 | if (parts.Count == 0) 28 | { 29 | return s; 30 | } 31 | 32 | if (parts[0] == string.Empty && parts.Count > 1) 33 | { 34 | while (s.Parent != null) 35 | { 36 | s = s.Parent; 37 | } 38 | } 39 | 40 | foreach (string part in parts) 41 | { 42 | if (part == ".") 43 | { 44 | continue; 45 | } 46 | 47 | if (part == "..") 48 | { 49 | s = s.Parent ?? s; 50 | } 51 | else if (!string.IsNullOrEmpty(part)) 52 | { 53 | s = s.GetChildDirectory(part); 54 | } 55 | } 56 | 57 | return s; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/IDirectoryStructure.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.HttpRepl 7 | { 8 | public interface IDirectoryStructure 9 | { 10 | IEnumerable DirectoryNames { get; } 11 | 12 | IDirectoryStructure Parent { get; } 13 | 14 | IDirectoryStructure GetChildDirectory(string name); 15 | 16 | IRequestInfo RequestInfo { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/IRequestInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.HttpRepl 7 | { 8 | public interface IRequestInfo 9 | { 10 | IReadOnlyDictionary> ContentTypesByMethod { get; } 11 | 12 | IReadOnlyList Methods { get; } 13 | 14 | string GetRequestBodyForContentType(ref string contentType, string method); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Microsoft.HttpRepl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.0 6 | true 7 | dotnet-httprepl 8 | latest 9 | Command line tool to for making HTTP calls and viewing their results. 10 | dotnet;http;httprepl 11 | 12 | win-x64;win-x86 13 | 14 | 15 | false 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/OpenApi/Either.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.OpenApi 5 | { 6 | public class Either 7 | { 8 | public Either(TOption1 option1) 9 | { 10 | Option1 = option1; 11 | IsOption1 = true; 12 | } 13 | 14 | public Either(TOption2 option2) 15 | { 16 | Option2 = option2; 17 | IsOption1 = false; 18 | } 19 | 20 | public bool IsOption1 { get; } 21 | 22 | public TOption1 Option1 { get; } 23 | 24 | public TOption2 Option2 { get; } 25 | 26 | public static implicit operator Either(TOption1 value) 27 | { 28 | return new Either(value); 29 | } 30 | 31 | public static implicit operator Either(TOption2 value) 32 | { 33 | return new Either(value); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/OpenApi/EitherConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Newtonsoft.Json; 6 | 7 | namespace Microsoft.HttpRepl.OpenApi 8 | { 9 | public class EitherConverter : JsonConverter 10 | { 11 | public override bool CanConvert(Type objectType) 12 | { 13 | return typeof(TOption1).IsAssignableFrom(objectType) || typeof(TOption2).IsAssignableFrom(objectType) || typeof(EitherConverter) == objectType; 14 | } 15 | 16 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 17 | { 18 | try 19 | { 20 | TOption1 option1 = serializer.Deserialize(reader); 21 | return new Either(option1); 22 | } 23 | catch 24 | { 25 | TOption2 option2 = serializer.Deserialize(reader); 26 | return new Either(option2); 27 | } 28 | } 29 | 30 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/OpenApi/EndpointMetadata.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.HttpRepl.OpenApi 7 | { 8 | public class EndpointMetadata 9 | { 10 | public EndpointMetadata(string path, IReadOnlyDictionary>> requestsByMethodAndContentType) 11 | { 12 | Path = path; 13 | AvailableRequests = requestsByMethodAndContentType ?? new Dictionary>>(); 14 | } 15 | 16 | public string Path { get; } 17 | 18 | public IReadOnlyDictionary>> AvailableRequests { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/OpenApi/EndpointMetadataReader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace Microsoft.HttpRepl.OpenApi 8 | { 9 | public class EndpointMetadataReader 10 | { 11 | private readonly List _readers = new List 12 | { 13 | new OpenApiV3EndpointMetadataReader(), 14 | new SwaggerV2EndpointMetadataReader(), 15 | new SwaggerV1EndpointMetadataReader() 16 | }; 17 | 18 | public void RegisterReader(IEndpointMetadataReader reader) 19 | { 20 | _readers.Add(reader); 21 | } 22 | 23 | public IEnumerable Read(JObject document) 24 | { 25 | foreach (IEndpointMetadataReader reader in _readers) 26 | { 27 | if (reader.CanHandle(document)) 28 | { 29 | IEnumerable result = reader.ReadMetadata(document); 30 | 31 | if (result != null) 32 | { 33 | return result; 34 | } 35 | } 36 | } 37 | 38 | return null; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/OpenApi/IEndpointMetadataReader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace Microsoft.HttpRepl.OpenApi 8 | { 9 | public interface IEndpointMetadataReader 10 | { 11 | bool CanHandle(JObject document); 12 | 13 | IEnumerable ReadMetadata(JObject document); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/OpenApi/Parameter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.HttpRepl.OpenApi 5 | { 6 | public class Parameter 7 | { 8 | public string Name { get; set; } 9 | 10 | public string Location { get; set; } 11 | 12 | public bool IsRequired { get; set; } 13 | 14 | public Schema Schema { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Preferences/IJsonConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.ConsoleHandling; 5 | 6 | namespace Microsoft.HttpRepl.Preferences 7 | { 8 | public interface IJsonConfig 9 | { 10 | int IndentSize { get; } 11 | 12 | AllowedColors DefaultColor { get; } 13 | 14 | AllowedColors ArrayBraceColor { get; } 15 | 16 | AllowedColors ObjectBraceColor { get; } 17 | 18 | AllowedColors CommaColor { get; } 19 | 20 | AllowedColors NameColor { get; } 21 | 22 | AllowedColors NameSeparatorColor { get; } 23 | 24 | AllowedColors BoolColor { get; } 25 | 26 | AllowedColors NumericColor { get; } 27 | 28 | AllowedColors StringColor { get; } 29 | 30 | AllowedColors NullColor { get; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Preferences/JsonConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.ConsoleHandling; 5 | 6 | namespace Microsoft.HttpRepl.Preferences 7 | { 8 | public class JsonConfig : IJsonConfig 9 | { 10 | private readonly HttpState _state; 11 | 12 | public int IndentSize => _state.GetIntPreference(WellKnownPreference.JsonIndentSize, 2); 13 | 14 | public AllowedColors DefaultColor => _state.GetColorPreference(WellKnownPreference.JsonColor); 15 | 16 | private AllowedColors DefaultBraceColor => _state.GetColorPreference(WellKnownPreference.JsonBraceColor, DefaultSyntaxColor); 17 | 18 | private AllowedColors DefaultSyntaxColor => _state.GetColorPreference(WellKnownPreference.JsonSyntaxColor, DefaultColor); 19 | 20 | private AllowedColors DefaultLiteralColor => _state.GetColorPreference(WellKnownPreference.JsonLiteralColor, DefaultColor); 21 | 22 | public AllowedColors ArrayBraceColor => _state.GetColorPreference(WellKnownPreference.JsonArrayBraceColor, DefaultBraceColor); 23 | 24 | public AllowedColors ObjectBraceColor => _state.GetColorPreference(WellKnownPreference.JsonObjectBraceColor, DefaultBraceColor); 25 | 26 | public AllowedColors CommaColor => _state.GetColorPreference(WellKnownPreference.JsonCommaColor, DefaultSyntaxColor); 27 | 28 | public AllowedColors NameColor => _state.GetColorPreference(WellKnownPreference.JsonNameColor, StringColor); 29 | 30 | public AllowedColors NameSeparatorColor => _state.GetColorPreference(WellKnownPreference.JsonNameSeparatorColor, DefaultSyntaxColor); 31 | 32 | public AllowedColors BoolColor => _state.GetColorPreference(WellKnownPreference.JsonBoolColor, DefaultLiteralColor); 33 | 34 | public AllowedColors NumericColor => _state.GetColorPreference(WellKnownPreference.JsonNumericColor, DefaultLiteralColor); 35 | 36 | public AllowedColors StringColor => _state.GetColorPreference(WellKnownPreference.JsonStringColor, DefaultLiteralColor); 37 | 38 | public AllowedColors NullColor => _state.GetColorPreference(WellKnownPreference.JsonNullColor, DefaultLiteralColor); 39 | 40 | public JsonConfig(HttpState state) 41 | { 42 | _state = state; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Preferences/RequestConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.ConsoleHandling; 5 | 6 | namespace Microsoft.HttpRepl.Preferences 7 | { 8 | public class RequestConfig : RequestOrResponseConfig 9 | { 10 | public RequestConfig(HttpState state) 11 | : base(state) 12 | { 13 | } 14 | 15 | public override AllowedColors BodyColor => State.GetColorPreference(WellKnownPreference.RequestBodyColor, base.BodyColor); 16 | 17 | public override AllowedColors SchemeColor => State.GetColorPreference(WellKnownPreference.RequestSchemeColor, base.SchemeColor); 18 | 19 | public override AllowedColors HeaderKeyColor => State.GetColorPreference(WellKnownPreference.RequestHeaderKeyColor, base.HeaderKeyColor); 20 | 21 | public override AllowedColors HeaderSeparatorColor => State.GetColorPreference(WellKnownPreference.RequestHeaderSeparatorColor, base.HeaderSeparatorColor); 22 | 23 | public override AllowedColors HeaderValueSeparatorColor => State.GetColorPreference(WellKnownPreference.RequestHeaderValueSeparatorColor, base.HeaderValueSeparatorColor); 24 | 25 | public override AllowedColors HeaderValueColor => State.GetColorPreference(WellKnownPreference.RequestHeaderValueColor, base.HeaderValueColor); 26 | 27 | public override AllowedColors HeaderColor => State.GetColorPreference(WellKnownPreference.RequestHeaderColor, base.HeaderColor); 28 | 29 | public override AllowedColors GeneralColor => State.GetColorPreference(WellKnownPreference.RequestColor, base.GeneralColor); 30 | 31 | public override AllowedColors ProtocolColor => State.GetColorPreference(WellKnownPreference.RequestProtocolColor, base.ProtocolColor); 32 | 33 | public override AllowedColors ProtocolNameColor => State.GetColorPreference(WellKnownPreference.RequestProtocolNameColor, base.ProtocolNameColor); 34 | 35 | public override AllowedColors ProtocolVersionColor => State.GetColorPreference(WellKnownPreference.RequestProtocolVersionColor, base.ProtocolVersionColor); 36 | 37 | public override AllowedColors ProtocolSeparatorColor => State.GetColorPreference(WellKnownPreference.RequestProtocolSeparatorColor, base.ProtocolSeparatorColor); 38 | 39 | public override AllowedColors StatusColor => State.GetColorPreference(WellKnownPreference.RequestStatusColor, base.StatusColor); 40 | 41 | public override AllowedColors StatusCodeColor => State.GetColorPreference(WellKnownPreference.RequestStatusCodeColor, base.StatusCodeColor); 42 | 43 | public override AllowedColors StatusReasonPhraseColor => State.GetColorPreference(WellKnownPreference.RequestStatusReaseonPhraseColor, base.StatusReasonPhraseColor); 44 | 45 | public AllowedColors MethodColor => State.GetColorPreference(WellKnownPreference.RequestMethodColor, GeneralColor); 46 | 47 | public AllowedColors AddressColor => State.GetColorPreference(WellKnownPreference.RequestAddressColor, GeneralColor); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Preferences/RequestOrResponseConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.ConsoleHandling; 5 | 6 | namespace Microsoft.HttpRepl.Preferences 7 | { 8 | public abstract class RequestOrResponseConfig 9 | { 10 | protected HttpState State { get; } 11 | 12 | protected RequestOrResponseConfig(HttpState state) 13 | { 14 | State = state; 15 | } 16 | 17 | public virtual AllowedColors BodyColor => State.GetColorPreference(WellKnownPreference.BodyColor, GeneralColor); 18 | 19 | public virtual AllowedColors SchemeColor => State.GetColorPreference(WellKnownPreference.SchemeColor, GeneralColor); 20 | 21 | public virtual AllowedColors HeaderKeyColor => State.GetColorPreference(WellKnownPreference.HeaderKeyColor, HeaderColor); 22 | 23 | public virtual AllowedColors HeaderSeparatorColor => State.GetColorPreference(WellKnownPreference.HeaderSeparatorColor, HeaderColor); 24 | 25 | public virtual AllowedColors HeaderValueSeparatorColor => State.GetColorPreference(WellKnownPreference.HeaderValueSeparatorColor, HeaderSeparatorColor); 26 | 27 | public virtual AllowedColors HeaderValueColor => State.GetColorPreference(WellKnownPreference.HeaderValueColor, HeaderColor); 28 | 29 | public virtual AllowedColors HeaderColor => State.GetColorPreference(WellKnownPreference.HeaderColor, GeneralColor); 30 | 31 | public virtual AllowedColors GeneralColor => State.GetColorPreference(WellKnownPreference.RequestOrResponseColor); 32 | 33 | public virtual AllowedColors ProtocolColor => State.GetColorPreference(WellKnownPreference.ProtocolColor, GeneralColor); 34 | 35 | public virtual AllowedColors ProtocolNameColor => State.GetColorPreference(WellKnownPreference.ProtocolNameColor, ProtocolColor); 36 | 37 | public virtual AllowedColors ProtocolVersionColor => State.GetColorPreference(WellKnownPreference.ProtocolVersionColor, ProtocolColor); 38 | 39 | public virtual AllowedColors ProtocolSeparatorColor => State.GetColorPreference(WellKnownPreference.ProtocolSeparatorColor, ProtocolColor); 40 | 41 | public virtual AllowedColors StatusColor => State.GetColorPreference(WellKnownPreference.StatusColor, GeneralColor); 42 | 43 | public virtual AllowedColors StatusCodeColor => State.GetColorPreference(WellKnownPreference.StatusCodeColor, StatusColor); 44 | 45 | public virtual AllowedColors StatusReasonPhraseColor => State.GetColorPreference(WellKnownPreference.StatusReaseonPhraseColor, StatusColor); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Preferences/ResponseConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.ConsoleHandling; 5 | 6 | namespace Microsoft.HttpRepl.Preferences 7 | { 8 | public class ResponseConfig : RequestOrResponseConfig 9 | { 10 | public ResponseConfig(HttpState state) 11 | : base(state) 12 | { 13 | } 14 | 15 | public override AllowedColors BodyColor => State.GetColorPreference(WellKnownPreference.ResponseBodyColor, base.BodyColor); 16 | 17 | public override AllowedColors SchemeColor => State.GetColorPreference(WellKnownPreference.ResponseSchemeColor, base.SchemeColor); 18 | 19 | public override AllowedColors HeaderKeyColor => State.GetColorPreference(WellKnownPreference.ResponseHeaderKeyColor, base.HeaderKeyColor); 20 | 21 | public override AllowedColors HeaderSeparatorColor => State.GetColorPreference(WellKnownPreference.ResponseHeaderSeparatorColor, base.HeaderSeparatorColor); 22 | 23 | public override AllowedColors HeaderValueSeparatorColor => State.GetColorPreference(WellKnownPreference.ResponseHeaderValueSeparatorColor, base.HeaderValueSeparatorColor); 24 | 25 | public override AllowedColors HeaderValueColor => State.GetColorPreference(WellKnownPreference.ResponseHeaderValueColor, base.HeaderValueColor); 26 | 27 | public override AllowedColors HeaderColor => State.GetColorPreference(WellKnownPreference.ResponseHeaderColor, base.HeaderColor); 28 | 29 | public override AllowedColors GeneralColor => State.GetColorPreference(WellKnownPreference.ResponseColor, base.GeneralColor); 30 | 31 | public override AllowedColors ProtocolColor => State.GetColorPreference(WellKnownPreference.ResponseProtocolColor, base.ProtocolColor); 32 | 33 | public override AllowedColors ProtocolNameColor => State.GetColorPreference(WellKnownPreference.ResponseProtocolNameColor, base.ProtocolNameColor); 34 | 35 | public override AllowedColors ProtocolVersionColor => State.GetColorPreference(WellKnownPreference.ResponseProtocolVersionColor, base.ProtocolVersionColor); 36 | 37 | public override AllowedColors ProtocolSeparatorColor => State.GetColorPreference(WellKnownPreference.ResponseProtocolSeparatorColor, base.ProtocolSeparatorColor); 38 | 39 | public override AllowedColors StatusColor => State.GetColorPreference(WellKnownPreference.ResponseStatusColor, base.StatusColor); 40 | 41 | public override AllowedColors StatusCodeColor => State.GetColorPreference(WellKnownPreference.ResponseStatusCodeColor, base.StatusCodeColor); 42 | 43 | public override AllowedColors StatusReasonPhraseColor => State.GetColorPreference(WellKnownPreference.ResponseStatusReaseonPhraseColor, base.StatusReasonPhraseColor); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Microsoft.HttpRepl": { 4 | "commandName": "Project", 5 | "commandLineArgs": "http://localhost" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /src/Microsoft.HttpRepl/Suggestions/ServerPathCompletion.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | namespace Microsoft.HttpRepl.Suggestions 9 | { 10 | public static class ServerPathCompletion 11 | { 12 | public static IEnumerable GetCompletions(HttpState programState, string normalCompletionString) 13 | { 14 | 15 | //If it's an absolute URI, nothing to suggest 16 | if (Uri.TryCreate(normalCompletionString, UriKind.Absolute, out Uri _)) 17 | { 18 | return null; 19 | } 20 | 21 | string path = normalCompletionString.Replace('\\', '/'); 22 | int searchFrom = normalCompletionString.Length - 1; 23 | int lastSlash = path.LastIndexOf('/', searchFrom); 24 | string prefix; 25 | 26 | if (lastSlash < 0) 27 | { 28 | path = string.Empty; 29 | prefix = normalCompletionString; 30 | } 31 | else 32 | { 33 | path = path.Substring(0, lastSlash + 1); 34 | prefix = normalCompletionString.Substring(lastSlash + 1); 35 | } 36 | 37 | IDirectoryStructure s = programState.Structure.TraverseTo(programState.PathSections.Reverse()).TraverseTo(path); 38 | 39 | if (s?.DirectoryNames == null) 40 | { 41 | return null; 42 | } 43 | 44 | List results = new List(); 45 | 46 | foreach (string child in s.DirectoryNames) 47 | { 48 | if (child.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) 49 | { 50 | results.Add(path + child); 51 | } 52 | } 53 | 54 | return results; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandHistory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Repl.Commanding 8 | { 9 | public class CommandHistory : ICommandHistory 10 | { 11 | private readonly int _maxEntries; 12 | private readonly List _commandLines = new List(); 13 | private int _currentCommand = -1; 14 | private int _suspensionDepth; 15 | 16 | public CommandHistory(int maxEntries = 50) 17 | { 18 | _maxEntries = maxEntries; 19 | } 20 | 21 | public void AddCommand(string command) 22 | { 23 | if (_suspensionDepth > 0) 24 | { 25 | return; 26 | } 27 | 28 | _commandLines.Add(command); 29 | if (_commandLines.Count > _maxEntries) 30 | { 31 | _commandLines.RemoveAt(0); 32 | } 33 | _currentCommand = -1; 34 | } 35 | 36 | public string GetNextCommand() 37 | { 38 | if (_commandLines.Count == 0) 39 | { 40 | return string.Empty; 41 | } 42 | 43 | if (_currentCommand == -1 || _currentCommand >= _commandLines.Count - 1) 44 | { 45 | _currentCommand = -1; 46 | return string.Empty; 47 | } 48 | 49 | return _commandLines[++_currentCommand]; 50 | } 51 | 52 | public string GetPreviousCommand() 53 | { 54 | if (_commandLines.Count == 0) 55 | { 56 | return string.Empty; 57 | } 58 | 59 | if (_currentCommand == -1) 60 | { 61 | _currentCommand = _commandLines.Count; 62 | } 63 | 64 | if (_currentCommand > 0) 65 | { 66 | return _commandLines[--_currentCommand]; 67 | } 68 | 69 | return _commandLines[0]; 70 | } 71 | 72 | public IDisposable SuspendHistory() 73 | { 74 | ++_suspensionDepth; 75 | return new Disposable(() => --_suspensionDepth); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandInputLocation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.Commanding 5 | { 6 | public enum CommandInputLocation 7 | { 8 | CommandName, 9 | Argument, 10 | OptionName, 11 | OptionValue 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandInputProcessingIssue.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.Commanding 5 | { 6 | public class CommandInputProcessingIssue 7 | { 8 | public CommandInputProcessingIssueKind Kind { get; } 9 | 10 | public string Text { get; } 11 | 12 | public CommandInputProcessingIssue(CommandInputProcessingIssueKind kind, string text) 13 | { 14 | Kind = kind; 15 | Text = text; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandInputProcessingIssueKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.Commanding 5 | { 6 | public enum CommandInputProcessingIssueKind 7 | { 8 | CommandMismatch, 9 | ArgumentCountOutOfRange, 10 | UnknownOption, 11 | OptionUseCountOutOfRange, 12 | MissingRequiredOptionInput, 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandInputSpecification.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.Repl.Commanding 7 | { 8 | public class CommandInputSpecification 9 | { 10 | public IReadOnlyList> CommandName { get; } 11 | 12 | public char OptionPreamble { get; } 13 | 14 | public int MinimumArguments { get; } 15 | 16 | public int MaximumArguments { get; } 17 | 18 | public IReadOnlyList Options { get; } 19 | 20 | public CommandInputSpecification(IReadOnlyList> name, char optionPreamble, IReadOnlyList options, int minimumArgs, int maximumArgs) 21 | { 22 | CommandName = name; 23 | OptionPreamble = optionPreamble; 24 | MinimumArguments = minimumArgs; 25 | MaximumArguments = maximumArgs; 26 | 27 | if (MinimumArguments < 0) 28 | { 29 | MinimumArguments = 0; 30 | } 31 | 32 | if (MaximumArguments < MinimumArguments) 33 | { 34 | MaximumArguments = MinimumArguments; 35 | } 36 | 37 | Options = options; 38 | } 39 | 40 | public static CommandInputSpecificationBuilder Create(string baseName, params string[] additionalNameParts) 41 | { 42 | List nameParts = new List {baseName}; 43 | nameParts.AddRange(additionalNameParts); 44 | return new CommandInputSpecificationBuilder(nameParts); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandInputSpecificationBuilder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Repl.Commanding 8 | { 9 | public class CommandInputSpecificationBuilder 10 | { 11 | private readonly List> _name; 12 | private char _optionPreamble; 13 | private int _minimumArgs; 14 | private int _maximumArgs; 15 | private readonly List _options = new List(); 16 | 17 | public CommandInputSpecificationBuilder(IReadOnlyList name) 18 | { 19 | _name = new List> { name }; 20 | _optionPreamble = '-'; 21 | } 22 | 23 | public CommandInputSpecificationBuilder WithOptionPreamble(char optionChar) 24 | { 25 | _optionPreamble = optionChar; 26 | return this; 27 | } 28 | 29 | public CommandInputSpecificationBuilder ExactArgCount(int count) 30 | { 31 | _minimumArgs = count; 32 | _maximumArgs = count; 33 | return this; 34 | } 35 | 36 | public CommandInputSpecificationBuilder MinimumArgCount(int count) 37 | { 38 | _minimumArgs = count; 39 | if (_maximumArgs < count) 40 | { 41 | _maximumArgs = count; 42 | } 43 | 44 | return this; 45 | } 46 | 47 | public CommandInputSpecificationBuilder MaximumArgCount(int count) 48 | { 49 | _maximumArgs = count; 50 | 51 | if (_minimumArgs > count) 52 | { 53 | _minimumArgs = count; 54 | } 55 | 56 | return this; 57 | } 58 | 59 | public CommandInputSpecificationBuilder WithOption(CommandOptionSpecification option) 60 | { 61 | _options.Add(option); 62 | return this; 63 | } 64 | 65 | public CommandInputSpecification Finish() 66 | { 67 | return new CommandInputSpecification(_name, _optionPreamble, _options, _minimumArgs, _maximumArgs); 68 | } 69 | 70 | public CommandInputSpecificationBuilder AlternateName(string baseName, params string[] additionalNameParts) 71 | { 72 | List nameParts = new List { baseName }; 73 | nameParts.AddRange(additionalNameParts); 74 | _name.Add(nameParts); 75 | return this; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/CommandOptionSpecification.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.Repl.Commanding 7 | { 8 | public class CommandOptionSpecification 9 | { 10 | public string Id { get; } 11 | 12 | public IReadOnlyList Forms { get; } 13 | 14 | public int MaximumOccurrences { get; } 15 | 16 | public int MinimumOccurrences { get; } 17 | 18 | public bool AcceptsValue { get; } 19 | 20 | public bool RequiresValue { get; } 21 | 22 | public CommandOptionSpecification(string id, bool acceptsValue = false, bool requiresValue = false, int minimumOccurrences = 0, int maximumOccurrences = int.MaxValue, params string[] forms) 23 | { 24 | Id = id; 25 | Forms = forms; 26 | MinimumOccurrences = minimumOccurrences; 27 | MaximumOccurrences = maximumOccurrences > minimumOccurrences ? maximumOccurrences : minimumOccurrences; 28 | RequiresValue = requiresValue; 29 | AcceptsValue = RequiresValue || acceptsValue; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/ICommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Microsoft.Repl.Parsing; 8 | 9 | namespace Microsoft.Repl.Commanding 10 | { 11 | public interface ICommand 12 | where TParseResult : ICoreParseResult 13 | { 14 | string GetHelpSummary(IShellState shellState, TProgramState programState); 15 | 16 | string GetHelpDetails(IShellState shellState, TProgramState programState, TParseResult parseResult); 17 | 18 | IEnumerable Suggest(IShellState shellState, TProgramState programState, TParseResult parseResult); 19 | 20 | bool? CanHandle(IShellState shellState, TProgramState programState, TParseResult parseResult); 21 | 22 | Task ExecuteAsync(IShellState shellState, TProgramState programState, TParseResult parseResult, CancellationToken cancellationToken); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/ICommandDispatcher.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Microsoft.Repl.Parsing; 8 | 9 | namespace Microsoft.Repl.Commanding 10 | { 11 | public interface ICommandDispatcher 12 | { 13 | IParser Parser { get; } 14 | 15 | IReadOnlyList CollectSuggestions(IShellState shellState); 16 | 17 | void OnReady(IShellState shellState); 18 | 19 | Task ExecuteCommandAsync(IShellState shellState, CancellationToken cancellationToken); 20 | } 21 | 22 | public interface ICommandDispatcher : ICommandDispatcher 23 | where TParseResult : ICoreParseResult 24 | { 25 | IEnumerable> Commands { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/ICommandHistory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Repl.Commanding 7 | { 8 | public interface ICommandHistory 9 | { 10 | string GetPreviousCommand(); 11 | 12 | string GetNextCommand(); 13 | 14 | void AddCommand(string command); 15 | 16 | IDisposable SuspendHistory(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Commanding/InputElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.Commanding 5 | { 6 | public class InputElement 7 | { 8 | public CommandInputLocation Location { get; } 9 | 10 | public string Text { get; } 11 | 12 | public string NormalizedText { get; } 13 | 14 | public InputElement Owner { get; } 15 | 16 | public int ParseResultSectionIndex { get; } 17 | 18 | public InputElement(CommandInputLocation location, string text, string normalizedText, int sectionIndex) 19 | : this(null, location, text, normalizedText, sectionIndex) 20 | { 21 | } 22 | 23 | public InputElement(InputElement owner, CommandInputLocation location, string text, string normalizedText, int sectionIndex) 24 | { 25 | Owner = owner; 26 | Location = location; 27 | Text = text; 28 | NormalizedText = normalizedText; 29 | ParseResultSectionIndex = sectionIndex; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ConsoleHandling/AllowedColors.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Repl.ConsoleHandling 7 | { 8 | [Flags] 9 | public enum AllowedColors 10 | { 11 | Black = 0x00, 12 | BoldBlack = Bold | Black, 13 | Red = 0x01, 14 | BoldRed = Bold | Red, 15 | Green = 0x02, 16 | BoldGreen = Bold | Green, 17 | Yellow = 0x03, 18 | BoldYellow = Bold | Yellow, 19 | Blue = 0x04, 20 | BoldBlue = Bold | Blue, 21 | Magenta = 0x05, 22 | BoldMagenta = Bold | Magenta, 23 | Cyan = 0x06, 24 | BoldCyan = Bold | Cyan, 25 | White = 0x07, 26 | BoldWhite = White | Bold, 27 | Bold = 0x100, 28 | None = 0x99 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ConsoleHandling/AnsiColorExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.ConsoleHandling 5 | { 6 | public static class AnsiColorExtensions 7 | { 8 | public static string Black(this string text) 9 | { 10 | return "\x1B[30m" + text + "\x1B[39m"; 11 | } 12 | 13 | public static string Red(this string text) 14 | { 15 | return "\x1B[31m" + text + "\x1B[39m"; 16 | } 17 | public static string Green(this string text) 18 | { 19 | return "\x1B[32m" + text + "\x1B[39m"; 20 | } 21 | 22 | public static string Yellow(this string text) 23 | { 24 | return "\x1B[33m" + text + "\x1B[39m"; 25 | } 26 | 27 | public static string Blue(this string text) 28 | { 29 | return "\x1B[34m" + text + "\x1B[39m"; 30 | } 31 | 32 | public static string Magenta(this string text) 33 | { 34 | return "\x1B[35m" + text + "\x1B[39m"; 35 | } 36 | 37 | public static string Cyan(this string text) 38 | { 39 | return "\x1B[36m" + text + "\x1B[39m"; 40 | } 41 | 42 | public static string White(this string text) 43 | { 44 | return "\x1B[37m" + text + "\x1B[39m"; 45 | } 46 | 47 | public static string Bold(this string text) 48 | { 49 | return "\x1B[1m" + text + "\x1B[22m"; 50 | } 51 | 52 | public static string SetColor(this string text, AllowedColors color) 53 | { 54 | if (color.HasFlag(AllowedColors.Bold)) 55 | { 56 | text = text.Bold(); 57 | color = color & ~AllowedColors.Bold; 58 | } 59 | 60 | switch (color) 61 | { 62 | case AllowedColors.Black: 63 | return text.Black(); 64 | case AllowedColors.Red: 65 | return text.Red(); 66 | case AllowedColors.Green: 67 | return text.Green(); 68 | case AllowedColors.Yellow: 69 | return text.Yellow(); 70 | case AllowedColors.Blue: 71 | return text.Blue(); 72 | case AllowedColors.Magenta: 73 | return text.Magenta(); 74 | case AllowedColors.Cyan: 75 | return text.Cyan(); 76 | case AllowedColors.White: 77 | return text.White(); 78 | default: 79 | return text; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ConsoleHandling/IConsoleManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Threading; 6 | 7 | namespace Microsoft.Repl.ConsoleHandling 8 | { 9 | public interface IConsoleManager : IWritable 10 | { 11 | Point Caret { get; } 12 | 13 | Point CommandStart { get; } 14 | 15 | int CaretPosition { get; } 16 | 17 | IWritable Error { get; } 18 | 19 | bool IsKeyAvailable { get; } 20 | 21 | void Clear(); 22 | 23 | void MoveCaret(int positions); 24 | 25 | ConsoleKeyInfo ReadKey(CancellationToken cancellationToken); 26 | 27 | void ResetCommandStart(); 28 | 29 | IDisposable AddBreakHandler(Action onBreak); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ConsoleHandling/IWritable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.ConsoleHandling 5 | { 6 | public interface IWritable 7 | { 8 | void Write(char c); 9 | 10 | void Write(string s); 11 | 12 | void WriteLine(); 13 | 14 | void WriteLine(string s); 15 | 16 | bool IsCaretVisible { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ConsoleHandling/Point.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.ConsoleHandling 5 | { 6 | public struct Point 7 | { 8 | public readonly int X; 9 | 10 | public readonly int Y; 11 | 12 | public Point(int x, int y) 13 | { 14 | X = x; 15 | Y = y; 16 | } 17 | 18 | public static bool operator >(Point left, Point right) 19 | { 20 | return left.Y > right.Y || (left.Y == right.Y && right.X > left.X); 21 | } 22 | 23 | public static bool operator <(Point left, Point right) 24 | { 25 | return left.Y < right.Y || (left.Y == right.Y && right.X < left.X); 26 | } 27 | 28 | public static bool operator ==(Point left, Point right) 29 | { 30 | return left.X == right.X && left.Y == right.Y; 31 | } 32 | 33 | public static bool operator !=(Point left, Point right) 34 | { 35 | return left.X != right.X || left.Y != right.Y; 36 | } 37 | 38 | public override bool Equals(object obj) 39 | { 40 | return obj is Point other && other.X == X && other.Y == Y; 41 | } 42 | 43 | public override int GetHashCode() 44 | { 45 | return X ^ Y; 46 | } 47 | 48 | public override string ToString() 49 | { 50 | return $"(X={X}, Y={Y})"; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ConsoleHandling/Writable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Repl.ConsoleHandling 7 | { 8 | internal class Writable : IWritable 9 | { 10 | private readonly Func _caretUpdater; 11 | private readonly Reporter _reporter; 12 | 13 | public Writable(Func caretUpdater, Reporter reporter) 14 | { 15 | _caretUpdater = caretUpdater; 16 | _reporter = reporter; 17 | } 18 | 19 | public bool IsCaretVisible 20 | { 21 | get => _reporter.IsCaretVisible; 22 | set => _reporter.IsCaretVisible = value; 23 | } 24 | 25 | public void Write(char c) 26 | { 27 | using (_caretUpdater()) 28 | { 29 | _reporter.Write(c); 30 | } 31 | } 32 | 33 | public void Write(string s) 34 | { 35 | using (_caretUpdater()) 36 | { 37 | _reporter.Write(s); 38 | } 39 | } 40 | 41 | public void WriteLine() 42 | { 43 | using (_caretUpdater()) 44 | { 45 | _reporter.WriteLine(); 46 | } 47 | } 48 | 49 | public void WriteLine(string s) 50 | { 51 | using (_caretUpdater()) 52 | { 53 | _reporter.WriteLine(s); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Disposable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Repl 7 | { 8 | public class Disposable : IDisposable 9 | { 10 | private Action _onDispose; 11 | 12 | public Disposable(Action onDispose) 13 | { 14 | _onDispose = onDispose; 15 | } 16 | public virtual void Dispose() 17 | { 18 | _onDispose?.Invoke(); 19 | _onDispose = null; 20 | } 21 | } 22 | 23 | public class Disposable : Disposable 24 | where T : class 25 | { 26 | public Disposable(T value, Action onDispose) 27 | : base (onDispose) 28 | { 29 | Value = value; 30 | } 31 | 32 | public T Value { get; private set; } 33 | 34 | public override void Dispose() 35 | { 36 | if (Value is IDisposable d) 37 | { 38 | d.Dispose(); 39 | Value = null; 40 | } 41 | 42 | base.Dispose(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/IShellState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.Commanding; 5 | using Microsoft.Repl.ConsoleHandling; 6 | using Microsoft.Repl.Input; 7 | using Microsoft.Repl.Suggestions; 8 | 9 | namespace Microsoft.Repl 10 | { 11 | public interface IShellState 12 | { 13 | IInputManager InputManager { get; } 14 | 15 | ICommandHistory CommandHistory { get; } 16 | 17 | IConsoleManager ConsoleManager { get; } 18 | 19 | ICommandDispatcher CommandDispatcher { get; } 20 | 21 | ISuggestionManager SuggestionManager { get; } 22 | 23 | bool IsExiting { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Input/AsyncKeyPressHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Microsoft.Repl.Input 9 | { 10 | public delegate Task AsyncKeyPressHandler(ConsoleKeyInfo keyInfo, IShellState state, CancellationToken cancellationToken); 11 | } 12 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Input/IInputManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Microsoft.Repl.Input 9 | { 10 | public interface IInputManager 11 | { 12 | bool IsOverwriteMode { get; set; } 13 | 14 | IInputManager RegisterKeyHandler(ConsoleKey key, AsyncKeyPressHandler handler); 15 | 16 | IInputManager RegisterKeyHandler(ConsoleKey key, ConsoleModifiers modifiers, AsyncKeyPressHandler handler); 17 | 18 | void ResetInput(); 19 | 20 | Task StartAsync(IShellState state, CancellationToken cancellationToken); 21 | 22 | void SetInput(IShellState state, string input); 23 | 24 | string GetCurrentBuffer(); 25 | 26 | void RemovePreviousCharacter(IShellState state); 27 | 28 | void RemoveCurrentCharacter(IShellState state); 29 | 30 | void Clear(IShellState state); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Microsoft.Repl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | A framework for creating REPLs in .NET Core. 6 | dotnet;repl 7 | false 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Parsing/ICoreParseResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.Repl.Parsing 7 | { 8 | public interface ICoreParseResult 9 | { 10 | int CaretPositionWithinCommandText { get; } 11 | 12 | int CaretPositionWithinSelectedSection { get; } 13 | 14 | string CommandText { get; } 15 | 16 | IReadOnlyList Sections { get; } 17 | 18 | bool IsQuotedSection(int index); 19 | 20 | int SelectedSection { get; } 21 | 22 | IReadOnlyDictionary SectionStartLookup { get; } 23 | 24 | ICoreParseResult Slice(int numberOfLeadingSectionsToRemove); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Parsing/IParser.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.Parsing 5 | { 6 | public interface IParser 7 | { 8 | ICoreParseResult Parse(string commandText, int caretPosition); 9 | } 10 | 11 | public interface IParser : IParser 12 | { 13 | new TParseResult Parse(string commandText, int caretPosition); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Scripting/IScriptExecutor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Microsoft.Repl.Scripting 9 | { 10 | public interface IScriptExecutor 11 | { 12 | Task ExecuteScriptAsync(IShellState shellState, IEnumerable commandTexts, CancellationToken cancellationToken); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Scripting/ScriptExecutor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.Repl.Commanding; 9 | using Microsoft.Repl.Parsing; 10 | 11 | namespace Microsoft.Repl.Scripting 12 | { 13 | public class ScriptExecutor : IScriptExecutor 14 | where TParseResult : ICoreParseResult 15 | { 16 | private readonly bool _hideScriptLinesFromHistory; 17 | 18 | public ScriptExecutor(bool hideScriptLinesFromHistory = true) 19 | { 20 | _hideScriptLinesFromHistory = hideScriptLinesFromHistory; 21 | } 22 | 23 | public async Task ExecuteScriptAsync(IShellState shellState, IEnumerable commandTexts, CancellationToken cancellationToken) 24 | { 25 | if (shellState.CommandDispatcher is ICommandDispatcher dispatcher) 26 | { 27 | IDisposable suppressor = _hideScriptLinesFromHistory ? shellState.CommandHistory.SuspendHistory() : null; 28 | 29 | using (suppressor) 30 | { 31 | foreach (string commandText in commandTexts) 32 | { 33 | if (string.IsNullOrWhiteSpace(commandText)) 34 | { 35 | continue; 36 | } 37 | 38 | if (cancellationToken.IsCancellationRequested) 39 | { 40 | break; 41 | } 42 | 43 | dispatcher.OnReady(shellState); 44 | shellState.ConsoleManager.ResetCommandStart(); 45 | shellState.InputManager.SetInput(shellState, commandText); 46 | await dispatcher.ExecuteCommandAsync(shellState, cancellationToken).ConfigureAwait(false); 47 | } 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Shell.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using Microsoft.Repl.Commanding; 7 | using Microsoft.Repl.Input; 8 | using Microsoft.Repl.Suggestions; 9 | 10 | namespace Microsoft.Repl 11 | { 12 | public class Shell 13 | { 14 | public Shell(IShellState shellState) 15 | { 16 | KeyHandlers.RegisterDefaultKeyHandlers(shellState.InputManager); 17 | ShellState = shellState; 18 | } 19 | 20 | public Shell(ICommandDispatcher dispatcher, ISuggestionManager suggestionManager = null) 21 | : this(new ShellState(dispatcher, suggestionManager)) 22 | { 23 | } 24 | 25 | public IShellState ShellState { get; } 26 | 27 | public Task RunAsync(CancellationToken cancellationToken) 28 | { 29 | ShellState.CommandDispatcher.OnReady(ShellState); 30 | return ShellState.InputManager.StartAsync(ShellState, cancellationToken); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/ShellState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Repl.Commanding; 5 | using Microsoft.Repl.ConsoleHandling; 6 | using Microsoft.Repl.Input; 7 | using Microsoft.Repl.Suggestions; 8 | 9 | namespace Microsoft.Repl 10 | { 11 | public class ShellState : IShellState 12 | { 13 | public ShellState(ICommandDispatcher commandDispatcher, ISuggestionManager suggestionManager = null, IInputManager inputManager = null, ICommandHistory commandHistory = null, IConsoleManager consoleManager = null) 14 | { 15 | InputManager = inputManager ?? new InputManager(); 16 | CommandHistory = commandHistory ?? new CommandHistory(); 17 | ConsoleManager = consoleManager ?? new ConsoleManager(); 18 | CommandDispatcher = commandDispatcher; 19 | SuggestionManager = suggestionManager ?? new SuggestionManager(); 20 | } 21 | 22 | public IInputManager InputManager { get; } 23 | 24 | public ICommandHistory CommandHistory { get; } 25 | 26 | public IConsoleManager ConsoleManager { get; } 27 | 28 | public ICommandDispatcher CommandDispatcher { get; } 29 | 30 | public bool IsExiting { get; set; } 31 | 32 | public ISuggestionManager SuggestionManager { get; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Suggestions/FileSystemCompletion.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | 9 | namespace Microsoft.Repl.Suggestions 10 | { 11 | public static class FileSystemCompletion 12 | { 13 | public static IEnumerable GetCompletions(string prefix) 14 | { 15 | if (prefix.StartsWith('\"')) 16 | { 17 | prefix = prefix.Substring(1); 18 | 19 | int lastQuote = prefix.LastIndexOf('\"'); 20 | 21 | if (lastQuote > -1) 22 | { 23 | prefix = prefix.Remove(lastQuote, 1); 24 | } 25 | 26 | while (prefix.EndsWith($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}")) 27 | { 28 | prefix = prefix.Substring(0, prefix.Length - 1); 29 | } 30 | } 31 | 32 | int lastPathIndex = prefix.LastIndexOfAny(new[] { '\\', '/' }); 33 | if (lastPathIndex < 0) 34 | { 35 | return null; 36 | } 37 | 38 | string dir = prefix.Substring(0, lastPathIndex + 1); 39 | 40 | if (dir.IndexOfAny(Path.GetInvalidPathChars()) > -1) 41 | { 42 | return null; 43 | } 44 | 45 | string partPrefix = prefix.Substring(lastPathIndex + 1); 46 | if (Directory.Exists(dir)) 47 | { 48 | return Directory.EnumerateDirectories(dir).Where(x => Path.GetFileName(x).StartsWith(partPrefix, StringComparison.OrdinalIgnoreCase)) 49 | .Union(Directory.EnumerateFiles(dir).Where(x => Path.GetFileName(x).StartsWith(partPrefix, StringComparison.OrdinalIgnoreCase))).Select(x => x.IndexOf(' ') > -1 ? $"\"{x}\"" : x); 50 | } 51 | 52 | return null; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Suggestions/ISuggestionManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Repl.Suggestions 5 | { 6 | public interface ISuggestionManager 7 | { 8 | void NextSuggestion(IShellState shellState); 9 | 10 | void PreviousSuggestion(IShellState shellState); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.Repl/Utils.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.Repl 7 | { 8 | public static class Utils 9 | { 10 | public static string Stringify(this IReadOnlyList keys) 11 | { 12 | return string.Join("", keys); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/dotnet-dev-certs/README.md: -------------------------------------------------------------------------------- 1 | dotnet-dev-certs 2 | ================ 3 | 4 | `dotnet-dev-certs` is a command line tool to generate certificates used in ASP.NET Core during development. 5 | 6 | ### How To Use 7 | 8 | Run `dotnet dev-certs --help` for more information about usage. 9 | -------------------------------------------------------------------------------- /src/dotnet-dev-certs/dotnet-dev-certs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | exe 6 | Command line tool to generate certificates used in ASP.NET Core during development. 7 | Microsoft.AspNetCore.DeveloperCertificates.Tools 8 | dotnet;developercertificates 9 | true 10 | 11 | win-x64;win-x86 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/dotnet-sql-cache/README.md: -------------------------------------------------------------------------------- 1 | dotnet-sql-cache 2 | ================ 3 | 4 | `dotnet-sql-cache` is a command line tool that creates table and indexes in Microsoft SQL Server database to be used for distributed caching 5 | 6 | ### How To Use 7 | 8 | Run `dotnet sql-cache --help` for more information about usage. 9 | -------------------------------------------------------------------------------- /src/dotnet-sql-cache/SqlQueries.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.Caching.SqlConfig.Tools 7 | { 8 | internal class SqlQueries 9 | { 10 | private const string CreateTableFormat = "CREATE TABLE {0}(" + 11 | // Maximum size of primary key column is 900 bytes (898 bytes from key + 2 additional bytes used by the 12 | // Sql Server). In the case where the key is greater than 898 bytes, then it gets truncated. 13 | // - Add collation to the key column to make it case-sensitive 14 | "Id nvarchar(449) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL, " + 15 | "Value varbinary(MAX) NOT NULL, " + 16 | "ExpiresAtTime datetimeoffset NOT NULL, " + 17 | "SlidingExpirationInSeconds bigint NULL," + 18 | "AbsoluteExpiration datetimeoffset NULL, " + 19 | "PRIMARY KEY (Id))"; 20 | 21 | private const string CreateNonClusteredIndexOnExpirationTimeFormat 22 | = "CREATE NONCLUSTERED INDEX Index_ExpiresAtTime ON {0}(ExpiresAtTime)"; 23 | 24 | private const string TableInfoFormat = 25 | "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE " + 26 | "FROM INFORMATION_SCHEMA.TABLES " + 27 | "WHERE TABLE_SCHEMA = '{0}' " + 28 | "AND TABLE_NAME = '{1}'"; 29 | 30 | public SqlQueries(string schemaName, string tableName) 31 | { 32 | if (string.IsNullOrEmpty(schemaName)) 33 | { 34 | throw new ArgumentException("Schema name cannot be empty or null"); 35 | } 36 | if (string.IsNullOrEmpty(tableName)) 37 | { 38 | throw new ArgumentException("Table name cannot be empty or null"); 39 | } 40 | 41 | var tableNameWithSchema = string.Format( 42 | "{0}.{1}", DelimitIdentifier(schemaName), DelimitIdentifier(tableName)); 43 | CreateTable = string.Format(CreateTableFormat, tableNameWithSchema); 44 | CreateNonClusteredIndexOnExpirationTime = string.Format( 45 | CreateNonClusteredIndexOnExpirationTimeFormat, 46 | tableNameWithSchema); 47 | TableInfo = string.Format(TableInfoFormat, EscapeLiteral(schemaName), EscapeLiteral(tableName)); 48 | } 49 | 50 | public string CreateTable { get; } 51 | 52 | public string CreateNonClusteredIndexOnExpirationTime { get; } 53 | 54 | public string TableInfo { get; } 55 | 56 | // From EF's SqlServerQuerySqlGenerator 57 | private string DelimitIdentifier(string identifier) 58 | { 59 | return "[" + identifier.Replace("]", "]]") + "]"; 60 | } 61 | 62 | private string EscapeLiteral(string literal) 63 | { 64 | return literal.Replace("'", "''"); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/dotnet-sql-cache/dotnet-sql-cache.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | exe 6 | Command line tool to create tables and indexes in a Microsoft SQL Server database for distributed caching. 7 | cache;distributedcache;sqlserver 8 | true 9 | 10 | win-x64;win-x86 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/ClearCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Extensions.CommandLineUtils; 5 | 6 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 7 | { 8 | internal class ClearCommand : ICommand 9 | { 10 | public static void Configure(CommandLineApplication command, CommandLineOptions options) 11 | { 12 | command.Description = "Deletes all the application secrets"; 13 | command.HelpOption(); 14 | 15 | command.OnExecute(() => 16 | { 17 | options.Command = new ClearCommand(); 18 | }); 19 | } 20 | 21 | public void Execute(CommandContext context) 22 | { 23 | context.SecretStore.Clear(); 24 | context.SecretStore.Save(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/CommandContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Extensions.Tools.Internal; 5 | 6 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 7 | { 8 | public class CommandContext 9 | { 10 | public CommandContext( 11 | SecretsStore store, 12 | IReporter reporter, 13 | IConsole console) 14 | { 15 | SecretStore = store; 16 | Reporter = reporter; 17 | Console = console; 18 | } 19 | 20 | public IConsole Console { get; } 21 | public IReporter Reporter { get; } 22 | public SecretsStore SecretStore { get; } 23 | } 24 | } -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/ICommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 5 | { 6 | public interface ICommand 7 | { 8 | void Execute(CommandContext context); 9 | } 10 | } -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/ListCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Extensions.CommandLineUtils; 5 | using Newtonsoft.Json; 6 | using Newtonsoft.Json.Linq; 7 | 8 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 9 | { 10 | internal class ListCommand : ICommand 11 | { 12 | private readonly bool _jsonOutput; 13 | 14 | public static void Configure(CommandLineApplication command, CommandLineOptions options) 15 | { 16 | command.Description = "Lists all the application secrets"; 17 | command.HelpOption(); 18 | 19 | var optJson = command.Option("--json", "Use json output. JSON is wrapped by '//BEGIN' and '//END'", 20 | CommandOptionType.NoValue); 21 | 22 | command.OnExecute(() => 23 | { 24 | options.Command = new ListCommand(optJson.HasValue()); 25 | }); 26 | } 27 | 28 | public ListCommand(bool jsonOutput) 29 | { 30 | _jsonOutput = jsonOutput; 31 | } 32 | 33 | public void Execute(CommandContext context) 34 | { 35 | if (_jsonOutput) 36 | { 37 | ReportJson(context); 38 | return; 39 | } 40 | 41 | if (context.SecretStore.Count == 0) 42 | { 43 | context.Reporter.Output(Resources.Error_No_Secrets_Found); 44 | } 45 | else 46 | { 47 | foreach (var secret in context.SecretStore.AsEnumerable()) 48 | { 49 | context.Reporter.Output(Resources.FormatMessage_Secret_Value_Format(secret.Key, secret.Value)); 50 | } 51 | } 52 | } 53 | 54 | private void ReportJson(CommandContext context) 55 | { 56 | var jObject = new JObject(); 57 | foreach(var item in context.SecretStore.AsEnumerable()) 58 | { 59 | jObject[item.Key] = item.Value; 60 | } 61 | 62 | context.Reporter.Output("//BEGIN"); 63 | context.Reporter.Output(jObject.ToString(Formatting.Indented)); 64 | context.Reporter.Output("//END"); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/MsBuildProjectFinder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using Microsoft.Extensions.Tools.Internal; 8 | 9 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 10 | { 11 | internal class MsBuildProjectFinder 12 | { 13 | private readonly string _directory; 14 | 15 | public MsBuildProjectFinder(string directory) 16 | { 17 | Ensure.NotNullOrEmpty(directory, nameof(directory)); 18 | 19 | _directory = directory; 20 | } 21 | 22 | public string FindMsBuildProject(string project) 23 | { 24 | var projectPath = project ?? _directory; 25 | 26 | if (!Path.IsPathRooted(projectPath)) 27 | { 28 | projectPath = Path.Combine(_directory, projectPath); 29 | } 30 | 31 | if (Directory.Exists(projectPath)) 32 | { 33 | var projects = Directory.EnumerateFileSystemEntries(projectPath, "*.*proj", SearchOption.TopDirectoryOnly) 34 | .Where(f => !".xproj".Equals(Path.GetExtension(f), StringComparison.OrdinalIgnoreCase)) 35 | .ToList(); 36 | 37 | if (projects.Count > 1) 38 | { 39 | throw new FileNotFoundException(Resources.FormatError_MultipleProjectsFound(projectPath)); 40 | } 41 | 42 | if (projects.Count == 0) 43 | { 44 | throw new FileNotFoundException(Resources.FormatError_NoProjectsFound(projectPath)); 45 | } 46 | 47 | return projects[0]; 48 | } 49 | 50 | if (!File.Exists(projectPath)) 51 | { 52 | throw new FileNotFoundException(Resources.FormatError_ProjectPath_NotFound(projectPath)); 53 | } 54 | 55 | return projectPath; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/ReadableJsonConfigurationSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using Microsoft.Extensions.Configuration.Json; 6 | 7 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 8 | { 9 | public class ReadableJsonConfigurationProvider : JsonConfigurationProvider 10 | { 11 | public ReadableJsonConfigurationProvider() 12 | : base(new JsonConfigurationSource()) 13 | { 14 | } 15 | 16 | public IDictionary CurrentData => Data; 17 | } 18 | } -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/RemoveCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.Extensions.CommandLineUtils; 5 | 6 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 7 | { 8 | internal class RemoveCommand : ICommand 9 | { 10 | private readonly string _keyName; 11 | 12 | public static void Configure(CommandLineApplication command, CommandLineOptions options) 13 | { 14 | command.Description = "Removes the specified user secret"; 15 | command.HelpOption(); 16 | 17 | var keyArg = command.Argument("[name]", "Name of the secret"); 18 | command.OnExecute(() => 19 | { 20 | if (keyArg.Value == null) 21 | { 22 | throw new CommandParsingException(command, Resources.FormatError_MissingArgument("name")); 23 | } 24 | 25 | options.Command = new RemoveCommand(keyArg.Value); 26 | }); 27 | } 28 | 29 | 30 | public RemoveCommand(string keyName) 31 | { 32 | _keyName = keyName; 33 | } 34 | 35 | public void Execute(CommandContext context) 36 | { 37 | if (!context.SecretStore.ContainsKey(_keyName)) 38 | { 39 | context.Reporter.Warn(Resources.FormatError_Missing_Secret(_keyName)); 40 | } 41 | else 42 | { 43 | context.SecretStore.Remove(_keyName); 44 | context.SecretStore.Save(); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Internal/SecretsStore.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.Configuration.UserSecrets; 11 | using Microsoft.Extensions.Tools.Internal; 12 | using Newtonsoft.Json.Linq; 13 | 14 | namespace Microsoft.Extensions.SecretManager.Tools.Internal 15 | { 16 | public class SecretsStore 17 | { 18 | private readonly string _secretsFilePath; 19 | private IDictionary _secrets; 20 | 21 | public SecretsStore(string userSecretsId, IReporter reporter) 22 | { 23 | Ensure.NotNull(userSecretsId, nameof(userSecretsId)); 24 | 25 | _secretsFilePath = PathHelper.GetSecretsPathFromSecretsId(userSecretsId); 26 | 27 | // workaround bug in configuration 28 | var secretDir = Path.GetDirectoryName(_secretsFilePath); 29 | Directory.CreateDirectory(secretDir); 30 | 31 | reporter.Verbose(Resources.FormatMessage_Secret_File_Path(_secretsFilePath)); 32 | _secrets = Load(userSecretsId); 33 | } 34 | 35 | public string this[string key] 36 | { 37 | get 38 | { 39 | return _secrets[key]; 40 | } 41 | } 42 | 43 | public int Count => _secrets.Count; 44 | 45 | public bool ContainsKey(string key) => _secrets.ContainsKey(key); 46 | 47 | public IEnumerable> AsEnumerable() => _secrets; 48 | 49 | public void Clear() => _secrets.Clear(); 50 | 51 | public void Set(string key, string value) => _secrets[key] = value; 52 | 53 | public void Remove(string key) 54 | { 55 | if (_secrets.ContainsKey(key)) 56 | { 57 | _secrets.Remove(key); 58 | } 59 | } 60 | 61 | public virtual void Save() 62 | { 63 | Directory.CreateDirectory(Path.GetDirectoryName(_secretsFilePath)); 64 | 65 | var contents = new JObject(); 66 | if (_secrets != null) 67 | { 68 | foreach (var secret in _secrets.AsEnumerable()) 69 | { 70 | contents[secret.Key] = secret.Value; 71 | } 72 | } 73 | 74 | File.WriteAllText(_secretsFilePath, contents.ToString(), Encoding.UTF8); 75 | } 76 | 77 | protected virtual IDictionary Load(string userSecretsId) 78 | { 79 | return new ConfigurationBuilder() 80 | .AddJsonFile(_secretsFilePath, optional: true) 81 | .Build() 82 | .AsEnumerable() 83 | .Where(i => i.Value != null) 84 | .ToDictionary(i => i.Key, i => i.Value, StringComparer.OrdinalIgnoreCase); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/dotnet-user-secrets/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("Microsoft.Extensions.SecretManager.Tools.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] 7 | -------------------------------------------------------------------------------- /src/dotnet-user-secrets/README.md: -------------------------------------------------------------------------------- 1 | dotnet-user-secrets 2 | =================== 3 | 4 | `dotnet-user-secrets` is a command line tool for managing the secrets in a user secret store. 5 | 6 | ### How To Use 7 | 8 | Run `dotnet user-secrets --help` for more information about usage. 9 | -------------------------------------------------------------------------------- /src/dotnet-user-secrets/assets/SecretManager.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/dotnet-watch/IFileSet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.DotNet.Watcher 7 | { 8 | public interface IFileSet : IEnumerable 9 | { 10 | bool Contains(string filePath); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/dotnet-watch/IFileSetFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.DotNet.Watcher 8 | { 9 | public interface IFileSetFactory 10 | { 11 | Task CreateAsync(CancellationToken cancellationToken); 12 | } 13 | } -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/FileSet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | namespace Microsoft.DotNet.Watcher.Internal 9 | { 10 | public class FileSet : IFileSet 11 | { 12 | private readonly HashSet _files; 13 | 14 | public FileSet(IEnumerable files) 15 | { 16 | _files = new HashSet(files, StringComparer.OrdinalIgnoreCase); 17 | } 18 | 19 | public bool Contains(string filePath) => _files.Contains(filePath); 20 | 21 | public int Count => _files.Count; 22 | 23 | public IEnumerator GetEnumerator() => _files.GetEnumerator(); 24 | IEnumerator IEnumerable.GetEnumerator() => _files.GetEnumerator(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/FileSetWatcher.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.Extensions.Tools.Internal; 9 | 10 | namespace Microsoft.DotNet.Watcher.Internal 11 | { 12 | public class FileSetWatcher : IDisposable 13 | { 14 | private readonly FileWatcher _fileWatcher; 15 | private readonly IFileSet _fileSet; 16 | 17 | public FileSetWatcher(IFileSet fileSet, IReporter reporter) 18 | { 19 | Ensure.NotNull(fileSet, nameof(fileSet)); 20 | 21 | _fileSet = fileSet; 22 | _fileWatcher = new FileWatcher(reporter); 23 | } 24 | 25 | public async Task GetChangedFileAsync(CancellationToken cancellationToken) 26 | { 27 | foreach (var file in _fileSet) 28 | { 29 | _fileWatcher.WatchDirectory(Path.GetDirectoryName(file)); 30 | } 31 | 32 | var tcs = new TaskCompletionSource(); 33 | cancellationToken.Register(() => tcs.TrySetResult(null)); 34 | 35 | Action callback = path => 36 | { 37 | if (_fileSet.Contains(path)) 38 | { 39 | tcs.TrySetResult(path); 40 | } 41 | }; 42 | 43 | _fileWatcher.OnFileChange += callback; 44 | var changedFile = await tcs.Task; 45 | _fileWatcher.OnFileChange -= callback; 46 | 47 | return changedFile; 48 | } 49 | 50 | public void Dispose() 51 | { 52 | _fileWatcher.Dispose(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/FileWatcher/FileWatcherFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.DotNet.Watcher.Internal 7 | { 8 | public static class FileWatcherFactory 9 | { 10 | public static IFileSystemWatcher CreateWatcher(string watchedDirectory) 11 | => CreateWatcher(watchedDirectory, CommandLineOptions.IsPollingEnabled); 12 | 13 | public static IFileSystemWatcher CreateWatcher(string watchedDirectory, bool usePollingWatcher) 14 | { 15 | return usePollingWatcher ? 16 | new PollingFileWatcher(watchedDirectory) : 17 | new DotnetFileWatcher(watchedDirectory) as IFileSystemWatcher; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/FileWatcher/IFileSystemWatcher.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.DotNet.Watcher.Internal 7 | { 8 | public interface IFileSystemWatcher : IDisposable 9 | { 10 | event EventHandler OnFileChange; 11 | 12 | event EventHandler OnError; 13 | 14 | string BasePath { get; } 15 | 16 | bool EnableRaisingEvents { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/MsBuildProjectFinder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using Microsoft.DotNet.Watcher.Tools; 8 | using Microsoft.Extensions.Tools.Internal; 9 | 10 | namespace Microsoft.DotNet.Watcher.Internal 11 | { 12 | internal class MsBuildProjectFinder 13 | { 14 | /// 15 | /// Finds a compatible MSBuild project. 16 | /// The base directory to search 17 | /// The filename of the project. Can be null. 18 | /// 19 | public static string FindMsBuildProject(string searchBase, string project) 20 | { 21 | Ensure.NotNullOrEmpty(searchBase, nameof(searchBase)); 22 | 23 | var projectPath = project ?? searchBase; 24 | 25 | if (!Path.IsPathRooted(projectPath)) 26 | { 27 | projectPath = Path.Combine(searchBase, projectPath); 28 | } 29 | 30 | if (Directory.Exists(projectPath)) 31 | { 32 | var projects = Directory.EnumerateFileSystemEntries(projectPath, "*.*proj", SearchOption.TopDirectoryOnly) 33 | .Where(f => !".xproj".Equals(Path.GetExtension(f), StringComparison.OrdinalIgnoreCase)) 34 | .ToList(); 35 | 36 | if (projects.Count > 1) 37 | { 38 | throw new FileNotFoundException(Resources.FormatError_MultipleProjectsFound(projectPath)); 39 | } 40 | 41 | if (projects.Count == 0) 42 | { 43 | throw new FileNotFoundException(Resources.FormatError_NoProjectsFound(projectPath)); 44 | } 45 | 46 | return projects[0]; 47 | } 48 | 49 | if (!File.Exists(projectPath)) 50 | { 51 | throw new FileNotFoundException(Resources.FormatError_ProjectPath_NotFound(projectPath)); 52 | } 53 | 54 | return projectPath; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/OutputCapture.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.DotNet.Watcher.Internal 7 | { 8 | public class OutputCapture 9 | { 10 | private readonly List _lines = new List(); 11 | public IEnumerable Lines => _lines; 12 | public void AddLine(string line) => _lines.Add(line); 13 | } 14 | } -------------------------------------------------------------------------------- /src/dotnet-watch/Internal/OutputSink.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.DotNet.Watcher.Internal 5 | { 6 | public class OutputSink 7 | { 8 | public OutputCapture Current { get; private set; } 9 | public OutputCapture StartCapture() 10 | { 11 | return (Current = new OutputCapture()); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/dotnet-watch/PrefixConsoleReporter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using Microsoft.Extensions.Tools.Internal; 7 | 8 | namespace Microsoft.DotNet.Watcher 9 | { 10 | public class PrefixConsoleReporter : ConsoleReporter 11 | { 12 | private object _lock = new object(); 13 | 14 | public PrefixConsoleReporter(IConsole console, bool verbose, bool quiet) 15 | : base(console, verbose, quiet) 16 | { } 17 | 18 | protected override void WriteLine(TextWriter writer, string message, ConsoleColor? color) 19 | { 20 | const string prefix = "watch : "; 21 | 22 | lock (_lock) 23 | { 24 | Console.ForegroundColor = ConsoleColor.DarkGray; 25 | writer.Write(prefix); 26 | Console.ResetColor(); 27 | 28 | base.WriteLine(writer, message, color); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/dotnet-watch/ProcessSpec.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using Microsoft.DotNet.Watcher.Internal; 7 | 8 | namespace Microsoft.DotNet.Watcher 9 | { 10 | public class ProcessSpec 11 | { 12 | public string Executable { get; set; } 13 | public string WorkingDirectory { get; set; } 14 | public IDictionary EnvironmentVariables { get; } = new Dictionary(); 15 | public IEnumerable Arguments { get; set; } 16 | public OutputCapture OutputCapture { get; set; } 17 | 18 | public string ShortDisplayName() 19 | => Path.GetFileNameWithoutExtension(Executable); 20 | 21 | public bool IsOutputCaptured => OutputCapture != null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/dotnet-watch/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("Microsoft.DotNet.Watcher.Tools.Tests, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] 7 | -------------------------------------------------------------------------------- /src/dotnet-watch/assets/DotNetWatch.targets: -------------------------------------------------------------------------------- 1 | 2 | 10 | 12 | 15 | 16 | 17 | 25 | 26 | <_CollectWatchItemsDependsOn Condition=" '$(TargetFrameworks)' != '' AND '$(TargetFramework)' == '' "> 27 | _CollectWatchItemsPerFramework; 28 | 29 | <_CollectWatchItemsDependsOn Condition=" '$(TargetFramework)' != '' "> 30 | _CoreCollectWatchItems; 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | <_TargetFramework Include="$(TargetFrameworks)" /> 39 | 40 | 41 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | <_WatchProjects Include="%(ProjectReference.Identity)" Condition="'%(ProjectReference.Watch)' != 'false'" /> 59 | 60 | 61 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/dotnet-watch/dotnet-watch.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | exe 6 | Command line tool to watch for source file changes during development and restart the dotnet command. 7 | Microsoft.DotNet.Watcher.Tools 8 | dotnet;watch 9 | true 10 | 11 | win-x64;win-x86 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/Microsoft.HttpRepl.Tests/JsonVisitorTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.HttpRepl.Formatting; 2 | using Microsoft.HttpRepl.Preferences; 3 | using Microsoft.Repl.ConsoleHandling; 4 | using Xunit; 5 | 6 | namespace Microsoft.HttpRepl.Tests 7 | { 8 | public class JsonVisitorTests 9 | { 10 | [Fact] 11 | public void JsonVisitor_ObjectWithComments() 12 | { 13 | string testData = @"[ 14 | { 15 | //Object 1 16 | ""property"": ""value"", 17 | ""and"": ""again"" 18 | }, 19 | { 20 | //Object 2 21 | }, 22 | [ 23 | //An array 24 | ], 25 | null, 26 | 1, 27 | 3.2, 28 | ""test"", 29 | false 30 | ]"; 31 | 32 | string formatted = JsonVisitor.FormatAndColorize(new MockJsonConfig(), testData); 33 | } 34 | 35 | private class MockJsonConfig : IJsonConfig 36 | { 37 | public int IndentSize => 2; 38 | 39 | public AllowedColors DefaultColor => AllowedColors.None; 40 | 41 | public AllowedColors ArrayBraceColor => AllowedColors.None; 42 | 43 | public AllowedColors ObjectBraceColor => AllowedColors.None; 44 | 45 | public AllowedColors CommaColor => AllowedColors.None; 46 | 47 | public AllowedColors NameColor => AllowedColors.None; 48 | 49 | public AllowedColors NameSeparatorColor => AllowedColors.None; 50 | 51 | public AllowedColors BoolColor => AllowedColors.None; 52 | 53 | public AllowedColors NumericColor => AllowedColors.None; 54 | 55 | public AllowedColors StringColor => AllowedColors.None; 56 | 57 | public AllowedColors NullColor => AllowedColors.None; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/Microsoft.HttpRepl.Tests/Microsoft.HttpRepl.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/Microsoft.Repl.Tests/Microsoft.Repl.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/Microsoft.Repl.Tests/ParserTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Repl.Parsing; 2 | using Xunit; 3 | 4 | namespace Microsoft.Repl.Tests 5 | { 6 | public class ParserTests 7 | { 8 | [Fact] 9 | public void ParserTests_Basic() 10 | { 11 | string testString = "\"this is a test\" of \"Escape\\\\Sequences\\\"\""; 12 | 13 | CoreParser parser = new CoreParser(); 14 | ICoreParseResult result = parser.Parse(testString, 29); 15 | 16 | Assert.Equal(3, result.Sections.Count); 17 | Assert.Equal(2, result.SelectedSection); 18 | Assert.Equal(0, result.SectionStartLookup[0]); 19 | Assert.Equal(17, result.SectionStartLookup[1]); 20 | Assert.Equal(20, result.SectionStartLookup[2]); 21 | Assert.Equal(7, result.CaretPositionWithinSelectedSection); 22 | Assert.Equal(29, result.CaretPositionWithinCommandText); 23 | Assert.Equal(testString, result.CommandText); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Shared/TestReporter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Xunit.Abstractions; 5 | 6 | namespace Microsoft.Extensions.Tools.Internal 7 | { 8 | public class TestReporter : IReporter 9 | { 10 | private readonly ITestOutputHelper _output; 11 | 12 | public TestReporter(ITestOutputHelper output) 13 | { 14 | _output = output; 15 | } 16 | 17 | public void Verbose(string message) 18 | { 19 | _output.WriteLine("verbose: " + message); 20 | } 21 | 22 | public void Output(string message) 23 | { 24 | _output.WriteLine("output: " + message); 25 | } 26 | 27 | public void Warn(string message) 28 | { 29 | _output.WriteLine("warn: " + message); 30 | } 31 | 32 | public void Error(string message) 33 | { 34 | _output.WriteLine("error: " + message); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /test/dotnet-user-secrets.Tests/MsBuildProjectFinderTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using Microsoft.Extensions.SecretManager.Tools.Internal; 6 | using Xunit; 7 | 8 | namespace Microsoft.Extensions.SecretManager.Tools.Tests 9 | { 10 | public class MsBuildProjectFinderTest 11 | { 12 | [Theory] 13 | [InlineData(".csproj")] 14 | [InlineData(".vbproj")] 15 | [InlineData(".fsproj")] 16 | public void FindsSingleProject(string extension) 17 | { 18 | using (var files = new TemporaryFileProvider()) 19 | { 20 | var filename = "TestProject" + extension; 21 | files.Add(filename, ""); 22 | 23 | var finder = new MsBuildProjectFinder(files.Root); 24 | 25 | Assert.Equal(Path.Combine(files.Root, filename), finder.FindMsBuildProject(null)); 26 | } 27 | } 28 | 29 | [Fact] 30 | public void ThrowsWhenNoFile() 31 | { 32 | using (var files = new TemporaryFileProvider()) 33 | { 34 | var finder = new MsBuildProjectFinder(files.Root); 35 | 36 | Assert.Throws(() => finder.FindMsBuildProject(null)); 37 | } 38 | } 39 | 40 | [Fact] 41 | public void DoesNotMatchXproj() 42 | { 43 | using (var files = new TemporaryFileProvider()) 44 | { 45 | var finder = new MsBuildProjectFinder(files.Root); 46 | files.Add("test.xproj", ""); 47 | 48 | Assert.Throws(() => finder.FindMsBuildProject(null)); 49 | } 50 | } 51 | 52 | [Fact] 53 | public void ThrowsWhenMultipleFile() 54 | { 55 | using (var files = new TemporaryFileProvider()) 56 | { 57 | files.Add("Test1.csproj", ""); 58 | files.Add("Test2.csproj", ""); 59 | var finder = new MsBuildProjectFinder(files.Root); 60 | 61 | Assert.Throws(() => finder.FindMsBuildProject(null)); 62 | } 63 | } 64 | 65 | [Fact] 66 | public void ThrowsWhenFileDoesNotExist() 67 | { 68 | using (var files = new TemporaryFileProvider()) 69 | { 70 | var finder = new MsBuildProjectFinder(files.Root); 71 | 72 | Assert.Throws(() => finder.FindMsBuildProject("test.csproj")); 73 | } 74 | } 75 | 76 | [Fact] 77 | public void ThrowsWhenRootDoesNotExist() 78 | { 79 | var files = new TemporaryFileProvider(); 80 | var finder = new MsBuildProjectFinder(files.Root); 81 | files.Dispose(); 82 | Assert.Throws(() => finder.FindMsBuildProject(null)); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test/dotnet-user-secrets.Tests/TemporaryFileProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace Microsoft.Extensions.SecretManager.Tools.Tests 9 | { 10 | internal class TemporaryFileProvider : IDisposable 11 | { 12 | public TemporaryFileProvider() 13 | { 14 | Root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "tmpfiles", Guid.NewGuid().ToString())).FullName; 15 | } 16 | 17 | public string Root { get; } 18 | 19 | public void Add(string filename, string contents) 20 | { 21 | File.WriteAllText(Path.Combine(Root, filename), contents, Encoding.UTF8); 22 | } 23 | 24 | public void Dispose() 25 | { 26 | Directory.Delete(Root, recursive: true); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/dotnet-user-secrets.Tests/dotnet-user-secrets.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | Microsoft.Extensions.SecretManager.Tools.Tests 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/AppWithDepsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Testing; 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests 12 | { 13 | public class AppWithDepsTests : IDisposable 14 | { 15 | private readonly AppWithDeps _app; 16 | 17 | public AppWithDepsTests(ITestOutputHelper logger) 18 | { 19 | _app = new AppWithDeps(logger); 20 | } 21 | 22 | [Fact] 23 | public async Task ChangeFileInDependency() 24 | { 25 | await _app.StartWatcherAsync(); 26 | 27 | var fileToChange = Path.Combine(_app.DependencyFolder, "Foo.cs"); 28 | var programCs = File.ReadAllText(fileToChange); 29 | File.WriteAllText(fileToChange, programCs); 30 | 31 | await _app.HasRestarted(); 32 | } 33 | 34 | public void Dispose() 35 | { 36 | _app.Dispose(); 37 | } 38 | 39 | private class AppWithDeps : WatchableApp 40 | { 41 | private const string Dependency = "Dependency"; 42 | 43 | public AppWithDeps(ITestOutputHelper logger) 44 | : base("AppWithDeps", logger) 45 | { 46 | Scenario.AddTestProjectFolder(Dependency); 47 | 48 | DependencyFolder = Path.Combine(Scenario.WorkFolder, Dependency); 49 | } 50 | 51 | public string DependencyFolder { get; private set; } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/NoDepsAppTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests 12 | { 13 | public class NoDepsAppTests : IDisposable 14 | { 15 | private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); 16 | 17 | private readonly WatchableApp _app; 18 | private readonly ITestOutputHelper _output; 19 | 20 | public NoDepsAppTests(ITestOutputHelper logger) 21 | { 22 | _app = new WatchableApp("NoDepsApp", logger); 23 | _output = logger; 24 | } 25 | 26 | [Fact] 27 | public async Task RestartProcessOnFileChange() 28 | { 29 | await _app.StartWatcherAsync(new[] { "--no-exit" }); 30 | var processIdentifier = await _app.GetProcessIdentifier(); 31 | 32 | // Then wait for it to restart when we change a file 33 | var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs"); 34 | var programCs = File.ReadAllText(fileToChange); 35 | File.WriteAllText(fileToChange, programCs); 36 | 37 | await _app.HasRestarted(); 38 | Assert.DoesNotContain(_app.Process.Output, l => l.StartsWith("Exited with error code")); 39 | 40 | var processIdentifier2 = await _app.GetProcessIdentifier(); 41 | Assert.NotEqual(processIdentifier, processIdentifier2); 42 | } 43 | 44 | [Fact] 45 | public async Task RestartProcessThatTerminatesAfterFileChange() 46 | { 47 | await _app.StartWatcherAsync(); 48 | var processIdentifier = await _app.GetProcessIdentifier(); 49 | await _app.HasExited(); // process should exit after run 50 | await _app.IsWaitingForFileChange(); 51 | 52 | var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs"); 53 | 54 | try 55 | { 56 | File.SetLastWriteTime(fileToChange, DateTime.Now); 57 | await _app.HasRestarted(); 58 | } 59 | catch 60 | { 61 | // retry 62 | File.SetLastWriteTime(fileToChange, DateTime.Now); 63 | await _app.HasRestarted(); 64 | } 65 | 66 | var processIdentifier2 = await _app.GetProcessIdentifier(); 67 | Assert.NotEqual(processIdentifier, processIdentifier2); 68 | await _app.HasExited(); // process should exit after run 69 | } 70 | 71 | public void Dispose() 72 | { 73 | _app.Dispose(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/AppWithDeps/AppWithDeps.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | exe 6 | true 7 | 8 | 9 | 99.9 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/AppWithDeps/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | using System.Threading; 7 | 8 | namespace ConsoleApplication 9 | { 10 | public class Program 11 | { 12 | private static readonly int processId = Process.GetCurrentProcess().Id; 13 | 14 | public static void Main(string[] args) 15 | { 16 | Console.WriteLine("Started"); 17 | // Process ID is insufficient because PID's may be reused. 18 | Console.WriteLine($"Process identifier = {Process.GetCurrentProcess().Id}, {Process.GetCurrentProcess().StartTime:hh:mm:ss.FF}"); 19 | Thread.Sleep(Timeout.Infinite); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/Dependency/Dependency.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | true 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/Dependency/Foo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Dependency 5 | { 6 | public class Foo 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/GlobbingApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | exe 6 | false 7 | true 8 | 9 | 10 | 99.9 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Threading; 9 | 10 | namespace ConsoleApplication 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | Console.WriteLine("Started"); 17 | // Process ID is insufficient because PID's may be reused. 18 | Console.WriteLine($"Process identifier = {Process.GetCurrentProcess().Id}, {Process.GetCurrentProcess().StartTime:hh:mm:ss.FF}"); 19 | Console.WriteLine("Defined types = " + typeof(Program).GetTypeInfo().Assembly.DefinedTypes.Count()); 20 | Thread.Sleep(Timeout.Infinite); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/exclude/Baz.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace GlobbingApp.exclude 5 | { 6 | public class Baz 7 | { 8 | "THIS FILE SHOULD NOT BE INCLUDED IN COMPILATION" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/include/Foo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace GlobbingApp.include 5 | { 6 | public class Foo 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/KitchenSink/KitchenSink.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | .net/obj 5 | .net/bin 6 | 7 | 8 | 9 | 10 | 11 | Exe 12 | netcoreapp3.0 13 | true 14 | 15 | 16 | 99.9 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/KitchenSink/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | 7 | namespace KitchenSink 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Console.WriteLine("Started"); 14 | // Process ID is insufficient because PID's may be reused. 15 | Console.WriteLine($"Process identifier = {Process.GetCurrentProcess().Id}, {Process.GetCurrentProcess().StartTime:hh:mm:ss.FF}"); 16 | Console.WriteLine("DOTNET_WATCH = " + Environment.GetEnvironmentVariable("DOTNET_WATCH")); 17 | Console.WriteLine("DOTNET_WATCH_ITERATION = " + Environment.GetEnvironmentVariable("DOTNET_WATCH_ITERATION")); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/NoDepsApp/NoDepsApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | exe 6 | true 7 | 8 | 9 | 99.9 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/TestProjects/NoDepsApp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | using System.Threading; 7 | 8 | namespace ConsoleApplication 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | Console.WriteLine("Started"); 15 | // Process ID is insufficient because PID's may be reused. 16 | Console.WriteLine($"Process identifier = {Process.GetCurrentProcess().Id}, {Process.GetCurrentProcess().StartTime:hh:mm:ss.FF}"); 17 | if (args.Length > 0 && args[0] == "--no-exit") 18 | { 19 | Thread.Sleep(Timeout.Infinite); 20 | } 21 | Console.WriteLine("Exiting"); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/dotnet-watch.FunctionalTests/dotnet-watch.FunctionalTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | $(DefaultItemExcludes);TestProjects\**\* 6 | Microsoft.DotNet.Watcher.Tools.FunctionalTests 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | <_Parameter1>TestSettings:RestoreSources 27 | <_Parameter2>$(RestoreSources) 28 | 29 | 30 | <_Parameter1>TestSettings:RuntimeFrameworkVersion 31 | <_Parameter2>$(RuntimeFrameworkVersion) 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /test/dotnet-watch.Tests/AssertEx.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using Xunit; 9 | using Xunit.Sdk; 10 | 11 | namespace Microsoft.DotNet.Watcher.Tools.Tests 12 | { 13 | public static class AssertEx 14 | { 15 | public static void EqualFileList(string root, IEnumerable expectedFiles, IEnumerable actualFiles) 16 | { 17 | var expected = expectedFiles.Select(p => Path.Combine(root, p)); 18 | EqualFileList(expected, actualFiles); 19 | } 20 | 21 | public static void EqualFileList(IEnumerable expectedFiles, IEnumerable actualFiles) 22 | { 23 | string normalize(string p) => p.Replace('\\', '/'); 24 | var expected = new HashSet(expectedFiles.Select(normalize)); 25 | var actual = new HashSet(actualFiles.Where(p => !string.IsNullOrEmpty(p)).Select(normalize)); 26 | if (!expected.SetEquals(actual)) 27 | { 28 | throw new AssertActualExpectedException( 29 | expected: "\n" + string.Join("\n", expected), 30 | actual: "\n" + string.Join("\n", actual), 31 | userMessage: "File sets should be equal"); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/dotnet-watch.Tests/CommandLineOptionsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using Microsoft.Extensions.CommandLineUtils; 8 | using Microsoft.Extensions.Tools.Internal; 9 | using Xunit; 10 | using Xunit.Abstractions; 11 | 12 | namespace Microsoft.DotNet.Watcher.Tools.Tests 13 | { 14 | public class CommandLineOptionsTests 15 | { 16 | private readonly IConsole _console; 17 | private readonly StringBuilder _stdout = new StringBuilder(); 18 | 19 | public CommandLineOptionsTests(ITestOutputHelper output) 20 | { 21 | _console = new TestConsole(output) 22 | { 23 | Out = new StringWriter(_stdout), 24 | }; 25 | } 26 | 27 | [Theory] 28 | [InlineData(new object[] { new[] { "-h" } })] 29 | [InlineData(new object[] { new[] { "-?" } })] 30 | [InlineData(new object[] { new[] { "--help" } })] 31 | [InlineData(new object[] { new[] { "--help", "--bogus" } })] 32 | [InlineData(new object[] { new[] { "--" } })] 33 | [InlineData(new object[] { new string[0] })] 34 | public void HelpArgs(string[] args) 35 | { 36 | var options = CommandLineOptions.Parse(args, _console); 37 | 38 | Assert.True(options.IsHelp); 39 | Assert.Contains("Usage: dotnet watch ", _stdout.ToString()); 40 | } 41 | 42 | [Theory] 43 | [InlineData(new[] { "run" }, new[] { "run" })] 44 | [InlineData(new[] { "run", "--", "subarg" }, new[] { "run", "--", "subarg" })] 45 | [InlineData(new[] { "--", "run", "--", "subarg" }, new[] { "run", "--", "subarg" })] 46 | [InlineData(new[] { "--unrecognized-arg" }, new[] { "--unrecognized-arg" })] 47 | public void ParsesRemainingArgs(string[] args, string[] expected) 48 | { 49 | var options = CommandLineOptions.Parse(args, _console); 50 | 51 | Assert.Equal(expected, options.RemainingArguments.ToArray()); 52 | Assert.False(options.IsHelp); 53 | Assert.Empty(_stdout.ToString()); 54 | } 55 | 56 | [Fact] 57 | public void CannotHaveQuietAndVerbose() 58 | { 59 | var ex = Assert.Throws(() => CommandLineOptions.Parse(new[] { "--quiet", "--verbose" }, _console)); 60 | Assert.Equal(Resources.Error_QuietAndVerboseSpecified, ex.Message); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/dotnet-watch.Tests/ConsoleReporterTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Text; 7 | using Microsoft.Extensions.Tools.Internal; 8 | using Xunit; 9 | 10 | namespace Microsoft.Extensions.Tools.Tests 11 | { 12 | public class ReporterTests 13 | { 14 | private static readonly string EOL = Environment.NewLine; 15 | 16 | [Fact] 17 | public void WritesToStandardStreams() 18 | { 19 | var testConsole = new TestConsole(); 20 | var reporter = new ConsoleReporter(testConsole, verbose: true, quiet: false); 21 | 22 | // stdout 23 | reporter.Verbose("verbose"); 24 | Assert.Equal("verbose" + EOL, testConsole.GetOutput()); 25 | testConsole.Clear(); 26 | 27 | reporter.Output("out"); 28 | Assert.Equal("out" + EOL, testConsole.GetOutput()); 29 | testConsole.Clear(); 30 | 31 | reporter.Warn("warn"); 32 | Assert.Equal("warn" + EOL, testConsole.GetOutput()); 33 | testConsole.Clear(); 34 | 35 | // stderr 36 | reporter.Error("error"); 37 | Assert.Equal("error" + EOL, testConsole.GetError()); 38 | testConsole.Clear(); 39 | } 40 | 41 | private class TestConsole : IConsole 42 | { 43 | private readonly StringBuilder _out; 44 | private readonly StringBuilder _error; 45 | 46 | public TestConsole() 47 | { 48 | _out = new StringBuilder(); 49 | _error = new StringBuilder(); 50 | Out = new StringWriter(_out); 51 | Error = new StringWriter(_error); 52 | } 53 | 54 | event ConsoleCancelEventHandler IConsole.CancelKeyPress 55 | { 56 | add { } 57 | remove { } 58 | } 59 | 60 | public string GetOutput() => _out.ToString(); 61 | public string GetError() => _error.ToString(); 62 | 63 | public void Clear() 64 | { 65 | _out.Clear(); 66 | _error.Clear(); 67 | } 68 | 69 | public void ResetColor() 70 | { 71 | ForegroundColor = default(ConsoleColor); 72 | } 73 | 74 | public TextWriter Out { get; } 75 | public TextWriter Error { get; } 76 | public TextReader In { get; } 77 | public bool IsInputRedirected { get; } 78 | public bool IsOutputRedirected { get; } 79 | public bool IsErrorRedirected { get; } 80 | public ConsoleColor ForegroundColor { get; set; } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /test/dotnet-watch.Tests/ProgramTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Microsoft.AspNetCore.Testing; 9 | using Microsoft.Extensions.Tools.Internal; 10 | using Xunit; 11 | using Xunit.Abstractions; 12 | 13 | namespace Microsoft.DotNet.Watcher.Tools.Tests 14 | { 15 | public class ProgramTests : IDisposable 16 | { 17 | private readonly TemporaryDirectory _tempDir; 18 | private readonly TestConsole _console; 19 | 20 | public ProgramTests(ITestOutputHelper output) 21 | { 22 | _tempDir = new TemporaryDirectory(); 23 | _console = new TestConsole(output); 24 | } 25 | 26 | [Fact] 27 | public async Task ConsoleCancelKey() 28 | { 29 | _tempDir 30 | .WithCSharpProject("testproj") 31 | .WithTargetFrameworks("netcoreapp3.0") 32 | .Dir() 33 | .WithFile("Program.cs") 34 | .Create(); 35 | 36 | var output = new StringBuilder(); 37 | _console.Error = _console.Out = new StringWriter(output); 38 | using (var app = new Program(_console, _tempDir.Root)) 39 | { 40 | var run = app.RunAsync(new[] { "run" }); 41 | 42 | await _console.CancelKeyPressSubscribed.TimeoutAfter(TimeSpan.FromSeconds(30)); 43 | _console.ConsoleCancelKey(); 44 | 45 | var exitCode = await run.TimeoutAfter(TimeSpan.FromSeconds(30)); 46 | 47 | Assert.Contains("Shutdown requested. Press Ctrl+C again to force exit.", output.ToString()); 48 | Assert.Equal(0, exitCode); 49 | } 50 | } 51 | 52 | public void Dispose() 53 | { 54 | _tempDir.Dispose(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/dotnet-watch.Tests/Utilities/TestProjectGraph.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.DotNet.Watcher.Tools.Tests 8 | { 9 | public class TestProjectGraph 10 | { 11 | private readonly TemporaryDirectory _directory; 12 | private Action _onCreate; 13 | private Dictionary _projects = new Dictionary(); 14 | public TestProjectGraph(TemporaryDirectory directory) 15 | { 16 | _directory = directory; 17 | } 18 | 19 | public void OnCreate(Action onCreate) 20 | { 21 | _onCreate = onCreate; 22 | } 23 | 24 | public TemporaryCSharpProject Find(string projectName) 25 | => _projects.ContainsKey(projectName) 26 | ? _projects[projectName] 27 | : null; 28 | 29 | public TemporaryCSharpProject GetOrCreate(string projectName) 30 | { 31 | TemporaryCSharpProject sourceProj; 32 | if (!_projects.TryGetValue(projectName, out sourceProj)) 33 | { 34 | sourceProj = _directory.SubDir(projectName).WithCSharpProject(projectName); 35 | _onCreate?.Invoke(sourceProj); 36 | _projects.Add(projectName, sourceProj); 37 | } 38 | return sourceProj; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/dotnet-watch.Tests/dotnet-watch.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | Microsoft.DotNet.Watcher.Tools.Tests 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/DotNetTools/da47b81a162ae6c9e3787752adb8bcd4a6c1cbe1/tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Key.snk -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/NotifyPropertyChanged.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.ComponentModel; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace Microsoft.VisualStudio.SecretManager.TestExtension 8 | { 9 | public abstract class NotifyPropertyChanged : INotifyPropertyChanged 10 | { 11 | public event PropertyChangedEventHandler PropertyChanged; 12 | 13 | protected void OnPropertyChanged([CallerMemberName] string propertyName = null) 14 | { 15 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/ProjectViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using Microsoft.VisualStudio.ProjectSystem; 6 | 7 | namespace Microsoft.VisualStudio.SecretManager.TestExtension 8 | { 9 | public class ProjectViewModel : NotifyPropertyChanged 10 | { 11 | public ProjectViewModel(UnconfiguredProject project) 12 | { 13 | Project = project; 14 | } 15 | 16 | internal UnconfiguredProject Project { get; } 17 | 18 | public string ProjectName => Path.GetFileNameWithoutExtension(Project.FullPath); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.VisualStudio.SecretManager.TestExtension")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Microsoft.VisualStudio.SecretManager.TestExtension")] 13 | [assembly: AssemblyCopyright("")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // Version information for an assembly consists of the following four values: 23 | // 24 | // Major Version 25 | // Minor Version 26 | // Build Number 27 | // Revision 28 | // 29 | // You can specify all the values or you can default the Build and Revision Numbers 30 | // by using the '*' as shown below: 31 | // [assembly: AssemblyVersion("1.0.*")] 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Windows.Input; 6 | 7 | namespace Microsoft.VisualStudio.SecretManager.TestExtension 8 | { 9 | public class RelayCommand : ICommand 10 | { 11 | readonly Action _execute = null; 12 | readonly Predicate _canExecute = null; 13 | 14 | public RelayCommand(Action execute) 15 | : this(execute, null) 16 | { 17 | } 18 | 19 | public RelayCommand(Action execute, Predicate canExecute) 20 | { 21 | if (execute == null) 22 | throw new ArgumentNullException("execute"); 23 | 24 | _execute = execute; 25 | _canExecute = canExecute; 26 | } 27 | 28 | public bool CanExecute(object parameter) 29 | { 30 | return _canExecute == null ? true : _canExecute((T)parameter); 31 | } 32 | 33 | public event EventHandler CanExecuteChanged 34 | { 35 | add { CommandManager.RequerySuggested += value; } 36 | remove { CommandManager.RequerySuggested -= value; } 37 | } 38 | 39 | public void Execute(object parameter) 40 | { 41 | _execute((T)parameter); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Resources/SecretManagerTestCommand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/DotNetTools/da47b81a162ae6c9e3787752adb8bcd4a6c1cbe1/tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Resources/SecretManagerTestCommand.png -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Resources/SecretManagerTestPackage.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/DotNetTools/da47b81a162ae6c9e3787752adb8bcd4a6c1cbe1/tooling/Microsoft.VisualStudio.SecretManager.TestExtension/Resources/SecretManagerTestPackage.ico -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/SecretManagerTestControl.xaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 16 | 18 | 20 | 21 | 22 | 24 | 26 | 28 | 30 | 31 | 32 | 36 | 38 | 39 | 87 | 88 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/SecretManagerTestControl.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.VisualStudio.SecretManager.TestExtension 5 | { 6 | using System.Diagnostics.CodeAnalysis; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | 10 | /// 11 | /// Interaction logic for SecretManagerTestControl. 12 | /// 13 | public partial class SecretManagerTestControl : UserControl 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public SecretManagerTestControl() 19 | { 20 | this.InitializeComponent(); 21 | } 22 | 23 | /// 24 | /// Handles click on the button by displaying a message box. 25 | /// 26 | /// The event sender. 27 | /// The event args. 28 | [SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions", Justification = "Sample code")] 29 | [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Default event handler naming pattern")] 30 | private void button1_Click(object sender, RoutedEventArgs e) 31 | { 32 | MessageBox.Show( 33 | string.Format(System.Globalization.CultureInfo.CurrentUICulture, "Invoked '{0}'", this.ToString()), 34 | "SecretManagerTest"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/SecretManagerTestPackage.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Diagnostics.CodeAnalysis; 6 | using System.Runtime.InteropServices; 7 | using Microsoft.VisualStudio.Shell; 8 | 9 | namespace Microsoft.VisualStudio.SecretManager.TestExtension 10 | { 11 | [PackageRegistration(UseManagedResourcesOnly = true)] 12 | [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About 13 | [ProvideMenuResource("Menus.ctmenu", 1)] 14 | [ProvideToolWindow(typeof(SecretManagerTestWindow))] 15 | [Guid(SecretManagerTestPackage.PackageGuidString)] 16 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")] 17 | public sealed class SecretManagerTestPackage : Package 18 | { 19 | public const string PackageGuidString = "7b771e3e-f599-4fde-95a9-e35019e705f7"; 20 | 21 | protected override void Initialize() 22 | { 23 | SecretManagerTestCommand.Initialize(this); 24 | base.Initialize(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/SecretManagerTestWindow.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | using Microsoft.VisualStudio.ComponentModelHost; 7 | using Microsoft.VisualStudio.ProjectSystem; 8 | using Microsoft.VisualStudio.Shell; 9 | 10 | namespace Microsoft.VisualStudio.SecretManager.TestExtension 11 | { 12 | [Guid("6afffd63-17b6-4ef2-b515-fee22d767631")] 13 | public class SecretManagerTestWindow : ToolWindowPane 14 | { 15 | public SecretManagerTestWindow() 16 | : base(null) 17 | { 18 | this.Caption = "SecretManager Test Window"; 19 | this.Content = new SecretManagerTestControl(); 20 | } 21 | 22 | protected override void Initialize() 23 | { 24 | base.Initialize(); 25 | 26 | var component = (IComponentModel)GetService(typeof(SComponentModel)); 27 | var projectService = component.GetService().GetProjectService(); 28 | ((SecretManagerTestControl)Content).DataContext = new SecretManagerViewModel(projectService); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager.TestExtension/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Microsoft.VisualStudio.SecretManager.TestExtension 6 | A test extension for Microsoft.VisualStudio.TestExtension 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Reflection; 5 | using Microsoft.VisualStudio.Shell; 6 | 7 | // required for VS to generate the pkgdef 8 | [assembly: AssemblyVersion("1.0.0.0")] 9 | [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.VisualStudio.SecretManager.dll")] 10 | [assembly: ProvideBindingRedirection( 11 | AssemblyName = "Microsoft.VisualStudio.SecretManager", 12 | GenerateCodeBase = true, 13 | PublicKeyToken = "adb9793829ddae60", 14 | OldVersionLowerBound = "0.0.0.0", 15 | OldVersionUpperBound = "1.0.0.0", 16 | NewVersion = "1.0.0.0")] 17 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager/SecretManagerFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.ComponentModel.Composition; 6 | using Microsoft.VisualStudio.ProjectSystem; 7 | using Microsoft.VisualStudio.Shell; 8 | 9 | namespace Microsoft.VisualStudio.SecretManager 10 | { 11 | internal class SecretManagerFactory 12 | { 13 | // This is capability is set in Microsoft.Extensions.Configuration.UserSecrets 14 | private const string CapabilityName = "LocalUserSecrets"; 15 | 16 | private readonly Lazy _secretManager; 17 | private readonly UnconfiguredProject _project; 18 | 19 | [ImportingConstructor] 20 | public SecretManagerFactory(UnconfiguredProject project, SVsServiceProvider vsServiceProvider) 21 | { 22 | _project = project; 23 | 24 | var serviceProvider = new Lazy(() => vsServiceProvider); 25 | 26 | _secretManager = new Lazy(() => 27 | { 28 | var propertiesProvider = _project.Services.ActiveConfiguredProjectProvider.ActiveConfiguredProject.Services.ProjectPropertiesProvider; 29 | return new ProjectLocalSecretsManager(propertiesProvider, serviceProvider); 30 | }); 31 | } 32 | 33 | [ExportVsProfferedProjectService(typeof(SVsProjectLocalSecrets))] 34 | [AppliesTo(CapabilityName)] 35 | public SVsProjectLocalSecrets ProjectLocalSecretsManager => _secretManager.Value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager/Sources/PathHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using Microsoft.VisualStudio.SecretManager; 7 | 8 | namespace Microsoft.Extensions.Configuration.UserSecrets 9 | { 10 | /// 11 | /// Provides paths for user secrets configuration files. 12 | /// 13 | internal class PathHelper 14 | { 15 | internal const string SecretsFileName = "secrets.json"; 16 | 17 | /// 18 | /// 19 | /// Returns the path to the JSON file that stores user secrets. 20 | /// 21 | /// 22 | /// This uses the current user profile to locate the secrets file on disk in a location outside of source control. 23 | /// 24 | /// 25 | /// The user secret ID. 26 | /// The full path to the secret file. 27 | public static string GetSecretsPathFromSecretsId(string userSecretsId) 28 | { 29 | if (string.IsNullOrEmpty(userSecretsId)) 30 | { 31 | throw new ArgumentException(Resources.Common_StringNullOrEmpty, nameof(userSecretsId)); 32 | } 33 | 34 | var badCharIndex = userSecretsId.IndexOfAny(Path.GetInvalidFileNameChars()); 35 | if (badCharIndex != -1) 36 | { 37 | throw new InvalidOperationException( 38 | string.Format( 39 | Resources.Error_Invalid_Character_In_UserSecrets_Id, 40 | userSecretsId[badCharIndex], 41 | badCharIndex)); 42 | } 43 | 44 | var root = Environment.GetEnvironmentVariable("APPDATA") ?? // On Windows it goes to %APPDATA%\Microsoft\UserSecrets\ 45 | Environment.GetEnvironmentVariable("HOME"); // On Mac/Linux it goes to ~/.microsoft/usersecrets/ 46 | 47 | if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPDATA"))) 48 | { 49 | return Path.Combine(root, "Microsoft", "UserSecrets", userSecretsId, SecretsFileName); 50 | } 51 | else 52 | { 53 | return Path.Combine(root, ".microsoft", "usersecrets", userSecretsId, SecretsFileName); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tooling/Microsoft.VisualStudio.SecretManager/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ASP.NET Core User Secrets Extension 6 | Microsoft.VisualStudio.SecretManager 7 | Enables IVsProjectSecrets for ASP.NET Core projects that use Microsoft.Extensions.Configuration.UserSecrets. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /version.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 3.0.0 4 | 16.0 5 | alpha1 6 | $(VersionPrefix) 7 | $(VersionPrefix)-$(VersionSuffix)-final 8 | $(VsixVersion).$(BuildNumber) 9 | $(VsixVersion).999999 10 | t000 11 | a- 12 | $(FeatureBranchVersionPrefix)$(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) 13 | $(VersionSuffix)-$(BuildNumber) 14 | 15 | 16 | --------------------------------------------------------------------------------