├── .gitignore ├── .gitmodules ├── .travis.yml ├── .vsts-ci ├── ci.yml ├── misc-analysis.yml ├── releaseBuild.yml └── templates │ ├── build.yml │ ├── compliance.yml │ └── test.yml ├── LICENSE ├── README.md ├── Solutions ├── .gitignore └── VS15_amd64 │ ├── Microsoft.Management.Infrastructure.Tests │ ├── Microsoft.Management.Infrastructure.Tests.csproj │ └── packages.config │ └── Microsoft.Management.Infrastructure │ ├── Microsoft.Management.Infrastructure.csproj │ └── Microsoft.Management.Infrastructure.sln ├── build.sh ├── global.json ├── nuget.config ├── packages └── System.Security.SecureString.4.0.0-rc1.nupkg ├── signing └── visualstudiopublic.snk ├── src ├── Microsoft.Management.Infrastructure │ ├── AssemblyInfo.cs │ ├── CimClass.cs │ ├── CimConverter.cs │ ├── CimException.cs │ ├── CimFlags.cs │ ├── CimInstance.cs │ ├── CimMethodDeclaration.cs │ ├── CimMethodParameter.cs │ ├── CimMethodParameterDeclaration.cs │ ├── CimMethodParametersCollection.cs │ ├── CimMethodResult.cs │ ├── CimMethodResultBase.cs │ ├── CimMethodStreamedResult.cs │ ├── CimProperty.cs │ ├── CimPropertyDeclaration.cs │ ├── CimQualifier.cs │ ├── CimSession.cs │ ├── CimSubscriptionResult.cs │ ├── CimSystemProperties.cs │ ├── CimType.cs │ ├── Generic │ │ ├── CimAsyncCollection.cs │ │ ├── CimAsyncResult.cs │ │ ├── CimAsyncStatus.cs │ │ ├── CimKeyedCollection.cs │ │ └── CimReadOnlyKeyedCollection.cs │ ├── Internal │ │ ├── CimApplication.cs │ │ ├── CimOperationCallbackProcessingContext.cs │ │ ├── ClassHandleExtensionMethods.cs │ │ ├── Data │ │ │ ├── CimClassPropertiesCollection.cs │ │ │ ├── CimClassPropertyOfClass.cs │ │ │ ├── CimClassQualifierCollection.cs │ │ │ ├── CimMethodDeclarationCollection.cs │ │ │ ├── CimMethodDeclarationOfClass.cs │ │ │ ├── CimMethodParameterBackedByCimProperty.cs │ │ │ ├── CimMethodParameterDeclarationCollection.cs │ │ │ ├── CimMethodParameterDeclarationOfMethod.cs │ │ │ ├── CimMethodParameterQualifierCollection.cs │ │ │ ├── CimMethodParameterQualifierOfMethod.cs │ │ │ ├── CimMethodQualifierCollection.cs │ │ │ ├── CimMethodQualifierOfMethod.cs │ │ │ ├── CimPropertiesCollection.cs │ │ │ ├── CimPropertyOfInstance.cs │ │ │ ├── CimPropertyQualifierCollection.cs │ │ │ ├── CimPropertyStandalone.cs │ │ │ ├── CimQualifierOfClass.cs │ │ │ └── CimQualifierOfProperty.cs │ │ ├── Helpers.cs │ │ ├── InstanceHandleExtensionMethods.cs │ │ ├── MiFlagsExtensionMethods.cs │ │ ├── MiTypeExtensionMethods.cs │ │ ├── NativeErrorCodeExtensionMethods.cs │ │ ├── Operations │ │ │ ├── CancellationMode.cs │ │ │ ├── CimAsyncCallbacksReceiverBase.cs │ │ │ ├── CimAsyncCancellationDisposable.cs │ │ │ ├── CimAsyncClassObservable.cs │ │ │ ├── CimAsyncClassObserverProxy.cs │ │ │ ├── CimAsyncDelegatedObservable.cs │ │ │ ├── CimAsyncIndicationObservable.cs │ │ │ ├── CimAsyncIndicationObserverProxy.cs │ │ │ ├── CimAsyncInstanceObservable.cs │ │ │ ├── CimAsyncInstanceObserverProxy.cs │ │ │ ├── CimAsyncMethodResultObservable.cs │ │ │ ├── CimAsyncMethodResultObserverProxy.cs │ │ │ ├── CimAsyncObservableBase.cs │ │ │ ├── CimAsyncObserverProxyBase.cs │ │ │ ├── CimOperation.cs │ │ │ ├── CimSyncClassEnumerable.cs │ │ │ ├── CimSyncClassEnumerator.cs │ │ │ ├── CimSyncEnumerableBase.cs │ │ │ ├── CimSyncEnumeratorBase.cs │ │ │ ├── CimSyncIndicationEnumerable.cs │ │ │ ├── CimSyncIndicationEnumerator.cs │ │ │ ├── CimSyncInstanceEnumerable.cs │ │ │ ├── CimSyncInstanceEnumerator.cs │ │ │ ├── ConvertingObservable.cs │ │ │ └── EmptyDisposable.cs │ │ ├── SanityHelpers.cs │ │ └── ValueHelpers.cs │ ├── Microsoft.Management.Infrastructure.csproj │ ├── Native │ │ ├── Enumerations │ │ │ ├── MI_AuthType.cs │ │ │ ├── MI_CallbackMode.cs │ │ │ ├── MI_CancellationReason.cs │ │ │ ├── MI_DestinationOptionsFlags.cs │ │ │ ├── MI_Flags.cs │ │ │ ├── MI_ImpersonationType.cs │ │ │ ├── MI_ModuleFlags.cs │ │ │ ├── MI_OperationCallback_ResponseType.cs │ │ │ ├── MI_OperationFlags.cs │ │ │ ├── MI_OperationOptionsFlags.cs │ │ │ ├── MI_PacketEncoding.cs │ │ │ ├── MI_PromptType.cs │ │ │ ├── MI_Protocol.cs │ │ │ ├── MI_ProxyType.cs │ │ │ ├── MI_Result.cs │ │ │ ├── MI_SerializationFormat.cs │ │ │ ├── MI_SerializerFlags.cs │ │ │ ├── MI_SubscriptionDeliveryType.cs │ │ │ ├── MI_Transport.cs │ │ │ ├── MI_Type.cs │ │ │ └── MI_WriteMessageChannel.cs │ │ ├── MI_Application.cs │ │ ├── MI_Class.cs │ │ ├── MI_ClassDecl.cs │ │ ├── MI_Deserializer.cs │ │ ├── MI_DestinationOptions.cs │ │ ├── MI_FunctionTableCache.cs │ │ ├── MI_Instance.cs │ │ ├── MI_NativeObject.cs │ │ ├── MI_NativeObjectWithFT.cs │ │ ├── MI_Operation.cs │ │ ├── MI_OperationOptions.cs │ │ ├── MI_ParameterSet.cs │ │ ├── MI_PlatformSpecific.cs │ │ ├── MI_PropertyDecl.cs │ │ ├── MI_QualifierDecl.cs │ │ ├── MI_QualifierSet.cs │ │ ├── MI_SerializationFTHelpers.cs │ │ ├── MI_Serializer.cs │ │ ├── MI_Session.cs │ │ ├── MI_SubscriptionDeliveryOptions.cs │ │ ├── NativeCimCredential.cs │ │ ├── NativeMethods.cs │ │ └── Structures │ │ │ ├── MI_Array.cs │ │ │ ├── MI_Datetime.cs │ │ │ ├── MI_DeserializerCallbacks.cs │ │ │ ├── MI_ExtendedArray.cs │ │ │ ├── MI_Interval.cs │ │ │ ├── MI_OperationCallbacks.cs │ │ │ ├── MI_SessionCreationCallbacks.cs │ │ │ ├── MI_String.cs │ │ │ ├── MI_Timestamp.cs │ │ │ ├── MI_UserCredentials.cs │ │ │ └── MI_Value.cs │ ├── NativeErrorCode.cs │ ├── Options │ │ ├── CimCredential.cs │ │ ├── CimSemantics.cs │ │ ├── CimSessionOptions.cs │ │ ├── DComSessionOptions.cs │ │ ├── Internal │ │ │ ├── CimOperationFlags.cs │ │ │ ├── CimOperationOptions.cs │ │ │ ├── CimSubscriptionDeliveryOptions.cs │ │ │ ├── ImpersonationType.cs │ │ │ ├── PacketEncoding.cs │ │ │ └── ProxyType.cs │ │ └── WSManSessionOptions.cs │ ├── Serialization │ │ ├── CimDeserializer.cs │ │ ├── CimMofDeserializer.cs │ │ ├── CimMofSerializer.cs │ │ ├── CimSerializer.cs │ │ └── MofDeserializerSchemaValidationOption.cs │ └── Strings.Designer.cs └── signing │ ├── map.json │ └── visualstudiopublic.snk ├── test.sh └── test └── Microsoft.Management.Infrastructure.Tests ├── AssemblyInfo.cs ├── CimInstanceTests.cs ├── Helpers ├── Assert.cs ├── Helpers.cs ├── MIAssert.cs ├── TDDFact.cs ├── TestMIProperty.cs ├── WindowsAssert.cs └── WindowsFact.cs ├── InternalTests └── CimApplicationTests.cs ├── Microsoft.Management.Infrastructure.Tests.csproj ├── NativeTests ├── .SlowTests.cs.swp ├── Fixtures │ ├── ApplicationFixture.cs │ ├── SessionFixture.cs │ └── StaticFixtures.cs ├── MIValueTests.cs ├── MOFDeserializerTests.cs ├── MOFSerializerTests.cs ├── NativeDeserializerTestsBase.cs ├── NativeSerializerTestsBase.cs ├── NativeTestsBase.cs ├── SanityTests.cs ├── SessionTests.cs ├── SlowTests.cs ├── TestData │ ├── AllTypesClass.cs │ └── SerializationTestData.cs ├── XMLDeserializerTests.cs └── XMLSerializerTests.cs ├── SerializationTests └── CimMofDeserializerTests.cs ├── UnitTests ├── CimClassTest.cs ├── CimInstanceTest.cs ├── CimMofDeserializerTest.cs ├── CimSessionTest.cs └── TestData │ ├── dmtftypes.mof │ ├── dscinstance.mof │ ├── dscschema.mof │ ├── mintinstance.mof │ └── mintschema.mof └── project.json /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/omi"] 2 | path = src/omi 3 | url = git@github.com:PowerShell/omi.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | sudo: required 3 | dist: trusty 4 | git: 5 | submodules: false 6 | before_install: 7 | - git config --global url.git@github.com:.insteadOf https://github.com/ 8 | - git submodule update --init 9 | - sudo apt-get install -y -qq curl make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 10 | - curl -s "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh" -o dotnet-install.sh 11 | - bash ./dotnet-install.sh -c rel-1.0.0 -v latest 12 | script: 13 | - ./build.sh 14 | - ./test.sh 15 | -------------------------------------------------------------------------------- /.vsts-ci/ci.yml: -------------------------------------------------------------------------------- 1 | name: MMI-$(Build.BuildId) 2 | trigger: 3 | branches: 4 | include: 5 | - master 6 | - release* 7 | pr: 8 | branches: 9 | include: 10 | - master 11 | - release* 12 | 13 | pool: 14 | vmImage: 'ubuntu-latest' 15 | 16 | steps: 17 | - template: templates/build.yml 18 | 19 | - template: templates/test.yml 20 | -------------------------------------------------------------------------------- /.vsts-ci/misc-analysis.yml: -------------------------------------------------------------------------------- 1 | name: MMI-$(Build.BuildId) 2 | trigger: 3 | branches: 4 | include: 5 | - master 6 | - release* 7 | pr: 8 | branches: 9 | include: 10 | - master 11 | - release* 12 | 13 | jobs: 14 | - job: credscan 15 | displayName: 'Secret Scan' 16 | pool: 'Hosted VS2017' 17 | 18 | steps: 19 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2 20 | displayName: 'Scan for secrets' 21 | inputs: 22 | debugMode: false 23 | 24 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2 25 | displayName: 'Publish Secret Scan Logs to Build Artifacts' 26 | continueOnError: true 27 | 28 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-postanalysis.PostAnalysis@1 29 | displayName: 'Check for failures' 30 | inputs: 31 | CredScan: true 32 | ToolLogsNotFoundAction: Error 33 | 34 | 35 | -------------------------------------------------------------------------------- /.vsts-ci/releaseBuild.yml: -------------------------------------------------------------------------------- 1 | name: MMI-$(Build.BuildId) 2 | trigger: 3 | branches: 4 | include: 5 | - master 6 | - release* 7 | pr: 8 | branches: 9 | include: 10 | - master 11 | - release* 12 | 13 | jobs: 14 | 15 | - job: build_MMI 16 | displayName: Build MMI 17 | pool: 18 | vmImage: 'ubuntu-latest' 19 | steps: 20 | - template: templates/build.yml 21 | 22 | - template: templates/compliance.yml 23 | parameters: 24 | parentJob: build_MMI 25 | -------------------------------------------------------------------------------- /.vsts-ci/templates/build.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - checkout: self 3 | 4 | - bash: sudo apt-get install libpam0g-dev libssl-dev libcurl4-openssl-dev 5 | displayName: 'apt-get dependencies' 6 | 7 | - bash: ./build.sh 8 | displayName: 'Build MMI' 9 | 10 | - task: PublishBuildArtifacts@1 11 | inputs: 12 | artifactName: 'release' 13 | pathToPublish: src/Microsoft.Management.Infrastructure/bin/Microsoft.Management.Infrastructure.dll 14 | 15 | - task: PublishBuildArtifacts@1 16 | inputs: 17 | artifactName: 'release' 18 | pathToPublish: src/Microsoft.Management.Infrastructure/bin/Microsoft.Management.Infrastructure.pdb 19 | -------------------------------------------------------------------------------- /.vsts-ci/templates/compliance.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | parentJob: build 3 | 4 | jobs: 5 | - job: compliance 6 | displayName: Compliance for MMI 7 | pool: 8 | name: Package ES CodeHub Lab E 9 | dependsOn: 10 | ${{ parameters.parentJob }} 11 | 12 | steps: 13 | - task: DownloadBuildArtifacts@0 14 | displayName: 'Download artifacts' 15 | inputs: 16 | buildType: current 17 | downloadType: single 18 | artifactName: release 19 | downloadPath: '$(System.ArtifactsDirectory)' 20 | 21 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-antimalware.AntiMalware@3 22 | displayName: 'Run Defender Scan' 23 | 24 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2 25 | displayName: 'Run CredScan' 26 | inputs: 27 | debugMode: false 28 | continueOnError: true 29 | 30 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-binskim.BinSkim@3 31 | displayName: 'Run BinSkim ' 32 | inputs: 33 | InputType: Basic 34 | AnalyzeTarget: '$(System.ArtifactsDirectory)/*.dll' 35 | AnalyzeSymPath: 'SRV*' 36 | AnalyzeVerbose: true 37 | AnalyzeHashes: true 38 | AnalyzeStatistics: true 39 | continueOnError: true 40 | 41 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@1 42 | displayName: 'Run PoliCheck' 43 | inputs: 44 | targetType: F 45 | optionsFC: 0 46 | optionsXS: 0 47 | optionsPE: '1|2|3|4' 48 | optionsHMENABLE: 0 49 | toolVersion: 5.8.2.1 50 | continueOnError: true 51 | 52 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2 53 | displayName: 'Publish Security Analysis Logs to Build Artifacts' 54 | continueOnError: true 55 | 56 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-uploadtotsa.TSAUpload@1 57 | displayName: 'TSA upload to Codebase: MMI_20190701 Version: TsaV2' 58 | inputs: 59 | tsaVersion: TsaV2 60 | codeBaseName: 'MMI_20190701' 61 | uploadAPIScan: false 62 | uploadFortifySCA: false 63 | uploadFxCop: false 64 | uploadModernCop: false 65 | uploadPREfast: false 66 | uploadRoslyn: false 67 | uploadTSLint: false 68 | 69 | - task: securedevelopmentteam.vss-secure-development-tools.build-task-report.SdtReport@1 70 | displayName: 'Create Security Analysis Report' 71 | inputs: 72 | TsvFile: false 73 | APIScan: true 74 | BinSkim: true 75 | CredScan: true 76 | PoliCheck: true 77 | PoliCheckBreakOn: Severity2Above 78 | 79 | - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0 80 | displayName: 'Component Detection' 81 | inputs: 82 | sourceScanPath: '$(Build.SourcesDirectory)' 83 | snapshotForceEnabled: true 84 | -------------------------------------------------------------------------------- /.vsts-ci/templates/test.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - bash: ./test.sh 3 | displayName: 'Execute Tests' 4 | 5 | - task: PublishTestResults@2 6 | inputs: 7 | testResultsFormat: 'VSTest' 8 | testResultsFiles: '**/*TestResults.trx' 9 | failTaskOnFailedTests: 'true' 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | powershell-mmi v.1.0 2 | 3 | Copyright (c) Microsoft Corporation 4 | 5 | All rights reserved. 6 | 7 | MIT License 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Microsoft.Management.Infrastructure 2 | =================================== 3 | 4 | [![Build Status](https://travis-ci.com/PowerShell/MMI.svg?token=31YifM4jfyVpBmEGitCm&branch=johnkord-mmi_changes)](https://travis-ci.com/PowerShell/MMI) 5 | 6 | This repo contains the `Microsoft.Management.Infrastructure` source code (and 7 | soon tests). This is a dependency of PowerShell, but is kept separate. 8 | 9 | Environment 10 | =========== 11 | 12 | Toolchain Setup 13 | --------------- 14 | 15 | MMI requires the following packages: 16 | 17 | ```sh 18 | sudo apt-get install libpam0g-dev libssl-dev libcurl4-openssl-dev 19 | ``` 20 | 21 | Also install [PowerShell][] from the latest release per their instructions. 22 | 23 | [powershell]: https://github.com/PowerShell/PowerShell 24 | 25 | Git Setup 26 | --------- 27 | 28 | MMI has a submodule, so clone recursively. 29 | 30 | ```sh 31 | git clone --recursive git@github.com:PowerShell/MMI.git 32 | ``` 33 | 34 | Build 35 | ----- 36 | ```sh 37 | ./build.sh 38 | ``` 39 | 40 | Test 41 | ---- 42 | ```sh 43 | ./test.sh 44 | ``` 45 | -------------------------------------------------------------------------------- /Solutions/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore nuget package directories 2 | Packages/ 3 | 4 | # Ignore native debug files 5 | *.VC.db 6 | *.VC.opendb -------------------------------------------------------------------------------- /Solutions/VS15_amd64/Microsoft.Management.Infrastructure.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Solutions/VS15_amd64/Microsoft.Management.Infrastructure/Microsoft.Management.Infrastructure.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Management.Infrastructure", "Microsoft.Management.Infrastructure.csproj", "{D7349798-7E56-4235-9266-3A84B1294155}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Management.Infrastructure.Tests", "..\Microsoft.Management.Infrastructure.Tests\Microsoft.Management.Infrastructure.Tests.csproj", "{50E90A15-286F-49CE-B164-B2487AE75A15}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D7349798-7E56-4235-9266-3A84B1294155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {D7349798-7E56-4235-9266-3A84B1294155}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {D7349798-7E56-4235-9266-3A84B1294155}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {D7349798-7E56-4235-9266-3A84B1294155}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {50E90A15-286F-49CE-B164-B2487AE75A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {50E90A15-286F-49CE-B164-B2487AE75A15}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {50E90A15-286F-49CE-B164-B2487AE75A15}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {50E90A15-286F-49CE-B164-B2487AE75A15}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Install OMI 4 | wget https://github.com/microsoft/omi/releases/download/v1.6.0/omi-1.6.0-0.ssl_110.ulinux.x64.deb -O omi-1.6.0-0.ssl_110.ulinux.x64.deb 5 | sudo apt-get install cron -y 6 | sudo apt install ./omi-1.6.0-0.ssl_110.ulinux.x64.deb 7 | 8 | # Build MMI 9 | PATH=$PATH:~/.dotnet dotnet build -f netstandard2.0 src/Microsoft.Management.Infrastructure/ -c Linux -o bin 10 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src", "test" ] 3 | } 4 | -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /packages/System.Security.SecureString.4.0.0-rc1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/MMI/cf32fc695b32c2eae848b693395c09222fe1d2ae/packages/System.Security.SecureString.4.0.0-rc1.nupkg -------------------------------------------------------------------------------- /signing/visualstudiopublic.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/MMI/cf32fc695b32c2eae848b693395c09222fe1d2ae/signing/visualstudiopublic.snk -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System.Reflection; 10 | using System.Resources; 11 | using System.Runtime.CompilerServices; 12 | using System.Runtime.InteropServices; 13 | 14 | 15 | [assembly: InternalsVisibleTo("XmlServerStore,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 16 | [assembly: InternalsVisibleTo("System.Management.Automation,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 17 | [assembly: InternalsVisibleTo("XmlServerStore,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 18 | [assembly: InternalsVisibleTo("Microsoft.CloudInfrastructure.Test.Common,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 19 | [assembly: InternalsVisibleTo("Microsoft.Windows.DSC.CoreConfProviders,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 20 | [assembly: InternalsVisibleTo("Microsoft.Monitoring.Commands,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 21 | [assembly: InternalsVisibleTo("Microsoft.Management.Infrastructure.CimCmdlets,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] 22 | [assembly: InternalsVisibleTo("Microsoft.Management.Infrastructure.Tests")] 23 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System; 13 | using System.Diagnostics.CodeAnalysis; 14 | 15 | namespace Microsoft.Management.Infrastructure 16 | { 17 | /// 18 | /// Cim flags 19 | /// 20 | [Flags] 21 | public enum CimFlags : long 22 | { 23 | None = (long)0, 24 | 25 | Class = (long)MI_Flags.MI_FLAG_CLASS, 26 | Method = (long)MI_Flags.MI_FLAG_METHOD, 27 | Property = (long)MI_Flags.MI_FLAG_PROPERTY, 28 | Parameter = (long)MI_Flags.MI_FLAG_PARAMETER, 29 | Association = (long)MI_Flags.MI_FLAG_ASSOCIATION, 30 | Indication = (long)MI_Flags.MI_FLAG_INDICATION, 31 | Reference = (long)MI_Flags.MI_FLAG_REFERENCE, 32 | Any = (long)MI_Flags.MI_FLAG_ANY, 33 | 34 | /* Qualifier flavors */ 35 | EnableOverride = (long)MI_Flags.MI_FLAG_ENABLEOVERRIDE, 36 | DisableOverride = (long)MI_Flags.MI_FLAG_DISABLEOVERRIDE, 37 | Restricted = (long)MI_Flags.MI_FLAG_RESTRICTED, 38 | ToSubclass = (long)MI_Flags.MI_FLAG_TOSUBCLASS, 39 | Translatable = (long)MI_Flags.MI_FLAG_TRANSLATABLE, 40 | 41 | /* Select boolean qualifier */ 42 | Key = (long)MI_Flags.MI_FLAG_KEY, 43 | In = (long)MI_Flags.MI_FLAG_IN, 44 | Out = (long)MI_Flags.MI_FLAG_OUT, 45 | Required = (long)MI_Flags.MI_FLAG_REQUIRED, 46 | Static = (long)MI_Flags.MI_FLAG_STATIC, 47 | Abstract = (long)MI_Flags.MI_FLAG_ABSTRACT, 48 | Terminal = (long)MI_Flags.MI_FLAG_TERMINAL, 49 | Expensive = (long)MI_Flags.MI_FLAG_EXPENSIVE, 50 | Stream = (long)MI_Flags.MI_FLAG_STREAM, 51 | ReadOnly = (long)MI_Flags.MI_FLAG_READONLY, 52 | 53 | /* Special flags */ 54 | NotModified = (long)MI_Flags.MI_FLAG_NOT_MODIFIED, 55 | NullValue = (long)MI_Flags.MI_FLAG_NULL, 56 | Borrow = (long)MI_Flags.MI_FLAG_BORROW, 57 | Adopt = (long)MI_Flags.MI_FLAG_ADOPT, 58 | }; 59 | 60 | /// 61 | /// CimSubscriptionDeliveryType 62 | /// 63 | [SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Justification = "This is a direct copy of the native flags enum")] 64 | public enum CimSubscriptionDeliveryType : int 65 | { 66 | None = (int)MI_SubscriptionDeliveryType.MI_SubscriptionDeliveryType_Push, 67 | Push = (int)MI_SubscriptionDeliveryType.MI_SubscriptionDeliveryType_Push, 68 | Pull = (int)MI_SubscriptionDeliveryType.MI_SubscriptionDeliveryType_Pull, 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimMethodDeclaration.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | 13 | namespace Microsoft.Management.Infrastructure 14 | { 15 | /// 16 | /// A method declaration of 17 | /// 18 | public abstract class CimMethodDeclaration 19 | { 20 | internal CimMethodDeclaration() 21 | { 22 | // do not allow 3rd parties to derive from / instantiate this class 23 | } 24 | 25 | /// 26 | /// Name of the method 27 | /// 28 | public abstract string Name { get; } 29 | 30 | /// 31 | /// Return type of the method 32 | /// 33 | public abstract CimType ReturnType { get; } 34 | 35 | /// 36 | /// Return type of the method 37 | /// 38 | public abstract CimReadOnlyKeyedCollection Parameters { get; } 39 | 40 | /// 41 | /// Qualifiers of the Method. 42 | /// 43 | public abstract CimReadOnlyKeyedCollection Qualifiers { get; } 44 | 45 | public override string ToString() 46 | { 47 | return this.Name; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimMethodParameterDeclaration.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | 13 | namespace Microsoft.Management.Infrastructure 14 | { 15 | /// 16 | /// A parameter declaration of 17 | /// 18 | public abstract class CimMethodParameterDeclaration 19 | { 20 | internal CimMethodParameterDeclaration() 21 | { 22 | // do not allow 3rd parties to derive from / instantiate this class 23 | } 24 | 25 | /// 26 | /// Name of the parameter 27 | /// 28 | public abstract string Name { get; } 29 | 30 | /// 31 | /// CIM type of the parameter 32 | /// 33 | public abstract CimType CimType { get; } 34 | 35 | /// 36 | /// Qualifiers of the parameter. 37 | /// 38 | public abstract CimReadOnlyKeyedCollection Qualifiers { get; } 39 | 40 | /// 41 | /// ClassName of the parameter's value. 42 | /// Only valid if the parameter type is or 43 | /// 44 | /// 45 | public abstract string ReferenceClassName { get; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimMethodResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using System; 13 | using System.Diagnostics; 14 | 15 | namespace Microsoft.Management.Infrastructure 16 | { 17 | /// 18 | /// Represents a regular - return value and all the out parameter values. 19 | /// 20 | /// 21 | /// 22 | public class CimMethodResult : CimMethodResultBase, IDisposable 23 | { 24 | private CimMethodParametersCollection _backingMethodParametersCollection; 25 | 26 | internal CimMethodResult(CimInstance backingInstance) 27 | { 28 | Debug.Assert(backingInstance != null, "Caller should verify backingInstance != null"); 29 | this._backingMethodParametersCollection = new CimMethodParametersCollection(backingInstance); 30 | } 31 | 32 | public CimMethodParameter ReturnValue 33 | { 34 | get 35 | { 36 | this.AssertNotDisposed(); 37 | return this.OutParameters["ReturnValue"]; 38 | } 39 | } 40 | 41 | public CimReadOnlyKeyedCollection OutParameters 42 | { 43 | get 44 | { 45 | this.AssertNotDisposed(); 46 | return this._backingMethodParametersCollection; 47 | } 48 | } 49 | 50 | #region IDisposable Members 51 | 52 | /// 53 | /// Releases resources associated with this object 54 | /// 55 | public void Dispose() 56 | { 57 | this.Dispose(true); 58 | GC.SuppressFinalize(this); 59 | } 60 | 61 | /// 62 | /// Releases resources associated with this object 63 | /// 64 | protected virtual void Dispose(bool disposing) 65 | { 66 | if (_disposed) 67 | { 68 | return; 69 | } 70 | 71 | if (disposing) 72 | { 73 | this._backingMethodParametersCollection.Dispose(); 74 | this._backingMethodParametersCollection = null; 75 | } 76 | 77 | _disposed = true; 78 | } 79 | 80 | internal void AssertNotDisposed() 81 | { 82 | if (this._disposed) 83 | { 84 | throw new ObjectDisposedException(this.ToString()); 85 | } 86 | } 87 | 88 | private bool _disposed; 89 | 90 | #endregion IDisposable Members 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimMethodResultBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | namespace Microsoft.Management.Infrastructure 12 | { 13 | /// 14 | /// Represents a method result - either 15 | /// 1) a regular method result - return value and all the out parameter values () 16 | /// or 17 | /// 2) a single item of a streamed out parameter array () 18 | /// 19 | public abstract class CimMethodResultBase 20 | { 21 | internal CimMethodResultBase() 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimMethodStreamedResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | namespace Microsoft.Management.Infrastructure 12 | { 13 | /// 14 | /// Represents a single item of a streamed out parameter array. 15 | /// 16 | public class CimMethodStreamedResult : CimMethodResultBase 17 | { 18 | internal CimMethodStreamedResult(string parameterName, object parameterValue, CimType parameterType) 19 | { 20 | this.ParameterName = parameterName; 21 | this.ItemValue = parameterValue; 22 | this.ItemType = parameterType; 23 | } 24 | 25 | public string ParameterName { get; private set; } 26 | 27 | public object ItemValue { get; private set; } 28 | public CimType ItemType { get; private set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimPropertyDeclaration.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using Microsoft.Management.Infrastructure.Internal; 13 | 14 | namespace Microsoft.Management.Infrastructure 15 | { 16 | /// 17 | /// A property declaration of 18 | /// 19 | public abstract class CimPropertyDeclaration 20 | { 21 | internal CimPropertyDeclaration() 22 | { 23 | // do not allow 3rd parties to derive from / instantiate this class 24 | } 25 | 26 | /// 27 | /// Name of the property 28 | /// 29 | public abstract string Name { get; } 30 | 31 | /// 32 | /// 33 | /// Default value of the property. null if the property doesn't have a value. 34 | /// 35 | /// 36 | public abstract object Value { get; } 37 | 38 | /// 39 | /// CIM type of the property 40 | /// 41 | /// See for a description of mapping between CIM types and .NET types. 42 | /// 43 | /// 44 | public abstract CimType CimType { get; } 45 | 46 | /// 47 | /// Flags of the property. 48 | /// 49 | public abstract CimFlags Flags { get; } 50 | 51 | /// 52 | /// Qualifiers of the property. 53 | /// 54 | public abstract CimReadOnlyKeyedCollection Qualifiers { get; } 55 | 56 | /// 57 | /// ClassName of the property's value. 58 | /// Only valid if the property type is or 59 | /// ; 60 | /// 61 | public abstract string ReferenceClassName { get; } 62 | 63 | public override string ToString() 64 | { 65 | return Helpers.ToStringFromNameAndValue(this.Name, this.Value); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimQualifier.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Internal; 12 | 13 | namespace Microsoft.Management.Infrastructure 14 | { 15 | /// 16 | /// A qualifier of 17 | /// 18 | public abstract class CimQualifier 19 | { 20 | internal CimQualifier() 21 | { 22 | // do not allow 3rd parties to derive from / instantiate this class 23 | } 24 | 25 | /// 26 | /// Name of the qualifier 27 | /// 28 | public abstract string Name { get; } 29 | 30 | /// 31 | /// 32 | /// Value of the qualifier. null if the qualifier doesn't have a value. 33 | /// 34 | /// 35 | /// See for a description of mapping between CIM types and .NET types. 36 | /// 37 | /// 38 | public abstract object Value { get; } 39 | 40 | /// 41 | /// CIM type of the qualifier 42 | /// 43 | public abstract CimType CimType { get; } 44 | 45 | /// 46 | /// Flags of the qualifier. 47 | /// 48 | public abstract CimFlags Flags { get; } 49 | 50 | public override string ToString() 51 | { 52 | return Helpers.ToStringFromNameAndValue(this.Name, this.Value); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimSubscriptionResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System; 13 | using System.Diagnostics; 14 | 15 | namespace Microsoft.Management.Infrastructure 16 | { 17 | /// 18 | /// Represents a SubscriptionResult 19 | /// 20 | public class CimSubscriptionResult : IDisposable 21 | { 22 | private CimInstance _resultInstance; 23 | private readonly string _bookmark; 24 | private readonly string _machineId; 25 | 26 | internal CimSubscriptionResult(MI_Instance handle, string bookmark, string machineId) 27 | { 28 | Debug.Assert(handle != null, "Caller should verify backingInstance != null"); 29 | this._resultInstance = new CimInstance(handle); 30 | this._bookmark = bookmark; 31 | this._machineId = machineId; 32 | } 33 | 34 | public string Bookmark 35 | { 36 | get 37 | { 38 | this.AssertNotDisposed(); 39 | return this._bookmark; 40 | } 41 | } 42 | 43 | public string MachineId 44 | { 45 | get 46 | { 47 | this.AssertNotDisposed(); 48 | return this._machineId; 49 | } 50 | } 51 | 52 | public CimInstance Instance 53 | { 54 | get 55 | { 56 | this.AssertNotDisposed(); 57 | return this._resultInstance; 58 | } 59 | } 60 | 61 | #region IDisposable Members 62 | 63 | /// 64 | /// Releases resources associated with this object 65 | /// 66 | public void Dispose() 67 | { 68 | this.Dispose(true); 69 | GC.SuppressFinalize(this); 70 | } 71 | 72 | /// 73 | /// Releases resources associated with this object 74 | /// 75 | protected virtual void Dispose(bool disposing) 76 | { 77 | if (_disposed) 78 | { 79 | return; 80 | } 81 | 82 | if (disposing) 83 | { 84 | this._resultInstance.Dispose(); 85 | this._resultInstance = null; 86 | } 87 | 88 | _disposed = true; 89 | } 90 | 91 | internal void AssertNotDisposed() 92 | { 93 | if (this._disposed) 94 | { 95 | throw new ObjectDisposedException(this.ToString()); 96 | } 97 | } 98 | 99 | private bool _disposed; 100 | 101 | #endregion IDisposable Members 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimSystemProperties.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | namespace Microsoft.Management.Infrastructure 12 | { 13 | public class CimSystemProperties 14 | { 15 | private string _namespace; 16 | private string _serverName; 17 | private string _className; 18 | private string _path; 19 | 20 | internal CimSystemProperties() 21 | { 22 | } 23 | 24 | internal void UpdateCimSystemProperties(string systemNamespace, string serverName, string className) 25 | { 26 | _namespace = systemNamespace; 27 | _serverName = serverName; 28 | _className = className; 29 | } 30 | 31 | internal void UpdateSystemPath(string Path) 32 | { 33 | _path = Path; 34 | } 35 | 36 | /// 37 | /// Namespace of CIM object 38 | /// 39 | public string Namespace 40 | { 41 | get 42 | { 43 | return _namespace; 44 | } 45 | } 46 | 47 | /// 48 | /// Server Name of CIM object 49 | /// 50 | public string ServerName 51 | { 52 | get 53 | { 54 | return _serverName; 55 | } 56 | } 57 | 58 | /// 59 | /// Class Name of CIM object 60 | /// 61 | public string ClassName 62 | { 63 | get 64 | { 65 | return _className; 66 | } 67 | } 68 | 69 | /// 70 | /// Object path of CIM object 71 | /// 72 | public string Path 73 | { 74 | get 75 | { 76 | return _path; 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/CimType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | namespace Microsoft.Management.Infrastructure 12 | { 13 | /// 14 | /// 15 | /// CIM type of a value. 16 | /// 17 | /// 18 | /// This is a .NET representation of intrinsic CIM types (as defined by DSP0004). 19 | /// 20 | /// The mapping of scalar types is as follows: 21 | /// - CIM: uint8 -> .NET: System.Byte 22 | /// - CIM: sint8 -> .NET: System.SByte 23 | /// - CIM: uint16 -> .NET: System.UInt16 24 | /// - CIM: sint16 -> .NET: System.Int16 25 | /// - CIM: uint32 -> .NET: System.UInt32 26 | /// - CIM: sint32 -> .NET: System.Int32 27 | /// - CIM: uint64 -> .NET: System.UInt64 28 | /// - CIM: sint64 -> .NET: System.Int64 29 | /// - CIM: string -> .NET: System.String 30 | /// - CIM: boolean -> .NET: System.Boolean 31 | /// - CIM: real32 -> .NET: System.Single 32 | /// - CIM: real64 -> .NET: System.Double 33 | /// - CIM: datetime -> .NET: either System.DateTime or System.TimeSpan 34 | /// - CIM: class ref -> .NET: CimInstance 35 | /// - CIM: char16 -> .NET: System.Char 36 | /// 37 | /// The mapping of arrays uses a single-dimensional .NET array of an appropriate type. 38 | /// The only exception is the CIM: datetime[] -> .NET: System.Object[] mapping 39 | /// (which is necessary because the CIM array can contain a mixture of dates and intervals). 40 | /// 41 | /// 42 | public enum CimType 43 | { 44 | Unknown = 0, 45 | 46 | Boolean, 47 | UInt8, 48 | SInt8, 49 | UInt16, 50 | SInt16, 51 | UInt32, 52 | SInt32, 53 | UInt64, 54 | SInt64, 55 | Real32, 56 | Real64, 57 | Char16, 58 | DateTime, 59 | String, 60 | Reference, 61 | Instance, 62 | 63 | BooleanArray, 64 | UInt8Array, 65 | SInt8Array, 66 | UInt16Array, 67 | SInt16Array, 68 | UInt32Array, 69 | SInt32Array, 70 | UInt64Array, 71 | SInt64Array, 72 | Real32Array, 73 | Real64Array, 74 | Char16Array, 75 | DateTimeArray, 76 | StringArray, 77 | ReferenceArray, 78 | InstanceArray, 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Generic/CimAsyncCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | 14 | namespace Microsoft.Management.Infrastructure.Generic 15 | { 16 | /// 17 | /// 18 | /// CimAsyncMultipleResults represents an asynchronous operation that returns a sequence of objects of type . 19 | /// 20 | /// 21 | /// The operation wrapped by CimAsyncMultipleResults doesn't start until the method is called. 22 | /// It is allowed to call more than once - each call will start another operation. 23 | /// 24 | /// 25 | /// Results of an operation are asynchronously communicated to the observer passed to the method. 26 | /// 27 | /// 28 | /// See and for more details 29 | /// about the asynchronous pattern exposed by this class. 30 | /// 31 | /// 32 | /// Type of results that the wrapped operation returns. 33 | public class CimAsyncMultipleResults : IObservable 34 | { 35 | private readonly IObservable _wrappedObservable; 36 | 37 | internal CimAsyncMultipleResults(IObservable wrappedObservable) 38 | { 39 | Debug.Assert(wrappedObservable != null, "Caller should verify wrappedObservable != null"); 40 | this._wrappedObservable = wrappedObservable; 41 | } 42 | 43 | #region IObservable Members 44 | 45 | /// 46 | /// 47 | /// Starts the operation and then communicates the results back to the given . 48 | /// 49 | /// 50 | /// It is allowed to call more than once - each call will start another operation. 51 | /// 52 | /// 53 | /// Observer that will receive asynchronous notifications about results of the operation 54 | /// IDiposable object that will cancel the operation when disposed. 55 | public IDisposable Subscribe(IObserver observer) 56 | { 57 | if (observer == null) 58 | { 59 | throw new ArgumentNullException("observer"); 60 | } 61 | 62 | return this._wrappedObservable.Subscribe(observer); 63 | } 64 | 65 | #endregion IObservable Members 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Generic/CimAsyncResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | 14 | namespace Microsoft.Management.Infrastructure.Generic 15 | { 16 | /// 17 | /// 18 | /// CimAsyncResult represents an asynchronous operation that returns a single object of type . 19 | /// 20 | /// 21 | /// The operation wrapped by CimAsyncResult doesn't start until the method is called. 22 | /// It is allowed to call more than once - each call will start another operation. 23 | /// 24 | /// 25 | /// Results of an operation are asynchronously communicated to the observer passed to the method. 26 | /// 27 | /// 28 | /// See and for more details 29 | /// about the asynchronous pattern exposed by this class. 30 | /// 31 | /// 32 | /// Type of results that the wrapped operation returns. 33 | public class CimAsyncResult : IObservable 34 | { 35 | private readonly IObservable _wrappedObservable; 36 | 37 | internal CimAsyncResult(IObservable wrappedObservable) 38 | { 39 | Debug.Assert(wrappedObservable != null, "Caller should verify wrappedObservable != null"); 40 | this._wrappedObservable = wrappedObservable; 41 | } 42 | 43 | #region IObservable Members 44 | 45 | /// 46 | /// 47 | /// Starts the operation and then communicates the results back to the given . 48 | /// 49 | /// 50 | /// It is allowed to call more than once - each call will start another operation. 51 | /// 52 | /// 53 | /// Observer that will receive asynchronous notifications about results of the operation 54 | /// IDiposable object that will cancel the operation when disposed. 55 | public IDisposable Subscribe(IObserver observer) 56 | { 57 | if (observer == null) 58 | { 59 | throw new ArgumentNullException("observer"); 60 | } 61 | 62 | return this._wrappedObservable.Subscribe(observer); 63 | } 64 | 65 | #endregion IObservable Members 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Generic/CimAsyncStatus.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | 14 | namespace Microsoft.Management.Infrastructure.Generic 15 | { 16 | /// 17 | /// 18 | /// CimAsyncStatus represents an asynchronous operation that returns no object/>. 19 | /// 20 | /// 21 | /// The operation wrapped by CimAsyncStatus doesn't start until the method is called. 22 | /// It is allowed to call more than once - each call will start another operation. 23 | /// 24 | /// 25 | /// Results of an operation are asynchronously communicated to the observer passed to the method. 26 | /// 27 | /// 28 | /// See and for more details 29 | /// about the asynchronous pattern exposed by this class. 30 | /// 31 | /// 32 | /// Type of results that the wrapped operation returns. 33 | public class CimAsyncStatus : IObservable 34 | { 35 | private readonly IObservable _wrappedObservable; 36 | 37 | internal CimAsyncStatus(IObservable wrappedObservable) 38 | { 39 | Debug.Assert(wrappedObservable != null, "Caller should verify wrappedObservable != null"); 40 | this._wrappedObservable = wrappedObservable; 41 | } 42 | 43 | #region IObservable Members 44 | 45 | /// 46 | /// 47 | /// Starts the operation and then communicates back to the given . 48 | /// 49 | /// 50 | /// It is allowed to call more than once - each call will start another operation. 51 | /// 52 | /// 53 | /// Observer that will receive asynchronous notifications about results of the operation 54 | /// IDiposable object that will cancel the operation when disposed. 55 | public IDisposable Subscribe(IObserver observer) 56 | { 57 | if (observer == null) 58 | { 59 | throw new ArgumentNullException("observer"); 60 | } 61 | 62 | return this._wrappedObservable.Subscribe(observer); 63 | } 64 | 65 | #endregion IObservable Members 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Generic/CimKeyedCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | namespace Microsoft.Management.Infrastructure.Generic 12 | { 13 | /// 14 | /// Represents a mutable collection of objects. 15 | /// The objects can be enumerated (the order is undefined) or can be accessed by their name. 16 | /// 17 | /// Type of items in the collection 18 | public abstract class CimKeyedCollection : CimReadOnlyKeyedCollection 19 | { 20 | internal CimKeyedCollection() 21 | { 22 | } 23 | 24 | /// 25 | /// Adds to the collection. 26 | /// 27 | /// Item to add 28 | public abstract void Add(T newItem); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Generic/CimReadOnlyKeyedCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System.Collections.Generic; 12 | 13 | namespace Microsoft.Management.Infrastructure.Generic 14 | { 15 | /// 16 | /// Represents an immutable collection of objects. 17 | /// The objects can be enumerated (the order is undefined) or can be accessed by their name. 18 | /// 19 | /// Type of items in the collection 20 | public abstract class CimReadOnlyKeyedCollection : IEnumerable 21 | { 22 | internal CimReadOnlyKeyedCollection() 23 | { 24 | } 25 | 26 | /// 27 | /// Number of items in the collection 28 | /// 29 | public abstract int Count { get; } 30 | 31 | /// 32 | /// Gets an item with a given 33 | /// 34 | /// 35 | /// 36 | public abstract T this[string itemName] { get; } 37 | 38 | /// 39 | /// Returns an enumerator that returns items from the collectio n 40 | /// 41 | /// 42 | public abstract IEnumerator GetEnumerator(); 43 | 44 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 45 | { 46 | return this.GetEnumerator(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/CimApplication.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal 15 | { 16 | internal static class CimApplication 17 | { 18 | #region Initializing CimApplication singleton 19 | 20 | static internal string ApplicationID = "CoreCLRSingletonAppDomain"; 21 | 22 | static private MI_Application GetApplicationHandle() 23 | { 24 | MI_Application applicationHandle; 25 | MI_Instance errorDetailsHandle; 26 | MI_Result result = MI_Application.Initialize(ApplicationID, 27 | out errorDetailsHandle, 28 | out applicationHandle); 29 | CimException.ThrowIfMiResultFailure(result, errorDetailsHandle); 30 | 31 | return applicationHandle; 32 | } 33 | 34 | static public MI_Application Handle 35 | { 36 | get 37 | { 38 | return CimApplication.LazyHandle.Value; 39 | } 40 | } 41 | 42 | private static readonly Lazy LazyHandle = new Lazy(CimApplication.GetApplicationHandle); 43 | 44 | #endregion Initializing CimApplication singleton 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/CimOperationCallbackProcessingContext.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Internal 10 | { 11 | internal class CimOperationCallbackProcessingContext 12 | { 13 | private bool inUserCode; 14 | private object managedOperationContext; 15 | 16 | internal CimOperationCallbackProcessingContext(object managedOperationContext) 17 | { 18 | this.inUserCode = false; 19 | this.managedOperationContext = managedOperationContext; 20 | } 21 | 22 | internal bool InUserCode 23 | { 24 | get 25 | { 26 | return this.inUserCode; 27 | } 28 | set 29 | { 30 | this.inUserCode = value; 31 | } 32 | } 33 | 34 | internal object ManagedOperationContext 35 | { 36 | get 37 | { 38 | return this.managedOperationContext; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/ClassHandleExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | using System; 11 | using Microsoft.Management.Infrastructure.Native; 12 | 13 | namespace Microsoft.Management.Infrastructure.Internal 14 | { 15 | internal static class ClassHandleExtensionMethods 16 | { 17 | public static MI_Class Clone(this MI_Class handleToClone) 18 | { 19 | if (handleToClone == null) 20 | { 21 | return null; 22 | } 23 | // TODO: handleToClone.AssertValidInternalState(); 24 | 25 | MI_Class clonedHandle; 26 | MI_Result result = handleToClone.Clone(out clonedHandle); 27 | CimException.ThrowIfMiResultFailure(result); 28 | return clonedHandle; 29 | } 30 | 31 | public static MI_Class[] CloneMIArray(this MI_Class[] arrayToClone) 32 | { 33 | if (arrayToClone == null) 34 | { 35 | throw new ArgumentNullException(); 36 | } 37 | 38 | MI_Class[] result = new MI_Class[arrayToClone.Length]; 39 | try 40 | { 41 | for (int i = 0; i < arrayToClone.Length; i++) 42 | { 43 | MI_Class origClass = arrayToClone[i]; 44 | result[i] = origClass == null ? null : origClass.Clone(); 45 | } 46 | } 47 | catch 48 | { 49 | // If we encounter an exception halfway through we need to rollback 50 | for (int i = 0; i < arrayToClone.Length; i++) 51 | { 52 | if (arrayToClone[i] == null) 53 | { 54 | break; 55 | } 56 | 57 | arrayToClone[i].Delete(); 58 | } 59 | 60 | throw; 61 | } 62 | 63 | return result; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Data/CimClassPropertiesCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using Microsoft.Management.Infrastructure.Native; 13 | using System; 14 | using System.Collections.Generic; 15 | 16 | namespace Microsoft.Management.Infrastructure.Internal.Data 17 | { 18 | internal class CimClassPropertiesCollection : CimReadOnlyKeyedCollection 19 | { 20 | private readonly MI_Class classHandle; 21 | 22 | internal CimClassPropertiesCollection(MI_Class classHandle) 23 | { 24 | this.classHandle = classHandle; 25 | } 26 | 27 | public override int Count 28 | { 29 | get 30 | { 31 | uint count; 32 | MI_Result result = this.classHandle.GetElementCount(out count); 33 | CimException.ThrowIfMiResultFailure(result); 34 | return (int)count; 35 | } 36 | } 37 | 38 | public override CimPropertyDeclaration this[string propertyName] 39 | { 40 | get 41 | { 42 | if (string.IsNullOrWhiteSpace(propertyName)) 43 | { 44 | throw new ArgumentNullException("propertyName"); 45 | } 46 | 47 | MI_Value value; 48 | bool valueExists; 49 | MI_Type type; 50 | string referenceClass; 51 | MI_QualifierSet qualifierSet; 52 | MI_Flags flags; 53 | UInt32 index; 54 | 55 | MI_Result result = this.classHandle.GetElement(propertyName, 56 | out value, 57 | out valueExists, 58 | out type, 59 | out referenceClass, 60 | out qualifierSet, 61 | out flags, 62 | out index); 63 | 64 | switch (result) 65 | { 66 | case MI_Result.MI_RESULT_NO_SUCH_PROPERTY: 67 | return null; 68 | 69 | default: 70 | CimException.ThrowIfMiResultFailure(result); 71 | return new CimClassPropertyOfClass(this.classHandle, (int)index); 72 | } 73 | } 74 | } 75 | 76 | public override IEnumerator GetEnumerator() 77 | { 78 | int count = this.Count; 79 | for (int i = 0; i < count; i++) 80 | { 81 | yield return new CimClassPropertyOfClass(this.classHandle, i); 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Data/CimClassQualifierCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using Microsoft.Management.Infrastructure.Native; 13 | using System; 14 | using System.Collections.Generic; 15 | 16 | namespace Microsoft.Management.Infrastructure.Internal.Data 17 | { 18 | internal class CimClassQualifierCollection : CimReadOnlyKeyedCollection 19 | { 20 | private readonly MI_Class classHandle; 21 | 22 | internal CimClassQualifierCollection(MI_Class classHandle) 23 | { 24 | this.classHandle = classHandle; 25 | } 26 | 27 | public override int Count 28 | { 29 | get 30 | { 31 | MI_QualifierSet qualifierSet; 32 | MI_Result result = this.classHandle.GetClassQualifierSet(out qualifierSet); 33 | CimException.ThrowIfMiResultFailure(result); 34 | 35 | UInt32 count; 36 | result = qualifierSet.GetQualifierCount(out count); 37 | CimException.ThrowIfMiResultFailure(result); 38 | 39 | return (int)count; 40 | } 41 | } 42 | 43 | public override CimQualifier this[string qualifierName] 44 | { 45 | get 46 | { 47 | if (string.IsNullOrWhiteSpace(qualifierName)) 48 | { 49 | throw new ArgumentNullException("qualifierName"); 50 | } 51 | 52 | MI_QualifierSet qualifierSet; 53 | MI_Result result = this.classHandle.GetClassQualifierSet(out qualifierSet); 54 | CimException.ThrowIfMiResultFailure(result); 55 | // TODO: there aren't many comments for the above pattern throughout the MMI sources, but if the above fails we shouldn't throw exception, just return MI_RESULT_NOT_FOUND like below. Make sure all of these cases are accounted for in MMI 56 | 57 | MI_Type qualifierType; 58 | MI_Flags qualifierFlags; 59 | MI_Value qualifierValue; 60 | UInt32 index; 61 | 62 | result = qualifierSet.GetQualifier(qualifierName, 63 | out qualifierType, 64 | out qualifierFlags, 65 | out qualifierValue, 66 | out index); 67 | 68 | switch (result) 69 | { 70 | case MI_Result.MI_RESULT_NOT_FOUND: 71 | return null; 72 | 73 | default: 74 | CimException.ThrowIfMiResultFailure(result); 75 | return new CimQualifierOfClass(this.classHandle, (int)index); 76 | } 77 | } 78 | } 79 | 80 | public override IEnumerator GetEnumerator() 81 | { 82 | int count = this.Count; 83 | for (int i = 0; i < count; i++) 84 | { 85 | yield return new CimQualifierOfClass(this.classHandle, i); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Data/CimMethodDeclarationCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using Microsoft.Management.Infrastructure.Native; 13 | using System; 14 | using System.Collections.Generic; 15 | 16 | namespace Microsoft.Management.Infrastructure.Internal.Data 17 | { 18 | internal class CimMethodDeclarationCollection : CimReadOnlyKeyedCollection 19 | { 20 | private readonly MI_Class classHandle; 21 | 22 | internal CimMethodDeclarationCollection(MI_Class classHandle) 23 | { 24 | this.classHandle = classHandle; 25 | } 26 | 27 | public override int Count 28 | { 29 | get 30 | { 31 | uint count; 32 | MI_Result result = this.classHandle.GetMethodCount(out count); 33 | CimException.ThrowIfMiResultFailure(result); 34 | return (int)count; 35 | } 36 | } 37 | 38 | public override CimMethodDeclaration this[string methodName] 39 | { 40 | get 41 | { 42 | if (string.IsNullOrWhiteSpace(methodName)) 43 | { 44 | throw new ArgumentNullException("methodName"); 45 | } 46 | 47 | MI_QualifierSet qualifierSet; 48 | MI_ParameterSet parameterSet; 49 | UInt32 index; 50 | MI_Result result = this.classHandle.GetMethod(methodName, 51 | out qualifierSet, 52 | out parameterSet, 53 | out index); 54 | 55 | switch (result) 56 | { 57 | case MI_Result.MI_RESULT_METHOD_NOT_FOUND: 58 | return null; 59 | 60 | default: 61 | CimException.ThrowIfMiResultFailure(result); 62 | return new CimMethodDeclarationOfClass(this.classHandle, (int)index); 63 | } 64 | } 65 | } 66 | 67 | public override IEnumerator GetEnumerator() 68 | { 69 | int count = this.Count; 70 | for (int i = 0; i < count; i++) 71 | { 72 | yield return new CimMethodDeclarationOfClass(this.classHandle, i); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Data/CimMethodDeclarationOfClass.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using Microsoft.Management.Infrastructure.Native; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal.Data 15 | { 16 | internal sealed class CimMethodDeclarationOfClass : CimMethodDeclaration 17 | { 18 | private readonly MI_Class classHandle; 19 | private readonly int index; 20 | 21 | internal CimMethodDeclarationOfClass(MI_Class classHandle, int index) 22 | { 23 | this.classHandle = classHandle; 24 | this.index = index; 25 | } 26 | 27 | public override string Name 28 | { 29 | get 30 | { 31 | string name; 32 | MI_QualifierSet qualifierSet; 33 | MI_ParameterSet parameterSet; 34 | MI_Result result = this.classHandle.GetMethodAt( 35 | (uint)this.index, 36 | out name, 37 | out qualifierSet, 38 | out parameterSet); 39 | CimException.ThrowIfMiResultFailure(result); 40 | return name; 41 | } 42 | } 43 | 44 | public override CimType ReturnType 45 | { 46 | get 47 | { 48 | MI_Type type; 49 | 50 | string name; 51 | MI_QualifierSet qualifierSet; 52 | MI_ParameterSet parameterSet; 53 | MI_Result result = this.classHandle.GetMethodAt( 54 | (uint)this.index, 55 | out name, 56 | out qualifierSet, 57 | out parameterSet); 58 | CimException.ThrowIfMiResultFailure(result); 59 | result = parameterSet.GetMethodReturnType(out type, qualifierSet); 60 | CimException.ThrowIfMiResultFailure(result); 61 | return type.ToCimType(); 62 | } 63 | } 64 | 65 | public override CimReadOnlyKeyedCollection Parameters 66 | { 67 | get 68 | { 69 | return new CimMethodParameterDeclarationCollection(this.classHandle, index); 70 | } 71 | } 72 | 73 | public override CimReadOnlyKeyedCollection Qualifiers 74 | { 75 | get 76 | { 77 | return new CimMethodQualifierCollection(classHandle, this.index); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Data/CimPropertiesCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Generic; 12 | using Microsoft.Management.Infrastructure.Native; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Collections.Generic; 16 | 17 | namespace Microsoft.Management.Infrastructure.Internal.Data 18 | { 19 | internal class CimPropertiesCollection : CimKeyedCollection 20 | { 21 | private readonly CimInstance _instance; 22 | 23 | internal CimPropertiesCollection(CimInstance instance) 24 | { 25 | this._instance = instance; 26 | } 27 | 28 | public override void Add(CimProperty newProperty) 29 | { 30 | if (newProperty == null) 31 | { 32 | throw new ArgumentNullException("newProperty"); 33 | } 34 | 35 | MI_Result result = this._instance.InstanceHandle.AddElement( 36 | newProperty.Name, 37 | ValueHelpers.ConvertToNativeLayer(newProperty.Value, newProperty.CimType), 38 | newProperty.CimType.FromCimType(), 39 | newProperty.Flags.FromCimFlags()); 40 | CimException.ThrowIfMiResultFailure(result); 41 | } 42 | 43 | public override int Count 44 | { 45 | get 46 | { 47 | uint count; 48 | MI_Result result = this._instance.InstanceHandle.GetElementCount(out count); 49 | CimException.ThrowIfMiResultFailure(result); 50 | return (int)count; 51 | } 52 | } 53 | 54 | public override CimProperty this[string propertyName] 55 | { 56 | get 57 | { 58 | if (string.IsNullOrWhiteSpace(propertyName)) 59 | { 60 | throw new ArgumentNullException("propertyName"); 61 | } 62 | 63 | MI_Value value; 64 | MI_Type type; 65 | MI_Flags flags; 66 | UInt32 index; 67 | MI_Result result = this._instance.InstanceHandle.GetElement(propertyName, 68 | out value, 69 | out type, 70 | out flags, 71 | out index); 72 | switch (result) 73 | { 74 | case MI_Result.MI_RESULT_NO_SUCH_PROPERTY: 75 | return null; 76 | 77 | default: 78 | CimException.ThrowIfMiResultFailure(result); 79 | return new CimPropertyOfInstance(this._instance, (int)index); 80 | } 81 | } 82 | } 83 | 84 | public override IEnumerator GetEnumerator() 85 | { 86 | int count = this.Count; 87 | for (int i = 0; i < count; i++) 88 | { 89 | yield return new CimPropertyOfInstance(this._instance, i); 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/InstanceHandleExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using Microsoft.Management.Infrastructure.Native; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal 15 | { 16 | internal static class InstanceHandleExtensionMethods 17 | { 18 | public static MI_Instance Clone(this MI_Instance handleToClone) 19 | { 20 | if (handleToClone == null || handleToClone.IsNull) 21 | { 22 | throw new ArgumentNullException(); 23 | } 24 | 25 | MI_Instance clonedHandle; 26 | MI_Result result = handleToClone.Clone(out clonedHandle); 27 | CimException.ThrowIfMiResultFailure(result); 28 | return clonedHandle; 29 | } 30 | 31 | public static MI_Instance[] CloneMIArray(this MI_Instance[] arrayToClone) 32 | { 33 | if (arrayToClone == null) 34 | { 35 | throw new ArgumentNullException(); 36 | } 37 | 38 | MI_Instance[] result = new MI_Instance[arrayToClone.Length]; 39 | try 40 | { 41 | for (int i = 0; i < arrayToClone.Length; i++) 42 | { 43 | MI_Instance origInstance = arrayToClone[i]; 44 | result[i] = origInstance == null ? null : origInstance.Clone(); 45 | } 46 | } 47 | catch 48 | { 49 | // If we encounter an exception halfway through we need to rollback 50 | for (int i = 0; i < arrayToClone.Length; i++) 51 | { 52 | if (arrayToClone[i] == null) 53 | { 54 | break; 55 | } 56 | 57 | arrayToClone[i].Delete(); 58 | } 59 | 60 | throw; 61 | } 62 | 63 | return result; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/MiFlagsExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | using Microsoft.Management.Infrastructure.Native; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal 16 | { 17 | internal static class MiFlagsExtensionMethods 18 | { 19 | public static CimFlags ToCimFlags(this MI_Flags miFlags) 20 | { 21 | return (CimFlags)miFlags; 22 | } 23 | public static MI_Flags FromCimFlags(this CimFlags cimFlags) 24 | { 25 | return (MI_Flags)cimFlags; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/NativeErrorCodeExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using Microsoft.Management.Infrastructure.Native; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal 15 | { 16 | internal static class NativeErrorCodeExtensionMethods 17 | { 18 | public static NativeErrorCode ToNativeErrorCode(this MI_Result miResult) 19 | { 20 | return (NativeErrorCode)miResult; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CancellationMode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | namespace Microsoft.Management.Infrastructure.Internal.Operations 12 | { 13 | internal enum CancellationMode 14 | { 15 | NoCancellationOccured, 16 | ThrowOperationCancelledException, 17 | SilentlyStopProducingResults, 18 | IgnoreCancellationRequests 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncCancellationDisposable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | using System.Security; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal.Operations 16 | { 17 | internal sealed class CimAsyncCancellationDisposable : IDisposable 18 | { 19 | private readonly CimOperation _operation; 20 | private bool _disposed; 21 | private readonly object _disposeThreadSafetyLock = new object(); 22 | #if(!_CORECLR) 23 | private readonly SecurityContext _securityContext = SecurityContext.Capture(); 24 | #else 25 | // 26 | // TODO: WE NEED TO USE WINDOWS IDENTITY 27 | // 28 | //private readonly WindowsIdentity _windowsIdentiy = new WindowsIdentity( LogonUser() ); 29 | 30 | #endif 31 | 32 | internal CimAsyncCancellationDisposable(CimOperation operation) 33 | { 34 | Debug.Assert(operation != null, "Caller should verify that operation != null"); 35 | this._operation = operation; 36 | } 37 | 38 | #region IDisposable Members 39 | 40 | public void Dispose() 41 | { 42 | lock (this._disposeThreadSafetyLock) 43 | { 44 | if (_disposed) 45 | { 46 | return; 47 | } 48 | _disposed = true; 49 | } 50 | 51 | #if(!_CORECLR) 52 | SecurityContext.Run( 53 | this._securityContext, 54 | callback: _ => this._operation.Cancel(CancellationMode.SilentlyStopProducingResults), 55 | state: null); 56 | this._securityContext.Dispose(); 57 | #endif 58 | } 59 | 60 | #endregion IDisposable Members 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncClassObservable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Diagnostics; 16 | 17 | namespace Microsoft.Management.Infrastructure.Internal.Operations 18 | { 19 | internal class CimAsyncClassObservable : CimAsyncObservableBase 20 | { 21 | private readonly bool _shortenLifetimeOfResults; 22 | 23 | internal CimAsyncClassObservable( 24 | CimOperationOptions operationOptions, 25 | Func operationStarter) 26 | : base(operationOptions, operationStarter) 27 | { 28 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 29 | } 30 | 31 | internal override CimAsyncClassObserverProxy CreateObserverProxy(IObserver observer) 32 | { 33 | Debug.Assert(observer != null, "Caller should verify observer != null"); 34 | return new CimAsyncClassObserverProxy(observer, _shortenLifetimeOfResults); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncClassObserverProxy.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using System; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal.Operations 16 | { 17 | internal class CimAsyncClassObserverProxy : CimAsyncObserverProxyBase 18 | { 19 | private readonly bool _shortenLifetimeOfResults; 20 | 21 | internal CimAsyncClassObserverProxy(IObserver observer, bool shortenLifetimeOfResults) 22 | : base(observer) 23 | { 24 | this._shortenLifetimeOfResults = shortenLifetimeOfResults; 25 | } 26 | 27 | internal void ClassCallback( 28 | CimOperationCallbackProcessingContext callbackProcessingContext, 29 | MI_Operation operationHandle, 30 | MI_Class ClassHandle, 31 | bool moreResults, 32 | MI_Result operationResult, 33 | String errorMessage, 34 | MI_Instance errorDetailsHandle) 35 | { 36 | CimClass currentItem = null; 37 | if ((ClassHandle != null) && (!ClassHandle.IsNull)) 38 | { 39 | if (!_shortenLifetimeOfResults) 40 | { 41 | ClassHandle = ClassHandle.Clone(); 42 | } 43 | currentItem = new CimClass(ClassHandle); 44 | } 45 | 46 | try 47 | { 48 | this.ProcessNativeCallback(callbackProcessingContext, currentItem, moreResults, operationResult, errorMessage, errorDetailsHandle); 49 | } 50 | finally 51 | { 52 | if (_shortenLifetimeOfResults) 53 | { 54 | if (currentItem != null) 55 | { 56 | currentItem.Dispose(); 57 | } 58 | } 59 | } 60 | } 61 | 62 | public override void RegisterAcceptedAsyncCallbacks(MI_OperationCallbacks operationCallbacks, CimOperationOptions operationOptions) 63 | { 64 | base.RegisterAcceptedAsyncCallbacks(operationCallbacks, operationOptions); 65 | // TODO: Uncomment and fix below 66 | //operationCallbacks.classResult = this.ClassCallback; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncDelegatedObservable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | using System.Threading; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal.Operations 16 | { 17 | internal class CimAsyncDelegatedObservable : IObservable 18 | { 19 | private readonly Action> _subscribe; 20 | 21 | internal CimAsyncDelegatedObservable(Action> subscribe) 22 | { 23 | Debug.Assert(subscribe != null, "Caller should verify subscribe != null"); 24 | this._subscribe = subscribe; 25 | } 26 | 27 | #region IObservable Members 28 | 29 | public IDisposable Subscribe(IObserver observer) 30 | { 31 | if (observer == null) 32 | { 33 | throw new ArgumentNullException("observer"); 34 | } 35 | 36 | ThreadPool.QueueUserWorkItem( 37 | delegate 38 | { 39 | this._subscribe(observer); 40 | }); 41 | 42 | // cannot cancel delegate-based observables 43 | return EmptyDisposable.Singleton; 44 | } 45 | 46 | #endregion IObservable Members 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncIndicationObservable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Diagnostics; 16 | 17 | namespace Microsoft.Management.Infrastructure.Internal.Operations 18 | { 19 | internal class CimAsyncIndicationObservable : CimAsyncObservableBase 20 | { 21 | private readonly bool _shortenLifetimeOfResults; 22 | 23 | internal CimAsyncIndicationObservable( 24 | CimOperationOptions operationOptions, 25 | Func operationStarter) 26 | : base(operationOptions, operationStarter) 27 | { 28 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 29 | } 30 | 31 | internal override CimAsyncIndicationObserverProxy CreateObserverProxy(IObserver observer) 32 | { 33 | Debug.Assert(observer != null, "Caller should verify observer != null"); 34 | return new CimAsyncIndicationObserverProxy(observer, _shortenLifetimeOfResults); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncIndicationObserverProxy.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using System; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal.Operations 16 | { 17 | internal class CimAsyncIndicationObserverProxy : CimAsyncObserverProxyBase 18 | { 19 | private readonly bool _shortenLifetimeOfResults; 20 | 21 | internal CimAsyncIndicationObserverProxy(IObserver observer, bool shortenLifetimeOfResults) 22 | : base(observer) 23 | { 24 | this._shortenLifetimeOfResults = shortenLifetimeOfResults; 25 | } 26 | 27 | internal void IndicationResultCallback( 28 | CimOperationCallbackProcessingContext callbackProcessingContext, 29 | MI_Operation operationHandle, 30 | MI_Instance instanceHandle, 31 | String bookMark, 32 | String machineID, 33 | bool moreResults, 34 | MI_Result operationResult, 35 | String errorMessage, 36 | MI_Instance errorDetailsHandle) 37 | { 38 | CimSubscriptionResult currentItem = null; 39 | if ((instanceHandle != null) && (!instanceHandle.IsNull)) 40 | { 41 | if (!_shortenLifetimeOfResults) 42 | { 43 | instanceHandle = instanceHandle.Clone(); 44 | } 45 | currentItem = new CimSubscriptionResult(instanceHandle, bookMark, machineID); 46 | } 47 | 48 | try 49 | { 50 | this.ProcessNativeCallback(callbackProcessingContext, currentItem, moreResults, operationResult, errorMessage, errorDetailsHandle); 51 | } 52 | finally 53 | { 54 | if (_shortenLifetimeOfResults) 55 | { 56 | if (currentItem != null) 57 | { 58 | currentItem.Dispose(); 59 | } 60 | } 61 | } 62 | } 63 | 64 | public override void RegisterAcceptedAsyncCallbacks(MI_OperationCallbacks operationCallbacks, CimOperationOptions operationOptions) 65 | { 66 | base.RegisterAcceptedAsyncCallbacks(operationCallbacks, operationOptions); 67 | // TODO: Uncomment and fix below 68 | //operationCallbacks.indicationResult = this.IndicationResultCallback; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncInstanceObservable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Diagnostics; 16 | 17 | namespace Microsoft.Management.Infrastructure.Internal.Operations 18 | { 19 | internal class CimAsyncInstanceObservable : CimAsyncObservableBase 20 | { 21 | private readonly bool _shortenLifetimeOfResults; 22 | private readonly Guid _CimSessionInstanceID; 23 | private readonly string _CimSessionComputerName; 24 | 25 | internal CimAsyncInstanceObservable( 26 | CimOperationOptions operationOptions, 27 | Guid cimSessionInstanceID, 28 | string cimSessionComputerName, 29 | Func operationStarter) 30 | : base(operationOptions, operationStarter) 31 | { 32 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 33 | this._CimSessionInstanceID = cimSessionInstanceID; 34 | this._CimSessionComputerName = cimSessionComputerName; 35 | } 36 | 37 | internal override CimAsyncInstanceObserverProxy CreateObserverProxy(IObserver observer) 38 | { 39 | Debug.Assert(observer != null, "Caller should verify observer != null"); 40 | return new CimAsyncInstanceObserverProxy(observer, 41 | this._CimSessionInstanceID, 42 | this._CimSessionComputerName, 43 | _shortenLifetimeOfResults); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncInstanceObserverProxy.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using System; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal.Operations 16 | { 17 | internal class CimAsyncInstanceObserverProxy : CimAsyncObserverProxyBase 18 | { 19 | private readonly bool _shortenLifetimeOfResults; 20 | private readonly Guid _CimSessionInstanceID; 21 | private readonly string _CimSessionComputerName; 22 | 23 | internal CimAsyncInstanceObserverProxy(IObserver observer, 24 | Guid cimSessionInstanceID, 25 | string cimSessionComputerName, 26 | bool shortenLifetimeOfResults) 27 | : base(observer) 28 | { 29 | this._shortenLifetimeOfResults = shortenLifetimeOfResults; 30 | this._CimSessionInstanceID = cimSessionInstanceID; 31 | this._CimSessionComputerName = cimSessionComputerName; 32 | } 33 | 34 | internal void InstanceResultCallback( 35 | CimOperationCallbackProcessingContext callbackProcessingContext, 36 | MI_Operation operationHandle, 37 | MI_Instance instanceHandle, 38 | bool moreResults, 39 | MI_Result operationResult, 40 | String errorMessage, 41 | MI_Instance errorDetailsHandle) 42 | { 43 | CimInstance currentItem = null; 44 | if ((instanceHandle != null) && (!instanceHandle.IsNull)) 45 | { 46 | if (!_shortenLifetimeOfResults) 47 | { 48 | instanceHandle = instanceHandle.Clone(); 49 | } 50 | currentItem = new CimInstance(instanceHandle); 51 | currentItem.SetCimSessionComputerName(this._CimSessionComputerName); 52 | currentItem.SetCimSessionInstanceId(this._CimSessionInstanceID); 53 | } 54 | 55 | try 56 | { 57 | this.ProcessNativeCallback(callbackProcessingContext, currentItem, moreResults, operationResult, errorMessage, errorDetailsHandle); 58 | } 59 | finally 60 | { 61 | if (_shortenLifetimeOfResults) 62 | { 63 | if (currentItem != null) 64 | { 65 | currentItem.Dispose(); 66 | } 67 | } 68 | } 69 | } 70 | 71 | public override void RegisterAcceptedAsyncCallbacks(MI_OperationCallbacks operationCallbacks, CimOperationOptions operationOptions) 72 | { 73 | base.RegisterAcceptedAsyncCallbacks(operationCallbacks, operationOptions); 74 | // TODO: Uncomment and fix below 75 | //operationCallbacks.instanceResult = this.InstanceResultCallback; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncMethodResultObservable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Diagnostics; 16 | 17 | namespace Microsoft.Management.Infrastructure.Internal.Operations 18 | { 19 | internal class CimAsyncMethodResultObservable : CimAsyncObservableBase 20 | { 21 | private readonly bool _shortenLifetimeOfResults; 22 | private readonly Guid _CimSessionInstanceID; 23 | private readonly string _CimSessionComputerName; 24 | 25 | internal CimAsyncMethodResultObservable( 26 | CimOperationOptions operationOptions, 27 | Guid cimSessionInstanceID, 28 | string cimSessionComputerName, 29 | Func operationStarter) 30 | : base(operationOptions, operationStarter) 31 | { 32 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 33 | this._CimSessionInstanceID = cimSessionInstanceID; 34 | this._CimSessionComputerName = cimSessionComputerName; 35 | } 36 | 37 | internal override CimAsyncMethodResultObserverProxy CreateObserverProxy(IObserver observer) 38 | { 39 | Debug.Assert(observer != null, "Caller should verify observer != null"); 40 | return new CimAsyncMethodResultObserverProxy(observer, 41 | this._CimSessionInstanceID, 42 | this._CimSessionComputerName, 43 | this._shortenLifetimeOfResults); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimAsyncObservableBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Diagnostics; 16 | using System.Threading; 17 | 18 | namespace Microsoft.Management.Infrastructure.Internal.Operations 19 | { 20 | internal abstract class CimAsyncObservableBase : IObservable 21 | where TObserverProxy : CimAsyncObserverProxyBase 22 | where TResult : class 23 | { 24 | private readonly Func _operationStarter; 25 | private readonly CancellationToken? _cancellationToken; 26 | private readonly bool _reportOperationStarted; 27 | 28 | internal CimAsyncObservableBase( 29 | CimOperationOptions operationOptions, 30 | Func operationStarter) 31 | { 32 | Debug.Assert(operationStarter != null, "Caller should verify operationStarter != null"); 33 | this._operationStarter = operationStarter; 34 | 35 | this._cancellationToken = operationOptions.GetCancellationToken(); 36 | this._reportOperationStarted = operationOptions.GetReportOperationStarted(); 37 | } 38 | 39 | internal abstract TObserverProxy CreateObserverProxy(IObserver observer); 40 | 41 | #region IObservable Members 42 | 43 | public IDisposable Subscribe(IObserver observer) 44 | { 45 | if (observer == null) 46 | { 47 | throw new ArgumentNullException("observer"); 48 | } 49 | 50 | TObserverProxy observerProxy = this.CreateObserverProxy(observer); 51 | observerProxy.SetReportOperationStarted(this._reportOperationStarted); 52 | 53 | MI_Operation operationHandle = this._operationStarter(observerProxy); 54 | CimOperation operation = new CimOperation(operationHandle, this._cancellationToken); 55 | 56 | observerProxy.SetOperation(operation); 57 | return new CimAsyncCancellationDisposable(operation); 58 | } 59 | 60 | #endregion IObservable Members 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncClassEnumerable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | 16 | namespace Microsoft.Management.Infrastructure.Internal.Operations 17 | { 18 | internal class CimSyncClassEnumerable : CimSyncEnumerableBase 19 | { 20 | private readonly bool _shortenLifetimeOfResults; 21 | 22 | internal CimSyncClassEnumerable( 23 | CimOperationOptions operationOptions, 24 | Func operationStarter) 25 | : base(operationOptions, operationStarter) 26 | { 27 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 28 | } 29 | 30 | internal override CimSyncClassEnumerator CreateEnumerator() 31 | { 32 | return new CimSyncClassEnumerator(this._shortenLifetimeOfResults); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncClassEnumerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System.Diagnostics; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal.Operations 15 | { 16 | internal class CimSyncClassEnumerator : CimSyncEnumeratorBase 17 | { 18 | internal CimSyncClassEnumerator(bool shortenLifetimeOfResults) 19 | : base(shortenLifetimeOfResults) 20 | { 21 | } 22 | 23 | internal override MI_Result NativeMoveNext(MI_Operation operationHandle, out CimClass currentItem, 24 | out bool moreResults, out MI_Result operationResult, 25 | out string errorMessage, out MI_Instance errorDetailsHandle) 26 | { 27 | Debug.Assert(operationHandle != null, "Caller should verify operationHandle != null"); 28 | 29 | currentItem = null; 30 | 31 | MI_Class classHandle; 32 | MI_Result functionResult = operationHandle.GetClass( 33 | out classHandle, 34 | out moreResults, 35 | out operationResult, 36 | out errorMessage, 37 | out errorDetailsHandle); 38 | 39 | if ((classHandle != null) && !classHandle.IsNull) 40 | { 41 | if (!this.ShortenLifetimeOfResults) 42 | { 43 | classHandle = classHandle.Clone(); 44 | } 45 | currentItem = new CimClass(classHandle); 46 | } 47 | 48 | return functionResult; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncEnumerableBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | using System.Collections.Generic; 16 | using System.Diagnostics; 17 | using System.Threading; 18 | 19 | namespace Microsoft.Management.Infrastructure.Internal.Operations 20 | { 21 | internal abstract class CimSyncEnumerableBase : IEnumerable 22 | where TEnumerator : CimSyncEnumeratorBase, IEnumerator 23 | where TItem : class 24 | { 25 | private readonly CancellationToken? _cancellationToken; 26 | private readonly Func _operationStarter; 27 | 28 | internal CimSyncEnumerableBase(CimOperationOptions operationOptions, Func operationStarter) 29 | { 30 | Debug.Assert(operationStarter != null, "Caller should verify that operationStarter != null"); 31 | 32 | this._cancellationToken = operationOptions.GetCancellationToken(); 33 | this._operationStarter = operationStarter; 34 | } 35 | 36 | internal abstract TEnumerator CreateEnumerator(); 37 | 38 | #region IEnumerable Members 39 | 40 | public IEnumerator GetEnumerator() 41 | { 42 | TEnumerator enumerator = this.CreateEnumerator(); 43 | CimOperation operation; 44 | 45 | MI_Operation operationHandle = this._operationStarter(enumerator); 46 | operation = new CimOperation(operationHandle, this._cancellationToken); 47 | 48 | enumerator.SetOperation(operation); 49 | return enumerator; 50 | } 51 | 52 | #endregion IEnumerable Members 53 | 54 | #region IEnumerable Members 55 | 56 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 57 | { 58 | return this.GetEnumerator(); 59 | } 60 | 61 | #endregion IEnumerable Members 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncIndicationEnumerable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | 16 | namespace Microsoft.Management.Infrastructure.Internal.Operations 17 | { 18 | internal class CimSyncIndicationEnumerable : CimSyncEnumerableBase 19 | { 20 | private readonly bool _shortenLifetimeOfResults; 21 | 22 | internal CimSyncIndicationEnumerable( 23 | CimOperationOptions operationOptions, 24 | Func operationStarter) 25 | : base(operationOptions, operationStarter) 26 | { 27 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 28 | } 29 | 30 | internal override CimSyncIndicationEnumerator CreateEnumerator() 31 | { 32 | return new CimSyncIndicationEnumerator(this._shortenLifetimeOfResults); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncIndicationEnumerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System.Diagnostics; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal.Operations 15 | { 16 | internal class CimSyncIndicationEnumerator : CimSyncEnumeratorBase 17 | { 18 | internal CimSyncIndicationEnumerator(bool shortenLifetimeOfResults) 19 | : base(shortenLifetimeOfResults) 20 | { 21 | } 22 | 23 | internal override MI_Result NativeMoveNext(MI_Operation operationHandle, out CimSubscriptionResult currentItem, 24 | out bool moreResults, out MI_Result operationResult, 25 | out string errorMessage, out MI_Instance errorDetailsHandle) 26 | { 27 | Debug.Assert(operationHandle != null, "Caller should verify operationHandle != null"); 28 | 29 | currentItem = null; 30 | 31 | MI_Instance instanceHandle; 32 | string bookmark; 33 | string machineID; 34 | MI_Result functionResult = operationHandle.GetIndication( 35 | out instanceHandle, 36 | out bookmark, 37 | out machineID, 38 | out moreResults, 39 | out operationResult, 40 | out errorMessage, 41 | out errorDetailsHandle); 42 | 43 | if ((instanceHandle != null) && !instanceHandle.IsNull) 44 | { 45 | if (!this.ShortenLifetimeOfResults) 46 | { 47 | instanceHandle = instanceHandle.Clone(); 48 | } 49 | currentItem = new CimSubscriptionResult(instanceHandle, bookmark, machineID); 50 | } 51 | 52 | return functionResult; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncInstanceEnumerable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using Microsoft.Management.Infrastructure.Options; 13 | using Microsoft.Management.Infrastructure.Options.Internal; 14 | using System; 15 | 16 | namespace Microsoft.Management.Infrastructure.Internal.Operations 17 | { 18 | internal class CimSyncInstanceEnumerable : CimSyncEnumerableBase 19 | { 20 | private readonly bool _shortenLifetimeOfResults; 21 | private readonly Guid _CimSessionInstanceID; 22 | private readonly string _CimSessionComputerName; 23 | 24 | internal CimSyncInstanceEnumerable( 25 | CimOperationOptions operationOptions, 26 | Guid cimSessionInstanceID, 27 | string cimSessionComputerName, 28 | Func operationStarter) 29 | : base(operationOptions, operationStarter) 30 | { 31 | this._shortenLifetimeOfResults = operationOptions.GetShortenLifetimeOfResults(); 32 | this._CimSessionInstanceID = cimSessionInstanceID; 33 | this._CimSessionComputerName = cimSessionComputerName; 34 | } 35 | 36 | internal override CimSyncInstanceEnumerator CreateEnumerator() 37 | { 38 | return new CimSyncInstanceEnumerator( 39 | this._CimSessionInstanceID, 40 | this._CimSessionComputerName, 41 | this._shortenLifetimeOfResults); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/CimSyncInstanceEnumerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System; 13 | using System.Diagnostics; 14 | 15 | namespace Microsoft.Management.Infrastructure.Internal.Operations 16 | { 17 | internal class CimSyncInstanceEnumerator : CimSyncEnumeratorBase 18 | { 19 | private readonly Guid _CimSessionInstanceID; 20 | private readonly string _CimSessionComputerName; 21 | 22 | internal CimSyncInstanceEnumerator( 23 | Guid cimSessionInstanceID, 24 | string cimSessionComputerName, 25 | bool shortenLifetimeOfResults) 26 | : base(shortenLifetimeOfResults) 27 | { 28 | this._CimSessionInstanceID = cimSessionInstanceID; 29 | this._CimSessionComputerName = cimSessionComputerName; 30 | } 31 | 32 | internal override MI_Result NativeMoveNext(MI_Operation operationHandle, out CimInstance currentItem, out bool moreResults, out MI_Result operationResult, out string errorMessage, out MI_Instance errorDetailsHandle) 33 | { 34 | Debug.Assert(operationHandle != null, "Caller should verify operationHandle != null"); 35 | 36 | currentItem = null; 37 | 38 | MI_Instance instanceHandle; 39 | MI_Result functionResult = operationHandle.GetInstance( 40 | out instanceHandle, 41 | out moreResults, 42 | out operationResult, 43 | out errorMessage, 44 | out errorDetailsHandle); 45 | 46 | if ((instanceHandle != null) && !instanceHandle.IsNull) 47 | { 48 | if (!this.ShortenLifetimeOfResults) 49 | { 50 | instanceHandle = instanceHandle.Clone(); 51 | } 52 | currentItem = new CimInstance(instanceHandle); 53 | currentItem.SetCimSessionComputerName(this._CimSessionComputerName); 54 | currentItem.SetCimSessionInstanceId(this._CimSessionInstanceID); 55 | } 56 | 57 | return functionResult; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/ConvertingObservable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Diagnostics; 13 | 14 | namespace Microsoft.Management.Infrastructure.Internal.Operations 15 | { 16 | internal sealed class ConvertingObservable : IObservable 17 | where TTargetType : class 18 | { 19 | private readonly IObservable _wrappedObservable; 20 | 21 | internal ConvertingObservable(IObservable wrappedObservable) 22 | { 23 | Debug.Assert(wrappedObservable != null, "Caller should verify wrappedObservable != null"); 24 | this._wrappedObservable = wrappedObservable; 25 | } 26 | 27 | public IDisposable Subscribe(IObserver observer) 28 | { 29 | var observerProxy = new ConvertingObserverProxy(observer); 30 | return this._wrappedObservable.Subscribe(observerProxy); 31 | } 32 | 33 | private class ConvertingObserverProxy : IObserver 34 | { 35 | private readonly IObserver _targetObserver; 36 | 37 | internal ConvertingObserverProxy(IObserver targetObserver) 38 | { 39 | Debug.Assert(targetObserver != null, "targetObserver != null"); 40 | this._targetObserver = targetObserver; 41 | } 42 | 43 | public void OnCompleted() 44 | { 45 | this._targetObserver.OnCompleted(); 46 | } 47 | 48 | public void OnError(Exception error) 49 | { 50 | this._targetObserver.OnError(error); 51 | } 52 | 53 | public void OnNext(TWrappedType value) 54 | { 55 | var targetValue = value as TTargetType; 56 | Debug.Assert(targetValue != null, "Expecting the conversion to always succeed"); 57 | this._targetObserver.OnNext(targetValue); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/Operations/EmptyDisposable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | 13 | namespace Microsoft.Management.Infrastructure.Internal.Operations 14 | { 15 | internal sealed class EmptyDisposable : IDisposable 16 | { 17 | private EmptyDisposable() 18 | { 19 | // should only instantiate through Singleton property 20 | } 21 | 22 | /// 23 | /// Releases resources associated with this object 24 | /// 25 | public void Dispose() 26 | { 27 | // a no-op 28 | } 29 | 30 | private static readonly Lazy lazySingleton = new Lazy( 31 | valueFactory: () => new EmptyDisposable(), 32 | isThreadSafe: true); 33 | 34 | internal static EmptyDisposable Singleton 35 | { 36 | get 37 | { 38 | return lazySingleton.Value; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Internal/SanityHelpers.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using System; 12 | using System.Collections; 13 | using System.Globalization; 14 | using System.Linq; 15 | using System.Text; 16 | 17 | namespace Microsoft.Management.Infrastructure.Internal 18 | { 19 | internal static class SanityHelpers 20 | { 21 | public static void AssertUnusedArg(object shouldBeNull) 22 | { 23 | if (shouldBeNull != null) 24 | { 25 | throw new NotSupportedException(); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Microsoft.Management.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | true 6 | 2.0.0-preview.1 7 | true 8 | ../signing/visualstudiopublic.snk" 9 | true 10 | 0649 11 | 12 | 13 | 14 | $(DefineConstants);_CORECLR;_LINUX 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_AuthType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | public class MI_AuthType 12 | { 13 | public static string DEFAULT = "Default"; 14 | public static string NONE = "None"; 15 | public static string DIGEST = "Digest"; 16 | public static string NEGO_WITH_CREDS = "NegoWithCreds"; 17 | public static string NEGO_NO_CREDS = "NegoNoCreds"; 18 | public static string BASIC = "Basic"; 19 | public static string KERBEROS = "Kerberos"; 20 | public static string CLIENT_CERTS = "ClientCerts"; 21 | public static string NTLM = "Ntlmdomain"; 22 | public static string CREDSSP = "CredSSP"; 23 | public static string ISSUER_CERT = "IssuerCert"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_CallbackMode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | public enum MI_CallbackMode : uint 12 | { 13 | Report = 0, 14 | Inquire = 1, 15 | Ignore = 2, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_CancellationReason.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_CancellationReason : uint 12 | { 13 | MI_REASON_NONE = 0, 14 | MI_REASON_TIMEOUT, 15 | MI_REASON_SHUTDOWN, 16 | MI_REASON_SERVICESTOP 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_DestinationOptionsFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_DestinationOptionsFlags : uint 12 | { 13 | Unused = 0 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_Flags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | [Flags] 14 | internal enum MI_Flags 15 | { 16 | None = 0, 17 | /* CIM meta types (or qualifier scopes) */ 18 | MI_FLAG_CLASS = (1 << 0), 19 | MI_FLAG_METHOD = (1 << 1), 20 | MI_FLAG_PROPERTY = (1 << 2), 21 | MI_FLAG_PARAMETER = (1 << 3), 22 | MI_FLAG_ASSOCIATION = (1 << 4), 23 | MI_FLAG_INDICATION = (1 << 5), 24 | MI_FLAG_REFERENCE = (1 << 6), 25 | MI_FLAG_ANY = (1 | 2 | 4 | 8 | 16 | 32 | 64), 26 | 27 | /* Qualifier flavors */ 28 | MI_FLAG_ENABLEOVERRIDE = (1 << 7), 29 | MI_FLAG_DISABLEOVERRIDE = (1 << 8), 30 | MI_FLAG_RESTRICTED = (1 << 9), 31 | MI_FLAG_TOSUBCLASS = (1 << 10), 32 | MI_FLAG_TRANSLATABLE = (1 << 11), 33 | 34 | /* Select boolean qualifier */ 35 | MI_FLAG_KEY = (1 << 12), 36 | MI_FLAG_IN = (1 << 13), 37 | MI_FLAG_OUT = (1 << 14), 38 | MI_FLAG_REQUIRED = (1 << 15), 39 | MI_FLAG_STATIC = (1 << 16), 40 | MI_FLAG_ABSTRACT = (1 << 17), 41 | MI_FLAG_TERMINAL = (1 << 18), 42 | MI_FLAG_EXPENSIVE = (1 << 19), 43 | MI_FLAG_STREAM = (1 << 20), 44 | MI_FLAG_READONLY = (1 << 21), 45 | 46 | /* Special flags */ 47 | MI_FLAG_EXTENDED = (1 << 12), 48 | MI_FLAG_NOT_MODIFIED = (1 << 25), // indicates that the property is not modified 49 | MI_FLAG_VERSION = (1 << 26 | 1 << 27 | 1 << 28), 50 | MI_FLAG_NULL = (1 << 29), 51 | MI_FLAG_BORROW = (1 << 30), 52 | MI_FLAG_ADOPT = (1 << 31) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_ImpersonationType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | public enum MI_ImpersonationType : uint 12 | { 13 | Default = 0, 14 | None = 1, 15 | Identify = 2, 16 | Impersonate = 3, 17 | Delegate = 4, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_ModuleFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | [Flags] 14 | internal enum MI_ModuleFlags 15 | { 16 | /** Whether standard qualifiers were generated */ 17 | MI_MODULE_FLAG_STANDARD_QUALIFIERS = (1 << 0), 18 | 19 | /** Whether description qualifiers were generated */ 20 | MI_MODULE_FLAG_DESCRIPTIONS = (1 << 1), 21 | 22 | /** Whether Values and ValueMap qualifiers were generated */ 23 | MI_MODULE_FLAG_VALUES = (1 << 2), 24 | 25 | /** Whether the MappingStrings qualifiers were generated */ 26 | MI_MODULE_FLAG_MAPPING_STRINGS = (1 << 3), 27 | 28 | /** Whether the boolean qualifiers were generated */ 29 | MI_MODULE_FLAG_BOOLEANS = (1 << 4), 30 | 31 | /** Whether C++ extensions were generated */ 32 | MI_MODULE_FLAG_CPLUSPLUS = (1 << 5), 33 | 34 | /** Whether translatable qualifiers were localized = (and STRING.RC generated), */ 35 | MI_MODULE_FLAG_LOCALIZED = (1 << 6), 36 | 37 | /** Whether filters are supported */ 38 | MI_MODULE_FLAG_FILTER_SUPPORT = (1 << 7) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_OperationCallback_ResponseType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_OperationCallback_ResponseType : uint 12 | { 13 | No = 0, 14 | Yes = 1, 15 | NoToAll = 2, 16 | YesToAll = 3 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_OperationFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | /* Flags to be passed into Session operation functions. 14 | * One item from each group can be bit-wise combined. 15 | */ 16 | 17 | [Flags] 18 | internal enum MI_OperationFlags 19 | { 20 | Default = 0x0000, 21 | MI_OPERATIONFLAGS_AUTOMATIC_ACK_RESULTS = 0x0000, 22 | MI_OPERATIONFLAGS_MANUAL_ACK_RESULTS = 0x0001, 23 | 24 | /* RTTI bitmasks in order to specify what options are acceptable to the client */ 25 | MI_OPERATIONFLAGS_NO_RTTI = 0x0400, /* All instance elements are string except embedded objects and references, but their elements will be strings also */ 26 | MI_OPERATIONFLAGS_BASIC_RTTI = 0x0002, /* All instance elements may be strings or the correct type */ 27 | MI_OPERATIONFLAGS_STANDARD_RTTI = 0x0800, /* All instance elements are of the correct type, but some hierarchy information may be lost due to optimizations */ 28 | MI_OPERATIONFLAGS_FULL_RTTI = 0x0004, /* All instance elements at every level of the instances class hierarchy will be accurate. This may be very expensive */ 29 | 30 | /* If no RTTI flag is specified (i.e. 0 for relevant RTTI bits) then the protocol handler itself will pick the best option */ 31 | MI_OPERATIONFLAGS_DEFAULT_RTTI = 0x0000, 32 | 33 | MI_OPERATIONFLAGS_NON_LOCALIZED_QUALIFIERS = 0x0000, 34 | MI_OPERATIONFLAGS_LOCALIZED_QUALIFIERS = 0x0008, 35 | 36 | MI_OPERATIONFLAGS_NON_EXPENSIVE_PROPERTIES_ONLY = 0x0000, 37 | MI_OPERATIONFLAGS_EXPENSIVE_PROPERTIES = 0x0040, 38 | 39 | MI_OPERATIONFLAGS_POLYMORPHISM_DEEP = 0x0000, 40 | MI_OPERATIONFLAGS_POLYMORPHISM_SHALLOW = 0x0080, 41 | MI_OPERATIONFLAGS_POLYMORPHISM_DEEP_BASE_PROPS_ONLY = 0x0180, 42 | 43 | /* Report an empty result when the operation has successfully started. 44 | * The first result may have a NULL instance/class/indication, with 45 | * moreResults set to MI_TRUE. If a result is delivered very quickly 46 | * the actual result will be delivered instead. 47 | * Not all operations or protocol handlers can achieve this. 48 | */ 49 | MI_OPERATIONFLAGS_REPORT_OPERATION_STARTED = 0x0200 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_OperationOptionsFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_OperationOptionsFlags : uint 12 | { 13 | Unused = 0 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_PacketEncoding.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | public class MI_PacketEncoding 12 | { 13 | public static string Default = "default"; 14 | public static string UTF8 = "UTF8"; 15 | public static string UTF16 = "UTF16"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_PromptType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_PromptType : uint 12 | { 13 | Normal = 0, 14 | Critical = 1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_Protocol.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal class MI_Protocol 12 | { 13 | internal const string DCOM = "WMIDCOM"; 14 | internal const string WSMan = "WINRM"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_ProxyType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | public class MI_ProxyType 12 | { 13 | public static string None = "None"; 14 | public static string WinHTTP = "WinHTTP"; 15 | public static string Auto = "Auto"; 16 | public static string IE = "IE"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_SerializationFormat.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal static class MI_SerializationFormat 12 | { 13 | internal const string XML = "MI_XML"; 14 | internal const string MOF = "MI_MOF_CIMV2_EXTV1"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_SerializerFlags.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_SerializerFlags 12 | { 13 | None = 0 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_SubscriptionDeliveryType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_SubscriptionDeliveryType : uint 12 | { 13 | MI_SubscriptionDeliveryType_Pull = 1, 14 | MI_SubscriptionDeliveryType_Push = 2, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_Transport.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | public class MI_Transport 12 | { 13 | public static string HTTPS = "HTTPS"; 14 | public static string HTTP = "HTTP"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_Type.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal class MI_TypeFlags 12 | { 13 | /* MI_ARRAY is not an actual type, rather this is the bit that signifies 14 | * the type is an array */ 15 | internal const MI_Type MI_ARRAY = (MI_Type)16; 16 | } 17 | 18 | internal enum MI_Type : uint 19 | { 20 | MI_BOOLEAN = 0, 21 | MI_UINT8 = 1, 22 | MI_SINT8 = 2, 23 | MI_UINT16 = 3, 24 | MI_SINT16 = 4, 25 | MI_UINT32 = 5, 26 | MI_SINT32 = 6, 27 | MI_UINT64 = 7, 28 | MI_SINT64 = 8, 29 | MI_REAL32 = 9, 30 | MI_REAL64 = 10, 31 | MI_CHAR16 = 11, 32 | MI_DATETIME = 12, 33 | MI_STRING = 13, 34 | MI_REFERENCE = 14, 35 | MI_INSTANCE = 15, 36 | MI_BOOLEANA = 16, 37 | MI_UINT8A = 17, 38 | MI_SINT8A = 18, 39 | MI_UINT16A = 19, 40 | MI_SINT16A = 20, 41 | MI_UINT32A = 21, 42 | MI_SINT32A = 22, 43 | MI_UINT64A = 23, 44 | MI_SINT64A = 24, 45 | MI_REAL32A = 25, 46 | MI_REAL64A = 26, 47 | MI_CHAR16A = 27, 48 | MI_DATETIMEA = 28, 49 | MI_STRINGA = 29, 50 | MI_REFERENCEA = 30, 51 | MI_INSTANCEA = 31 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Enumerations/MI_WriteMessageChannel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | internal enum MI_WriteMessageChannel : uint 12 | { 13 | Warning = 0, 14 | Verbose = 1, 15 | Debug = 2 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/MI_ClassDecl.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace Microsoft.Management.Infrastructure.Native 13 | { 14 | internal class MI_ClassDecl : MI_NativeObject 15 | { 16 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 17 | private struct MI_ClassDeclMembers 18 | { 19 | internal UInt32 flags; 20 | internal UInt32 code; 21 | internal string name; 22 | internal IntPtr qualifiers; 23 | internal UInt32 numQualifiers; 24 | internal IntPtr properties; 25 | internal UInt32 numProperties; 26 | internal UInt32 size; 27 | internal string superClass; 28 | internal DirectPtr superClassDecl; 29 | internal IntPtr methods; 30 | internal UInt32 numMethods; 31 | internal IntPtr schema; 32 | internal IntPtr providerFT; 33 | internal IntPtr owningClass; 34 | } 35 | 36 | // Marshal implements these with Reflection - pay this hit only once 37 | private static int MI_ClassDeclMembersSize = Marshal.SizeOf(); 38 | 39 | private MI_ClassDecl(bool isDirect) : base(isDirect) 40 | { 41 | } 42 | 43 | private MI_ClassDecl(IntPtr existingPtr) : base(existingPtr) 44 | { 45 | } 46 | 47 | internal static MI_ClassDecl NewDirectPtr() 48 | { 49 | return new MI_ClassDecl(true); 50 | } 51 | 52 | internal static MI_ClassDecl NewIndirectPtr() 53 | { 54 | return new MI_ClassDecl(false); 55 | } 56 | 57 | internal static MI_ClassDecl NewFromDirectPtr(IntPtr ptr) 58 | { 59 | return new MI_ClassDecl(ptr); 60 | } 61 | 62 | internal static MI_ClassDecl Null { get { return null; } } 63 | 64 | protected override int MembersSize { get { return MI_ClassDeclMembersSize; } } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/MI_FunctionTableCache.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Runtime.InteropServices; 11 | using System.Collections.Concurrent; 12 | 13 | namespace Microsoft.Management.Infrastructure.Native 14 | { 15 | internal static class MI_FunctionTableCache 16 | { 17 | internal static ConcurrentDictionary functionPtrCache; 18 | 19 | static MI_FunctionTableCache() 20 | { 21 | MI_FunctionTableCache.functionPtrCache = new ConcurrentDictionary(); 22 | } 23 | 24 | internal static unsafe T GetFTAsOffsetFromPtr(IntPtr ptr, int offset) where T : new() 25 | { 26 | IntPtr ftPtr = IntPtr.Zero; 27 | unsafe 28 | { 29 | // Just as easily could be implemented with Marshal 30 | // but that would copy more than the one pointer we need 31 | IntPtr structurePtr = ptr; 32 | if (structurePtr == IntPtr.Zero) 33 | { 34 | throw new InvalidOperationException(); 35 | } 36 | 37 | ftPtr = *((IntPtr*)((byte*)structurePtr + offset)); 38 | } 39 | 40 | if (ftPtr == IntPtr.Zero) 41 | { 42 | throw new InvalidOperationException(); 43 | } 44 | 45 | object existingFtObject; 46 | if(MI_FunctionTableCache.functionPtrCache.TryGetValue(ftPtr, out existingFtObject)) 47 | { 48 | return (T)existingFtObject; 49 | } 50 | else 51 | { 52 | // No apparent way to implement this in an unsafe block 53 | T res = new T(); 54 | Marshal.PtrToStructure(ftPtr, res); 55 | 56 | // No need to check result. If another thread managed to get here first 57 | // then it will write the same logical value since that's the 58 | // whole principal we're relying on for the optimization 59 | MI_FunctionTableCache.functionPtrCache.TryAdd(ftPtr, res); 60 | 61 | return res; 62 | } 63 | 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/MI_NativeObjectWithFT.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace Microsoft.Management.Infrastructure.Native 13 | { 14 | internal abstract class MI_NativeObjectWithFT : MI_NativeObject where FunctionTableType : new() 15 | { 16 | // Marshal implements these with Reflection - pay this hit only once 17 | protected static readonly int MI_NativeObjectNormalMembersLayoutFTOffset = (int)Marshal.OffsetOf("ft"); 18 | 19 | public static implicit operator DirectPtr(MI_NativeObjectWithFT instance) 20 | { 21 | // If the indirect pointer is zero then the object has not 22 | // been initialized and it is not valid to refer to its data 23 | if (instance != null && instance.Ptr == IntPtr.Zero) 24 | { 25 | throw new InvalidCastException(); 26 | } 27 | 28 | return new DirectPtr() { ptr = instance == null ? IntPtr.Zero : instance.Ptr }; 29 | } 30 | 31 | protected Lazy mft; 32 | 33 | protected MI_NativeObjectWithFT(bool isDirect) : base(isDirect) 34 | { 35 | this.SetupMFT(this.MarshalFT); 36 | } 37 | 38 | protected MI_NativeObjectWithFT(IntPtr existingPtr) : base(existingPtr) 39 | { 40 | this.SetupMFT(this.MarshalFT); 41 | } 42 | 43 | protected MI_NativeObjectWithFT(bool isDirect, Func mftThunk) : base(isDirect) 44 | { 45 | this.SetupMFT(mftThunk); 46 | } 47 | 48 | protected MI_NativeObjectWithFT(IntPtr existingPtr, Func mftThunk) : base(existingPtr) 49 | { 50 | this.SetupMFT(mftThunk); 51 | } 52 | 53 | private void SetupMFT(Func mftThunk) 54 | { 55 | this.mft = new Lazy(mftThunk); 56 | } 57 | 58 | private FunctionTableType MarshalFT() 59 | { 60 | return MI_FunctionTableCache.GetFTAsOffsetFromPtr(this.Ptr, this.FunctionTableOffset); 61 | } 62 | 63 | protected static void CheckMembersTableMatchesNormalLayout(string ftMember) 64 | { 65 | int actualFTOffSet = (int)Marshal.OffsetOf(ftMember); 66 | int actualMembersSize = Marshal.SizeOf(); 67 | 68 | if (actualFTOffSet != MI_NativeObjectNormalMembersLayoutFTOffset || 69 | actualMembersSize != MI_NativeObjectNormalMembersLayoutSize) 70 | { 71 | throw new InvalidCastException(); 72 | } 73 | } 74 | 75 | protected virtual int FunctionTableOffset { get { return MI_NativeObjectNormalMembersLayoutFTOffset; } } 76 | 77 | protected FunctionTableType ft 78 | { 79 | get 80 | { 81 | if (this.IsNull) 82 | { 83 | throw new InvalidOperationException(); 84 | } 85 | 86 | return this.mft.Value; 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/MI_PlatformSpecific.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | using System.Runtime.InteropServices; 14 | 15 | internal class MI_PlatformSpecific 16 | { 17 | #if !_LINUX 18 | internal const UnmanagedType AppropriateStringType = UnmanagedType.LPWStr; 19 | internal const CharSet AppropriateCharSet = CharSet.Unicode; 20 | internal const CallingConvention MiMainCallConvention = CallingConvention.Cdecl; 21 | internal const CallingConvention MiCallConvention = CallingConvention.StdCall; 22 | internal const string MI = "mi.dll"; 23 | internal const string MOFCodecHost = "mimofcodec.dll"; 24 | 25 | internal static string PtrToString(IntPtr ptr) 26 | { 27 | return Marshal.PtrToStringUni(ptr); 28 | } 29 | 30 | internal static IntPtr StringToPtr(string str) 31 | { 32 | return Marshal.StringToHGlobalUni(str); 33 | } 34 | 35 | #else 36 | internal const UnmanagedType AppropriateStringType = UnmanagedType.LPStr; 37 | internal const CharSet AppropriateCharSet = CharSet.Ansi; 38 | internal const CallingConvention MiMainCallConvention = CallingConvention.Cdecl; 39 | internal const CallingConvention MiCallConvention = CallingConvention.Cdecl; 40 | internal const string MI = "libmi"; 41 | internal const string MOFCodecHost = "libmi"; 42 | 43 | internal static string PtrToString(IntPtr ptr) 44 | { 45 | return Marshal.PtrToStringAnsi(ptr); 46 | } 47 | 48 | internal static IntPtr StringToPtr(string str) 49 | { 50 | return Marshal.StringToHGlobalAnsi(str); 51 | } 52 | #endif 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/MI_SerializationFTHelpers.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace Microsoft.Management.Infrastructure.Native 13 | { 14 | internal class MI_SerializationFTHelpers 15 | { 16 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 17 | private struct MI_ClientFT_V1 18 | { 19 | public IntPtr g_applicationFT; 20 | public IntPtr _sessionFT; 21 | public IntPtr _operationFT; 22 | public IntPtr _hostedProviderFT; 23 | public IntPtr _serializerFT; 24 | public IntPtr _deserializerFT; 25 | public IntPtr g_subscriptionDeliveryOptionsFT; 26 | public IntPtr g_destinationOptionsFT; 27 | public IntPtr g_operationOptionsFT; 28 | public IntPtr _utilitiesFT; 29 | } 30 | 31 | private struct SerializationFTPair 32 | { 33 | public MI_Serializer.MI_SerializerFT SerializationFT; 34 | public MI_Deserializer.MI_DeserializerFT DeserializationFT; 35 | } 36 | 37 | private static Lazy XmlSerializationFTs = new Lazy(() => GetXmlSerializationFTs()); 38 | 39 | internal static MI_Serializer.MI_SerializerFT XMLSerializationFT { get { return XmlSerializationFTs.Value.SerializationFT; } } 40 | 41 | internal static MI_Deserializer.MI_DeserializerFT XMLDeserializationFT { get { return XmlSerializationFTs.Value.DeserializationFT; } } 42 | 43 | private static SerializationFTPair GetXmlSerializationFTs() 44 | { 45 | IntPtr module = NativeMethods.LoadLibrary("mi.dll"); 46 | if (module == IntPtr.Zero) 47 | { 48 | throw new InvalidOperationException(); 49 | } 50 | 51 | try 52 | { 53 | IntPtr exportedAddress = NativeMethods.GetProcAddress(module, "mi_clientFT_V1"); 54 | IntPtr structAddress = Marshal.ReadIntPtr(exportedAddress); 55 | MI_ClientFT_V1 clientFT = Marshal.PtrToStructure(structAddress); 56 | return new SerializationFTPair() 57 | { 58 | SerializationFT = Marshal.PtrToStructure(clientFT._serializerFT), 59 | DeserializationFT = Marshal.PtrToStructure(clientFT._deserializerFT), 60 | }; 61 | } 62 | finally 63 | { 64 | NativeMethods.FreeLibrary(module); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/NativeCimCredential.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using Microsoft.Management.Infrastructure.Options; 10 | using System.Security; 11 | 12 | namespace Microsoft.Management.Infrastructure.Native 13 | { 14 | public class NativeCimCredential 15 | { 16 | private SecureString passwordSecureStr; 17 | private bool credentialIsCertificate; 18 | 19 | internal NativeCimCredential(bool bIsCertificate, SecureString secureStr) 20 | { 21 | passwordSecureStr = null; 22 | credentialIsCertificate = bIsCertificate; 23 | if (secureStr != null && secureStr.Length > 0) 24 | { 25 | passwordSecureStr = secureStr.Copy(); 26 | } 27 | } 28 | 29 | internal SecureString GetSecureString() 30 | { 31 | return passwordSecureStr; 32 | } 33 | 34 | internal void AssertValidInternalState() 35 | { 36 | return; 37 | } 38 | 39 | internal static void CreateCimCredential(string authenticationMechanism, string certificateThumbprint, out NativeCimCredential credential) 40 | { 41 | // TODO: Implement 42 | credential = new NativeCimCredential(true, new SecureString()); 43 | } 44 | 45 | internal static void CreateCimCredential(string authenticationMechanism, string domain, string userName, SecureString password, out NativeCimCredential credential) 46 | { 47 | // TODO: Implement 48 | credential = new NativeCimCredential(true, new SecureString()); 49 | } 50 | 51 | internal static void CreateCimCredential(string authenticationMechanism, out NativeCimCredential credential) 52 | { 53 | // TODO: Implement 54 | credential = new NativeCimCredential(true, new SecureString()); 55 | } 56 | 57 | internal static void CreateCimCredential(CertificateAuthenticationMechanism authenticationMechanism, string certificateThumbprint, out NativeCimCredential credential) 58 | { 59 | // TODO: Implement 60 | credential = new NativeCimCredential(true, new SecureString()); 61 | } 62 | 63 | internal static void CreateCimCredential(PasswordAuthenticationMechanism authenticationMechanism, string domain, string userName, SecureString password, out NativeCimCredential credential) 64 | { 65 | // TODO: Implement 66 | credential = new NativeCimCredential(true, new SecureString()); 67 | } 68 | 69 | internal static void CreateCimCredential(ImpersonatedAuthenticationMechanism authenticationMechanism, out NativeCimCredential credential) 70 | { 71 | // TODO: Implement 72 | credential = new NativeCimCredential(true, new SecureString()); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | namespace Microsoft.Management.Infrastructure.Native 10 | { 11 | using System; 12 | using System.Runtime.InteropServices; 13 | 14 | internal static class NativeMethods 15 | { 16 | [DllImport(MI_PlatformSpecific.MI, CallingConvention = MI_PlatformSpecific.MiMainCallConvention)] 17 | internal static extern MI_Result MI_Application_InitializeV1( 18 | UInt32 flags, 19 | [MarshalAs(MI_PlatformSpecific.AppropriateStringType)] string applicationID, 20 | MI_Instance.IndirectPtr extendedError, 21 | [In, Out] MI_Application.DirectPtr application 22 | ); 23 | 24 | [DllImport(MI_PlatformSpecific.MOFCodecHost, CallingConvention = MI_PlatformSpecific.MiMainCallConvention)] 25 | internal static extern MI_Result MI_Application_NewSerializer_Mof( 26 | MI_Application.DirectPtr application, 27 | MI_SerializerFlags flags, 28 | [MarshalAs(UnmanagedType.LPWStr)]string format, 29 | MI_Serializer.DirectPtr serializer 30 | ); 31 | 32 | [DllImport(MI_PlatformSpecific.MOFCodecHost, CallingConvention = MI_PlatformSpecific.MiMainCallConvention)] 33 | internal static extern MI_Result MI_Application_NewDeserializer_Mof( 34 | MI_Application.DirectPtr application, 35 | MI_SerializerFlags flags, 36 | [MarshalAs(UnmanagedType.LPWStr)] string format, 37 | MI_Deserializer.DirectPtr serializer 38 | ); 39 | 40 | [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)] 41 | internal static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPWStr)]string lpFileName); 42 | 43 | [DllImport("kernel32.dll", SetLastError = true)] 44 | [return: MarshalAs(UnmanagedType.Bool)] 45 | internal static extern bool FreeLibrary(IntPtr hModule); 46 | 47 | [DllImport("kernel32", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] 48 | internal static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName); 49 | 50 | internal static readonly int IntPtrSize = Marshal.SizeOf(); 51 | 52 | [UnmanagedFunctionPointer(MI_PlatformSpecific.MiMainCallConvention)] 53 | internal delegate IntPtr MI_MainFunction(IntPtr callbackContext); 54 | 55 | internal static unsafe void memcpy(byte* dst, byte* src, int size, uint count) 56 | { 57 | long byteCount = size * count; 58 | for (long i = 0; i < byteCount; i++) 59 | { 60 | *dst++ = *src++; 61 | } 62 | } 63 | 64 | internal static unsafe void memset(IntPtr dst, byte val, int byteCount) 65 | { 66 | unsafe 67 | { 68 | memset((byte*)dst, val, (uint)byteCount); 69 | } 70 | } 71 | 72 | private static unsafe void memset(byte* dst, byte val, uint byteCount) 73 | { 74 | for (long i = 0; i < byteCount; i++) 75 | { 76 | *dst++ = val; 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Structures/MI_Array.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace Microsoft.Management.Infrastructure.Native 13 | { 14 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 15 | internal struct MI_Array 16 | { 17 | internal IntPtr data; 18 | internal UInt32 size; 19 | 20 | public static int MI_ArraySize = (int)Marshal.SizeOf(); 21 | 22 | public static T[] ReadAsManagedPointerArray(IntPtr miArrayPtr, Func conversion) 23 | { 24 | if (miArrayPtr == IntPtr.Zero) 25 | { 26 | throw new ArgumentNullException(); 27 | } 28 | 29 | unsafe 30 | { 31 | MI_Array* arrayPtr = (MI_Array*)miArrayPtr; 32 | if (arrayPtr->data == IntPtr.Zero) 33 | { 34 | return null; 35 | } 36 | 37 | uint arraySize = arrayPtr->size; 38 | T[] res = new T[arraySize]; 39 | for (int i = 0; i < arraySize; i++) 40 | { 41 | res[i] = conversion(((IntPtr*)(arrayPtr->data))[i]); 42 | } 43 | 44 | return res; 45 | } 46 | } 47 | 48 | public static void WritePointerArray(IntPtr miArrayPtr, IntPtr[] ptrs) 49 | { 50 | unsafe 51 | { 52 | MI_Array* arrayPtr = (MI_Array*)miArrayPtr; 53 | 54 | // Reuse of an MI_Array without freeing is unsupported 55 | if (arrayPtr->data != IntPtr.Zero || arrayPtr->size != 0) 56 | { 57 | throw new InvalidOperationException(); 58 | } 59 | 60 | // No special case for null since previous reuse check forces 61 | // the entire MI_Array structure to be zeroed, which 62 | // is what we wanted anyway 63 | if (ptrs != null) 64 | { 65 | arrayPtr->data = Marshal.AllocHGlobal(NativeMethods.IntPtrSize * ptrs.Length); 66 | Marshal.Copy(ptrs, 0, arrayPtr->data, ptrs.Length); 67 | arrayPtr->size = (uint)ptrs.Length; 68 | } 69 | } 70 | } 71 | 72 | public static void WriteNativeObjectPointers(IntPtr miArrayPtr, MI_NativeObject[] objects) 73 | { 74 | var size = objects.Length; 75 | IntPtr[] ptrs = new IntPtr[size]; 76 | for (int i = 0; i < size; i++) 77 | { 78 | ptrs[i] = objects[i].Ptr; 79 | } 80 | 81 | WritePointerArray(miArrayPtr, ptrs); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Structures/MI_Interval.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | using System.Runtime.InteropServices; 14 | 15 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 16 | internal struct MI_Interval 17 | { 18 | internal UInt32 days; 19 | internal UInt32 hours; 20 | internal UInt32 minutes; 21 | internal UInt32 seconds; 22 | internal UInt32 microseconds; 23 | internal UInt32 __padding1; 24 | internal UInt32 __padding2; 25 | internal UInt32 __padding3; 26 | 27 | public static implicit operator TimeSpan(MI_Interval interval) 28 | { 29 | throw new NotImplementedException(); 30 | } 31 | 32 | public static implicit operator MI_Interval(TimeSpan timespan) 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Structures/MI_SessionCreationCallbacks.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Runtime.InteropServices; 11 | 12 | namespace Microsoft.Management.Infrastructure.Native 13 | { 14 | internal class MI_SessionCreationCallbacks 15 | { 16 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 17 | internal class MI_SessionCreationCallbacksNative 18 | { 19 | private IntPtr callbackContext; 20 | internal MI_SessionCallbacks_WriteMessageNative writeMessage; 21 | internal MI_SessionCallbacks_WriteErrorNative writeError; 22 | 23 | [UnmanagedFunctionPointer(MI_PlatformSpecific.MiCallConvention, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 24 | internal delegate void MI_SessionCallbacks_WriteErrorNative(IntPtr application, IntPtr callbackContext, IntPtr instance); 25 | 26 | [UnmanagedFunctionPointer(MI_PlatformSpecific.MiCallConvention, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 27 | internal delegate void MI_SessionCallbacks_WriteMessageNative(IntPtr application, IntPtr callbackContext, MI_WriteMessageChannel channel, IntPtr message); 28 | } 29 | 30 | internal MI_SessionCallbacks_WriteMessage writeMessage; 31 | internal MI_SessionCallbacks_WriteError writeError; 32 | 33 | internal static MI_SessionCreationCallbacks Null 34 | { 35 | get 36 | { 37 | return null; 38 | } 39 | } 40 | 41 | internal delegate void MI_SessionCallbacks_WriteError(MI_Application application, object callbackContext, MI_Instance instance); 42 | 43 | internal delegate void MI_SessionCallbacks_WriteMessage(MI_Application application, object callbackContext, MI_WriteMessageChannel channel, string message); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Structures/MI_String.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | using System.Runtime.InteropServices; 14 | 15 | [StructLayout(LayoutKind.Sequential)] 16 | internal class MI_String 17 | { 18 | private IntPtr ptr; 19 | 20 | private MI_String() 21 | { 22 | } 23 | 24 | private MI_String(IntPtr ptr) 25 | { 26 | this.ptr = ptr; 27 | } 28 | 29 | public static implicit operator IntPtr(MI_String wrapper) 30 | { 31 | return wrapper.ptr; 32 | } 33 | 34 | internal static MI_String NewIndirectPtr() 35 | { 36 | return new MI_String(); 37 | } 38 | 39 | internal static MI_String NewFromDirectPtr(IntPtr existingPtr) 40 | { 41 | return new MI_String(existingPtr); 42 | } 43 | 44 | internal string Value 45 | { 46 | get 47 | { 48 | return this.ptr == IntPtr.Zero ? null : MI_PlatformSpecific.PtrToString(this.ptr); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Structures/MI_Timestamp.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | using System.Runtime.InteropServices; 14 | 15 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 16 | internal struct MI_Timestamp 17 | { 18 | internal UInt32 year; 19 | internal UInt32 month; 20 | internal UInt32 day; 21 | internal UInt32 hour; 22 | internal UInt32 minute; 23 | internal UInt32 second; 24 | internal UInt32 microseconds; 25 | internal Int32 utc; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Native/Structures/MI_UserCredentials.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | 11 | namespace Microsoft.Management.Infrastructure.Native 12 | { 13 | using System.Runtime.InteropServices; 14 | 15 | [StructLayout(LayoutKind.Explicit, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 16 | internal struct MI_UserCredentials 17 | { 18 | [StructLayout(LayoutKind.Sequential, CharSet = MI_PlatformSpecific.AppropriateCharSet)] 19 | internal struct MI_UsernamePasswordCreds 20 | { 21 | internal string domain; 22 | internal string username; 23 | internal string password; 24 | } 25 | 26 | [FieldOffset(0)] 27 | internal IntPtr authenticationType; 28 | 29 | [FieldOffset(16)] 30 | internal MI_UsernamePasswordCreds usernamePassword; 31 | 32 | [FieldOffset(8)] 33 | internal IntPtr certificateThumbprint; 34 | 35 | internal string authenticationTypeString 36 | { 37 | get 38 | { 39 | return MI_PlatformSpecific.PtrToString(this.authenticationType); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/NativeErrorCode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System.Diagnostics.CodeAnalysis; 13 | 14 | namespace Microsoft.Management.Infrastructure 15 | { 16 | /// 17 | /// Error codes defined by the native MI Client API 18 | /// 19 | [SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "NativeErrorCode is a regular enum, not a flags enum. No idea why FxCop complained about this enum.")] 20 | public enum NativeErrorCode 21 | { 22 | Ok = (int)MI_Result.MI_RESULT_OK, 23 | Failed = (int)MI_Result.MI_RESULT_FAILED, 24 | AccessDenied = (int)MI_Result.MI_RESULT_ACCESS_DENIED, 25 | InvalidNamespace = (int)MI_Result.MI_RESULT_INVALID_NAMESPACE, 26 | InvalidParameter = (int)MI_Result.MI_RESULT_INVALID_PARAMETER, 27 | InvalidClass = (int)MI_Result.MI_RESULT_INVALID_CLASS, 28 | NotFound = (int)MI_Result.MI_RESULT_NOT_FOUND, 29 | NotSupported = (int)MI_Result.MI_RESULT_NOT_SUPPORTED, 30 | ClassHasChildren = (int)MI_Result.MI_RESULT_CLASS_HAS_CHILDREN, 31 | ClassHasInstances = (int)MI_Result.MI_RESULT_CLASS_HAS_INSTANCES, 32 | InvalidSuperClass = (int)MI_Result.MI_RESULT_INVALID_SUPERCLASS, 33 | AlreadyExists = (int)MI_Result.MI_RESULT_ALREADY_EXISTS, 34 | NoSuchProperty = (int)MI_Result.MI_RESULT_NO_SUCH_PROPERTY, 35 | TypeMismatch = (int)MI_Result.MI_RESULT_TYPE_MISMATCH, 36 | QueryLanguageNotSupported = (int)MI_Result.MI_RESULT_QUERY_LANGUAGE_NOT_SUPPORTED, 37 | InvalidQuery = (int)MI_Result.MI_RESULT_INVALID_QUERY, 38 | MethodNotAvailable = (int)MI_Result.MI_RESULT_METHOD_NOT_AVAILABLE, 39 | MethodNotFound = (int)MI_Result.MI_RESULT_METHOD_NOT_FOUND, 40 | NamespaceNotEmpty = (int)MI_Result.MI_RESULT_NAMESPACE_NOT_EMPTY, 41 | InvalidEnumerationContext = (int)MI_Result.MI_RESULT_INVALID_ENUMERATION_CONTEXT, 42 | InvalidOperationTimeout = (int)MI_Result.MI_RESULT_INVALID_OPERATION_TIMEOUT, 43 | PullHasBeenAbandoned = (int)MI_Result.MI_RESULT_PULL_HAS_BEEN_ABANDONED, 44 | PullCannotBeAbandoned = (int)MI_Result.MI_RESULT_PULL_CANNOT_BE_ABANDONED, 45 | FilteredEnumerationNotSupported = (int)MI_Result.MI_RESULT_FILTERED_ENUMERATION_NOT_SUPPORTED, 46 | ContinuationOnErrorNotSupported = (int)MI_Result.MI_RESULT_CONTINUATION_ON_ERROR_NOT_SUPPORTED, 47 | ServerLimitsExceeded = (int)MI_Result.MI_RESULT_SERVER_LIMITS_EXCEEDED, 48 | ServerIsShuttingDown = (int)MI_Result.MI_RESULT_SERVER_IS_SHUTTING_DOWN, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Options/Internal/ImpersonationType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | 13 | namespace Microsoft.Management.Infrastructure.Options 14 | { 15 | public enum ImpersonationType : uint 16 | { 17 | None = MI_ImpersonationType.None, 18 | Default = MI_ImpersonationType.Default, 19 | Delegate = MI_ImpersonationType.Delegate, 20 | Identify = MI_ImpersonationType.Identify, 21 | Impersonate = MI_ImpersonationType.Impersonate, 22 | }; 23 | } 24 | 25 | namespace Microsoft.Management.Infrastructure.Options.Internal 26 | { 27 | internal static class ImpersonationTypeExtensionMethods 28 | { 29 | public static MI_ImpersonationType ToNativeType(this ImpersonationType impersonationType) 30 | { 31 | return (MI_ImpersonationType)impersonationType; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Options/Internal/PacketEncoding.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System; 13 | using System.Globalization; 14 | 15 | namespace Microsoft.Management.Infrastructure.Options 16 | { 17 | public enum PacketEncoding 18 | { 19 | Default, 20 | Utf8, 21 | Utf16, 22 | // TODO/FIXME: make sure that updates in the native API are reflected here - Paul was planning to add options for big/little endian 23 | }; 24 | } 25 | 26 | namespace Microsoft.Management.Infrastructure.Options.Internal 27 | { 28 | internal static class PacketEncodingExtensionMethods 29 | { 30 | public static string ToNativeType(this PacketEncoding packetEncoding) 31 | { 32 | switch (packetEncoding) 33 | { 34 | case PacketEncoding.Default: 35 | return MI_PacketEncoding.Default; 36 | 37 | case PacketEncoding.Utf8: 38 | return MI_PacketEncoding.UTF8; 39 | 40 | case PacketEncoding.Utf16: 41 | return MI_PacketEncoding.UTF16; 42 | 43 | default: 44 | throw new ArgumentOutOfRangeException("packetEncoding"); 45 | } 46 | } 47 | 48 | public static PacketEncoding FromNativeType(string packetEncoding) 49 | { 50 | #if (!_CORECLR) 51 | if (String.Compare(packetEncoding, MI_PacketEncoding.Default, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 52 | #else 53 | if ( String.Compare( packetEncoding, MI_PacketEncoding.Default, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 54 | #endif 55 | { 56 | return PacketEncoding.Default; 57 | } 58 | #if(!_CORECLR) 59 | else if (String.Compare(packetEncoding, MI_PacketEncoding.UTF8, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 60 | #else 61 | else if ( String.Compare( packetEncoding, MI_PacketEncoding.UTF8, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 62 | #endif 63 | { 64 | return PacketEncoding.Utf8; 65 | } 66 | #if(!_CORECLR) 67 | else if (String.Compare(packetEncoding, MI_PacketEncoding.UTF16, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 68 | #else 69 | else if ( String.Compare( packetEncoding, MI_PacketEncoding.UTF16, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 70 | #endif 71 | { 72 | return PacketEncoding.Utf16; 73 | } 74 | else 75 | { 76 | throw new ArgumentOutOfRangeException("packetEncoding"); 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Options/Internal/ProxyType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Native; 12 | using System; 13 | using System.Globalization; 14 | 15 | namespace Microsoft.Management.Infrastructure.Options 16 | { 17 | public enum ProxyType 18 | { 19 | None, 20 | WinHttp, 21 | Auto, 22 | InternetExplorer, 23 | }; 24 | } 25 | 26 | namespace Microsoft.Management.Infrastructure.Options.Internal 27 | { 28 | internal static class ProxyTypeExtensionMethods 29 | { 30 | public static string ToNativeType(this ProxyType proxyType) 31 | { 32 | switch (proxyType) 33 | { 34 | case ProxyType.None: 35 | return MI_ProxyType.None; 36 | 37 | case ProxyType.WinHttp: 38 | return MI_ProxyType.WinHTTP; 39 | 40 | case ProxyType.Auto: 41 | return MI_ProxyType.Auto; 42 | 43 | case ProxyType.InternetExplorer: 44 | return MI_ProxyType.IE; 45 | 46 | default: 47 | throw new ArgumentOutOfRangeException("proxyType"); 48 | } 49 | } 50 | 51 | public static ProxyType FromNativeType(string proxyType) 52 | { 53 | #if(!_CORECLR) 54 | if (String.Compare(proxyType, MI_ProxyType.None, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 55 | #else 56 | if ( String.Compare( proxyType, MI_ProxyType.None, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 57 | #endif 58 | { 59 | return ProxyType.None; 60 | } 61 | #if(!_CORECLR) 62 | else if (String.Compare(proxyType, MI_ProxyType.WinHTTP, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 63 | #else 64 | else if ( String.Compare( proxyType, MI_ProxyType.WinHTTP, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 65 | #endif 66 | { 67 | return ProxyType.WinHttp; 68 | } 69 | #if(!_CORECLR) 70 | else if (String.Compare(proxyType, MI_ProxyType.Auto, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 71 | #else 72 | else if ( String.Compare( proxyType, MI_ProxyType.Auto, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 73 | #endif 74 | { 75 | return ProxyType.Auto; 76 | } 77 | #if(!_CORECLR) 78 | else if (String.Compare(proxyType, MI_ProxyType.IE, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase) == 0) 79 | #else 80 | else if ( String.Compare( proxyType, MI_ProxyType.IE, StringComparison.CurrentCultureIgnoreCase ) == 0 ) 81 | #endif 82 | { 83 | return ProxyType.InternetExplorer; 84 | } 85 | else 86 | { 87 | throw new ArgumentOutOfRangeException("proxyType"); 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Serialization/CimMofSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Internal; 12 | using Microsoft.Management.Infrastructure.Native; 13 | using System; 14 | using System.Diagnostics; 15 | 16 | namespace Microsoft.Management.Infrastructure.Serialization 17 | { 18 | /// 19 | /// Class use to craete a mof serializer 20 | /// 21 | internal static class CimMofSerializer 22 | { 23 | #region Constructors 24 | 25 | private static CimSerializer CreateCimMofSerializer(string format, uint flags) 26 | { 27 | Debug.Assert(!string.IsNullOrEmpty(format), "Caller should verify that format != null"); 28 | 29 | MI_Serializer tmpHandle; 30 | // TODO: Fix MI_SerializerFlags in next line to come from "flags" 31 | MI_Result result = CimApplication.Handle.NewSerializer(MI_SerializerFlags.None, 32 | format, 33 | out tmpHandle); 34 | if (result == MI_Result.MI_RESULT_INVALID_PARAMETER) 35 | { 36 | throw new ArgumentOutOfRangeException("format"); 37 | } 38 | return new CimSerializer(tmpHandle); 39 | } 40 | 41 | /// 42 | /// Instantiates a default serializer 43 | /// 44 | public static CimSerializer Create() 45 | { 46 | return CreateCimMofSerializer(format: "MI_MOF_CIMV2_EXTV1", flags: 0); 47 | } 48 | 49 | #endregion Constructors 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Microsoft.Management.Infrastructure/Serialization/MofDeserializerSchemaValidationOption.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | 11 | using Microsoft.Management.Infrastructure.Internal; 12 | using Microsoft.Management.Infrastructure.Native; 13 | using Microsoft.Management.Infrastructure.Options; 14 | using System; 15 | using System.Collections.Generic; 16 | using System.Diagnostics; 17 | using System.Diagnostics.CodeAnalysis; 18 | using System.Linq; 19 | 20 | namespace Microsoft.Management.Infrastructure.Serialization 21 | { 22 | /// 23 | /// Schema validation option 24 | /// 25 | /// 26 | [SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Justification = "This is a direct representation of the native flags (which doesn't have None)")] 27 | internal enum MofDeserializerSchemaValidationOption : int 28 | { 29 | /* MOF schema validation option's value */ 30 | Default = 0, 31 | Strict = 1, 32 | Loose = 2, 33 | IgnorePropertyType = 3, 34 | Ignore = 4 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /src/signing/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "monad/src/graphicalhost/visualstudiopublic.snk": "visualstudiopublic.snk" 3 | } 4 | -------------------------------------------------------------------------------- /src/signing/visualstudiopublic.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/MMI/cf32fc695b32c2eae848b693395c09222fe1d2ae/src/signing/visualstudiopublic.snk -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | mkdir -p test/Microsoft.Management.Infrastructure.Tests/bin/ 3 | cp /opt/omi/lib/libmi.so test/Microsoft.Management.Infrastructure.Tests/bin/ 4 | /opt/omi/bin/omiserver -i -d --livetime 120 --httpport 0 --httpsport 0 5 | PATH=$PATH:~/.dotnet dotnet test test/Microsoft.Management.Infrastructure.Tests/ -c Linux -o bin --logger "trx;LogFileName=TestResults.trx" 6 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System.Reflection; 10 | using System.Resources; 11 | using System.Runtime.CompilerServices; 12 | using System.Runtime.InteropServices; 13 | using Xunit; 14 | 15 | // 0 means use one thread per processor 16 | //[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, MaxParallelThreads = 0)] 17 | [assembly: CollectionBehavior(DisableTestParallelization = true)] 18 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/Helpers/Helpers.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.IO; 11 | using System.Text; 12 | 13 | namespace MMI.Tests 14 | { 15 | using System.Reflection; 16 | using System.Runtime.InteropServices; 17 | 18 | public static class Helpers 19 | { 20 | private readonly static BindingFlags PrivateBindingFlags = BindingFlags.Instance | BindingFlags.NonPublic; 21 | 22 | public static Y GetPrivateProperty(this X self, string name) 23 | { 24 | object[] emptyArgs = new object[] { }; 25 | var property = typeof(X).GetProperty(name, PrivateBindingFlags); 26 | return (Y)property.GetMethod.Invoke(self, emptyArgs); 27 | } 28 | 29 | public static Y GetPrivateVariable(this X self, string name) 30 | { 31 | return (Y)typeof(X).GetField(name, PrivateBindingFlags).GetValue(self); 32 | } 33 | 34 | public static string GetStringRepresentationOfSerializedData(byte[] data) 35 | { 36 | #if !_CORECLR 37 | return Encoding.Unicode.GetString(data); 38 | #else 39 | return Encoding.ASCII.GetString(data); 40 | #endif 41 | } 42 | 43 | /// 44 | /// convert string to byte[] 45 | /// 46 | /// 47 | public static byte[] GetBytesFromString(string str) 48 | { 49 | System.Text.UTF8Encoding encoding = new UTF8Encoding(); 50 | return encoding.GetBytes(str); 51 | } 52 | 53 | /// 54 | /// Read file content to byte[] 55 | /// 56 | /// 57 | /// 58 | public static byte[] GetBytesFromFile(string filePath) 59 | { 60 | string s = File.ReadAllText(filePath); 61 | System.Text.UTF8Encoding encoding = new UTF8Encoding(); 62 | return encoding.GetBytes(s); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/Helpers/TDDFact.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | using Xunit; 15 | 16 | namespace MMI.Tests 17 | { 18 | internal class TDDFact : 19 | #if _TDD 20 | FactAttribute 21 | #else 22 | Attribute 23 | #endif 24 | { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/Helpers/TestMIProperty.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | 15 | namespace MMI.Tests 16 | { 17 | using Microsoft.Management.Infrastructure.Native; 18 | 19 | internal class TestMIProperty 20 | { 21 | private MI_Value actualValue; 22 | 23 | public TestMIProperty(MI_Value value, MI_Type type, MI_Flags flags) 24 | { 25 | this.actualValue = value; 26 | this.Type = type; 27 | this.Flags = flags; 28 | } 29 | 30 | public object Value { get { return this.actualValue.GetValue(this.Type); } } 31 | public MI_Type Type { get; private set; } 32 | public MI_Flags Flags { get; private set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/Helpers/WindowsAssert.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | using System.Threading.Tasks; 15 | using Microsoft.Management.Infrastructure.Native; 16 | 17 | namespace MMI.Tests 18 | { 19 | 20 | internal static class WindowsAssert 21 | { 22 | internal static void Equal(T expected, T actual) 23 | { 24 | #if !_LINUX 25 | Assert.Equal(expected, actual); 26 | #endif 27 | } 28 | internal static void Equal(T expected, T actual, string message) 29 | { 30 | #if !_LINUX 31 | Assert.Equal(expected, actual, message); 32 | #endif 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/Helpers/WindowsFact.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | using Xunit; 15 | 16 | namespace MMI.Tests 17 | { 18 | internal class WindowsFact : 19 | #if _LINUX 20 | Attribute 21 | #else 22 | FactAttribute 23 | #endif 24 | { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/InternalTests/CimApplicationTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using Microsoft.Management.Infrastructure.Internal; 10 | using Xunit; 11 | 12 | namespace MMI.Tests.Internal 13 | { 14 | /// 15 | /// Example test that the string is correct. 16 | /// 17 | public class CimApplicationTests 18 | { 19 | [Fact] 20 | public void ApplicationIDSane() 21 | { 22 | Assert.Equal("CoreCLRSingletonAppDomain", CimApplication.ApplicationID, "Expect test framework to be sane"); 23 | } 24 | 25 | [Fact] 26 | public void CimApplicationInitializes() 27 | { 28 | Assert.NotNull(CimApplication.Handle, "Expect the application handle to initialize properly"); 29 | Assert.False(CimApplication.Handle.IsNull, "Expect the pointer to be logically non-null"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/Microsoft.Management.Infrastructure.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | false 6 | true 7 | ../../signing/visualstudiopublic.snk" 8 | true 9 | 0649 10 | false 11 | 12 | 13 | 14 | $(DefineConstants);_CORECLR;_LINUX 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/.SlowTests.cs.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/MMI/cf32fc695b32c2eae848b693395c09222fe1d2ae/test/Microsoft.Management.Infrastructure.Tests/NativeTests/.SlowTests.cs.swp -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/Fixtures/ApplicationFixture.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class ApplicationFixture 21 | { 22 | private readonly string ApplicationName = "MMINativeTests"; 23 | 24 | internal MI_Application Application { get; private set; } 25 | 26 | public ApplicationFixture() 27 | { 28 | MI_Instance extendedError = null; 29 | MI_Application newApplication; 30 | MI_Result res = MI_Application.Initialize(ApplicationName, out extendedError, out newApplication); 31 | MIAssert.Succeeded(res, "Expect basic application initialization to succeed"); 32 | this.Application = newApplication; 33 | } 34 | 35 | public void Dispose() 36 | { 37 | if (this.Application != null) 38 | { 39 | var shutdownTask = Task.Factory.StartNew(() => this.Application.Close()); 40 | bool completed = shutdownTask.Wait(TimeSpan.FromSeconds(5)); 41 | Assert.True(completed, "Expect shutdown to complete successfully (did you leave an object open?)"); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/Fixtures/SessionFixture.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class SessionFixture : IDisposable 21 | { 22 | internal MI_Session Session { get; private set; } 23 | 24 | public SessionFixture() 25 | { 26 | var application = StaticFixtures.Application; 27 | 28 | MI_Session newSession; 29 | MI_Instance extendedError = null; 30 | MI_Result res = application.NewSession(null, 31 | null, 32 | MI_DestinationOptions.Null, 33 | MI_SessionCreationCallbacks.Null, 34 | out extendedError, 35 | out newSession); 36 | MIAssert.Succeeded(res, "Expect simple NewSession to succeed"); 37 | this.Session = newSession; 38 | } 39 | 40 | public virtual void Dispose() 41 | { 42 | if (this.Session != null) 43 | { 44 | this.Session.Close(IntPtr.Zero, null); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/Fixtures/StaticFixtures.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | 17 | namespace MMI.Tests.Native 18 | { 19 | public static class StaticFixtures 20 | { 21 | private static Lazy appFixture; 22 | 23 | internal static MI_Application Application { get { return appFixture.Value.Application; } } 24 | 25 | private static Lazy sessionFixture; 26 | 27 | internal static MI_Session Session { get { return sessionFixture.Value.Session; } } 28 | 29 | static StaticFixtures() 30 | { 31 | // This stuff leaks 32 | appFixture = new Lazy(() => new ApplicationFixture()); 33 | sessionFixture = new Lazy(() => new SessionFixture()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/MOFSerializerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class MOFSerializerTests : NativeSerializerTestsBase 21 | { 22 | public MOFSerializerTests() : base(MI_SerializationFormat.MOF) 23 | { 24 | } 25 | 26 | [Fact] 27 | public void CanSerializeInstance() 28 | { 29 | this.TestInstanceSerializationInput(SerializationTestData.CreateBasicSerializableTestInstance, 30 | SerializationTestData.BasicSerializableTestInstanceMOFRepresentation); 31 | } 32 | 33 | /*[WindowsFact] 34 | public void CanSerializeClass() 35 | { 36 | string serialized = this.GetStringRepresentationFromClassThunk(SerializationTestData.GetSerializableTestClass); 37 | 38 | // Storing entire serialization of a class is too finicky here. Just check that there's something 39 | // expected inside the serialized string 40 | Xunit.Assert.Contains(SerializationTestData.SingletonClassSerializableClassHeuristicString, serialized); 41 | }*/ 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/NativeSerializerTestsBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class NativeSerializerTestsBase : NativeTestsBase 21 | { 22 | internal MI_Serializer Serializer { get; private set; } 23 | 24 | public NativeSerializerTestsBase(string format) 25 | { 26 | MI_Serializer newSerializer; 27 | MI_Result res = this.Application.NewSerializer(MI_SerializerFlags.None, 28 | format, 29 | out newSerializer); 30 | MIAssert.Succeeded(res, "Expect simple NewSerializer to succeed"); 31 | this.Serializer = newSerializer; 32 | } 33 | 34 | public virtual void Dispose() 35 | { 36 | if (this.Serializer != null) 37 | { 38 | this.Serializer.Close(); 39 | } 40 | } 41 | 42 | internal void TestInstanceSerializationInput(Func instanceGetter, string expected) 43 | { 44 | string serializedString = this.GetStringRepresentationFromInstanceThunk(instanceGetter); 45 | Assert.Equal(expected, serializedString, "Expect serialized version to match canonical serialization"); 46 | } 47 | 48 | internal string GetStringRepresentationFromInstanceThunk(Func instanceGetter) 49 | { 50 | byte[] serializedInstance = this.GetSerializationFromInstanceThunk(instanceGetter); 51 | return Helpers.GetStringRepresentationOfSerializedData(serializedInstance); 52 | } 53 | 54 | internal string GetStringRepresentationFromClassThunk(Func classGetter) 55 | { 56 | byte[] serializedInstance = this.GetSerializationFromClassThunk(classGetter); 57 | return Helpers.GetStringRepresentationOfSerializedData(serializedInstance); 58 | } 59 | 60 | internal byte[] GetSerializationFromInstanceThunk(Func instanceGetter) 61 | { 62 | MI_Instance toSerialize = instanceGetter(); 63 | 64 | byte[] serializedInstance; 65 | var res = this.Serializer.SerializeInstance(MI_SerializerFlags.None, toSerialize, out serializedInstance); 66 | MIAssert.Succeeded(res); 67 | toSerialize.Delete(); 68 | return serializedInstance; 69 | } 70 | 71 | internal byte[] GetSerializationFromClassThunk(Func classGetter) 72 | { 73 | MI_Class toSerialize = classGetter(); 74 | 75 | byte[] serializedInstance; 76 | var res = this.Serializer.SerializeClass(MI_SerializerFlags.None, toSerialize, out serializedInstance); 77 | MIAssert.Succeeded(res); 78 | toSerialize.Delete(); 79 | return serializedInstance; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/NativeTestsBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | 17 | namespace MMI.Tests.Native 18 | { 19 | public class NativeTestsBase 20 | { 21 | internal MI_Application Application { get { return StaticFixtures.Application; } } 22 | 23 | internal MI_Session Session { get { return StaticFixtures.Session; } } 24 | 25 | protected NativeTestsBase() 26 | { 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/SanityTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class SanityTests : NativeTestsBase 21 | { 22 | public SanityTests() : base() 23 | { 24 | } 25 | 26 | [Fact] 27 | public void CanGetSetOperationOptionsInterval() 28 | { 29 | MI_OperationOptions options; 30 | this.Application.NewOperationOptions(false, out options); 31 | 32 | MI_Interval myInterval = new MI_Interval() 33 | { 34 | days = 21, 35 | hours = 2, 36 | seconds = 1 37 | }; 38 | 39 | var res = options.SetInterval("MyCustomOption", myInterval, MI_OperationOptionsFlags.Unused); 40 | MIAssert.Succeeded(res, "Expect to be able to set an interval"); 41 | 42 | MI_Interval retrievedInterval; 43 | MI_OperationOptionsFlags retrievedFlags; 44 | UInt32 optionIndex; 45 | res = options.GetInterval("MyCustomOption", out retrievedInterval, out optionIndex, out retrievedFlags); 46 | MIAssert.Succeeded(res, "Expect to be able to get an interval"); 47 | 48 | MIAssert.MIIntervalsEqual(myInterval, retrievedInterval); 49 | } 50 | 51 | [Fact] 52 | public void DirectInstanceTableAccessesThrowWhenNotInitialized() 53 | { 54 | Xunit.Assert.Throws(() => MI_Instance.NewDirectPtr().Delete()); 55 | } 56 | 57 | [Fact] 58 | public void IndirectInstanceTableAccessesThrowWhenNotInitialized() 59 | { 60 | Assert.Throws(() => MI_Instance.NewIndirectPtr().Delete()); 61 | } 62 | 63 | [Fact] 64 | public void DirectApplicationTableAccessesThrowWhenNotInitialized() 65 | { 66 | Assert.Throws(() => MI_Application.NewDirectPtr().Close()); 67 | } 68 | 69 | [Fact] 70 | public void IndirectApplicationTableAccessesThrowWhenNotInitialized() 71 | { 72 | Assert.Throws(() => MI_Application.NewIndirectPtr().Close()); 73 | } 74 | 75 | [Fact] 76 | public void DirectSessionTableAccessesThrowWhenNotInitialized() 77 | { 78 | Assert.Throws(() => MI_Session.NewDirectPtr().Close(IntPtr.Zero, null)); 79 | } 80 | 81 | [Fact] 82 | public void IndirectSessionTableAccessesThrowWhenNotInitialized() 83 | { 84 | Assert.Throws(() => MI_Session.NewIndirectPtr().Close(IntPtr.Zero, null)); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/SlowTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class SlowTests 21 | { 22 | public class SessionTestConnection 23 | { 24 | [WindowsFact] 25 | public void BadHost() 26 | { 27 | MI_Session badSession; 28 | MI_Instance extendedError = null; 29 | MI_Result res = StaticFixtures.Application.NewSession(null, 30 | "badhost", 31 | MI_DestinationOptions.Null, 32 | MI_SessionCreationCallbacks.Null, 33 | out extendedError, 34 | out badSession); 35 | MIAssert.Succeeded(res, "Expect simple NewSession to succeed"); 36 | 37 | MI_Operation operation = null; 38 | badSession.TestConnection(0, null, out operation); 39 | 40 | bool moreResults; 41 | MI_Result result; 42 | string errorMessage = null; 43 | MI_Instance instance = null; 44 | MI_Instance errorDetails = null; 45 | res = operation.GetInstance(out instance, out moreResults, out result, out errorMessage, out errorDetails); 46 | MIAssert.Succeeded(res, "Expect the GetInstance operation to succeed"); 47 | MIAssert.Failed(result, "Expect the actual retrieval to fail"); 48 | Assert.True(!String.IsNullOrEmpty(errorMessage), "Expect error message to be available"); 49 | 50 | res = operation.Close(); 51 | MIAssert.Succeeded(res, "Expect to be able to close operation now"); 52 | 53 | res = badSession.Close(IntPtr.Zero, null); 54 | MIAssert.Succeeded(res, "Expect to be able to close the bad session"); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/XMLDeserializerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class XMLDeserializerTests : NativeDeserializerTestsBase 21 | { 22 | public XMLDeserializerTests() : base(MI_SerializationFormat.XML) 23 | { 24 | } 25 | 26 | [WindowsFact] 27 | public void CanDeserializeInstance() 28 | { 29 | this.VerifyRoundTripInstance(); 30 | } 31 | 32 | [WindowsFact] 33 | public void CanDeserializeClass() 34 | { 35 | this.VerifyRoundTripClass(); 36 | } 37 | 38 | [WindowsFact] 39 | public void CanDeserializeInstanceWithCallback() 40 | { 41 | this.VerifyRoundtripWithCallback(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/NativeTests/XMLSerializerTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | using System; 10 | using System.Collections; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Runtime.InteropServices; 14 | using Microsoft.Management.Infrastructure.Native; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | namespace MMI.Tests.Native 19 | { 20 | public class XMLSerializerTests : NativeSerializerTestsBase 21 | { 22 | public XMLSerializerTests() : base(MI_SerializationFormat.XML) 23 | { 24 | } 25 | 26 | [WindowsFact] 27 | public void CanSerializeInstance() 28 | { 29 | this.TestInstanceSerializationInput(SerializationTestData.CreateBasicSerializableTestInstance, 30 | SerializationTestData.BasicSerializableTestInstanceXMLRepresentation); 31 | } 32 | 33 | [WindowsFact] 34 | public void CanSerializeClass() 35 | { 36 | string serialized = this.GetStringRepresentationFromClassThunk(SerializationTestData.GetSerializableTestClass); 37 | 38 | // Storing entire serialization of a class is too finicky here. Just check that there's something 39 | // expected inside the serialized string 40 | Xunit.Assert.Contains(SerializationTestData.SingletonClassSerializableClassHeuristicString, serialized); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/UnitTests/CimClassTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | namespace Microsoft.Management.Infrastructure.UnitTests 11 | { 12 | using Microsoft.Management.Infrastructure; 13 | using Microsoft.Management.Infrastructure.Native; 14 | using System; 15 | using MMI.Tests; 16 | using Xunit; 17 | 18 | public class CimClassTest 19 | { 20 | [TDDFact] 21 | public void TODO() 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/UnitTests/CimSessionTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | **============================================================================== 3 | ** 4 | ** Copyright (c) Microsoft Corporation. All rights reserved. See file LICENSE 5 | ** for license information. 6 | ** 7 | **============================================================================== 8 | */ 9 | 10 | using Microsoft.Management.Infrastructure; 11 | using Xunit; 12 | 13 | namespace MMI.Tests.UnitTests 14 | { 15 | 16 | 17 | 18 | public class CimSessionTest 19 | { 20 | #region Test create 21 | [TDDFact] 22 | public void Create_ComputerName_Null() 23 | { 24 | using (CimSession cimSession = CimSession.Create(null)) 25 | { 26 | Assert.NotNull(cimSession, "cimSession should not be null"); 27 | Assert.Null(cimSession.ComputerName, "cimSession.ComputerName should not be the same as the value passed to Create method"); 28 | } 29 | } 30 | 31 | [TDDFact] 32 | public void Create_ComputerName_Localhost() 33 | { 34 | using (CimSession cimSession = CimSession.Create("localhost")) 35 | { 36 | Assert.NotNull(cimSession, "cimSession should not be null"); 37 | Assert.Equal("localhost", cimSession.ComputerName, "cimSession.ComputerName should not be the same as the value passed to Create method"); 38 | Assert.True(cimSession.ToString().Contains("localhost"), "cimSession.ToString should contain computer name"); 39 | } 40 | } 41 | // Todo: will add more test cases 42 | #endregion Test create 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/UnitTests/TestData/mintinstance.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/MMI/cf32fc695b32c2eae848b693395c09222fe1d2ae/test/Microsoft.Management.Infrastructure.Tests/UnitTests/TestData/mintinstance.mof -------------------------------------------------------------------------------- /test/Microsoft.Management.Infrastructure.Tests/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Microsoft.Management.Infrastructure.Tests", 3 | "version": "1.0.0-*", 4 | "authors": [ "cbnilrem", "andschwa" ], 5 | 6 | "buildOptions": { 7 | "keyFile": "../../src/signing/visualstudiopublic.snk", 8 | "delaySign": true, 9 | "publicSign": false 10 | }, 11 | 12 | "dependencies": { 13 | "Microsoft.Management.Infrastructure": "1.0.0-*" 14 | }, 15 | 16 | "configurations": { 17 | "Linux": { 18 | "buildOptions": { 19 | "define": [ "_LINUX" ] 20 | } 21 | } 22 | }, 23 | 24 | "frameworks": { 25 | "netcoreapp1.0": { 26 | "imports": [ "dnxcore50", "portable-net45+win8" ], 27 | "dependencies": { 28 | "Microsoft.NETCore.App": "1.0.0-rc2-*", 29 | "xunit": "2.1.0", 30 | "dotnet-test-xunit": "1.0.0-rc2-192208-24" 31 | }, 32 | "buildOptions": { 33 | "define": [ "_CORECLR" ] 34 | } 35 | } 36 | }, 37 | 38 | "testRunner": "xunit", 39 | 40 | "runtimes": { 41 | "ubuntu.14.04-x64": { }, 42 | "centos.7-x64": { }, 43 | "win7-x64": { }, 44 | "win81-x64": { }, 45 | "win10-x64": { }, 46 | "osx.10.10-x64": { }, 47 | "osx.10.11-x64": { } 48 | } 49 | } 50 | --------------------------------------------------------------------------------