├── .gitattributes
├── .github
└── workflows
│ └── dotnetcore.yml
├── .gitignore
├── LICENSE
├── PowerShellAsync.sln
├── PowerShellAsync
├── AsyncCmdlet.cs
├── PowerShellAsync.csproj
└── TTRider.PowerShellAsync.dll.nuspec
├── PowerShellAsyncExample
├── PowerShellAsyncExample.sln
└── PowerShellAsyncExample
│ ├── MultiSqlCmdlet.cs
│ ├── PowerShellAsyncExample.csproj
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── packages.config
├── UnitTests
├── AsyncCmdletTests.cs
├── Infrastructure
│ ├── PsCommandContext.cs
│ ├── TestPsHost.cs
│ ├── TestPsHostRawUserInterface.cs
│ └── TestPsHostUserInterface.cs
└── UnitTests.csproj
└── readme.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.github/workflows/dotnetcore.yml:
--------------------------------------------------------------------------------
1 | name: .NET Core
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 |
17 | # Setup .NET
18 | - name: Setup .NET Core
19 | uses: actions/setup-dotnet@v1
20 | with:
21 | dotnet-version: 3.1.101
22 |
23 | - name: Restore
24 | run: dotnet restore
25 |
26 | - name: Build with dotnet
27 | run: dotnet build --no-restore --configuration Release
28 |
29 | - name: Test
30 | run: dotnet test --no-restore --verbosity normal
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # =========================
18 | # Operating System Files
19 | # =========================
20 |
21 | # OSX
22 | # =========================
23 |
24 | .DS_Store
25 | .AppleDouble
26 | .LSOverride
27 |
28 | # Icon must end with two \r
29 | Icon
30 |
31 |
32 | # Thumbnails
33 | ._*
34 |
35 | # Files that might appear on external disk
36 | .Spotlight-V100
37 | .Trashes
38 |
39 | # Directories potentially created on remote AFP share
40 | .AppleDB
41 | .AppleDesktop
42 | Network Trash Folder
43 | Temporary Items
44 | .apdisk
45 | =======
46 | *.user
47 | /PowerShellAsync/bin/Debug
48 | /PowerShellAsync/obj/Debug
49 | /UnitTests/bin/Debug
50 | /UnitTests/obj/Debug
51 | *.suo
52 | /packages
53 | /MigrationBackup
54 |
55 | /TestResults
56 | /PowerShellAsyncExample/packages
57 | /PowerShellAsyncExample/PowerShellAsyncExample/bin/Debug
58 | /PowerShellAsyncExample/PowerShellAsyncExample/obj/Debug
59 |
60 | # Visual Studio 2015/2017 cache/options directory
61 | .vs/
62 | .vscode/
63 |
64 | # Build results
65 | [Dd]ebug/
66 | [Dd]ebugPublic/
67 | [Rr]elease/
68 | [Rr]eleases/
69 | x64/
70 | x86/
71 | bld/
72 | [Bb]in/
73 | [Oo]bj/
74 | [Ll]og/
75 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 ttrider
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/PowerShellAsync.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30021.99
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellAsync", "PowerShellAsync\PowerShellAsync.csproj", "{07698A5B-BB2B-40BE-88A8-63486216E6EC}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{C0C70598-5BD7-4D71-944B-7CC8D2DFDA17}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{15E3F177-5F88-4053-8591-2B25CED3DE35}"
11 | ProjectSection(SolutionItems) = preProject
12 | LICENSE = LICENSE
13 | readme.md = readme.md
14 | EndProjectSection
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Release|Any CPU = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {07698A5B-BB2B-40BE-88A8-63486216E6EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {07698A5B-BB2B-40BE-88A8-63486216E6EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {07698A5B-BB2B-40BE-88A8-63486216E6EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {07698A5B-BB2B-40BE-88A8-63486216E6EC}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {C0C70598-5BD7-4D71-944B-7CC8D2DFDA17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {C0C70598-5BD7-4D71-944B-7CC8D2DFDA17}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {C0C70598-5BD7-4D71-944B-7CC8D2DFDA17}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {C0C70598-5BD7-4D71-944B-7CC8D2DFDA17}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {7D6544FA-4938-4572-BEAA-B9326E3E361F}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/PowerShellAsync/AsyncCmdlet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Management.Automation;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 | //using JetBrains.Annotations;
7 |
8 | namespace TTRider.PowerShellAsync
9 | {
10 | ///
11 | /// Base class for async-enabled cmdlets
12 | ///
13 | public abstract class AsyncCmdlet : PSCmdlet
14 | {
15 | protected int BoundedCapacity { get; set; }
16 |
17 | protected AsyncCmdlet(int boundedCapacity = 50)
18 | {
19 | this.BoundedCapacity = Math.Max(1, boundedCapacity);
20 | }
21 |
22 | #region sealed overrides
23 | protected sealed override void BeginProcessing()
24 | {
25 | AsyncCmdletSynchronizationContext.Async(BeginProcessingAsync, BoundedCapacity);
26 | }
27 |
28 | protected sealed override void ProcessRecord()
29 | {
30 | AsyncCmdletSynchronizationContext.Async(ProcessRecordAsync, BoundedCapacity);
31 | }
32 |
33 | protected sealed override void EndProcessing()
34 | {
35 | AsyncCmdletSynchronizationContext.Async(EndProcessingAsync, BoundedCapacity);
36 | }
37 |
38 | protected sealed override void StopProcessing()
39 | {
40 | AsyncCmdletSynchronizationContext.Async(StopProcessingAsync, BoundedCapacity);
41 | }
42 |
43 | #endregion sealed overrides
44 |
45 | #region intercepted methods
46 | public new void WriteDebug(string text)
47 | {
48 | AsyncCmdletSynchronizationContext.PostItem(new MarshalItemAction(base.WriteDebug, text));
49 | }
50 |
51 | public new void WriteError(ErrorRecord errorRecord)
52 | {
53 | AsyncCmdletSynchronizationContext.PostItem(new MarshalItemAction(base.WriteError, errorRecord));
54 | }
55 |
56 | public new void WriteObject(object sendToPipeline)
57 | {
58 | AsyncCmdletSynchronizationContext.PostItem(new MarshalItemAction