├── .appveyor.yml
├── .gitattributes
├── .github
└── ISSUE_TEMPLATE.md
├── .gitignore
├── .travis.yml
├── .vsts-pipelines
└── builds
│ ├── ci-internal.yml
│ └── ci-public.yml
├── CONTRIBUTING.md
├── Directory.Build.props
├── Directory.Build.targets
├── EventNotification.sln
├── LICENSE.txt
├── NuGet.config
├── NuGetPackageVerifier.json
├── README.md
├── build.cmd
├── build.sh
├── build
├── Key.snk
├── dependencies.props
├── repo.props
└── sources.props
├── korebuild-lock.txt
├── korebuild.json
├── run.cmd
├── run.ps1
├── run.sh
├── src
├── Directory.Build.props
└── Microsoft.Extensions.DiagnosticAdapter
│ ├── DiagnosticListenerExtensions.cs
│ ├── DiagnosticNameAttribute.cs
│ ├── DiagnosticSourceAdapter.cs
│ ├── IDiagnosticSourceMethodAdapter.cs
│ ├── Infrastructure
│ ├── IProxy.cs
│ └── IProxyFactory.cs
│ ├── Internal
│ ├── InvalidProxyOperationException.cs
│ ├── ProxyAssembly.cs
│ ├── ProxyBase.cs
│ ├── ProxyBaseOfT.cs
│ ├── ProxyEnumerable.cs
│ ├── ProxyFactory.cs
│ ├── ProxyList.cs
│ ├── ProxyMethodEmitter.cs
│ ├── ProxyTypeCache.cs
│ ├── ProxyTypeCacheResult.cs
│ └── ProxyTypeEmitter.cs
│ ├── Microsoft.Extensions.DiagnosticAdapter.csproj
│ ├── Properties
│ ├── AssemblyInfo.cs
│ └── Resources.Designer.cs
│ ├── ProxyDiagnosticSourceMethodAdapter.cs
│ ├── Resources.resx
│ ├── baseline.net461.json
│ ├── baseline.netcore.json
│ ├── baseline.netframework.json
│ └── breakingchanges.netcore.json
├── test
├── Directory.Build.props
└── Microsoft.Extensions.DiagnosticAdapter.Test
│ ├── DiagnosticSourceAdapterTest.cs
│ ├── Internal
│ ├── ProxyFactoryTest.cs
│ └── ProxyTypeEmitterTest.cs
│ ├── Microsoft.Extensions.DiagnosticAdapter.Test.csproj
│ └── ProxyDiagnosticSourceMethodAdapterTest.cs
└── 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 |
--------------------------------------------------------------------------------
/.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
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | THIS ISSUE TRACKER IS CLOSED - please log new issues here: https://github.com/aspnet/Home/issues
2 |
3 | For information about this change, see https://github.com/aspnet/Announcements/issues/283
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Oo]bj/
2 | [Bb]in/
3 | TestResults/
4 | .nuget/
5 | .build/
6 | .testPublish/
7 | *.sln.ide/
8 | _ReSharper.*/
9 | packages/
10 | artifacts/
11 | PublishProfiles/
12 | .vs/
13 | bower_components/
14 | node_modules/
15 | debugSettings.json
16 | project.lock.json
17 | *.user
18 | *.suo
19 | *.cache
20 | *.docstates
21 | _ReSharper.*
22 | nuget.exe
23 | *net45.csproj
24 | *net451.csproj
25 | *k10.csproj
26 | *.psess
27 | *.vsp
28 | *.pidb
29 | *.userprefs
30 | *DS_Store
31 | *.ncrunchsolution
32 | *.*sdf
33 | *.ipch
34 | .settings
35 | *.sln.ide
36 | node_modules
37 | *launchSettings.json
38 | *.orig
39 | global.json
40 |
--------------------------------------------------------------------------------
/.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 ASP.NET Core
12 | https://github.com/aspnet/eventnotification
13 | git
14 | $(MSBuildThisFileDirectory)
15 | $(MSBuildThisFileDirectory)build\Key.snk
16 | true
17 | true
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(MicrosoftNETCoreApp20PackageVersion)
4 | $(MicrosoftNETCoreApp21PackageVersion)
5 | $(MicrosoftNETCoreApp22PackageVersion)
6 | $(NETStandardLibrary20PackageVersion)
7 |
8 | 99.9
9 |
10 |
11 |
--------------------------------------------------------------------------------
/EventNotification.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 15
3 | VisualStudioVersion = 15.0.26815.3
4 | MinimumVisualStudioVersion = 15.0.26730.03
5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8B66E199-1AFE-4B68-AC71-4521C46EC4CD}"
6 | ProjectSection(SolutionItems) = preProject
7 | src\Directory.Build.props = src\Directory.Build.props
8 | EndProjectSection
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D75011A4-DEEE-48DE-BB83-CE042F2AC05B}"
11 | ProjectSection(SolutionItems) = preProject
12 | test\Directory.Build.props = test\Directory.Build.props
13 | EndProjectSection
14 | EndProject
15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.DiagnosticAdapter", "src\Microsoft.Extensions.DiagnosticAdapter\Microsoft.Extensions.DiagnosticAdapter.csproj", "{87808F3C-362E-4261-AA4A-EE40BA39D64E}"
16 | EndProject
17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.DiagnosticAdapter.Test", "test\Microsoft.Extensions.DiagnosticAdapter.Test\Microsoft.Extensions.DiagnosticAdapter.Test.csproj", "{02754747-C385-4662-AD58-49CE54C3D7AF}"
18 | EndProject
19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3000A721-AF6D-46D5-839C-60A2EC4A9693}"
20 | ProjectSection(SolutionItems) = preProject
21 | .appveyor.yml = .appveyor.yml
22 | .gitattributes = .gitattributes
23 | .gitignore = .gitignore
24 | .travis.yml = .travis.yml
25 | build.cmd = build.cmd
26 | build.ps1 = build.ps1
27 | build.sh = build.sh
28 | CONTRIBUTING.md = CONTRIBUTING.md
29 | Directory.Build.props = Directory.Build.props
30 | Directory.Build.targets = Directory.Build.targets
31 | LICENSE.txt = LICENSE.txt
32 | NuGet.config = NuGet.config
33 | NuGetPackageVerifier.json = NuGetPackageVerifier.json
34 | README.md = README.md
35 | version.xml = version.xml
36 | EndProjectSection
37 | EndProject
38 | Global
39 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
40 | Debug|Any CPU = Debug|Any CPU
41 | Release|Any CPU = Release|Any CPU
42 | EndGlobalSection
43 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
44 | {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {02754747-C385-4662-AD58-49CE54C3D7AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {02754747-C385-4662-AD58-49CE54C3D7AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {02754747-C385-4662-AD58-49CE54C3D7AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {02754747-C385-4662-AD58-49CE54C3D7AF}.Release|Any CPU.Build.0 = Release|Any CPU
52 | EndGlobalSection
53 | GlobalSection(SolutionProperties) = preSolution
54 | HideSolutionNode = FALSE
55 | EndGlobalSection
56 | GlobalSection(NestedProjects) = preSolution
57 | {87808F3C-362E-4261-AA4A-EE40BA39D64E} = {8B66E199-1AFE-4B68-AC71-4521C46EC4CD}
58 | {02754747-C385-4662-AD58-49CE54C3D7AF} = {D75011A4-DEEE-48DE-BB83-CE042F2AC05B}
59 | EndGlobalSection
60 | GlobalSection(ExtensibilityGlobals) = postSolution
61 | SolutionGuid = {AB0EDBB3-E00B-4334-A17A-054D3771E912}
62 | EndGlobalSection
63 | EndGlobal
64 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright (c) .NET Foundation and Contributors
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/NuGetPackageVerifier.json:
--------------------------------------------------------------------------------
1 | {
2 | "Default": {
3 | "rules": [
4 | "DefaultCompositeRule"
5 | ]
6 | }
7 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | EventNotification [Archived]
2 | ============================
3 |
4 | **This GitHub project has been archived.** Ongoing development on this project can be found in .
5 |
6 | Notice
7 | -------
8 |
9 | The infrastructure for publishing notifications has moved to the .NET Framework. See the new [`DiagnosticSource`](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSource.cs) and [`DiagnosticListener`](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs) APIs in the `System.Diagnostics.DiagnosticSource` package. The infrastructure provided here is for subscribing to events using runtime-generated proxies.
10 |
11 | This project is part of .NET Extensions. You can find samples, documentation and getting started instructions at the [Extensions](https://github.com/aspnet/Extensions) repo.
12 |
--------------------------------------------------------------------------------
/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/EventNotification/faf917b447af15d41b48ffacb7882377deae3caa/build/Key.snk
--------------------------------------------------------------------------------
/build/dependencies.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
4 |
5 |
6 | 3.0.0-alpha1-20180919.1
7 | 3.0.0-alpha1-10549
8 | 2.0.9
9 | 2.1.3
10 | 2.2.0-preview2-26905-02
11 | 15.6.1
12 | 2.0.3
13 | 4.6.0-preview1-26907-04
14 | 0.10.0
15 | 2.3.1
16 | 2.4.0
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/build/repo.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Internal.AspNetCore.Universe.Lineup
7 | https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/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 |
12 |
13 | $(RestoreSources);
14 | https://api.nuget.org/v3/index.json;
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/korebuild-lock.txt:
--------------------------------------------------------------------------------
1 | version:3.0.0-alpha1-20180919.1
2 | commithash:3066ae0a230870ea07e3f132605b5e5493f8bbd4
3 |
--------------------------------------------------------------------------------
/korebuild.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json",
3 | "channel": "master"
4 | }
5 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/run.ps1:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env powershell
2 | #requires -version 4
3 |
4 | <#
5 | .SYNOPSIS
6 | Executes KoreBuild commands.
7 |
8 | .DESCRIPTION
9 | Downloads korebuild if required. Then executes the KoreBuild command. To see available commands, execute with `-Command help`.
10 |
11 | .PARAMETER Command
12 | The KoreBuild command to run.
13 |
14 | .PARAMETER Path
15 | The folder to build. Defaults to the folder containing this script.
16 |
17 | .PARAMETER Channel
18 | The channel of KoreBuild to download. Overrides the value from the config file.
19 |
20 | .PARAMETER DotNetHome
21 | The directory where .NET Core tools will be stored.
22 |
23 | .PARAMETER ToolsSource
24 | The base url where build tools can be downloaded. Overrides the value from the config file.
25 |
26 | .PARAMETER Update
27 | Updates KoreBuild to the latest version even if a lock file is present.
28 |
29 | .PARAMETER Reinstall
30 | Re-installs KoreBuild
31 |
32 | .PARAMETER ConfigFile
33 | The path to the configuration file that stores values. Defaults to korebuild.json.
34 |
35 | .PARAMETER ToolsSourceSuffix
36 | The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores.
37 |
38 | .PARAMETER CI
39 | Sets up CI specific settings and variables.
40 |
41 | .PARAMETER Arguments
42 | Arguments to be passed to the command
43 |
44 | .NOTES
45 | This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be.
46 | When the lockfile is not present, KoreBuild will create one using latest available version from $Channel.
47 |
48 | The $ConfigFile is expected to be an JSON file. It is optional, and the configuration values in it are optional as well. Any options set
49 | in the file are overridden by command line parameters.
50 |
51 | .EXAMPLE
52 | Example config file:
53 | ```json
54 | {
55 | "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json",
56 | "channel": "master",
57 | "toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools"
58 | }
59 | ```
60 | #>
61 | [CmdletBinding(PositionalBinding = $false)]
62 | param(
63 | [Parameter(Mandatory = $true, Position = 0)]
64 | [string]$Command,
65 | [string]$Path = $PSScriptRoot,
66 | [Alias('c')]
67 | [string]$Channel,
68 | [Alias('d')]
69 | [string]$DotNetHome,
70 | [Alias('s')]
71 | [string]$ToolsSource,
72 | [Alias('u')]
73 | [switch]$Update,
74 | [switch]$Reinstall,
75 | [string]$ToolsSourceSuffix,
76 | [string]$ConfigFile = $null,
77 | [switch]$CI,
78 | [Parameter(ValueFromRemainingArguments = $true)]
79 | [string[]]$Arguments
80 | )
81 |
82 | Set-StrictMode -Version 2
83 | $ErrorActionPreference = 'Stop'
84 |
85 | #
86 | # Functions
87 | #
88 |
89 | function Get-KoreBuild {
90 |
91 | $lockFile = Join-Path $Path 'korebuild-lock.txt'
92 |
93 | if (!(Test-Path $lockFile) -or $Update) {
94 | Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile $ToolsSourceSuffix
95 | }
96 |
97 | $version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
98 | if (!$version) {
99 | Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'"
100 | }
101 | $version = $version.TrimStart('version:').Trim()
102 | $korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)
103 |
104 | if ($Reinstall -and (Test-Path $korebuildPath)) {
105 | Remove-Item -Force -Recurse $korebuildPath
106 | }
107 |
108 | if (!(Test-Path $korebuildPath)) {
109 | Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
110 | New-Item -ItemType Directory -Path $korebuildPath | Out-Null
111 | $remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip"
112 |
113 | try {
114 | $tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
115 | Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix
116 | if (Get-Command -Name 'Microsoft.PowerShell.Archive\Expand-Archive' -ErrorAction Ignore) {
117 | # Use built-in commands where possible as they are cross-plat compatible
118 | Microsoft.PowerShell.Archive\Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
119 | }
120 | else {
121 | # Fallback to old approach for old installations of PowerShell
122 | Add-Type -AssemblyName System.IO.Compression.FileSystem
123 | [System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath)
124 | }
125 | }
126 | catch {
127 | Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore
128 | throw
129 | }
130 | finally {
131 | Remove-Item $tmpfile -ErrorAction Ignore
132 | }
133 | }
134 |
135 | return $korebuildPath
136 | }
137 |
138 | function Join-Paths([string]$path, [string[]]$childPaths) {
139 | $childPaths | ForEach-Object { $path = Join-Path $path $_ }
140 | return $path
141 | }
142 |
143 | function Get-RemoteFile([string]$RemotePath, [string]$LocalPath, [string]$RemoteSuffix) {
144 | if ($RemotePath -notlike 'http*') {
145 | Copy-Item $RemotePath $LocalPath
146 | return
147 | }
148 |
149 | $retries = 10
150 | while ($retries -gt 0) {
151 | $retries -= 1
152 | try {
153 | Invoke-WebRequest -UseBasicParsing -Uri $($RemotePath + $RemoteSuffix) -OutFile $LocalPath
154 | return
155 | }
156 | catch {
157 | Write-Verbose "Request failed. $retries retries remaining"
158 | }
159 | }
160 |
161 | Write-Error "Download failed: '$RemotePath'."
162 | }
163 |
164 | #
165 | # Main
166 | #
167 |
168 | # Load configuration or set defaults
169 |
170 | $Path = Resolve-Path $Path
171 | if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' }
172 |
173 | if (Test-Path $ConfigFile) {
174 | try {
175 | $config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json
176 | if ($config) {
177 | if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
178 | if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
179 | }
180 | }
181 | catch {
182 | Write-Host -ForegroundColor Red $Error[0]
183 | Write-Error "$ConfigFile contains invalid JSON."
184 | exit 1
185 | }
186 | }
187 |
188 | if (!$DotNetHome) {
189 | $DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
190 | elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
191 | elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
192 | else { Join-Path $PSScriptRoot '.dotnet'}
193 | }
194 |
195 | if (!$Channel) { $Channel = 'master' }
196 | if (!$ToolsSource) { $ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools' }
197 |
198 | # Execute
199 |
200 | $korebuildPath = Get-KoreBuild
201 | Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
202 |
203 | try {
204 | Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile -CI:$CI
205 | Invoke-KoreBuildCommand $Command @Arguments
206 | }
207 | finally {
208 | Remove-Module 'KoreBuild' -ErrorAction Ignore
209 | }
210 |
--------------------------------------------------------------------------------
/run.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -euo pipefail
4 |
5 | #
6 | # variables
7 | #
8 |
9 | RESET="\033[0m"
10 | RED="\033[0;31m"
11 | YELLOW="\033[0;33m"
12 | MAGENTA="\033[0;95m"
13 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14 | [ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet"
15 | verbose=false
16 | update=false
17 | reinstall=false
18 | repo_path="$DIR"
19 | channel=''
20 | tools_source=''
21 | tools_source_suffix=''
22 | ci=false
23 |
24 | #
25 | # Functions
26 | #
27 | __usage() {
28 | echo "Usage: $(basename "${BASH_SOURCE[0]}") command [options] [[--] ...]"
29 | echo ""
30 | echo "Arguments:"
31 | echo " command The command to be run."
32 | echo " ... Arguments passed to the command. Variable number of arguments allowed."
33 | echo ""
34 | echo "Options:"
35 | echo " --verbose Show verbose output."
36 | echo " -c|--channel The channel of KoreBuild to download. Overrides the value from the config file.."
37 | echo " --config-file The path to the configuration file that stores values. Defaults to korebuild.json."
38 | echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
39 | echo " --path The directory to build. Defaults to the directory containing the script."
40 | echo " -s|--tools-source|-ToolsSource The base url where build tools can be downloaded. Overrides the value from the config file."
41 | echo " --tools-source-suffix|-ToolsSourceSuffix The suffix to append to tools-source. Useful for query strings."
42 | echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
43 | echo " --reinstall Reinstall KoreBuild."
44 | echo " --ci Apply CI specific settings and environment variables."
45 | echo ""
46 | echo "Description:"
47 | echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be."
48 | echo " When the lockfile is not present, KoreBuild will create one using latest available version from \$channel."
49 |
50 | if [[ "${1:-}" != '--no-exit' ]]; then
51 | exit 2
52 | fi
53 | }
54 |
55 | get_korebuild() {
56 | local version
57 | local lock_file="$repo_path/korebuild-lock.txt"
58 | if [ ! -f "$lock_file" ] || [ "$update" = true ]; then
59 | __get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" "$tools_source_suffix"
60 | fi
61 | version="$(grep 'version:*' -m 1 "$lock_file")"
62 | if [[ "$version" == '' ]]; then
63 | __error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'"
64 | return 1
65 | fi
66 | version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
67 | local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version"
68 |
69 | if [ "$reinstall" = true ] && [ -d "$korebuild_path" ]; then
70 | rm -rf "$korebuild_path"
71 | fi
72 |
73 | {
74 | if [ ! -d "$korebuild_path" ]; then
75 | mkdir -p "$korebuild_path"
76 | local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip"
77 | tmpfile="$(mktemp)"
78 | echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}"
79 | if __get_remote_file "$remote_path" "$tmpfile" "$tools_source_suffix"; then
80 | unzip -q -d "$korebuild_path" "$tmpfile"
81 | fi
82 | rm "$tmpfile" || true
83 | fi
84 |
85 | source "$korebuild_path/KoreBuild.sh"
86 | } || {
87 | if [ -d "$korebuild_path" ]; then
88 | echo "Cleaning up after failed installation"
89 | rm -rf "$korebuild_path" || true
90 | fi
91 | return 1
92 | }
93 | }
94 |
95 | __error() {
96 | echo -e "${RED}error: $*${RESET}" 1>&2
97 | }
98 |
99 | __warn() {
100 | echo -e "${YELLOW}warning: $*${RESET}"
101 | }
102 |
103 | __machine_has() {
104 | hash "$1" > /dev/null 2>&1
105 | return $?
106 | }
107 |
108 | __get_remote_file() {
109 | local remote_path=$1
110 | local local_path=$2
111 | local remote_path_suffix=$3
112 |
113 | if [[ "$remote_path" != 'http'* ]]; then
114 | cp "$remote_path" "$local_path"
115 | return 0
116 | fi
117 |
118 | local failed=false
119 | if __machine_has wget; then
120 | wget --tries 10 --quiet -O "$local_path" "${remote_path}${remote_path_suffix}" || failed=true
121 | else
122 | failed=true
123 | fi
124 |
125 | if [ "$failed" = true ] && __machine_has curl; then
126 | failed=false
127 | curl --retry 10 -sSL -f --create-dirs -o "$local_path" "${remote_path}${remote_path_suffix}" || failed=true
128 | fi
129 |
130 | if [ "$failed" = true ]; then
131 | __error "Download failed: $remote_path" 1>&2
132 | return 1
133 | fi
134 | }
135 |
136 | #
137 | # main
138 | #
139 |
140 | command="${1:-}"
141 | shift
142 |
143 | while [[ $# -gt 0 ]]; do
144 | case $1 in
145 | -\?|-h|--help)
146 | __usage --no-exit
147 | exit 0
148 | ;;
149 | -c|--channel|-Channel)
150 | shift
151 | channel="${1:-}"
152 | [ -z "$channel" ] && __usage
153 | ;;
154 | --config-file|-ConfigFile)
155 | shift
156 | config_file="${1:-}"
157 | [ -z "$config_file" ] && __usage
158 | if [ ! -f "$config_file" ]; then
159 | __error "Invalid value for --config-file. $config_file does not exist."
160 | exit 1
161 | fi
162 | ;;
163 | -d|--dotnet-home|-DotNetHome)
164 | shift
165 | DOTNET_HOME="${1:-}"
166 | [ -z "$DOTNET_HOME" ] && __usage
167 | ;;
168 | --path|-Path)
169 | shift
170 | repo_path="${1:-}"
171 | [ -z "$repo_path" ] && __usage
172 | ;;
173 | -s|--tools-source|-ToolsSource)
174 | shift
175 | tools_source="${1:-}"
176 | [ -z "$tools_source" ] && __usage
177 | ;;
178 | --tools-source-suffix|-ToolsSourceSuffix)
179 | shift
180 | tools_source_suffix="${1:-}"
181 | [ -z "$tools_source_suffix" ] && __usage
182 | ;;
183 | -u|--update|-Update)
184 | update=true
185 | ;;
186 | --reinstall|-[Rr]einstall)
187 | reinstall=true
188 | ;;
189 | --ci|-[Cc][Ii])
190 | ci=true
191 | ;;
192 | --verbose|-Verbose)
193 | verbose=true
194 | ;;
195 | --)
196 | shift
197 | break
198 | ;;
199 | *)
200 | break
201 | ;;
202 | esac
203 | shift
204 | done
205 |
206 | if ! __machine_has unzip; then
207 | __error 'Missing required command: unzip'
208 | exit 1
209 | fi
210 |
211 | if ! __machine_has curl && ! __machine_has wget; then
212 | __error 'Missing required command. Either wget or curl is required.'
213 | exit 1
214 | fi
215 |
216 | [ -z "${config_file:-}" ] && config_file="$repo_path/korebuild.json"
217 | if [ -f "$config_file" ]; then
218 | if __machine_has jq ; then
219 | if jq '.' "$config_file" >/dev/null ; then
220 | config_channel="$(jq -r 'select(.channel!=null) | .channel' "$config_file")"
221 | config_tools_source="$(jq -r 'select(.toolsSource!=null) | .toolsSource' "$config_file")"
222 | else
223 | __error "$config_file contains invalid JSON."
224 | exit 1
225 | fi
226 | elif __machine_has python ; then
227 | if python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then
228 | config_channel="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")"
229 | config_tools_source="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")"
230 | else
231 | __error "$config_file contains invalid JSON."
232 | exit 1
233 | fi
234 | elif __machine_has python3 ; then
235 | if python3 -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then
236 | config_channel="$(python3 -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")"
237 | config_tools_source="$(python3 -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")"
238 | else
239 | __error "$config_file contains invalid JSON."
240 | exit 1
241 | fi
242 | else
243 | __error 'Missing required command: jq or python. Could not parse the JSON file.'
244 | exit 1
245 | fi
246 |
247 | [ ! -z "${config_channel:-}" ] && channel="$config_channel"
248 | [ ! -z "${config_tools_source:-}" ] && tools_source="$config_tools_source"
249 | fi
250 |
251 | [ -z "$channel" ] && channel='master'
252 | [ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools'
253 |
254 | get_korebuild
255 | set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" "$ci"
256 | invoke_korebuild_command "$command" "$@"
257 |
--------------------------------------------------------------------------------
/src/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticListenerExtensions.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.DiagnosticAdapter;
5 |
6 | namespace System.Diagnostics
7 | {
8 | public static class DiagnosticListenerExtensions
9 | {
10 | public static IDisposable SubscribeWithAdapter(this DiagnosticListener diagnostic, object target)
11 | {
12 | var adapter = new DiagnosticSourceAdapter(target);
13 | return diagnostic.Subscribe(adapter, (Predicate)adapter.IsEnabled);
14 | }
15 |
16 | public static IDisposable SubscribeWithAdapter(
17 | this DiagnosticListener diagnostic,
18 | object target,
19 | Func isEnabled)
20 | {
21 | var adapter = new DiagnosticSourceAdapter(target, isEnabled);
22 | return diagnostic.Subscribe(adapter, (Predicate)adapter.IsEnabled);
23 | }
24 |
25 | public static IDisposable SubscribeWithAdapter(
26 | this DiagnosticListener diagnostic,
27 | object target,
28 | Func isEnabled)
29 | {
30 | var adapter = new DiagnosticSourceAdapter(target, isEnabled);
31 | return diagnostic.Subscribe(adapter, (Predicate)adapter.IsEnabled);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticNameAttribute.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.DiagnosticAdapter
7 | {
8 | public class DiagnosticNameAttribute : Attribute
9 | {
10 | public DiagnosticNameAttribute(string name)
11 | {
12 | Name = name;
13 | }
14 |
15 | public string Name { get; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticSourceAdapter.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.Concurrent;
6 | using System.Collections.Generic;
7 | using System.Diagnostics;
8 | using System.Reflection;
9 | using Microsoft.Extensions.DiagnosticAdapter.Internal;
10 |
11 | namespace Microsoft.Extensions.DiagnosticAdapter
12 | {
13 | public class DiagnosticSourceAdapter : IObserver>
14 | {
15 | private readonly Listener _listener;
16 | private readonly IDiagnosticSourceMethodAdapter _methodAdapter;
17 |
18 | public DiagnosticSourceAdapter(object target)
19 | : this(target, (Func)null, new ProxyDiagnosticSourceMethodAdapter())
20 | {
21 | }
22 |
23 | public DiagnosticSourceAdapter(object target, Func isEnabled)
24 | : this(target, isEnabled, methodAdapter: new ProxyDiagnosticSourceMethodAdapter())
25 | {
26 | }
27 |
28 | public DiagnosticSourceAdapter(object target, Func isEnabled)
29 | : this(target, isEnabled, methodAdapter: new ProxyDiagnosticSourceMethodAdapter())
30 | {
31 | }
32 |
33 | public DiagnosticSourceAdapter(
34 | object target,
35 | Func isEnabled,
36 | IDiagnosticSourceMethodAdapter methodAdapter)
37 | : this(target, isEnabled: (isEnabled == null) ? (Func)null : (a, b, c) => isEnabled(a), methodAdapter: methodAdapter)
38 | {
39 | }
40 |
41 | public DiagnosticSourceAdapter(
42 | object target,
43 | Func isEnabled,
44 | IDiagnosticSourceMethodAdapter methodAdapter)
45 | {
46 | _methodAdapter = methodAdapter;
47 | _listener = EnlistTarget(target, isEnabled);
48 | }
49 |
50 | private static Listener EnlistTarget(object target, Func isEnabled)
51 | {
52 | var listener = new Listener(target, isEnabled);
53 |
54 | var typeInfo = target.GetType().GetTypeInfo();
55 | var methodInfos = typeInfo.DeclaredMethods;
56 | foreach (var methodInfo in methodInfos)
57 | {
58 | var diagnosticNameAttribute = methodInfo.GetCustomAttribute();
59 | if (diagnosticNameAttribute != null)
60 | {
61 | var subscription = new Subscription(methodInfo);
62 | listener.Subscriptions.Add(diagnosticNameAttribute.Name, subscription);
63 | }
64 | }
65 |
66 | return listener;
67 | }
68 |
69 | public bool IsEnabled(string diagnosticName)
70 | {
71 | return IsEnabled(diagnosticName, null);
72 | }
73 |
74 | public bool IsEnabled(string diagnosticName, object arg1, object arg2 = null)
75 | {
76 | if (_listener.Subscriptions.Count == 0)
77 | {
78 | return false;
79 | }
80 |
81 | return
82 | _listener.Subscriptions.ContainsKey(diagnosticName) &&
83 | (_listener.IsEnabled == null || _listener.IsEnabled(diagnosticName, arg1, arg2));
84 | }
85 |
86 | public void Write(string diagnosticName, object parameters)
87 | {
88 | if (parameters == null)
89 | {
90 | return;
91 | }
92 |
93 | Subscription subscription;
94 | if (!_listener.Subscriptions.TryGetValue(diagnosticName, out subscription))
95 | {
96 | return;
97 | }
98 |
99 | var succeeded = false;
100 | foreach (var adapter in subscription.Adapters)
101 | {
102 | if (adapter(_listener.Target, parameters))
103 | {
104 | succeeded = true;
105 | break;
106 | }
107 | }
108 |
109 | if (!succeeded)
110 | {
111 | var newAdapter = _methodAdapter.Adapt(subscription.MethodInfo, parameters.GetType());
112 | try
113 | {
114 | succeeded = newAdapter(_listener.Target, parameters);
115 | }
116 | catch (InvalidProxyOperationException ex)
117 | {
118 | throw new InvalidOperationException(
119 | Resources.FormatConverter_UnableToGenerateProxy(subscription.MethodInfo.Name),
120 | ex);
121 | }
122 | Debug.Assert(succeeded);
123 |
124 | subscription.Adapters.Add(newAdapter);
125 | }
126 | }
127 |
128 | void IObserver>.OnNext(KeyValuePair value)
129 | {
130 | Write(value.Key, value.Value);
131 | }
132 |
133 | void IObserver>.OnError(Exception error)
134 | {
135 | // Do nothing
136 | }
137 |
138 | void IObserver>.OnCompleted()
139 | {
140 | // Do nothing
141 | }
142 |
143 | private class Listener
144 | {
145 | public Listener(object target, Func isEnabled)
146 | {
147 | Target = target;
148 | IsEnabled = isEnabled;
149 |
150 | Subscriptions = new Dictionary(StringComparer.Ordinal);
151 | }
152 |
153 | public Func IsEnabled { get; }
154 |
155 | public object Target { get; }
156 |
157 | public Dictionary Subscriptions { get; }
158 | }
159 |
160 | private class Subscription
161 | {
162 | public Subscription(MethodInfo methodInfo)
163 | {
164 | MethodInfo = methodInfo;
165 |
166 | Adapters = new ConcurrentBag>();
167 | }
168 |
169 | public ConcurrentBag> Adapters { get; }
170 |
171 | public MethodInfo MethodInfo { get; }
172 | }
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/src/Microsoft.Extensions.DiagnosticAdapter/IDiagnosticSourceMethodAdapter.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.DiagnosticAdapter
8 | {
9 | public interface IDiagnosticSourceMethodAdapter
10 | {
11 | Func