├── .gitattributes ├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .paket ├── paket.exe └── paket.targets ├── .travis.yml ├── FSharp.Management.Tests.sln ├── FSharp.Management.nuspec ├── FSharp.Management.sln ├── ISSUE_TEMPLATE.md ├── LICENSE.txt ├── README.md ├── RELEASE_NOTES.md ├── appveyor.yml ├── build.cmd ├── build.fsx ├── build.sh ├── docs ├── content │ ├── CommonFolders.fsx │ ├── FileSystemProvider.fsx │ ├── PowerShellProvider.fsx │ ├── RegistryProvider.fsx │ ├── SystemTimeZonesProvider.fsx │ ├── WMIProvider.fsx │ └── index.fsx ├── files │ └── img │ │ ├── FileSystemProvider.png │ │ ├── PowerShellProvider.png │ │ ├── RegistryProvider.png │ │ ├── RelativeFileSystemProvider.png │ │ ├── SystemTimeZonesProvider.png │ │ ├── WMIProvider.png │ │ ├── logo.pdn │ │ └── logo.png └── tools │ ├── generate.fsx │ └── templates │ └── template.cshtml ├── lib └── README.md ├── packages └── README.md ├── paket.dependencies ├── paket.lock ├── src ├── FSharp.Management.PowerShell.ExternalRuntime │ ├── App.config │ ├── AssemblyInfo.fs │ ├── FSharp.Management.PowerShell.ExternalRuntime.fsproj │ ├── Program.fs │ └── paket.references ├── FSharp.Management.PowerShell │ ├── AssemblyInfo.fs │ ├── ExternalRuntime.fs │ ├── FSharp.Management.PowerShell.fsproj │ ├── HostedRuntime.fs │ ├── PowerShellProvider.fs │ ├── Runtime.fs │ ├── TypeInference.fs │ ├── Types.fs │ └── paket.references ├── FSharp.Management.WMI.DesignTime │ ├── AssemblyInfo.fs │ ├── FSharp.Management.WMI.DesignTime.fsproj │ ├── WmiProvider.DesignTime.fs │ └── paket.references ├── FSharp.Management.WMI │ ├── AssemblyInfo.fs │ ├── FSharp.Management.WMI.fsproj │ ├── WmiProvider.Runtime.fs │ └── paket.references └── FSharp.Management │ ├── AssemblyInfo.fs │ ├── CommonFolders.fs │ ├── FSharp.Management.fsproj │ ├── FileSystemProvider.fs │ ├── RegistryProvider.fs │ ├── StringReaderProvider.fs │ ├── SystemTypeProviders.fs │ ├── TypeProviders.Helper.fs │ └── paket.references └── tests └── FSharp.Management.Tests ├── App.config ├── CommonFolders.Tests.fs ├── FSharp.Management.Tests.fsproj ├── FileSystemProvider.Tests.fs ├── PowerShellProvider.Tests.fs ├── Program.fs ├── RegistryProvider.Tests.fs ├── StringReaderProvider.Tests.data ├── StringReaderProvider.Tests.fs ├── SystemTimeZonesProvider.Tests.fs ├── WMI.Tests.fs ├── paket.references └── testModule.psm1 /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | 65 | *.sh text eol=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | Please provide a succinct description of your issue. 4 | 5 | ### Repro steps 6 | 7 | Please provide the steps required to reproduce the problem 8 | 9 | 1. Step A 10 | 11 | 2. Step B 12 | 13 | ### Expected behavior 14 | 15 | Please provide a description of the behavior you expect. 16 | 17 | ### Actual behavior 18 | 19 | Please provide a description of the actual behavior you observe. 20 | 21 | ### Known workarounds 22 | 23 | Please provide a description of any known workarounds. 24 | 25 | ### Related information 26 | 27 | * Operating system 28 | * Branch 29 | * .NET Runtime, CoreCLR or Mono Version 30 | * Performance information, links to performance testing scripts 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # Enable nuget.exe in the .nuget folder (though normally executables are not tracked) 99 | !.nuget/NuGet.exe 100 | 101 | # Windows Azure Build Output 102 | csx 103 | *.build.csdef 104 | 105 | # Windows Store app package directory 106 | AppPackages/ 107 | 108 | # Others 109 | sql/ 110 | *.Cache 111 | ClientBin/ 112 | [Ss]tyle[Cc]op.* 113 | ~$* 114 | *~ 115 | *.dbmdl 116 | *.[Pp]ublish.xml 117 | *.pfx 118 | *.publishsettings 119 | 120 | # RIA/Silverlight projects 121 | Generated_Code/ 122 | 123 | # Backup & report files from converting an old project file to a newer 124 | # Visual Studio version. Backup files are not needed, because we have git ;-) 125 | _UpgradeReport_Files/ 126 | Backup*/ 127 | UpgradeLog*.XML 128 | UpgradeLog*.htm 129 | 130 | # SQL Server files 131 | App_Data/*.mdf 132 | App_Data/*.ldf 133 | 134 | 135 | #LightSwitch generated files 136 | GeneratedArtifacts/ 137 | _Pvt_Extensions/ 138 | ModelManifest.xml 139 | 140 | # ========================= 141 | # Windows detritus 142 | # ========================= 143 | 144 | # Windows image file caches 145 | Thumbs.db 146 | ehthumbs.db 147 | 148 | # Folder config file 149 | Desktop.ini 150 | 151 | # Recycle Bin used on file shares 152 | $RECYCLE.BIN/ 153 | 154 | # Mac desktop service store files 155 | .DS_Store 156 | 157 | # =================================================== 158 | # Exclude F# project specific directories and files 159 | # =================================================== 160 | 161 | # NuGet Packages Directory 162 | packages/ 163 | paket-files/ 164 | 165 | # Generated documentation folder 166 | docs/output/ 167 | 168 | # Temp folder used for publishing docs 169 | temp/ 170 | .fake 171 | .vs 172 | 173 | # Test results produced by build 174 | TestResults.xml 175 | TestResult.xml 176 | release.cmd 177 | nuget/ 178 | 179 | # Nuget outputs 180 | nuget/*.nupkg 181 | docs/content/license.md 182 | docs/content/release-notes.md 183 | .fake 184 | docs/tools/FSharp.Formatting.svclog 185 | 186 | # paket file 187 | Paket.Restore.targets 188 | -------------------------------------------------------------------------------- /.paket/paket.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/.paket/paket.exe -------------------------------------------------------------------------------- /.paket/paket.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | true 8 | $(MSBuildThisFileDirectory) 9 | $(MSBuildThisFileDirectory)..\ 10 | 11 | 12 | 13 | $(PaketToolsPath)paket.exe 14 | $(PaketToolsPath)paket.bootstrapper.exe 15 | "$(PaketExePath)" 16 | mono --runtime=v4.0.30319 $(PaketExePath) 17 | "$(PaketBootStrapperExePath)" 18 | mono --runtime=v4.0.30319 $(PaketBootStrapperExePath) 19 | 20 | $(MSBuildProjectDirectory)\paket.references 21 | $(MSBuildProjectFullPath).paket.references 22 | $(PaketCommand) restore --references-files "$(PaketReferences)" 23 | $(PaketBootStrapperCommand) 24 | 25 | RestorePackages; $(BuildDependsOn); 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | 3 | sudo: false # use the new container-based Travis infrastructure 4 | 5 | script: 6 | - ./build.sh -------------------------------------------------------------------------------- /FSharp.Management.Tests.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 2013 3 | VisualStudioVersion = 12.0.21005.1 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{CB00A473-7BDD-4349-A894-EF585C0F9CA9}" 6 | ProjectSection(SolutionItems) = preProject 7 | paket.dependencies = paket.dependencies 8 | paket.lock = paket.lock 9 | EndProjectSection 10 | EndProject 11 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Management.Tests", "tests\FSharp.Management.Tests\FSharp.Management.Tests.fsproj", "{E789C72A-5CFD-436B-8EF1-61AA2852A89F}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /FSharp.Management.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @build.number@ 6 | @authors@ 7 | @authors@ 8 | http://github.com/fsprojects/FSharp.Management/blob/master/LICENSE.txt 9 | http://fsprojects.github.com/FSharp.Management 10 | false 11 | @summary@ 12 | @description@ 13 | @releaseNotes@ 14 | Copyright 2016 15 | @tags@ 16 | https://raw.githubusercontent.com/fsprojects/FSharp.Management/master/docs/files/img/logo.png 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /FSharp.Management.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 2013 3 | VisualStudioVersion = 12.0.31101.0 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{B2E65953-5C2D-420F-8857-CE8FC59AC3F1}" 6 | ProjectSection(SolutionItems) = preProject 7 | paket.dependencies = paket.dependencies 8 | paket.lock = paket.lock 9 | EndProjectSection 10 | EndProject 11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1}" 12 | EndProject 13 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Management", "src\FSharp.Management\FSharp.Management.fsproj", "{7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}" 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{BF60BC93-E09B-4E5F-9D85-95A519479D54}" 16 | ProjectSection(SolutionItems) = preProject 17 | build.fsx = build.fsx 18 | README.md = README.md 19 | RELEASE_NOTES.md = RELEASE_NOTES.md 20 | EndProjectSection 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{83F16175-43B1-4C90-A1EE-8E351C33435D}" 23 | ProjectSection(SolutionItems) = preProject 24 | docs\tools\generate.fsx = docs\tools\generate.fsx 25 | docs\tools\templates\template.cshtml = docs\tools\templates\template.cshtml 26 | EndProjectSection 27 | EndProject 28 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D5255-776D-4B61-85F9-73C37AA1FB9A}" 29 | ProjectSection(SolutionItems) = preProject 30 | docs\content\CommonFolders.fsx = docs\content\CommonFolders.fsx 31 | docs\content\FileSystemProvider.fsx = docs\content\FileSystemProvider.fsx 32 | docs\content\index.fsx = docs\content\index.fsx 33 | docs\content\PowerShellProvider.fsx = docs\content\PowerShellProvider.fsx 34 | docs\content\RegistryProvider.fsx = docs\content\RegistryProvider.fsx 35 | docs\content\SystemTimeZonesProvider.fsx = docs\content\SystemTimeZonesProvider.fsx 36 | docs\content\WMIProvider.fsx = docs\content\WMIProvider.fsx 37 | EndProjectSection 38 | EndProject 39 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Management.PowerShell.ExternalRuntime", "src\FSharp.Management.PowerShell.ExternalRuntime\FSharp.Management.PowerShell.ExternalRuntime.fsproj", "{282940BD-C7BE-4F1A-BF91-19E591ED7BD7}" 40 | EndProject 41 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Management.WMI", "src\FSharp.Management.WMI\FSharp.Management.WMI.fsproj", "{1D29693F-C472-4B03-A8CE-73CA0689012B}" 42 | EndProject 43 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Management.WMI.DesignTime", "src\FSharp.Management.WMI.DesignTime\FSharp.Management.WMI.DesignTime.fsproj", "{743C0C7B-79DA-44CC-9CB4-F3B25A5B0F08}" 44 | EndProject 45 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Management.PowerShell", "src\FSharp.Management.PowerShell\FSharp.Management.PowerShell.fsproj", "{04EE2403-5410-4CA5-AE4F-99015F1AB105}" 46 | EndProject 47 | Global 48 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 49 | Debug|Any CPU = Debug|Any CPU 50 | Release|Any CPU = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 53 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 54 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Debug|Any CPU.Build.0 = Debug|Any CPU 55 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Release|Any CPU.Build.0 = Release|Any CPU 57 | {282940BD-C7BE-4F1A-BF91-19E591ED7BD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 58 | {282940BD-C7BE-4F1A-BF91-19E591ED7BD7}.Debug|Any CPU.Build.0 = Debug|Any CPU 59 | {282940BD-C7BE-4F1A-BF91-19E591ED7BD7}.Release|Any CPU.ActiveCfg = Release|Any CPU 60 | {282940BD-C7BE-4F1A-BF91-19E591ED7BD7}.Release|Any CPU.Build.0 = Release|Any CPU 61 | {1D29693F-C472-4B03-A8CE-73CA0689012B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 62 | {1D29693F-C472-4B03-A8CE-73CA0689012B}.Debug|Any CPU.Build.0 = Debug|Any CPU 63 | {1D29693F-C472-4B03-A8CE-73CA0689012B}.Release|Any CPU.ActiveCfg = Release|Any CPU 64 | {1D29693F-C472-4B03-A8CE-73CA0689012B}.Release|Any CPU.Build.0 = Release|Any CPU 65 | {743C0C7B-79DA-44CC-9CB4-F3B25A5B0F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 66 | {743C0C7B-79DA-44CC-9CB4-F3B25A5B0F08}.Debug|Any CPU.Build.0 = Debug|Any CPU 67 | {743C0C7B-79DA-44CC-9CB4-F3B25A5B0F08}.Release|Any CPU.ActiveCfg = Release|Any CPU 68 | {743C0C7B-79DA-44CC-9CB4-F3B25A5B0F08}.Release|Any CPU.Build.0 = Release|Any CPU 69 | {04EE2403-5410-4CA5-AE4F-99015F1AB105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 70 | {04EE2403-5410-4CA5-AE4F-99015F1AB105}.Debug|Any CPU.Build.0 = Debug|Any CPU 71 | {04EE2403-5410-4CA5-AE4F-99015F1AB105}.Release|Any CPU.ActiveCfg = Release|Any CPU 72 | {04EE2403-5410-4CA5-AE4F-99015F1AB105}.Release|Any CPU.Build.0 = Release|Any CPU 73 | EndGlobalSection 74 | GlobalSection(SolutionProperties) = preSolution 75 | HideSolutionNode = FALSE 76 | EndGlobalSection 77 | GlobalSection(NestedProjects) = preSolution 78 | {83F16175-43B1-4C90-A1EE-8E351C33435D} = {A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1} 79 | {8E6D5255-776D-4B61-85F9-73C37AA1FB9A} = {A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1} 80 | EndGlobalSection 81 | EndGlobal 82 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | ### Description 3 | 4 | Please provide a succinct description of your issue. 5 | 6 | ### Repro steps 7 | 8 | Please provide the steps required to reproduce the problem 9 | 10 | 1. Step A 11 | 12 | 2. Step B 13 | 14 | ### Expected behavior 15 | 16 | Please provide a description of the behaviour you expect. 17 | 18 | ### Actual behavior 19 | 20 | Please provide a description of the actual behaviour you observe. 21 | 22 | ### Known workarounds 23 | 24 | Please provide a description of any known workarounds. 25 | 26 | ### Related information 27 | 28 | * Operating system 29 | * Branch 30 | * Database versions and sample databases being used 31 | * .NET Runtime, CoreCLR or Mono Version 32 | 33 | 34 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2013, F# Foundation 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | ------------------------------------------------------------ 16 | 17 | Apache License, Version 2.0 18 | =========================== 19 | 20 | Apache License 21 | Version 2.0, January 2004 22 | http://www.apache.org/licenses/ 23 | 24 | ### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 25 | 26 | 27 | **1. Definitions.** 28 | 29 | - "License" shall mean the terms and conditions for use, reproduction, 30 | and distribution as defined by Sections 1 through 9 of this document. 31 | 32 | - "Licensor" shall mean the copyright owner or entity authorized by 33 | the copyright owner that is granting the License. 34 | 35 | - "Legal Entity" shall mean the union of the acting entity and all 36 | other entities that control, are controlled by, or are under common 37 | control with that entity. For the purposes of this definition, 38 | "control" means (i) the power, direct or indirect, to cause the 39 | direction or management of such entity, whether by contract or 40 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 41 | outstanding shares, or (iii) beneficial ownership of such entity. 42 | 43 | - "You" (or "Your") shall mean an individual or Legal Entity 44 | exercising permissions granted by this License. 45 | 46 | - "Source" form shall mean the preferred form for making modifications, 47 | including but not limited to software source code, documentation 48 | source, and configuration files. 49 | 50 | - "Object" form shall mean any form resulting from mechanical 51 | transformation or translation of a Source form, including but 52 | not limited to compiled object code, generated documentation, 53 | and conversions to other media types. 54 | 55 | - "Work" shall mean the work of authorship, whether in Source or 56 | Object form, made available under the License, as indicated by a 57 | copyright notice that is included in or attached to the work 58 | (an example is provided in the Appendix below). 59 | 60 | - "Derivative Works" shall mean any work, whether in Source or Object 61 | form, that is based on (or derived from) the Work and for which the 62 | editorial revisions, annotations, elaborations, or other modifications 63 | represent, as a whole, an original work of authorship. For the purposes 64 | of this License, Derivative Works shall not include works that remain 65 | separable from, or merely link (or bind by name) to the interfaces of, 66 | the Work and Derivative Works thereof. 67 | 68 | - "Contribution" shall mean any work of authorship, including 69 | the original version of the Work and any modifications or additions 70 | to that Work or Derivative Works thereof, that is intentionally 71 | submitted to Licensor for inclusion in the Work by the copyright owner 72 | or by an individual or Legal Entity authorized to submit on behalf of 73 | the copyright owner. For the purposes of this definition, "submitted" 74 | means any form of electronic, verbal, or written communication sent 75 | to the Licensor or its representatives, including but not limited to 76 | communication on electronic mailing lists, source code control systems, 77 | and issue tracking systems that are managed by, or on behalf of, the 78 | Licensor for the purpose of discussing and improving the Work, but 79 | excluding communication that is conspicuously marked or otherwise 80 | designated in writing by the copyright owner as "Not a Contribution." 81 | 82 | - "Contributor" shall mean Licensor and any individual or Legal Entity 83 | on behalf of whom a Contribution has been received by Licensor and 84 | subsequently incorporated within the Work. 85 | 86 | **2. Grant of Copyright License.** 87 | Subject to the terms and conditions of 88 | this License, each Contributor hereby grants to You a perpetual, 89 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 90 | copyright license to reproduce, prepare Derivative Works of, 91 | publicly display, publicly perform, sublicense, and distribute the 92 | Work and such Derivative Works in Source or Object form. 93 | 94 | **3. Grant of Patent License.** 95 | Subject to the terms and conditions of 96 | this License, each Contributor hereby grants to You a perpetual, 97 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 98 | (except as stated in this section) patent license to make, have made, 99 | use, offer to sell, sell, import, and otherwise transfer the Work, 100 | where such license applies only to those patent claims licensable 101 | by such Contributor that are necessarily infringed by their 102 | Contribution(s) alone or by combination of their Contribution(s) 103 | with the Work to which such Contribution(s) was submitted. If You 104 | institute patent litigation against any entity (including a 105 | cross-claim or counterclaim in a lawsuit) alleging that the Work 106 | or a Contribution incorporated within the Work constitutes direct 107 | or contributory patent infringement, then any patent licenses 108 | granted to You under this License for that Work shall terminate 109 | as of the date such litigation is filed. 110 | 111 | **4. Redistribution.** 112 | You may reproduce and distribute copies of the 113 | Work or Derivative Works thereof in any medium, with or without 114 | modifications, and in Source or Object form, provided that You 115 | meet the following conditions: 116 | 117 | - You must give any other recipients of the Work or 118 | Derivative Works a copy of this License; and 119 | 120 | - You must cause any modified files to carry prominent notices 121 | stating that You changed the files; and 122 | 123 | - You must retain, in the Source form of any Derivative Works 124 | that You distribute, all copyright, patent, trademark, and 125 | attribution notices from the Source form of the Work, 126 | excluding those notices that do not pertain to any part of 127 | the Derivative Works; and 128 | 129 | - If the Work includes a "NOTICE" text file as part of its 130 | distribution, then any Derivative Works that You distribute must 131 | include a readable copy of the attribution notices contained 132 | within such NOTICE file, excluding those notices that do not 133 | pertain to any part of the Derivative Works, in at least one 134 | of the following places: within a NOTICE text file distributed 135 | as part of the Derivative Works; within the Source form or 136 | documentation, if provided along with the Derivative Works; or, 137 | within a display generated by the Derivative Works, if and 138 | wherever such third-party notices normally appear. The contents 139 | of the NOTICE file are for informational purposes only and 140 | do not modify the License. You may add Your own attribution 141 | notices within Derivative Works that You distribute, alongside 142 | or as an addendum to the NOTICE text from the Work, provided 143 | that such additional attribution notices cannot be construed 144 | as modifying the License. 145 | 146 | You may add Your own copyright statement to Your modifications and 147 | may provide additional or different license terms and conditions 148 | for use, reproduction, or distribution of Your modifications, or 149 | for any such Derivative Works as a whole, provided Your use, 150 | reproduction, and distribution of the Work otherwise complies with 151 | the conditions stated in this License. 152 | 153 | **5. Submission of Contributions.** 154 | Unless You explicitly state otherwise, 155 | any Contribution intentionally submitted for inclusion in the Work 156 | by You to the Licensor shall be under the terms and conditions of 157 | this License, without any additional terms or conditions. 158 | Notwithstanding the above, nothing herein shall supersede or modify 159 | the terms of any separate license agreement you may have executed 160 | with Licensor regarding such Contributions. 161 | 162 | **6. Trademarks.** 163 | This License does not grant permission to use the trade 164 | names, trademarks, service marks, or product names of the Licensor, 165 | except as required for reasonable and customary use in describing the 166 | origin of the Work and reproducing the content of the NOTICE file. 167 | 168 | **7. Disclaimer of Warranty.** 169 | Unless required by applicable law or 170 | agreed to in writing, Licensor provides the Work (and each 171 | Contributor provides its Contributions) on an "AS IS" BASIS, 172 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 173 | implied, including, without limitation, any warranties or conditions 174 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 175 | PARTICULAR PURPOSE. You are solely responsible for determining the 176 | appropriateness of using or redistributing the Work and assume any 177 | risks associated with Your exercise of permissions under this License. 178 | 179 | **8. Limitation of Liability.** 180 | In no event and under no legal theory, 181 | whether in tort (including negligence), contract, or otherwise, 182 | unless required by applicable law (such as deliberate and grossly 183 | negligent acts) or agreed to in writing, shall any Contributor be 184 | liable to You for damages, including any direct, indirect, special, 185 | incidental, or consequential damages of any character arising as a 186 | result of this License or out of the use or inability to use the 187 | Work (including but not limited to damages for loss of goodwill, 188 | work stoppage, computer failure or malfunction, or any and all 189 | other commercial damages or losses), even if such Contributor 190 | has been advised of the possibility of such damages. 191 | 192 | **9. Accepting Warranty or Additional Liability.** 193 | While redistributing 194 | the Work or Derivative Works thereof, You may choose to offer, 195 | and charge a fee for, acceptance of support, warranty, indemnity, 196 | or other liability obligations and/or rights consistent with this 197 | License. However, in accepting such obligations, You may act only 198 | on Your own behalf and on Your sole responsibility, not on behalf 199 | of any other Contributor, and only if You agree to indemnify, 200 | defend, and hold each Contributor harmless for any liability 201 | incurred by, or claims asserted against, such Contributor by reason 202 | of your accepting any such warranty or additional liability. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Issue Stats](http://issuestats.com/github/fsprojects/FSharp.Management/badge/issue)](http://issuestats.com/github/fsprojects/FSharp.Management) 2 | [![Issue Stats](http://issuestats.com/github/fsprojects/FSharp.Management/badge/pr)](http://issuestats.com/github/fsprojects/FSharp.Management) 3 | 4 | FSharp.Management [![NuGet Status](https://buildstats.info/nuget/FSharp.Management)](https://www.nuget.org/packages/FSharp.Management/) 5 | =========================== 6 | 7 | The FSharp.Management project contains various type providers for the management of the machine. 8 | 9 | * [FileSystem](http://fsprojects.github.io/FSharp.Management/FileSystemProvider.html) 10 | * [Registry](http://fsprojects.github.io/FSharp.Management/RegistryProvider.html) 11 | * [WMI](http://fsprojects.github.io/FSharp.Management/WMIProvider.html) 12 | * [PowerShell](http://fsprojects.github.io/FSharp.Management/PowerShellProvider.html) 13 | * [SystemTimeZonesProvider](http://fsprojects.github.io/FSharp.Management/SystemTimeZonesProvider.html) 14 | 15 | Documentation available here. 16 | 17 | ## Building 18 | [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/n94phug4pgecalte?svg=true)](https://ci.appveyor.com/project/sergey-tihon/fsharp-management-6aqlt) 19 | [![Travis build status](https://travis-ci.org/fsprojects/FSharp.Management.png)](https://travis-ci.org/fsprojects/FSharp.Management/) 20 | 21 | * Install [PowerShell 3.0](http://www.microsoft.com/en-us/download/details.aspx?id=34595) 22 | * Execute in PowerShell `x86` with admin rights `set-executionpolicy remotesigned` 23 | * Run build.cmd 24 | 25 | ## Maintainer(s) 26 | 27 | - [@forki](https://github.com/forki) 28 | - [@vasily-kirichenko](https://github.com/vasily-kirichenko) 29 | - [@sergey-tihon](https://github.com/sergey-tihon) 30 | - [@dtchepak](https://github.com/dtchepak) 31 | 32 | The default maintainer account for projects under "fsprojects" is [@fsprojectsgit](https://github.com/fsprojectsgit) - F# Community Project Incubation Space (repo management) 33 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | #### 0.4.5 - 12.05.2017 2 | * Added Mono 5 support - https://github.com/fsprojects/FSharp.Management/issues/82 3 | 4 | #### 0.4.4 - 05.05.2017 5 | * Added support for custom runspaces (PS TP) - https://github.com/fsprojects/FSharp.Management/pull/80 6 | 7 | #### 0.4.3 - 07.11.2016 8 | * Updated Type Provider SDK 9 | 10 | #### 0.4.2 - 21.08.2016 11 | * FIXED: PS Type provider type failed with Set-Location - https://github.com/fsprojects/FSharp.Management/issues/73 12 | 13 | #### 0.4.0 - 08.04.2016 14 | * BREAKING CHANGE: Support of Powershell pipeline errors - https://github.com/fsprojects/FSharp.Management/pull/66 15 | 16 | #### 0.3.1 - 28.10.2015 17 | * PowerShell module script support https://github.com/fsprojects/FSharp.Management/pull/62 18 | * PowerShell TypeProviders compiled for .NET 4.5 due to bug in Win10 - https://connect.microsoft.com/VisualStudio/feedback/details/1817986/unable-to-use-system-management-automation-dll-assembly-in-a-net-4-0-application-on-windows-10 19 | 20 | #### 0.3.0 - 27.07.2015 21 | * Added SystemTimeZonesProvider 22 | 23 | #### 0.2.1 - 07.07.2015 24 | * Added support of loading modules in PowerShellProvider 25 | * Added ability to call Azure PowerShell cmdlets. https://github.com/fsprojects/FSharp.Management/issues/47 26 | * New type inference approach for PS TP and new tests 27 | * Added paket dependency to FSharp.TypeProviders.StarterPack 28 | 29 | #### 0.2.0 - 03.01.2015 30 | * Use latest type provider sources 31 | * Use paket 32 | 33 | #### 0.1.1 - 25.06.2014 34 | * Fix memory leak - https://github.com/fsprojects/FSharp.Management/pull/42 35 | 36 | #### 0.1.0 - 31.12.2013 37 | * Initial release of FileSystemProvider 38 | * Initial release of RegistryProvider 39 | * Initial release of PowershellProvider 40 | * Initial release of WMI provider 41 | 42 | #### 0.1.0-alpha2 - 28.12.2013 43 | * Moved to fsprojects - https://github.com/fsprojects/FSharp.Management 44 | * New optional parameter watch in the file system provider allows to configure the FileSystemWatcher 45 | 46 | #### 0.1.0-alpha1 - 27.12.2013 47 | * Fixed FileSystem type provider invalidation 48 | * Splitted all type providers 49 | * Change "Parent" folder to ".." in relative type provider 50 | * Updated docs 51 | 52 | #### 0.0.13-alpha - 24.12.2013 53 | * Parent property in FileSystem type provider is lazy 54 | 55 | #### 0.0.12-alpha - 21.12.2013 56 | * Allows specification of a "root" folder in FileSystem type provider 57 | 58 | #### 0.0.11-alpha - 20.12.2013 59 | * Separate project for the powershell provider 60 | 61 | #### 0.0.10-alpha - 20.12.2013 62 | * Caching of the WMI provider 63 | 64 | #### 0.0.9-alpha - 20.12.2013 65 | * Delay for invalidation of the relative path type provider 66 | 67 | #### 0.0.8-alpha - 20.12.2013 68 | * Fixed bug in relative path type provider 69 | 70 | #### 0.0.7-alpha - 20.12.2013 71 | * FileSystem type provider invalidates itself whenever any child dirs/files changed in any way 72 | 73 | #### 0.0.6-alpha - 19.12.2013 74 | * Relative path type provider returns relative paths 75 | 76 | #### 0.0.5-alpha - 19.12.2013 77 | * Unified FileSystem type provider and relative path type provider 78 | * Made the FileSystem type provider robust against access problems 79 | 80 | #### 0.0.4-alpha - 19.12.2013 81 | * Relative path type provider allows to go up 82 | * Using latest provided types API from Sample pack 83 | 84 | #### 0.0.3-alpha - 19.12.2013 85 | * First version of the relative path type provider 86 | 87 | #### 0.0.2-alpha - 17.12.2013 88 | * Include FSharp.Management.PowerShell.ExternalRuntime 89 | 90 | #### 0.0.1-alpha - 17.12.2013 91 | * Initial release of FileSystemProvider 92 | * Initial release of RegistryProvider 93 | * Initial release of PowershellProvider 94 | * Initial release of WMI provider -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | init: 2 | - git config --global core.autocrlf input 3 | build_script: 4 | - cmd: build.cmd 5 | test: off 6 | version: 0.0.1.{build} 7 | artifacts: 8 | - path: bin 9 | name: bin 10 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | 4 | .paket\paket.exe restore 5 | if errorlevel 1 ( 6 | exit /b %errorlevel% 7 | ) 8 | 9 | packages\build\FAKE\tools\FAKE.exe build.fsx %* 10 | -------------------------------------------------------------------------------- /build.fsx: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // FAKE build script 3 | // -------------------------------------------------------------------------------------- 4 | 5 | #r @"packages/build/FAKE/tools/FakeLib.dll" 6 | open Fake 7 | open Fake.Git 8 | open Fake.AssemblyInfoFile 9 | open Fake.ReleaseNotesHelper 10 | open Fake.Testing.Expecto 11 | open System 12 | open System.IO 13 | #if MONO 14 | #else 15 | #load "packages/build/SourceLink.Fake/tools/Fake.fsx" 16 | open SourceLink 17 | #endif 18 | 19 | 20 | let projects = [|"FSharp.Management" 21 | "FSharp.Management.PowerShell" 22 | "FSharp.Management.PowerShell.ExternalRuntime" 23 | "FSharp.Management.WMI" 24 | "FSharp.Management.WMI.DesignTime"|] 25 | 26 | let summary = "Various type providers for management of the machine." 27 | let description = "Various type providers for management of the machine." 28 | let authors = ["Steffen Forkmann"; "Sergey Tihon"; "Daniel Mohl"; "Tomas Petricek"; "Ryan Riley"; "Mauricio Scheffer"; "Phil Trelford"; "Vasily Kirichenko"; "Reed Copsey, Jr."] 29 | let tags = "F# fsharp typeproviders Management PowerShell" 30 | 31 | let solutionFile = "FSharp.Management" 32 | 33 | let testAssemblies = "tests/**/bin/Release/*.Tests*.exe" 34 | let gitHome = "https://github.com/fsprojects" 35 | let gitName = "FSharp.Management" 36 | let cloneUrl = "https://github.com/fsprojects/FSharp.Management.git" 37 | let nugetDir = "./nuget/" 38 | 39 | // Read additional information from the release notes document 40 | Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ 41 | let release = parseReleaseNotes (IO.File.ReadAllLines "RELEASE_NOTES.md") 42 | 43 | // Generate assembly info files with the right version & up-to-date information 44 | Target "AssemblyInfo" (fun _ -> 45 | for project in projects do 46 | let fileName = "src/" + project + "/AssemblyInfo.fs" 47 | CreateFSharpAssemblyInfo fileName 48 | [ Attribute.Title project 49 | Attribute.Product project 50 | Attribute.Description summary 51 | Attribute.Version release.AssemblyVersion 52 | Attribute.FileVersion release.AssemblyVersion ] 53 | ) 54 | 55 | // -------------------------------------------------------------------------------------- 56 | // Clean build results & restore NuGet packages 57 | 58 | Target "Clean" (fun _ -> 59 | CleanDirs ["bin"; "temp"; nugetDir] 60 | ) 61 | 62 | Target "CleanDocs" (fun _ -> 63 | CleanDirs ["docs/output"] 64 | ) 65 | 66 | // -------------------------------------------------------------------------------------- 67 | // Build library & test project 68 | 69 | Target "Build" (fun _ -> 70 | !! (solutionFile + ".sln") 71 | |> MSBuildRelease "" "Rebuild" 72 | |> ignore 73 | ) 74 | 75 | Target "BuildTests" (fun _ -> 76 | !! (solutionFile + ".Tests.sln") 77 | |> MSBuildRelease "" "Rebuild" 78 | |> ignore 79 | ) 80 | 81 | // -------------------------------------------------------------------------------------- 82 | // Run the unit tests 83 | 84 | Target "RunTests" (fun _ -> 85 | !! testAssemblies 86 | |> Expecto (fun p -> 87 | { p with 88 | Parallel = false} ) 89 | |> ignore 90 | ) 91 | 92 | 93 | // -------------------------------------------------------------------------------------- 94 | // Build a NuGet package 95 | 96 | Target "NuGet" (fun _ -> 97 | // Format the description to fit on a single line (remove \r\n and double-spaces) 98 | let description = description.Replace("\r", "") 99 | .Replace("\n", "") 100 | .Replace(" ", " ") 101 | let project = projects.[0] 102 | 103 | let nugetDocsDir = nugetDir @@ "docs" 104 | let nugetlibDir = nugetDir @@ "lib/net40" 105 | 106 | CleanDir nugetDocsDir 107 | CleanDir nugetlibDir 108 | 109 | CopyDir nugetlibDir "bin" (fun file -> file.Contains "FSharp.Core." |> not) 110 | CopyDir nugetDocsDir "./docs/output" allFiles 111 | 112 | NuGet (fun p -> 113 | { p with 114 | Authors = authors 115 | Project = project 116 | Summary = summary 117 | Description = description 118 | Version = release.NugetVersion 119 | ReleaseNotes = release.Notes |> toLines 120 | Tags = tags 121 | OutputPath = nugetDir 122 | AccessKey = getBuildParamOrDefault "nugetkey" "" 123 | Publish = hasBuildParam "nugetkey" 124 | Dependencies = [] }) 125 | (project + ".nuspec") 126 | ) 127 | 128 | // -------------------------------------------------------------------------------------- 129 | // Generate the documentation 130 | 131 | Target "GenerateReferenceDocs" (fun _ -> 132 | if not <| executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"; "--define:REFERENCE"] [] then 133 | failwith "generating reference documentation failed" 134 | ) 135 | 136 | let generateHelp' fail debug = 137 | let args = 138 | if debug then ["--define:HELP"] 139 | else ["--define:RELEASE"; "--define:HELP"] 140 | if executeFSIWithArgs "docs/tools" "generate.fsx" args [] then 141 | traceImportant "Help generated" 142 | else 143 | if fail then 144 | failwith "generating help documentation failed" 145 | else 146 | traceImportant "generating help documentation failed" 147 | 148 | let generateHelp fail = 149 | generateHelp' fail false 150 | 151 | Target "GenerateHelp" (fun _ -> 152 | DeleteFile "docs/content/release-notes.md" 153 | CopyFile "docs/content/" "RELEASE_NOTES.md" 154 | Rename "docs/content/release-notes.md" "docs/content/RELEASE_NOTES.md" 155 | 156 | DeleteFile "docs/content/license.md" 157 | CopyFile "docs/content/" "LICENSE.txt" 158 | Rename "docs/content/license.md" "docs/content/LICENSE.txt" 159 | 160 | generateHelp true 161 | ) 162 | 163 | Target "GenerateHelpDebug" (fun _ -> 164 | DeleteFile "docs/content/release-notes.md" 165 | CopyFile "docs/content/" "RELEASE_NOTES.md" 166 | Rename "docs/content/release-notes.md" "docs/content/RELEASE_NOTES.md" 167 | 168 | DeleteFile "docs/content/license.md" 169 | CopyFile "docs/content/" "LICENSE.txt" 170 | Rename "docs/content/license.md" "docs/content/LICENSE.txt" 171 | 172 | generateHelp' true true 173 | ) 174 | 175 | Target "KeepRunning" (fun _ -> 176 | use watcher = !! "docs/content/**/*.*" |> WatchChanges (fun changes -> 177 | generateHelp false 178 | ) 179 | 180 | traceImportant "Waiting for help edits. Press any key to stop." 181 | 182 | System.Console.ReadKey() |> ignore 183 | 184 | watcher.Dispose() 185 | ) 186 | 187 | Target "GenerateDocs" DoNothing 188 | 189 | let createIndexFsx lang = 190 | let content = """(*** hide ***) 191 | // This block of code is omitted in the generated HTML documentation. Use 192 | // it to define helpers that you do not want to show in the documentation. 193 | #I "../../../bin" 194 | 195 | (** 196 | F# Project Scaffold ({0}) 197 | ========================= 198 | *) 199 | """ 200 | let targetDir = "docs/content" @@ lang 201 | let targetFile = targetDir @@ "index.fsx" 202 | ensureDirectory targetDir 203 | System.IO.File.WriteAllText(targetFile, System.String.Format(content, lang)) 204 | 205 | Target "AddLangDocs" (fun _ -> 206 | let args = System.Environment.GetCommandLineArgs() 207 | if args.Length < 4 then 208 | failwith "Language not specified." 209 | 210 | args.[3..] 211 | |> Seq.iter (fun lang -> 212 | if lang.Length <> 2 && lang.Length <> 3 then 213 | failwithf "Language must be 2 or 3 characters (ex. 'de', 'fr', 'ja', 'gsw', etc.): %s" lang 214 | 215 | let templateFileName = "template.cshtml" 216 | let templateDir = "docs/tools/templates" 217 | let langTemplateDir = templateDir @@ lang 218 | let langTemplateFileName = langTemplateDir @@ templateFileName 219 | 220 | if System.IO.File.Exists(langTemplateFileName) then 221 | failwithf "Documents for specified language '%s' have already been added." lang 222 | 223 | ensureDirectory langTemplateDir 224 | Copy langTemplateDir [ templateDir @@ templateFileName ] 225 | 226 | createIndexFsx lang) 227 | ) 228 | 229 | // -------------------------------------------------------------------------------------- 230 | // Release Scripts 231 | 232 | Target "ReleaseDocs" (fun _ -> 233 | let ghPages = "gh-pages" 234 | let ghPagesLocal = "temp/gh-pages" 235 | Repository.clone "temp" (cloneUrl) ghPages 236 | Branches.checkoutBranch ghPagesLocal ghPages 237 | fullclean "temp/gh-pages" 238 | CopyRecursive "docs/output" ghPagesLocal true |> printfn "%A" 239 | CommandHelper.runSimpleGitCommand ghPagesLocal "add ." |> printfn "%s" 240 | let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion 241 | CommandHelper.runSimpleGitCommand ghPagesLocal cmd |> printfn "%s" 242 | Branches.push ghPagesLocal 243 | ) 244 | 245 | Target "Release" DoNothing 246 | 247 | Target "BuildPackage" DoNothing 248 | 249 | 250 | // -------------------------------------------------------------------------------------- 251 | // Run all targets by default. Invoke 'build ' to override 252 | 253 | Target "All" DoNothing 254 | 255 | "Clean" 256 | ==> "AssemblyInfo" 257 | ==> "Build" 258 | #if MONO 259 | #else 260 | ==> "BuildTests" 261 | ==> "RunTests" 262 | #endif 263 | ==> "All" 264 | 265 | "All" 266 | ==> "NuGet" 267 | ==> "BuildPackage" 268 | 269 | "CleanDocs" 270 | ==> "GenerateHelp" 271 | ==> "GenerateReferenceDocs" 272 | ==> "GenerateDocs" 273 | 274 | "CleanDocs" 275 | ==> "GenerateHelpDebug" 276 | 277 | "GenerateHelp" 278 | ==> "KeepRunning" 279 | 280 | "GenerateDocs" 281 | ==> "ReleaseDocs" 282 | ==> "Release" 283 | 284 | "BuildPackage" 285 | ==> "Release" 286 | 287 | RunTargetOrDefault "All" 288 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if test "$OS" = "Windows_NT" 3 | then 4 | # use .Net 5 | 6 | .paket/paket.exe restore 7 | exit_code=$? 8 | if [ $exit_code -ne 0 ]; then 9 | exit $exit_code 10 | fi 11 | 12 | packages/build/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx 13 | else 14 | # use mono 15 | 16 | mono .paket/paket.exe restore 17 | exit_code=$? 18 | if [ $exit_code -ne 0 ]; then 19 | exit $exit_code 20 | fi 21 | mono packages/build/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx 22 | fi 23 | -------------------------------------------------------------------------------- /docs/content/CommonFolders.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | The CommonFolders module 6 | ============================ 7 | 8 | This tutorial shows the use of the CommonFolders module. 9 | It simplifies runtime access to various common folder locations on the system, including 10 | folders related to the current user, the shared user folders, system wide folders, and 11 | folders specific to the currently executing process. 12 | 13 | This is particularly useful when combined with the RelativePath type provider for working 14 | with project data and deployed. For example, the following copies a file from the project's 15 | doc\contents to the user's roaming application data folder. 16 | *) 17 | 18 | // Reference the type provider dll 19 | #r "FSharp.Management.dll" 20 | open FSharp.Management 21 | open System.IO 22 | 23 | // Get the currently executing user's application data folder 24 | let userAppData = CommonFolders.GetUser UserPath.RoamingApplicationData 25 | 26 | // Let the type provider do it's work - grab the docs subfolder 27 | type Docs = RelativePath<"docs"> 28 | 29 | // now you have typed access to your filesystem 30 | let currentFile = Docs.content.CommonFolders.fsx 31 | 32 | currentFile 33 | // [fsi:val it : string = "content\CommonFolders.fsx"] 34 | 35 | // Get the location of the installed executable 36 | let exePath = CommonFolders.GetApplication ApplicationPath.EntryPointLocation 37 | 38 | // Build the source and target path - This assumes the exe is in bin\Release or similar 39 | let sourcePath = Path.Combine(exePath, "..\\..", currentFile) 40 | let targetPath = Path.Combine(userAppData, "SomeCompany\\SomeProgram", currentFile) 41 | 42 | // Make sure it exists on the system 43 | Directory.CreateDirectory(Path.GetDirectoryName(targetPath)) 44 | // [fsi:val it : System.IO.DirectoryInfo = ] 45 | // [fsi: content {Attributes = Directory; ] 46 | // [fsi: ... ] 47 | 48 | // Copy the source to the target location 49 | File.Copy(sourcePath, targetPath) 50 | // [fsi:val it : unit = () ] 51 | 52 | // File is now in the appropriate user's [Application data]\SomeCompany\SomeProgram\content\CommonFolders.fsx 53 | 54 | (** 55 | 56 | The CommonFolders module supports pulling data from various locations, based on any provided 57 | UserPath, SharedPath, SystemPath, or ApplicationPath. Note that many of these paths are wrappers 58 | around Environment.GetFolderPath, though a few pull from other APIs. 59 | 60 | Some examples of getting common folders include: 61 | *) 62 | 63 | // Get the currently executing user's application data folder, both roaming and local profile 64 | let userAppData = CommonFolders.GetUser UserPath.RoamingApplicationData 65 | let userLocalAppData = CommonFolders.GetUser UserPath.LocalApplicationData 66 | 67 | // Get the user's Desktop 68 | let userDesktop = CommonFolders.GetUser UserPath.Desktop 69 | 70 | // Get user's pictures 71 | let userDesktop = CommonFolders.GetUser UserPath.Pictures 72 | 73 | // Get the Windows install folder: 74 | let windows = CommonFolders.GetSystem SystemPath.Windows 75 | 76 | // Get the temp folder 77 | let windows = CommonFolders.GetSystem SystemPath.Temp 78 | 79 | // Get the shared documents folder 80 | let sharedAppData = CommonFolders.GetSharedUser SharedPath.Documents 81 | -------------------------------------------------------------------------------- /docs/content/FileSystemProvider.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | The FileSystem type provider 6 | ============================ 7 | 8 | This tutorial shows the use of the file system type provider. 9 | It allows to browse your file system via Intellisense and provides compile time checks for directories and files. 10 | The FileSystem type provider invalidates itself whenever any child dirs/files changed in any way. 11 | *) 12 | 13 | // reference the type provider dll 14 | #r "FSharp.Management.dll" 15 | open FSharp.Management 16 | 17 | // Let the type provider do it's work 18 | type Users = FileSystem<"C:\\Users"> 19 | 20 | // now you have typed access to your filesystem 21 | Users.``All Users``.Path 22 | // [fsi:val it : string = "C:\Users\All Users\"] 23 | 24 | (** 25 | 26 | ![alt text](img/FileSystemProvider.png "Intellisense for the file system") 27 | 28 | The FileSystem type provider also allows a second, optional parameter to be specified which provides a relative 29 | root path for the returned paths. The above example could be written without referencing the drive in the 30 | resulting paths via: 31 | *) 32 | 33 | // Let the type provider do it's work 34 | type UsersWithoutDrive = FileSystem<"C:\\Users", relativeTo = "C:"> 35 | 36 | // now you have typed access to your filesystem 37 | UsersWithoutDrive.``All Users``.Path 38 | // [fsi:val it : string = "Users\All Users\"] 39 | 40 | (** 41 | 42 | A third, optional "watch" parameter can be used to specify that the file system should be watched for changes, 43 | and the type provider invalidated if new files are added or removed. This is false by default, which means 44 | adding new files will not show up immediately without invalidating the type provider by some external mechanism, 45 | such as restarting the IDE. 46 | *) 47 | 48 | // Create a type provider that automatically watches for new files or changes to folders 49 | type UsersWithChanges = FileSystem<"C:\\Users", watch = true> 50 | 51 | // Now you have typed access to your filesystem 52 | UsersWithChanges.``All Users``.Path 53 | 54 | // [fsi:val it : string = "C:\Users\All Users\"] 55 | 56 | (** 57 | 58 | Relative paths 59 | -------------- 60 | 61 | For web frameworks it's interesting to reference resources like images. 62 | With the help of the FileSystemProvider we can browse the project via Intellisense and get compile time safety for relative paths. 63 | 64 | Note that the RelativePath type provider also supports the optional "watch" parameter, with false as the default. 65 | 66 | ![alt text](img/RelativeFileSystemProvider.png "Intellisense for the current subfolders") 67 | 68 | *) 69 | 70 | // reference the type provider dll 71 | #r "FSharp.Management.dll" 72 | open FSharp.Management 73 | 74 | // Create a type relative to the project's root path 75 | type Relative = RelativePath<".", watch = false> 76 | 77 | // Browse the project 78 | Relative.``..``.files.img.``PowerShellProvider.png`` 79 | // [fsi:val it : string = "..\files\img\PowerShellProvider.png" -------------------------------------------------------------------------------- /docs/content/PowerShellProvider.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | #I @"C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0" 4 | 5 | (** 6 | The PowerShell type provider 7 | ============================ 8 | 9 | Requirements: 10 | 11 | - .NET 4.5 12 | - PowerShell 3.0 13 | 14 | This tutorial shows the use of the PowerShell type provider. 15 | *) 16 | 17 | // reference the type provider dll 18 | #r "System.Management.Automation.dll" 19 | #r "FSharp.Management.PowerShell.dll" 20 | 21 | open FSharp.Management 22 | 23 | // Let the type provider infer the signatures of available cmdlets 24 | type PS = PowerShellProvider< "Microsoft.PowerShell.Management;Microsoft.PowerShell.Core" > 25 | 26 | // now you have typed access to your PowerShell and you can browse it via Intellisense 27 | PS.``Get-EventLog``(logName="Application", entryType=[|"Error"|], newest=2) 28 | // [fsi:val it :] 29 | // [fsi: PowerShellProvider.Types.PsCmdletResult,] 30 | // [fsi: List,] 31 | // [fsi: List>,] 32 | // [fsi: List>] 33 | // [fsi:= Success] 34 | // [fsi: (Choice2Of3] 35 | // [fsi: [System.Diagnostics.EventLogEntry] 36 | // [fsi: {Category = "(0)";] 37 | // [fsi: CategoryNumber = 0s;] 38 | // [fsi: Container = null;] 39 | // [fsi: Data = [||];] 40 | // [fsi: EntryType = Error;] 41 | // [fsi: EventID = 1022;] 42 | // [fsi: Index = 72795;] 43 | // [fsi: InstanceId = 1022L;] 44 | // [fsi: MachineName = "xxx";] 45 | // [fsi: Message = ".NET Runtime version 4.0.30319.0 - Loading profiler failed during ...";] 46 | // [fsi: ReplacementStrings = [|".NET Runtime version 4.0.30319.0 - Loading profiler failed during ..."|];] 47 | // [fsi: Site = null;] 48 | // [fsi: Source = ".NET Runtime";] 49 | // [fsi: TimeGenerated = 4/8/2016 7:46:57 PM;] 50 | // [fsi: TimeWritten = 4/8/2016 7:46:57 PM;] 51 | // [fsi: UserName = "xxx";};] 52 | // [fsi: System.Diagnostics.EventLogEntry] 53 | // [fsi: {Category = "(0)";] 54 | // [fsi: CategoryNumber = 0s;] 55 | // [fsi: Container = null;] 56 | // [fsi: Data = [||];] 57 | // [fsi: EntryType = Error;] 58 | // [fsi: EventID = 1022;] 59 | // [fsi: Index = 72794;] 60 | // [fsi: InstanceId = 1022L;] 61 | // [fsi: MachineName = "xxx";] 62 | // [fsi: Message = ".NET Runtime version 4.0.30319.0 - Loading profiler failed during ...";] 63 | // [fsi: ReplacementStrings = [|".NET Runtime version 4.0.30319.0 - Loading profiler failed during ..."|];] 64 | // [fsi: Site = null;] 65 | // [fsi: Source = ".NET Runtime";] 66 | // [fsi: TimeGenerated = 4/8/2016 7:46:25 PM;] 67 | // [fsi: TimeWritten = 4/8/2016 7:46:25 PM;] 68 | // [fsi: UserName = "xxx";}])] 69 | 70 | (** 71 | 72 | ![alt text](img/PowerShellProvider.png "Intellisense for the PowerShell") 73 | 74 | Manage Windows services 75 | -------------------- 76 | *) 77 | #r "System.ServiceProcess.dll" 78 | 79 | let service = 80 | match PS.``Get-Service``(name=[|"Windows Search"|]) with 81 | | Success(services) when services.Length = 1 -> 82 | services.Head 83 | | _ -> failwith "Choice is ambiguous or service not found" 84 | // [fsi:val service : ServiceProcess.ServiceController =] 85 | // [fsi: System.ServiceProcess.ServiceController] 86 | // [fsi: {CanPauseAndContinue = false;] 87 | // [fsi: CanShutdown = true;] 88 | // [fsi: CanStop = true;] 89 | // [fsi: Container = null;] 90 | // [fsi: DependentServices = [|System.ServiceProcess.ServiceController;] 91 | // [fsi: System.ServiceProcess.ServiceController|];] 92 | // [fsi: DisplayName = "Windows Search";] 93 | // [fsi: MachineName = ".";] 94 | // [fsi: ServiceHandle = SafeServiceHandle;] 95 | // [fsi: ServiceName = "WSearch";] 96 | // [fsi: ServiceType = Win32OwnProcess;] 97 | // [fsi: ServicesDependedOn = [|System.ServiceProcess.ServiceController|];] 98 | // [fsi: Site = null;] 99 | // [fsi: Status = Running;}] 100 | 101 | PS.``Start-Service``(inputObject=[|service|]) 102 | 103 | (** 104 | Working with Snapins 105 | -------------------- 106 | *) 107 | // get all registered PowerShell Snapins 108 | PS.``Get-PSSnapin``(registered=true) 109 | // [fsi:val it :] 110 | // [fsi: PsCmdletResult,] 111 | // [fsi: List> =] 112 | // [fsi: Success] 113 | // [fsi: [WDeploySnapin3.0] 114 | // [fsi: {ApplicationBase = "C:\Program Files\IIS\Microsoft Web Deploy V3\";] 115 | // [fsi: AssemblyName = "Microsoft.Web.Deployment.PowerShell, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";] 116 | // [fsi: Description = "This is a PowerShell snap-in that contains cmdlets for managing Microsoft Web Deployment infrastructure.";] 117 | // [fsi: Formats = seq [];] 118 | // [fsi: IsDefault = false;] 119 | // [fsi: LogPipelineExecutionDetails = false;] 120 | // [fsi: ModuleName = "Microsoft.Web.Deployment.PowerShell.dll";] 121 | // [fsi: Name = "WDeploySnapin3.0";] 122 | // [fsi: PSVersion = 2.0;] 123 | // [fsi: Types = seq [];] 124 | // [fsi: Vendor = "Microsoft";] 125 | // [fsi: Version = 9.0.0.0;}]] 126 | 127 | (** 128 | Working with Script Module files 129 | -------------------- 130 | 131 | - The `PowerShell` script execution should be enable on the system, make sure the execution policy is appropriately set 132 | (Example: `set-executionpolicy remotesigned` Note that `x86` and `x64` runtimes have different execution policy settings) 133 | - The exported function in the module file needs to have the `OutputType` attribute 134 | if they return a value 135 | 136 | 137 | This following module definition 138 | 139 | ```PowerShell 140 | function doSomething { 141 | [OutputType([string])] 142 | param ( 143 | [string] $test 144 | ) 145 | return $test 146 | } 147 | 148 | export-moduleMember -function doSomething 149 | ``` 150 | 151 | can be referenced like so 152 | 153 | *) 154 | 155 | let []ModuleFile = 156 | __SOURCE_DIRECTORY__ + @"\..\..\tests\FSharp.Management.Tests\testModule.psm1" 157 | 158 | type PSFileModule = PowerShellProvider< ModuleFile > 159 | 160 | PSFileModule.doSomething(test="testString") 161 | // [fsi:val it : ] 162 | // [fsi: PsCmdletResult,List>] 163 | // [fsi:= Success ["testString"]] 164 | 165 | 166 | 167 | (** 168 | Parallel commands execution 169 | -------------------- 170 | 171 | - The "CustomRunspace" method will create a separate runspace where you can execute all provided commands. The runspace is closed on disposing 172 | *) 173 | 174 | use runspace = new PSFileModule.CustomRunspace() 175 | runspace.doSomething(test="testString") 176 | 177 | (** 178 | This can be used to execute commands in parallel 179 | *) 180 | 181 | ["testString1"; "testString2"; "testString3"] 182 | |> Seq.map (fun testString -> async { 183 | use runspace = new PSFileModule.CustomRunspace() 184 | runspace.doSomething(test=testString) 185 | }) 186 | |> Async.Parallel 187 | |> Async.RunSynchronously 188 | |> ignore 189 | -------------------------------------------------------------------------------- /docs/content/RegistryProvider.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | The Registry type provider 6 | ========================== 7 | 8 | This tutorial shows the use of the registry type provider. 9 | *) 10 | 11 | // reference the type provider dll 12 | #r "FSharp.Management.dll" 13 | open FSharp.Management 14 | 15 | // use the registry type provider to get typed access to your registry and browse it via Intellisense 16 | Registry.HKEY_CURRENT_USER.Path 17 | // [fsi:val it : string = "HKEY_CURRENT_USER"] 18 | 19 | Registry.HKEY_LOCAL_MACHINE.SOFTWARE.Microsoft.Path 20 | // [fsi:val it : string = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft"] 21 | 22 | (** 23 | 24 | ![alt text](img/RegistryProvider.png "Intellisense for the registry") 25 | 26 | *) -------------------------------------------------------------------------------- /docs/content/SystemTimeZonesProvider.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | The SystemTimeZones type provider 6 | ========================== 7 | 8 | This tutorial shows the use of the SystemTimeZones type provider. 9 | 10 | ![alt text](img/SystemTimeZonesProvider.png "Intellisense for the system time zones") 11 | 12 | *) 13 | 14 | #r "FSharp.Management.dll" 15 | open FSharp.Management 16 | open System 17 | 18 | (** 19 | 20 | Answer to a [question from stackoverflow.com](http://stackoverflow.com/questions/2961848/how-to-use-timezoneinfo-to-get-local-time-during-daylight-savings-time). 21 | 22 | *) 23 | 24 | let utc = DateTime(2010, 6, 2, 16, 37, 19, DateTimeKind.Utc) 25 | let ctsTZ = SystemTimeZones.``(UTC-06:00) Central Time (US & Canada)`` 26 | printfn "Central Standard Time: %A" <| TimeZoneInfo.ConvertTimeFromUtc(utc, ctsTZ) 27 | // Central Standard Time: 6/2/2010 11:37:19 AM -------------------------------------------------------------------------------- /docs/content/WMIProvider.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | The WMI type provider 6 | ===================== 7 | 8 | This tutorial shows the use of the [Windows Management Instrumentation (WMI)](http://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx) type provider. 9 | *) 10 | 11 | // reference the type provider dll 12 | #r "System.Management.dll" 13 | #r "FSharp.Management.WMI.dll" 14 | 15 | open FSharp.Management 16 | 17 | // Let the type provider infer the local machine 18 | type Local = WmiProvider<"localhost"> 19 | let data = Local.GetDataContext() 20 | 21 | (** 22 | 23 | ![alt text](img/WMIProvider.png "Intellisense for WMI") 24 | 25 | *) 26 | 27 | // Add a handler to watch WMI queries getting executed (optional) 28 | data.QueryExecuted.Add(printfn "Query executed: %s") 29 | 30 | // list all local drives 31 | [for d in data.Win32_DiskDrive -> d.Name, d.Description] 32 | // [fsi:Query executed: select * from Win32_DiskDrive] 33 | // [fsi:val it : (string * string) list =] 34 | // [fsi: [("\\.\PHYSICALDRIVE0", "Laufwerk"); ("\\.\PHYSICALDRIVE1", "Laufwerk")] 35 | 36 | // Access some WMI data from the data connection 37 | [for d in data.CIM_DiskDrive -> 38 | [for c in d.Capabilities -> c.Is_SMART_Notification]] 39 | // [fsi:Query executed: select * from CIM_DiskDrive] 40 | // [fsi:val it : bool list list = [[false; false]; [false; false]]] 41 | -------------------------------------------------------------------------------- /docs/content/index.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | FSharp.Management 6 | =========================== 7 | 8 | The FSharp.Management project contains various type providers for the management of the machine. 9 | 10 | * [FileSystem](FileSystemProvider.html) 11 | * [Registry](RegistryProvider.html) 12 | * [WMI](WMIProvider.html) 13 | * [PowerShell](PowerShellProvider.html) 14 | * [SystemTimeZonesProvider](SystemTimeZonesProvider.html) 15 | 16 | In addition, a set of utilities for dealing with common paths on the system at runtime are provided. 17 | 18 | * [CommonFolders](CommonFolders.html) 19 | 20 |
21 |
22 |
23 |
24 | The library can be installed from NuGet: 25 |
PM> Install-Package FSharp.Management
26 |
27 |
28 |
29 |
30 | 31 | Example 32 | ------- 33 | 34 | This example demonstrates the use of the FileSystem type provider: 35 | 36 | *) 37 | // reference the type provider dll 38 | #r "FSharp.Management.dll" 39 | open FSharp.Management 40 | 41 | // Let the type provider do it's work 42 | type Users = FileSystem<"C:\\Users\\"> 43 | 44 | // now you have typed access to your filesystem and you can browse it via Intellisense 45 | Users.AllUsers.Path 46 | // [fsi:val it : string = "C:\Users\All Users"] 47 | 48 | (** 49 | 50 | Contributing and copyright 51 | -------------------------- 52 | 53 | The project is hosted on [GitHub][gh] where you can [report issues][issues], fork 54 | the project and submit pull requests. If you're adding new public API, please also 55 | consider adding [samples][content] that can be turned into a documentation. You might 56 | also want to read [library design notes][readme] to understand how it works. 57 | 58 | The library is available under Public Domain license, which allows modification and 59 | redistribution for both commercial and non-commercial purposes. For more information see the 60 | [License file][license] in the GitHub repository. 61 | 62 | [content]: https://github.com/fsprojects/FSharp.Management/tree/master/docs/content 63 | [gh]: https://github.com/fsprojects/FSharp.Management 64 | [issues]: https://github.com/fsprojects/FSharp.Management/issues 65 | [readme]: https://github.com/fsprojects/FSharp.Management/blob/master/README.md 66 | [license]: https://github.com/fsprojects/FSharp.Management/blob/master/LICENSE.txt 67 | *) 68 | -------------------------------------------------------------------------------- /docs/files/img/FileSystemProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/FileSystemProvider.png -------------------------------------------------------------------------------- /docs/files/img/PowerShellProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/PowerShellProvider.png -------------------------------------------------------------------------------- /docs/files/img/RegistryProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/RegistryProvider.png -------------------------------------------------------------------------------- /docs/files/img/RelativeFileSystemProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/RelativeFileSystemProvider.png -------------------------------------------------------------------------------- /docs/files/img/SystemTimeZonesProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/SystemTimeZonesProvider.png -------------------------------------------------------------------------------- /docs/files/img/WMIProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/WMIProvider.png -------------------------------------------------------------------------------- /docs/files/img/logo.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/logo.pdn -------------------------------------------------------------------------------- /docs/files/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FSharp.Management/38c1db9bba35ea64ebe5f9d48ff23cf0ad8119cf/docs/files/img/logo.png -------------------------------------------------------------------------------- /docs/tools/generate.fsx: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // Builds the documentation from `.fsx` and `.md` files in the 'docs/content' directory 3 | // (the generated documentation is stored in the 'docs/output' directory) 4 | // -------------------------------------------------------------------------------------- 5 | 6 | // Binaries that have XML documentation (in a corresponding generated XML file) 7 | let referenceBinaries = [ "FSharp.Management.dll" ] 8 | // Web site location for the generated documentation 9 | let website = "/FSharp.Management" 10 | 11 | let githubLink = "http://github.com/fsprojects/FSharp.Management" 12 | 13 | // Specify more information about your project 14 | let info = 15 | [ "project-name", "FSharp.Management" 16 | "project-author", "Steffen Forkmann" 17 | "project-summary", "Various type providers for management of the machine." 18 | "project-github", githubLink 19 | "project-nuget", "https://www.nuget.org/packages/FSharp.Management" ] 20 | 21 | // -------------------------------------------------------------------------------------- 22 | // For typical project, no changes are needed below 23 | // -------------------------------------------------------------------------------------- 24 | 25 | #I "../../packages/build/FAKE/tools/" 26 | #load "../../packages/build/FSharp.Formatting/FSharp.Formatting.fsx" 27 | #r "NuGet.Core.dll" 28 | #r "FakeLib.dll" 29 | open Fake 30 | open System.IO 31 | open Fake.FileHelper 32 | open FSharp.Literate 33 | open FSharp.MetadataFormat 34 | 35 | // When called from 'build.fsx', use the public project URL as 36 | // otherwise, use the current 'output' directory. 37 | #if RELEASE 38 | let root = website 39 | #else 40 | let root = "file://" + (__SOURCE_DIRECTORY__ @@ "../output") 41 | #endif 42 | 43 | // Paths with template/source/output locations 44 | let bin = __SOURCE_DIRECTORY__ @@ "../../bin" 45 | let content = __SOURCE_DIRECTORY__ @@ "../content" 46 | let output = __SOURCE_DIRECTORY__ @@ "../output" 47 | let files = __SOURCE_DIRECTORY__ @@ "../files" 48 | let templates = __SOURCE_DIRECTORY__ @@ "templates" 49 | let formatting = __SOURCE_DIRECTORY__ @@ "../../packages/build/FSharp.Formatting/" 50 | let docTemplate = "docpage.cshtml" 51 | 52 | // Where to look for *.csproj templates (in this order) 53 | let layoutRootsAll = new System.Collections.Generic.Dictionary() 54 | layoutRootsAll.Add("en",[ templates; formatting @@ "templates" 55 | formatting @@ "templates/reference" ]) 56 | subDirectories (directoryInfo templates) 57 | |> Seq.iter (fun d -> 58 | let name = d.Name 59 | if name.Length = 2 || name.Length = 3 then 60 | layoutRootsAll.Add( 61 | name, [templates @@ name 62 | formatting @@ "templates" 63 | formatting @@ "templates/reference" ])) 64 | 65 | // Copy static files and CSS + JS from F# Formatting 66 | let copyFiles () = 67 | CopyRecursive files output true |> Log "Copying file: " 68 | ensureDirectory (output @@ "content") 69 | CopyRecursive (formatting @@ "styles") (output @@ "content") true 70 | |> Log "Copying styles and scripts: " 71 | 72 | let binaries = 73 | let manuallyAdded = 74 | referenceBinaries 75 | |> List.map (fun b -> bin @@ b) 76 | 77 | let conventionBased = 78 | directoryInfo bin 79 | |> subDirectories 80 | |> Array.map (fun d -> d.FullName @@ (sprintf "%s.dll" d.Name)) 81 | |> List.ofArray 82 | 83 | conventionBased @ manuallyAdded 84 | 85 | let libDirs = 86 | let conventionBasedbinDirs = 87 | directoryInfo bin 88 | |> subDirectories 89 | |> Array.map (fun d -> d.FullName) 90 | |> List.ofArray 91 | 92 | conventionBasedbinDirs @ [bin] 93 | 94 | // Build API reference from XML comments 95 | let buildReference () = 96 | CleanDir (output @@ "reference") 97 | MetadataFormat.Generate 98 | ( binaries, output @@ "reference", layoutRootsAll.["en"], 99 | parameters = ("root", root)::info, 100 | sourceRepo = githubLink @@ "tree/master", 101 | sourceFolder = __SOURCE_DIRECTORY__ @@ ".." @@ "..", 102 | publicOnly = true,libDirs = libDirs ) 103 | 104 | // Build documentation from `fsx` and `md` files in `docs/content` 105 | let buildDocumentation () = 106 | 107 | // First, process files which are placed in the content root directory. 108 | 109 | Literate.ProcessDirectory 110 | ( content, docTemplate, output, replacements = ("root", root)::info, 111 | layoutRoots = layoutRootsAll.["en"], 112 | generateAnchors = true, 113 | processRecursive = false) 114 | 115 | // And then process files which are placed in the sub directories 116 | // (some sub directories might be for specific language). 117 | 118 | let subdirs = Directory.EnumerateDirectories(content, "*", SearchOption.TopDirectoryOnly) 119 | for dir in subdirs do 120 | let dirname = (new DirectoryInfo(dir)).Name 121 | let layoutRoots = 122 | // Check whether this directory name is for specific language 123 | let key = layoutRootsAll.Keys 124 | |> Seq.tryFind (fun i -> i = dirname) 125 | match key with 126 | | Some lang -> layoutRootsAll.[lang] 127 | | None -> layoutRootsAll.["en"] // "en" is the default language 128 | 129 | Literate.ProcessDirectory 130 | ( dir, docTemplate, output @@ dirname, replacements = ("root", root)::info, 131 | layoutRoots = layoutRoots, 132 | generateAnchors = true ) 133 | 134 | // Generate 135 | copyFiles() 136 | #if HELP 137 | buildDocumentation() 138 | #endif 139 | #if REFERENCE 140 | buildReference() 141 | #endif 142 | 143 | -------------------------------------------------------------------------------- /docs/tools/templates/template.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | @Title 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 |
24 |
25 | 29 |

@Properties["project-name"]

30 |
31 |
32 |
33 |
34 | @RenderBody() 35 |
36 |
37 | FSharp.Management 38 | 54 |
55 |
56 |
57 | Fork me on GitHub 58 | 59 | 60 | -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | This file is in the `lib` directory. 2 | 3 | Any **libraries** on which your project depends and which are **NOT managed via NuGet** should be kept **in this directory**. 4 | This typically includes custom builds of third-party software, private (i.e. to a company) codebases, and native libraries. 5 | 6 | --- 7 | NOTE: 8 | 9 | This file is a placeholder, used to preserve directory structure in Git. 10 | 11 | This file does not need to be edited. 12 | -------------------------------------------------------------------------------- /packages/README.md: -------------------------------------------------------------------------------- 1 | This file is in the `packages` directory. 2 | 3 | Any NuGet packages on which your project depends will be downloaded to this directory. 4 | Additionally, packages required by the build process will be stored here. 5 | 6 | It is **strongly advised** that the **contents of this directory not be committed** to source control 7 | (with the sole exception being this `README.md` file). 8 | 9 | --- 10 | NOTE: 11 | 12 | This file is a placeholder, used to preserve directory structure in Git. 13 | 14 | This file does not need to be edited. 15 | -------------------------------------------------------------------------------- /paket.dependencies: -------------------------------------------------------------------------------- 1 | source https://nuget.org/api/v2 2 | 3 | nuget FSharp.Core ~> 3 4 | nuget System.Management.Automation_PowerShell_3.0 5 | 6 | github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fsi 7 | github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fs 8 | 9 | group Test 10 | source https://nuget.org/api/v2 11 | framework: net461 12 | 13 | nuget Expecto redirects:force 14 | 15 | group Build 16 | source https://nuget.org/api/v2 17 | framework: net461 18 | 19 | nuget SourceLink.Fake 20 | nuget FAKE 21 | nuget FSharp.Formatting 22 | nuget NuGet.CommandLine 23 | -------------------------------------------------------------------------------- /paket.lock: -------------------------------------------------------------------------------- 1 | NUGET 2 | remote: https://www.nuget.org/api/v2 3 | FSharp.Core (3.1.2.5) 4 | System.Management.Automation_PowerShell_3.0 (6.3.9600.17400) 5 | GITHUB 6 | remote: fsprojects/FSharp.TypeProviders.StarterPack 7 | src/ProvidedTypes.fs (1dab4f94411500794342f61f877feab772e5a754) 8 | src/ProvidedTypes.fsi (1dab4f94411500794342f61f877feab772e5a754) 9 | GROUP Build 10 | RESTRICTION: == net461 11 | NUGET 12 | remote: https://www.nuget.org/api/v2 13 | FAKE (4.61.3) 14 | FSharp.Compiler.Service (2.0.0.6) 15 | FSharp.Formatting (2.14.4) 16 | FSharp.Compiler.Service (2.0.0.6) 17 | FSharpVSPowerTools.Core (>= 2.3 < 2.4) 18 | FSharpVSPowerTools.Core (2.3) 19 | FSharp.Compiler.Service (>= 2.0.0.3) 20 | NuGet.CommandLine (4.1) 21 | SourceLink.Fake (1.1) 22 | 23 | GROUP Test 24 | RESTRICTION: == net461 25 | NUGET 26 | remote: https://www.nuget.org/api/v2 27 | Argu (3.7) - redirects: force 28 | Expecto (5.0) - redirects: force 29 | Argu (>= 3.7) 30 | FSharp.Core (>= 4.1.12) 31 | Mono.Cecil (>= 0.10.0-beta5) 32 | FSharp.Core (4.2.1) - redirects: force 33 | Mono.Cecil (0.10.0-beta6) - redirects: force 34 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell.ExternalRuntime/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell.ExternalRuntime/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | do () 11 | 12 | module internal AssemblyVersionInformation = 13 | let [] AssemblyTitle = "FSharp.Management.PowerShell.ExternalRuntime" 14 | let [] AssemblyProduct = "FSharp.Management.PowerShell.ExternalRuntime" 15 | let [] AssemblyDescription = "Various type providers for management of the machine." 16 | let [] AssemblyVersion = "0.4.5" 17 | let [] AssemblyFileVersion = "0.4.5" 18 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell.ExternalRuntime/FSharp.Management.PowerShell.ExternalRuntime.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 282940bd-c7be-4f1a-bf91-19e591ed7bd7 9 | Exe 10 | FSharp.Management.PowerShell.ExternalRuntime 11 | FSharp.Management.PowerShell.ExternalRuntime 12 | v4.5 13 | true 14 | 4.4.0.0 15 | FSharp.Management.PowerShell.ExternalRuntime 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | false 23 | ..\..\bin\ 24 | DEBUG;TRACE 25 | 3 26 | x64 27 | 28 | 29 | false 30 | 31 | 32 | pdbonly 33 | true 34 | true 35 | ..\..\bin 36 | TRACE 37 | 3 38 | AnyCPU 39 | ..\..\bin\FSharp.Management.PowerShell.ExternalRuntime.XML 40 | true 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | FSharp.Management.PowerShell 57 | {04ee2403-5410-4ca5-ae4f-99015f1ab105} 58 | True 59 | 60 | 61 | 62 | 11 63 | 64 | 65 | 66 | 67 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 68 | 69 | 70 | 71 | 72 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 73 | 74 | 75 | 76 | 77 | 84 | 85 | 86 | 87 | 88 | 89 | ..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll 90 | True 91 | True 92 | 93 | 94 | 95 | 96 | 97 | 98 | ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll 99 | True 100 | True 101 | 102 | 103 | 104 | 105 | 106 | 107 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll 108 | True 109 | True 110 | 111 | 112 | 113 | 114 | 115 | 116 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll 117 | True 118 | True 119 | 120 | 121 | 122 | 123 | 124 | 125 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll 126 | True 127 | True 128 | 129 | 130 | 131 | 132 | 133 | 134 | ..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45\FSharp.Core.dll 135 | True 136 | True 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | ..\..\packages\System.Management.Automation_PowerShell_3.0\lib\net40\System.Management.Automation.dll 146 | True 147 | True 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell.ExternalRuntime/Program.fs: -------------------------------------------------------------------------------- 1 | open FSharp.Management.PowerShellProvider.ExternalRuntime 2 | 3 | open System 4 | open System.ServiceModel 5 | 6 | [] 7 | let main argv = 8 | if Environment.Version.Major < 4 9 | then failwith ".NET runtime should be version 4+" 10 | if not <| Environment.Is64BitProcess 11 | then failwith "Process should be 64bit" 12 | 13 | let snapIns, _modules = argv |> Array.partition (fun x-> x.StartsWith("+") |> not) 14 | let modules = _modules |> Array.map (fun x->x.TrimStart([|'+'|])) 15 | 16 | use psRuntimeService = new PSRuntimeService(snapIns, modules) 17 | let serviceHost = new ServiceHost(psRuntimeService, [|Uri(ExternalPowerShellHost)|]) 18 | serviceHost.AddServiceEndpoint( 19 | typeof, 20 | getNetNamedPipeBinding(), 21 | ExternalPowerShellServiceName) 22 | |> ignore 23 | 24 | serviceHost.Open() 25 | 26 | for endpoint in serviceHost.Description.Endpoints do 27 | printfn "%s" (endpoint.Address.Uri.AbsoluteUri) 28 | 29 | Console.ReadLine() |> ignore 30 | 0 -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell.ExternalRuntime/paket.references: -------------------------------------------------------------------------------- 1 | FSharp.Core 2 | System.Management.Automation_PowerShell_3.0 -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | do () 11 | 12 | module internal AssemblyVersionInformation = 13 | let [] AssemblyTitle = "FSharp.Management.PowerShell" 14 | let [] AssemblyProduct = "FSharp.Management.PowerShell" 15 | let [] AssemblyDescription = "Various type providers for management of the machine." 16 | let [] AssemblyVersion = "0.4.5" 17 | let [] AssemblyFileVersion = "0.4.5" 18 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/ExternalRuntime.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.PowerShellProvider.ExternalRuntime 2 | 3 | open System 4 | open System.IO 5 | open System.ServiceModel 6 | open System.ServiceModel.Description 7 | open System.Runtime.Serialization 8 | open HostedRuntime 9 | 10 | [] 11 | type PSCmdLetInfoDTO() = 12 | [] 13 | member val RawName = "" with get, set 14 | [] 15 | member val ResultObjectTypes = Array.empty with get, set 16 | [] 17 | member val ParametersNames = Array.empty with get, set 18 | [] 19 | member val IsMandatory = Array.empty with get, set 20 | [] 21 | member val ParametersTypes = Array.empty with get, set 22 | 23 | [] 24 | type IPSRuntimeService = 25 | [] 26 | abstract member GetAllCmdlets : unit -> PSCmdLetInfoDTO[] 27 | [] 28 | abstract member GetXmlDoc : commandName : string -> string 29 | 30 | 31 | [] 32 | type PSRuntimeService(snapIns:string[], modules:string[]) = 33 | let psRuntimeHosted = new PSRuntimeHosted(snapIns, modules) 34 | let psRuntime = psRuntimeHosted :> IPSRuntime 35 | let serializeType = (fun (t:Type) -> t.AssemblyQualifiedName) 36 | interface IPSRuntimeService with 37 | member __.GetAllCmdlets() = 38 | psRuntime.AllCommands() 39 | |> Array.map (fun cmdlet -> 40 | let paramNames, isMandaroty, paramTypes = 41 | cmdlet.ParametersInfo |> Array.unzip3 42 | PSCmdLetInfoDTO( 43 | RawName = cmdlet.Name, 44 | ResultObjectTypes = (cmdlet.ResultObjectTypes |> Array.map serializeType), 45 | ParametersNames = paramNames, 46 | IsMandatory = isMandaroty, 47 | ParametersTypes = (paramTypes |> Array.map serializeType))) 48 | member __.GetXmlDoc rawName = 49 | psRuntime.GetXmlDoc(rawName) 50 | interface IDisposable with 51 | member __.Dispose() = 52 | (psRuntimeHosted :> IDisposable).Dispose() 53 | 54 | [] 55 | let ExternalPowerShellHost = "net.pipe://localhost/" 56 | [] 57 | let ExternalPowerShellServiceName = "PowerShellRuntimeForTypeProvider" 58 | 59 | let getNetNamedPipeBinding() = 60 | let binding = NetNamedPipeBinding() 61 | let maxSize = 50000000 62 | binding.MaxBufferPoolSize <- (int64)maxSize 63 | binding.MaxBufferSize <- maxSize 64 | binding.MaxReceivedMessageSize <- (int64)maxSize 65 | binding.ReaderQuotas.MaxArrayLength <- maxSize 66 | binding.ReaderQuotas.MaxBytesPerRead <- maxSize 67 | binding.ReaderQuotas.MaxStringContentLength <- maxSize 68 | binding 69 | 70 | 71 | type PSRuntimeServiceClient(serviceUrl: string) = 72 | inherit ClientBase( 73 | new ServiceEndpoint( 74 | ContractDescription.GetContract(typeof), 75 | getNetNamedPipeBinding(), 76 | EndpointAddress(serviceUrl))) 77 | interface IPSRuntimeService with 78 | member this.GetAllCmdlets() = 79 | this.Channel.GetAllCmdlets() 80 | member this.GetXmlDoc rawName = 81 | this.Channel.GetXmlDoc(rawName) 82 | 83 | 84 | /// PowerShell runtime executed in external 64bit process 85 | type PSRuntimeExternal(snapIns: string[], modules: string[]) = 86 | let psProcess, serviceUrl = 87 | let pr = new System.Diagnostics.Process() 88 | pr.StartInfo.UseShellExecute <- false 89 | pr.StartInfo.CreateNoWindow <- true 90 | 91 | let fullPath = System.Reflection.Assembly.GetAssembly(typeof).Location 92 | let directory = Path.GetDirectoryName( fullPath ) 93 | let externalRuntime = Path.Combine(directory, "FSharp.Management.PowerShell.ExternalRuntime.exe") 94 | 95 | pr.StartInfo.FileName <- externalRuntime 96 | 97 | let parameters = Array.append snapIns (Array.map (sprintf "+%s") modules) 98 | pr.StartInfo.Arguments <- String.Join(" ", parameters) 99 | 100 | pr.StartInfo.RedirectStandardInput <- true 101 | pr.StartInfo.RedirectStandardOutput <- true 102 | pr.Start() |> ignore 103 | let url = pr.StandardOutput.ReadLine() 104 | pr, url 105 | let client = new PSRuntimeServiceClient(serviceUrl) 106 | let clientService = client :> IPSRuntimeService 107 | let unSerializeType = 108 | (fun typeName -> 109 | let ty = Type.GetType(typeName) 110 | if (ty = null) then 111 | failwithf "Type does not found '%s'" typeName 112 | ty) 113 | 114 | interface IDisposable with 115 | member __.Dispose() = 116 | try 117 | client.Close() 118 | finally 119 | psProcess.StandardInput.WriteLine() 120 | psProcess.WaitForExit() 121 | 122 | interface IPSRuntime with 123 | member __.Runspace = failwith "Not implemented" 124 | member __.AllCommands() = 125 | clientService.GetAllCmdlets() 126 | |> Array.map (fun dto -> 127 | let resultObjectTypes = (dto.ResultObjectTypes |> Array.map unSerializeType) 128 | let paramTypes = (dto.ParametersTypes |> Array.map unSerializeType) 129 | { 130 | Name = dto.RawName 131 | UniqueID = dto.RawName; 132 | ResultObjectTypes = resultObjectTypes 133 | ResultType = (resultObjectTypes |> TypeInference.buildResultType) 134 | ParametersInfo = (Array.zip3 (dto.ParametersNames) (dto.IsMandatory) (paramTypes)) 135 | }) 136 | member __.Execute(_, _) = failwith "Not implemented" 137 | member __.GetXmlDoc rawName = clientService.GetXmlDoc(rawName) 138 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/FSharp.Management.PowerShell.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 04ee2403-5410-4ca5-ae4f-99015f1ab105 9 | Library 10 | FSharp.Management.PowerShell 11 | FSharp.Management.PowerShell 12 | v4.5 13 | 4.4.0.0 14 | FSharp.Management.PowerShell 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | 3 25 | bin\Debug\FSharp.Management.PowerShell.XML 26 | Program 27 | D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe 28 | D:\Personal\GitHub\FSharp.Management\ 29 | FSharp.Management.Tests.sln 30 | 31 | 32 | pdbonly 33 | true 34 | true 35 | bin\Release\ 36 | TRACE 37 | 3 38 | bin\Release\FSharp.Management.PowerShell.XML 39 | 40 | 41 | 11 42 | 43 | 44 | 45 | 46 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 47 | 48 | 49 | 50 | 51 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 52 | 53 | 54 | 55 | 56 | 63 | 64 | 65 | 66 | True 67 | paket-files/ProvidedTypes.fsi 68 | 69 | 70 | True 71 | paket-files/ProvidedTypes.fsi 72 | 73 | 74 | True 75 | paket-files/ProvidedTypes.fs 76 | 77 | 78 | 79 | TypeProviders.Helper.fs 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | ..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll 103 | True 104 | True 105 | 106 | 107 | 108 | 109 | 110 | 111 | ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll 112 | True 113 | True 114 | 115 | 116 | 117 | 118 | 119 | 120 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll 121 | True 122 | True 123 | 124 | 125 | 126 | 127 | 128 | 129 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll 130 | True 131 | True 132 | 133 | 134 | 135 | 136 | 137 | 138 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll 139 | True 140 | True 141 | 142 | 143 | 144 | 145 | 146 | 147 | ..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45\FSharp.Core.dll 148 | True 149 | True 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | ..\..\packages\System.Management.Automation_PowerShell_3.0\lib\net40\System.Management.Automation.dll 159 | True 160 | True 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/HostedRuntime.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.PowerShellProvider.HostedRuntime 2 | 3 | open TypeInference 4 | 5 | open System 6 | open System.Management.Automation 7 | open System.Management.Automation.Runspaces 8 | open System.Threading 9 | open System.Security.Principal 10 | 11 | type IPSRuntime = 12 | abstract member AllCommands : unit -> PSCommandSignature[] 13 | abstract member Execute : string * obj seq -> obj 14 | abstract member GetXmlDoc : string -> string 15 | abstract member Runspace : System.Management.Automation.Runspaces.Runspace 16 | 17 | /// PowerShell runtime built into the current process 18 | type PSRuntimeHosted(snapIns:string[], modules:string[]) = 19 | let runSpace = 20 | try 21 | let initState = InitialSessionState.CreateDefault() 22 | initState.AuthorizationManager <- new Microsoft.PowerShell.PSAuthorizationManager("Microsoft.PowerShell") 23 | 24 | // Import SnapIns 25 | for snapIn in snapIns do 26 | if not <| String.IsNullOrEmpty(snapIn) then 27 | let _, ex = initState.ImportPSSnapIn(snapIn) 28 | if ex <> null then 29 | failwithf "ImportPSSnapInExceptions: %s" ex.Message 30 | 31 | // Import modules 32 | let modules = modules |> Array.filter (String.IsNullOrWhiteSpace >> not) 33 | if not <| Array.isEmpty modules then 34 | initState.ImportPSModule(modules); 35 | 36 | let rs = RunspaceFactory.CreateRunspace(initState) 37 | Thread.CurrentPrincipal <- GenericPrincipal(GenericIdentity("PowerShellTypeProvider"), null) 38 | rs.Open() 39 | rs 40 | with 41 | | e -> failwithf "Could not create PowerShell Runspace: '%s'" e.Message 42 | let commandInfos = 43 | //Get-Command -CommandType @("cmdlet","function") -ListImported 44 | PowerShell.Create(Runspace=runSpace) 45 | .AddCommand("Get-Command") 46 | .AddParameter("CommandType", ["cmdlet"; "function"]) // Get only cmdlets and functions (without aliases) 47 | .AddParameter("ListImported") // Get only commands imported into current runtime 48 | .Invoke() 49 | |> Seq.map (fun x -> 50 | match x.BaseObject with 51 | | :? CommandInfo as ci -> ci 52 | | w -> failwithf "Unsupported type of command: %A" w) 53 | |> Seq.toArray 54 | let commands = 55 | try 56 | commandInfos 57 | |> Seq.map (fun cmd -> 58 | match cmd with 59 | | :? CmdletInfo | :? FunctionInfo-> 60 | if cmd.ParameterSets.Count > 0 then 61 | seq { 62 | // Generate function for each command's parameter set 63 | for pSet in cmd.ParameterSets do 64 | let cmdSignature = getPSCommandSignature cmd pSet 65 | yield cmdSignature.UniqueID, cmdSignature 66 | } 67 | else 68 | failwithf "Command is not loaded: %A" cmd 69 | | _ -> failwithf "Unexpected type of command: %A" cmd 70 | ) 71 | |> Seq.concat 72 | |> Map.ofSeq 73 | with 74 | | e -> failwithf "Could not load command: %s\n%s" e.Message e.StackTrace 75 | let allCommands = commands |> Map.toSeq |> Seq.map snd |> Seq.toArray 76 | 77 | let getXmlDoc(cmdName:string) = 78 | let result = 79 | PowerShell.Create(Runspace=runSpace) 80 | .AddCommand("Get-Help") 81 | .AddParameter("Name", cmdName) 82 | .Invoke() 83 | |> Seq.toArray 84 | 85 | let (?) (this : PSObject) (prop : string) : obj = 86 | let prop = this.Properties |> Seq.find (fun p -> p.Name = prop) 87 | prop.Value 88 | match result with 89 | | [|help|] -> 90 | let lines = 91 | let description = (help?description :?> obj []) 92 | if description = null then [||] 93 | else 94 | description 95 | |> CollectionConverter.Convert 96 | |> List.toArray 97 | |> Array.map (fun x->x?Text :?> string) 98 | sprintf "%s" 99 | (String.Join("", lines |> Array.map (fun s->s.Replace("<","").Replace(">","")))) 100 | | _ -> String.Empty 101 | let xmlDocs = System.Collections.Generic.Dictionary<_,_>() 102 | 103 | interface IPSRuntime with 104 | member __.Runspace = runSpace 105 | member __.AllCommands() = allCommands 106 | member __.Execute(uniqueId, parameters:obj seq) = 107 | let cmd = commands.[uniqueId] 108 | 109 | // Create and execute PowerShell command 110 | let ps = PowerShell.Create(Runspace=runSpace).AddCommand(cmd.Name) 111 | parameters |> Seq.iteri (fun i value-> 112 | let key, _,ty = cmd.ParametersInfo.[i] 113 | match ty with 114 | | _ when ty = typeof-> 115 | if (unbox value) then 116 | ps.AddParameter(key) |> ignore 117 | | _ when ty.IsValueType -> 118 | if (value <> System.Activator.CreateInstance(ty)) 119 | then ps.AddParameter(key, value) |> ignore 120 | | _ -> 121 | if (value <> null) 122 | then ps.AddParameter(key, value) |> ignore 123 | ) 124 | let result = ps.Invoke() 125 | 126 | // Infer type of the result 127 | match getTypeOfObjects cmd.ResultObjectTypes result with 128 | | None -> 129 | if ps.Streams.Error.Count > 0 then 130 | let errors = ps.Streams.Error |> Seq.cast |> List.ofSeq 131 | cmd.ResultType.GetMethod("NewFailure").Invoke(null, [|errors|]) 132 | else 133 | let boxedResult = if result.Count > 0 then 134 | box (new PSObject(result)) 135 | else 136 | box None 137 | 138 | cmd.ResultType.GetMethod("NewSuccess").Invoke(null, [|boxedResult|]) // Result of execution is empty object 139 | 140 | | Some(tyOfObj) -> 141 | let collectionConverter = 142 | typedefof>.MakeGenericType(tyOfObj) 143 | let collectionObj = 144 | if (tyOfObj = typeof) then box result 145 | else result |> Seq.map (fun x->x.BaseObject) |> box 146 | let typedCollection = 147 | collectionConverter.GetMethod("Convert").Invoke(null, [|collectionObj|]) 148 | 149 | let choise = 150 | if (cmd.ResultObjectTypes.Length = 1) 151 | then typedCollection 152 | else let ind = cmd.ResultObjectTypes |> Array.findIndex (fun x-> x = tyOfObj) 153 | let funcName = sprintf "NewChoice%dOf%d" (ind+1) (cmd.ResultObjectTypes.Length) 154 | cmd.ResultType.GetGenericArguments().[0] // GenericTypeArguments in .NET 4.5 155 | .GetMethod(funcName).Invoke(null, [|typedCollection|]) 156 | 157 | cmd.ResultType.GetMethod("NewSuccess").Invoke(null, [|choise|]) 158 | member __.GetXmlDoc (cmdName:string) = 159 | if not <| xmlDocs.ContainsKey cmdName 160 | then xmlDocs.Add(cmdName, getXmlDoc cmdName) 161 | xmlDocs.[cmdName] 162 | 163 | interface IDisposable with 164 | member __.Dispose () = runSpace.Dispose() -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/PowerShellProvider.fs: -------------------------------------------------------------------------------- 1 | namespace FSharp.Management.PowerShellProvider 2 | 3 | open System.Reflection 4 | open ProviderImplementation.ProvidedTypes 5 | open Microsoft.FSharp.Core.CompilerServices 6 | open FSharp.Management.Helper 7 | 8 | [] 9 | type public PowerShellProvider(_cfg: TypeProviderConfig) as this = 10 | inherit TypeProviderForNamespaces() 11 | 12 | // Get the assembly and namespace used to host the provided types 13 | let baseTy = typeof 14 | let staticParams = [ProvidedStaticParameter("Modules", typeof, parameterDefaultValue = "") 15 | ProvidedStaticParameter("PSSnapIns", typeof, parameterDefaultValue = "") 16 | ProvidedStaticParameter("Is64BitRequired", typeof, parameterDefaultValue = false)] 17 | 18 | // Expose all available cmdlets as methods 19 | let shell = ProvidedTypeDefinition(thisAssembly, rootNamespace, "PowerShellProvider", Some(baseTy)) 20 | let helpText = 21 | """Typed representation of a PowerShell runspace 22 | List of Modules that will be loaded at the start (separated by semicolon). 23 | List of PSSnapIn that will be added at the start (separated by semicolon). 24 | Mark that 64bit runtime should be used for PowerShell""" 25 | do shell.AddXmlDoc helpText 26 | do shell.DefineStaticParameters( 27 | parameters=staticParams, 28 | instantiationFunction=(fun typeName parameterValues -> 29 | let modules = parameterValues.[0] :?> string 30 | let psSnapIns = parameterValues.[1] :?> string 31 | let is64bitRequired = parameterValues.[2] :?> bool 32 | 33 | let createMembers areStatic = [ 34 | let runtime = Runtime.Current(psSnapIns.Split(';'), modules.Split(';'), is64bitRequired, true) 35 | for cmdlet in runtime.AllCommands() do 36 | let paramList = 37 | [for (name, isMandatory, ty) in cmdlet.ParametersInfo -> 38 | let newTy, defValue = 39 | match ty with 40 | | _ when ty = typeof -> 41 | typeof, box false 42 | | _ when ty.IsValueType -> 43 | ty, box None //System.Activator.CreateInstance(ty) 44 | | _ -> ty, null 45 | match isMandatory with 46 | | true -> ProvidedParameter(TypeInference.toCamelCase name, newTy) 47 | | false -> ProvidedParameter(TypeInference.toCamelCase name, newTy, optionalValue=defValue)] 48 | let providedMethod = 49 | ProvidedMethod( 50 | methodName = cmdlet.Name, 51 | parameters = paramList, 52 | returnType = cmdlet.ResultType, 53 | IsStaticMethod = areStatic, 54 | InvokeCode = 55 | fun args -> 56 | let mapToParameters (args:Quotations.Expr list) = 57 | if args.Length <> paramList.Length then 58 | failwithf "Expected %d arguments but received %d" paramList.Length args.Length 59 | 60 | let elements = [ for i in 0..(paramList.Length-1) -> 61 | Quotations.Expr.Coerce(args.[i], typeof) ] 62 | Quotations.Expr.NewArray(typeof, elements) 63 | 64 | let uid = cmdlet.UniqueID 65 | if areStatic then 66 | let parameters = mapToParameters args 67 | <@@ Runtime.Current(psSnapIns.Split(';'), modules.Split(';'), is64bitRequired, false) 68 | .Execute(uid, (%%parameters : obj[])) @@> 69 | else 70 | let constructorExpression, args = 71 | match args with 72 | | head :: tail -> head, tail 73 | | [] -> failwith "Constructor should create runspace" 74 | 75 | let runspace = Quotations.Expr.Coerce(constructorExpression, typeof) 76 | let parameters = mapToParameters args 77 | <@@ (%%runspace : HostedRuntime.IPSRuntime).Execute(uid, (%%parameters : obj[])) @@>) 78 | 79 | 80 | providedMethod.AddXmlDocDelayed(fun() ->runtime.GetXmlDoc(cmdlet.Name)) 81 | yield providedMethod :> MemberInfo 82 | ] 83 | 84 | let pty = ProvidedTypeDefinition(thisAssembly, rootNamespace, typeName, Some(baseTy)) 85 | pty.AddMembersDelayed(fun() -> createMembers true) 86 | 87 | let customRunspace = ProvidedTypeDefinition("CustomRunspace", Some(typeof)) 88 | customRunspace.AddMember <| ProvidedConstructor([], InvokeCode = fun args -> <@@ new HostedRuntime.PSRuntimeHosted(psSnapIns.Split(';'), modules.Split(';')) :> HostedRuntime.IPSRuntime @@>) 89 | customRunspace.AddInterfaceImplementation <| typeof 90 | customRunspace.AddMemberDelayed <| fun _ -> ProvidedMethod("Dispose", [], typeof, 91 | InvokeCode = 92 | fun args -> 93 | let runspace = Quotations.Expr.Coerce(args |> Seq.head, typeof) 94 | <@@ (%%runspace : System.IDisposable).Dispose() @@>) 95 | customRunspace.AddMemberDelayed <| fun _ -> ProvidedProperty("Runspace", typeof, 96 | GetterCode = 97 | fun args -> 98 | let runspace = Quotations.Expr.Coerce(args |> Seq.head, typeof) 99 | <@@ (%%runspace : HostedRuntime.IPSRuntime).Runspace @@>) 100 | customRunspace.AddMembersDelayed <| fun _ -> createMembers false 101 | 102 | pty.AddMember(customRunspace) 103 | 104 | pty)) 105 | 106 | do this.AddNamespace(rootNamespace, [ shell ]) 107 | do this.Disposing.Add(fun _ -> Runtime.disposeAll()) 108 | 109 | [] 110 | do() -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/Runtime.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.PowerShellProvider.Runtime 2 | 3 | open System 4 | open HostedRuntime 5 | open ExternalRuntime 6 | 7 | let private runtimes = ref Map.empty 8 | 9 | /// PowerShell runtime resolver 10 | let Current(snapIns, modules, is64bitRequired, isDesignTime) = 11 | let key = (snapIns, modules, isDesignTime) 12 | if (not <| Map.containsKey key !runtimes) then 13 | let value = 14 | if (is64bitRequired && not(Environment.Is64BitProcess)) then 15 | if (isDesignTime) 16 | then new PSRuntimeExternal(snapIns, modules) :> IPSRuntime 17 | else failwith "You should compile your code as x64 application" 18 | else 19 | new PSRuntimeHosted(snapIns, modules) :> IPSRuntime 20 | runtimes := (!runtimes |> Map.add key value) 21 | (!runtimes).[key] 22 | 23 | /// Release external PowerShell runtimes 24 | let disposeAll() = 25 | (!runtimes) 26 | |> Seq.iter (fun kvPair -> 27 | match kvPair.Value with 28 | | :? IDisposable as x -> x.Dispose() 29 | | _ -> ignore() 30 | ) -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/TypeInference.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.PowerShellProvider.TypeInference 2 | 3 | open System 4 | open System.Management.Automation 5 | open FSharp.Management 6 | 7 | type PSCommandSignature = 8 | { 9 | Name : string // PowerShell command name 10 | UniqueID: string // Unique command identifier 11 | ParametersInfo : (string*bool*Type)[] 12 | ResultType : Type 13 | ResultObjectTypes : Type[] 14 | } 15 | 16 | let getOutputTypes (command:CommandInfo) = 17 | let types = 18 | command.OutputType 19 | |> Seq.map (fun psTy -> 20 | match psTy.Type with 21 | | null -> typeof 22 | | ty -> ty) 23 | |> Seq.toArray 24 | match types with 25 | | _ when 0 < types.Length && types.Length <= 7 26 | -> types 27 | | _ -> Array.empty 28 | 29 | let buildResultType (resultObjectTypes:Type[]) = 30 | let tys = 31 | resultObjectTypes 32 | |> Array.map (fun ty -> 33 | typedefof>.MakeGenericType([|ty|])) 34 | let choise = 35 | match tys.Length with 36 | | 1 -> tys.[0] 37 | | 2 -> typedefof>.MakeGenericType(tys) 38 | | 3 -> typedefof>.MakeGenericType(tys) 39 | | 4 -> typedefof>.MakeGenericType(tys) 40 | | 5 -> typedefof>.MakeGenericType(tys) 41 | | 6 -> typedefof>.MakeGenericType(tys) 42 | | 7 -> typedefof>.MakeGenericType(tys) 43 | | _ -> typeof //TODO: test it 44 | 45 | let failType = 46 | typeof> 47 | 48 | let returnType = 49 | [|choise; failType|] 50 | 51 | typedefof>.MakeGenericType(returnType) 52 | 53 | let getParameterProperties (parameterSet: CommandParameterSetInfo) = 54 | match parameterSet.Parameters with 55 | | null -> [||] 56 | | parameters -> 57 | parameters 58 | |> Seq.map (fun p-> p.Name, p.IsMandatory, p.ParameterType) 59 | |> Seq.toArray 60 | 61 | let getPSCommandSignature (command:CommandInfo) (parameterSet:CommandParameterSetInfo) = 62 | let resultObjectTypes = getOutputTypes command 63 | { 64 | Name = command.Name 65 | UniqueID = command.Name + parameterSet.Name; 66 | ResultObjectTypes = resultObjectTypes 67 | ResultType = buildResultType resultObjectTypes 68 | ParametersInfo = getParameterProperties parameterSet 69 | } 70 | 71 | 72 | 73 | let toCamelCase s = 74 | if (String.IsNullOrEmpty(s) || not <| Char.IsLetter(s.[0]) || Char.IsLower(s.[0])) 75 | then s 76 | else sprintf "%c%s" (Char.ToLower(s.[0])) (s.Substring(1)) 77 | 78 | type CollectionConverter<'T> = 79 | static member Convert (objSeq:obj seq) = 80 | objSeq |> Seq.cast<'T> |> Seq.toList 81 | 82 | let getTypeOfObjects (types:Type[]) (collection:PSObject seq) = 83 | let typeCandidates = 84 | types |> Array.filter (fun ty -> 85 | collection |> Seq.map(fun x->x.BaseObject) |> Seq.forall (ty.IsInstanceOfType)) 86 | match typeCandidates with 87 | | [|ty|] -> Some(ty) 88 | | _ -> None -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/Types.fs: -------------------------------------------------------------------------------- 1 | [] 2 | module FSharp.Management.PowerShellProviderTypes 3 | 4 | type PsCmdletResult<'TSuccess,'TFailure> = 5 | | Success of 'TSuccess 6 | | Failure of 'TFailure -------------------------------------------------------------------------------- /src/FSharp.Management.PowerShell/paket.references: -------------------------------------------------------------------------------- 1 | FSharp.Core 2 | System.Management.Automation_PowerShell_3.0 3 | File:ProvidedTypes.fsi 4 | File:ProvidedTypes.fs -------------------------------------------------------------------------------- /src/FSharp.Management.WMI.DesignTime/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | do () 11 | 12 | module internal AssemblyVersionInformation = 13 | let [] AssemblyTitle = "FSharp.Management.WMI.DesignTime" 14 | let [] AssemblyProduct = "FSharp.Management.WMI.DesignTime" 15 | let [] AssemblyDescription = "Various type providers for management of the machine." 16 | let [] AssemblyVersion = "0.4.5" 17 | let [] AssemblyFileVersion = "0.4.5" 18 | -------------------------------------------------------------------------------- /src/FSharp.Management.WMI.DesignTime/FSharp.Management.WMI.DesignTime.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | {743c0c7b-79da-44cc-9cb4-f3b25a5b0f08} 9 | Library 10 | FSharp.Management 11 | FSharp.Management.WMI.DesignTime 12 | v4.0 13 | 4.3.0.0 14 | FSharp.Management 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | ..\..\bin\ 23 | DEBUG;TRACE 24 | 3 25 | 26 | 27 | Project 28 | C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe 29 | 30 | 31 | 32 | 33 | pdbonly 34 | true 35 | true 36 | ..\..\bin 37 | TRACE 38 | 3 39 | 40 | 41 | 42 | 43 | 11 44 | 45 | 46 | 47 | 48 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 49 | 50 | 51 | 52 | 53 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 54 | 55 | 56 | 57 | 58 | 65 | 66 | 67 | 68 | True 69 | paket-files/ProvidedTypes.fsi 70 | 71 | 72 | True 73 | paket-files/ProvidedTypes.fsi 74 | 75 | 76 | True 77 | paket-files/ProvidedTypes.fs 78 | 79 | 80 | 81 | TypeProvider.Helper.fs 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | ..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll 97 | True 98 | True 99 | 100 | 101 | 102 | 103 | 104 | 105 | ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll 106 | True 107 | True 108 | 109 | 110 | 111 | 112 | 113 | 114 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll 115 | True 116 | True 117 | 118 | 119 | 120 | 121 | 122 | 123 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll 124 | True 125 | True 126 | 127 | 128 | 129 | 130 | 131 | 132 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll 133 | True 134 | True 135 | 136 | 137 | 138 | 139 | 140 | 141 | ..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45\FSharp.Core.dll 142 | True 143 | True 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /src/FSharp.Management.WMI.DesignTime/paket.references: -------------------------------------------------------------------------------- 1 | FSharp.Core 2 | File:ProvidedTypes.fsi 3 | File:ProvidedTypes.fs -------------------------------------------------------------------------------- /src/FSharp.Management.WMI/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | do () 11 | 12 | module internal AssemblyVersionInformation = 13 | let [] AssemblyTitle = "FSharp.Management.WMI" 14 | let [] AssemblyProduct = "FSharp.Management.WMI" 15 | let [] AssemblyDescription = "Various type providers for management of the machine." 16 | let [] AssemblyVersion = "0.4.5" 17 | let [] AssemblyFileVersion = "0.4.5" 18 | -------------------------------------------------------------------------------- /src/FSharp.Management.WMI/FSharp.Management.WMI.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | {1d29693f-c472-4b03-a8ce-73ca0689012b} 9 | Library 10 | FSharp.Management 11 | FSharp.Management.WMI 12 | v4.0 13 | 4.3.0.0 14 | FSharp.Management 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | ..\..\bin\ 23 | DEBUG;TRACE 24 | 3 25 | 26 | 27 | Program 28 | C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe 29 | D:\Dropbox\Code\FSharp.Management\FSharp.Management.Tests.sln 30 | 31 | 32 | pdbonly 33 | true 34 | true 35 | ..\..\bin 36 | TRACE 37 | 3 38 | ..\..\bin\FSharp.Management.XML 39 | 40 | 41 | 11 42 | 43 | 44 | 45 | 46 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 47 | 48 | 49 | 50 | 51 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 52 | 53 | 54 | 55 | 56 | 63 | 64 | 65 | 66 | True 67 | paket-files/ProvidedTypes.fsi 68 | 69 | 70 | True 71 | paket-files/ProvidedTypes.fsi 72 | 73 | 74 | True 75 | paket-files/ProvidedTypes.fs 76 | 77 | 78 | 79 | TypeProvider.Helper.fs 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | ..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll 101 | True 102 | True 103 | 104 | 105 | 106 | 107 | 108 | 109 | ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll 110 | True 111 | True 112 | 113 | 114 | 115 | 116 | 117 | 118 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll 119 | True 120 | True 121 | 122 | 123 | 124 | 125 | 126 | 127 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll 128 | True 129 | True 130 | 131 | 132 | 133 | 134 | 135 | 136 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll 137 | True 138 | True 139 | 140 | 141 | 142 | 143 | 144 | 145 | ..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45\FSharp.Core.dll 146 | True 147 | True 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /src/FSharp.Management.WMI/paket.references: -------------------------------------------------------------------------------- 1 | FSharp.Core 2 | File:ProvidedTypes.fsi 3 | File:ProvidedTypes.fs -------------------------------------------------------------------------------- /src/FSharp.Management/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | do () 11 | 12 | module internal AssemblyVersionInformation = 13 | let [] AssemblyTitle = "FSharp.Management" 14 | let [] AssemblyProduct = "FSharp.Management" 15 | let [] AssemblyDescription = "Various type providers for management of the machine." 16 | let [] AssemblyVersion = "0.4.5" 17 | let [] AssemblyFileVersion = "0.4.5" 18 | -------------------------------------------------------------------------------- /src/FSharp.Management/CommonFolders.fs: -------------------------------------------------------------------------------- 1 | namespace FSharp.Management 2 | 3 | open System 4 | open System.IO 5 | open System.Reflection 6 | 7 | [] 8 | /// Common identifiers for specific folders on the system 9 | module PathIdentifiers = 10 | /// Folders specific to the current User 11 | type UserPath = 12 | | RoamingApplicationData = 26 13 | | LocalApplicationData = 28 14 | | Desktop = 16 15 | | Documents = 5 16 | | Pictures = 39 17 | | Videos = 14 18 | | Favorites = 6 19 | | Startup = 7 20 | 21 | // Folders shared across all users of the system 22 | type SharedPath = 23 | | ApplicationData = 35 24 | | Documents = 46 25 | | Desktop = 25 26 | | Music = 53 27 | | Pictures = 54 28 | | Video = 55 29 | 30 | /// Common system folders 31 | type SystemPath = 32 | | Windows = 36 33 | | SystemX86 = 41 34 | | System = 37 35 | | Temp = -1 36 | 37 | /// Folders related to the currently executing application 38 | type ApplicationPath = 39 | | EntryPointLocation = 0 40 | | EntryPointShadowCopiedLocation = 1 41 | | FSharpManagementLocation = 2 42 | | FSharpManagementShadowCopiedLocation = 3 43 | 44 | [] 45 | /// Module containing functions for working with common folder paths 46 | module CommonFolders = 47 | let private getSpecialDirectory (pathID : int) = 48 | Environment.GetFolderPath(enum(pathID)) 49 | 50 | /// Get a folder from the set of current-user specific folders 51 | let GetUser (path : UserPath) = 52 | getSpecialDirectory <| int path 53 | 54 | /// Get a folder related to the folders shared between users of the system 55 | let GetSharedUser (path : SharedPath) = 56 | getSpecialDirectory <| int path 57 | 58 | /// Get a system folder 59 | let GetSystem (path : SystemPath) = 60 | match path with 61 | | SystemPath.Temp -> System.IO.Path.GetTempPath() 62 | | _ -> getSpecialDirectory <| int path 63 | 64 | /// Get a folder specific to the currently executing application 65 | let GetApplication (appPath : ApplicationPath) = 66 | let (codeBasePath, path) = 67 | match appPath with 68 | | ApplicationPath.EntryPointLocation -> 69 | try 70 | (true, Assembly.GetEntryAssembly().CodeBase) 71 | with 72 | | exn -> failwith "Unable to load entry assembly location" 73 | | ApplicationPath.EntryPointShadowCopiedLocation -> 74 | try 75 | (false, Assembly.GetEntryAssembly().Location) 76 | with 77 | | exn -> failwith "Unable to load entry assembly location" 78 | | ApplicationPath.FSharpManagementLocation -> (true, Assembly.GetExecutingAssembly().CodeBase) 79 | | ApplicationPath.FSharpManagementShadowCopiedLocation -> (false, Assembly.GetExecutingAssembly().Location) 80 | | _ -> failwith "Unknown path specified" 81 | 82 | match codeBasePath with 83 | | true -> 84 | let uri = UriBuilder(path) 85 | let unesc = Uri.UnescapeDataString uri.Path 86 | Path.GetDirectoryName unesc 87 | | false -> 88 | Path.GetDirectoryName(path) 89 | -------------------------------------------------------------------------------- /src/FSharp.Management/FSharp.Management.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 7e90d6ce-a10b-4858-a5bc-41df7250cbca 9 | Library 10 | FSharp.Management 11 | FSharp.Management 12 | v4.0 13 | 4.3.0.0 14 | FSharp.Management 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | ..\..\bin\ 23 | DEBUG;TRACE 24 | 3 25 | 26 | 27 | Program 28 | C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe 29 | ..\FSharp.Management.Tests.sln 30 | 31 | 32 | pdbonly 33 | true 34 | true 35 | ..\..\bin 36 | TRACE 37 | 3 38 | ..\..\bin\FSharp.Management.XML 39 | 40 | 41 | 11 42 | 43 | 44 | 45 | 46 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 47 | 48 | 49 | 50 | 51 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 52 | 53 | 54 | 55 | 56 | 63 | 64 | 65 | 66 | True 67 | paket-files/ProvidedTypes.fsi 68 | 69 | 70 | True 71 | paket-files/ProvidedTypes.fsi 72 | 73 | 74 | True 75 | paket-files/ProvidedTypes.fs 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | ..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll 97 | True 98 | True 99 | 100 | 101 | 102 | 103 | 104 | 105 | ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll 106 | True 107 | True 108 | 109 | 110 | 111 | 112 | 113 | 114 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll 115 | True 116 | True 117 | 118 | 119 | 120 | 121 | 122 | 123 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll 124 | True 125 | True 126 | 127 | 128 | 129 | 130 | 131 | 132 | ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll 133 | True 134 | True 135 | 136 | 137 | 138 | 139 | 140 | 141 | ..\..\packages\FSharp.Core\lib\portable-net45+sl5+netcore45\FSharp.Core.dll 142 | True 143 | True 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /src/FSharp.Management/FileSystemProvider.fs: -------------------------------------------------------------------------------- 1 | /// originally from https://gist.github.com/1241061 2 | module internal FSharp.Management.FilesTypeProvider 3 | 4 | open ProviderImplementation.ProvidedTypes 5 | open FSharp.Management.Helper 6 | open System 7 | open System.IO 8 | 9 | type PathType = 10 | | Directory 11 | | File 12 | 13 | let getPathType path = 14 | if Directory.Exists(path) then Directory 15 | else if File.Exists(path) then File 16 | else failwith (sprintf "Path [%s] does not exist" path) 17 | 18 | let fixDirectoryPath path = 19 | if path = "" then 20 | "." 21 | else if path.EndsWith(Path.AltDirectorySeparatorChar.ToString()) || path.EndsWith(Path.DirectorySeparatorChar.ToString()) then path 22 | else path + Path.DirectorySeparatorChar.ToString() 23 | 24 | let fixPath path = 25 | let t = getPathType path 26 | match t with 27 | | File -> path 28 | | Directory -> fixDirectoryPath path 29 | 30 | let GetRelativePath fromPath toPath = 31 | let fromUri = Uri(fixPath fromPath) 32 | let toUri = Uri(fixPath toPath) 33 | 34 | let relative = fromUri.MakeRelativeUri toUri 35 | let path = Uri.UnescapeDataString(relative.ToString()) 36 | path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar) 37 | 38 | let watchDir dir (ctx : Context) = 39 | let watcher = 40 | new FileSystemWatcher( 41 | Path.GetFullPath dir, IncludeSubdirectories = false, 42 | NotifyFilter = (NotifyFilters.CreationTime ||| 43 | NotifyFilters.Size ||| 44 | NotifyFilters.DirectoryName ||| 45 | NotifyFilters.FileName)) 46 | let onChanged = (fun (fsargs : FileSystemEventArgs) -> 47 | match fsargs.ChangeType with 48 | | WatcherChangeTypes.Changed | WatcherChangeTypes.Created | WatcherChangeTypes.Deleted -> ctx.Trigger() 49 | | _ -> ()) 50 | 51 | try 52 | watcher.Deleted.Add onChanged 53 | watcher.Renamed.Add onChanged 54 | watcher.Created.Add onChanged 55 | watcher.Error.Add (fun _ -> watcher.Dispose()) 56 | watcher.EnableRaisingEvents <- true 57 | ctx.Disposing.Add watcher.Dispose 58 | with 59 | | _ -> watcher.Dispose() 60 | 61 | let createFileProperties (dir:DirectoryInfo,dirNodeType:ProvidedTypeDefinition,relative) = 62 | try 63 | for file in dir.EnumerateFiles() do 64 | try 65 | let path = 66 | match relative with 67 | | Some sourcePath -> GetRelativePath sourcePath file.FullName 68 | | None -> file.FullName 69 | 70 | let pathField = ProvidedLiteralField(file.Name,typeof,path) 71 | pathField.AddXmlDoc(sprintf "Path to '%s'" path) 72 | dirNodeType.AddMember pathField 73 | with _ -> () 74 | with _ -> () 75 | 76 | let rec annotateDirectoryNode (ownerType: ProvidedTypeDefinition) (dir: DirectoryInfo) withParent relative watch ctx () = 77 | if watch then 78 | watchDir dir.FullName ctx 79 | 80 | ownerType.HideObjectMethods <- true 81 | ownerType.AddXmlDoc(sprintf "A strongly typed interface to '%s'" dir.FullName) 82 | 83 | let path = 84 | match relative with 85 | | Some sourcePath -> fixDirectoryPath <| GetRelativePath sourcePath dir.FullName 86 | | None -> fixDirectoryPath dir.FullName 87 | 88 | let pathField = ProvidedLiteralField("Path",typeof,path) 89 | pathField.AddXmlDoc(sprintf "Path to '%s'" path) 90 | ownerType.AddMember pathField 91 | createFileProperties(dir,ownerType,relative) 92 | 93 | if withParent && dir.Parent <> null then 94 | try ownerType.AddMemberDelayed (createDirectoryNode dir.Parent ".." withParent relative watch ctx) 95 | with _ -> () 96 | 97 | try 98 | for subDir in dir.EnumerateDirectories() do 99 | try 100 | let name = subDir.Name // Pull out name first to verify permissions 101 | ownerType.AddMemberDelayed (createDirectoryNode subDir name false relative watch ctx) 102 | with _ -> () 103 | with _ -> () 104 | 105 | ownerType 106 | 107 | and createDirectoryNode (dir: DirectoryInfo) propertyName withParent relative watch ctx = 108 | annotateDirectoryNode (ProvidedTypeDefinition(propertyName, Some typeof)) dir withParent relative watch ctx 109 | 110 | let createRootType typeName (dir: DirectoryInfo) withParent relative watch ctx = 111 | annotateDirectoryNode (erasedType thisAssembly rootNamespace typeName) dir withParent relative watch ctx () 112 | 113 | let createRelativePathSystem (resolutionFolder: string) ctx = 114 | let relativeFileSystem = erasedType thisAssembly rootNamespace "RelativePath" 115 | 116 | relativeFileSystem.DefineStaticParameters( 117 | parameters = 118 | [ ProvidedStaticParameter("relativeTo", typeof) 119 | ProvidedStaticParameter("watch", typeof, false) ], 120 | instantiationFunction = (fun typeName parameterValues -> 121 | match parameterValues with 122 | | [| :? string as relativePath; :? bool as watch |] -> 123 | let folder = 124 | match relativePath with 125 | | "" | "." -> Path.GetFullPath(resolutionFolder) 126 | | _ -> Path.GetFullPath(Path.Combine(resolutionFolder, relativePath)) 127 | match Directory.Exists(folder) with 128 | | false -> failwith (sprintf "Specified directory [%s] could not be found" folder) 129 | | true -> createRootType typeName (new DirectoryInfo(folder)) true (Some folder) watch ctx 130 | | _ -> failwith "Wrong static parameters to type provider")) 131 | 132 | relativeFileSystem 133 | 134 | let createTypedFileSystem ctx = 135 | let typedFileSystem = erasedType thisAssembly rootNamespace "FileSystem" 136 | 137 | typedFileSystem.DefineStaticParameters( 138 | parameters = 139 | [ ProvidedStaticParameter("path", typeof) 140 | ProvidedStaticParameter("relativeTo", typeof, "") 141 | ProvidedStaticParameter("watch", typeof, false) ], 142 | instantiationFunction = (fun typeName parameterValues -> 143 | match parameterValues with 144 | | [| :? string as path; :? string as relativePath; :? bool as watch |] -> 145 | let dir = new DirectoryInfo(path) 146 | let relative = 147 | match relativePath with 148 | | "" -> None 149 | | _ -> Some relativePath 150 | match Directory.Exists(path) with 151 | | false -> failwith (sprintf "Specified directory [%s] could not be found" path) 152 | | true -> createRootType typeName dir false relative watch ctx 153 | | _ -> failwith "Wrong static parameters to type provider")) 154 | 155 | typedFileSystem 156 | -------------------------------------------------------------------------------- /src/FSharp.Management/RegistryProvider.fs: -------------------------------------------------------------------------------- 1 | module internal FSharp.Management.RegistryProvider 2 | 3 | open ProviderImplementation.ProvidedTypes 4 | open FSharp.Management.Helper 5 | open Microsoft.Win32 6 | 7 | let getAccessibleSubkeys (registryKey:RegistryKey) = 8 | registryKey.GetSubKeyNames() 9 | |> Seq.choose (fun name -> 10 | try 11 | Some (registryKey.OpenSubKey name,name) 12 | with _ -> None) // TODO: Handle access violation 13 | 14 | let getAccessibleValues (registryKey:RegistryKey) = 15 | registryKey.GetValueNames() 16 | |> Seq.filter (System.String.IsNullOrEmpty >> not) 17 | |> Seq.choose (fun name -> 18 | try 19 | Some (registryKey.GetValueKind name,name) 20 | with _ -> None) // TODO: Handle access violation 21 | 22 | let registryProperty<'a> key valueName = 23 | ProvidedProperty( 24 | propertyName = valueName, 25 | propertyType = typeof<'a>, 26 | IsStatic = true, 27 | GetterCode = (fun _ -> <@@ Registry.GetValue(key, valueName,"") :?> 'a @@>), 28 | SetterCode = (fun args -> <@@ Registry.SetValue(key, valueName, (%%args.[0] : 'a)) @@>)) 29 | 30 | let rec createRegistryNode (registryKey:RegistryKey,subkeyName) () = 31 | let registryNodeType = runtimeType subkeyName 32 | registryNodeType.HideObjectMethods <- true 33 | registryNodeType.AddXmlDoc(sprintf "A strongly typed interface to '%s'" registryKey.Name) 34 | let pathField = ProvidedLiteralField("Path",typeof,registryKey.Name) 35 | pathField.AddXmlDoc(sprintf "Full path to '%s'" registryKey.Name) 36 | registryNodeType.AddMember pathField 37 | 38 | for (kind,name) in getAccessibleValues registryKey do 39 | let property = 40 | match kind with 41 | // TODO: pattern matching 42 | | RegistryValueKind.String -> registryProperty registryKey.Name name 43 | | _ -> registryProperty registryKey.Name name 44 | 45 | registryNodeType.AddMember property 46 | 47 | for (subkey,name) in getAccessibleSubkeys registryKey do 48 | registryNodeType.AddMemberDelayed (createRegistryNode(subkey,name)) 49 | 50 | registryNodeType 51 | 52 | let createTypedRegistry() = 53 | let registryType = erasedType thisAssembly rootNamespace "Registry" 54 | let subNodes = 55 | [Registry.ClassesRoot; Registry.CurrentConfig; Registry.CurrentUser; 56 | Registry.LocalMachine; Registry.PerformanceData; Registry.Users] 57 | |> Seq.map (fun key -> key,key.Name) 58 | 59 | for (subkey,name) in subNodes do 60 | registryType.AddMemberDelayed (createRegistryNode(subkey,name)) 61 | 62 | registryType -------------------------------------------------------------------------------- /src/FSharp.Management/StringReaderProvider.fs: -------------------------------------------------------------------------------- 1 | module internal FSharp.Management.StringReaderProvider 2 | 3 | open ProviderImplementation.ProvidedTypes 4 | open FSharp.Management.Helper 5 | open System.IO 6 | 7 | let createType typeName filePath = 8 | let typedStringReader = erasedType thisAssembly rootNamespace typeName 9 | 10 | let content = File.ReadAllText(filePath) 11 | 12 | let contentField = ProvidedLiteralField("Content", typeof, content) 13 | contentField.AddXmlDoc(sprintf "Content of '%s'" filePath) 14 | typedStringReader.AddMember contentField 15 | 16 | typedStringReader 17 | 18 | let createTypedStringReader (resolutionFolder: string) = 19 | let typedStringReader = erasedType thisAssembly rootNamespace "StringReader" 20 | 21 | typedStringReader.DefineStaticParameters( 22 | parameters = 23 | [ ProvidedStaticParameter("path", typeof) ], 24 | instantiationFunction = (fun typeName parameterValues -> 25 | match parameterValues with 26 | | [| :? string as path |] -> 27 | let filePath = 28 | match Path.IsPathRooted(path) with 29 | | false -> Path.Combine(resolutionFolder, path) 30 | | true -> path 31 | if not <| File.Exists(filePath) then 32 | failwithf "Specified file [%s] could not be found" path 33 | createType typeName filePath 34 | | _ -> failwith "Wrong static parameters to type provider")) 35 | 36 | typedStringReader -------------------------------------------------------------------------------- /src/FSharp.Management/SystemTypeProviders.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.NamespaceProvider 2 | 3 | open System 4 | open Microsoft.FSharp.Core.CompilerServices 5 | open ProviderImplementation.ProvidedTypes 6 | open FSharp.Management.Helper 7 | 8 | [] 9 | /// [omit] 10 | type public RegistrySystemProvider(_cfg : TypeProviderConfig) as this = 11 | inherit TypeProviderForNamespaces() 12 | do this.AddNamespace(rootNamespace, [ RegistryProvider.createTypedRegistry() ]) 13 | 14 | [] 15 | /// [omit] 16 | type public FileSystemProvider(_cfg : TypeProviderConfig) as this = 17 | inherit TypeProviderForNamespaces() 18 | let ctx = new Context(this.Invalidate) 19 | do 20 | this.Disposing.Add(fun _ -> (ctx :> IDisposable).Dispose()) 21 | this.AddNamespace(rootNamespace, [FilesTypeProvider.createTypedFileSystem ctx]) 22 | 23 | [] 24 | /// [omit] 25 | type public RelativeFileSystemProvider(cfg : TypeProviderConfig) as this = 26 | inherit TypeProviderForNamespaces() 27 | let ctx = new Context(this.Invalidate) 28 | 29 | do 30 | this.Disposing.Add(fun _ -> (ctx :> IDisposable).Dispose()) 31 | this.AddNamespace(rootNamespace, [FilesTypeProvider.createRelativePathSystem cfg.ResolutionFolder ctx]) 32 | 33 | 34 | [] 35 | /// [omit] 36 | type public SystemTimeZonesProvider(cfg : TypeProviderConfig) as this = 37 | inherit TypeProviderForNamespaces() 38 | 39 | do 40 | let root = erasedType thisAssembly rootNamespace "SystemTimeZones" 41 | root.AddMembersDelayed <| fun() -> 42 | [ 43 | for x in TimeZoneInfo.GetSystemTimeZones() -> 44 | let id = x.Id 45 | ProvidedProperty(x.DisplayName, typeof, [], IsStatic = true, GetterCode = fun _ -> <@@ TimeZoneInfo.FindSystemTimeZoneById id @@>) 46 | ] 47 | this.AddNamespace(rootNamespace, [root]) 48 | 49 | [] 50 | /// [omit] 51 | type public StringReaderProvider(cfg : TypeProviderConfig) as this = 52 | inherit TypeProviderForNamespaces() 53 | do this.AddNamespace(rootNamespace, [ StringReaderProvider.createTypedStringReader cfg.ResolutionFolder ]) 54 | 55 | [] 56 | do() -------------------------------------------------------------------------------- /src/FSharp.Management/TypeProviders.Helper.fs: -------------------------------------------------------------------------------- 1 | /// Starting to implement some helpers on top of ProvidedTypes API 2 | module internal FSharp.Management.Helper 3 | 4 | open System 5 | open System.IO 6 | open ProviderImplementation.ProvidedTypes 7 | 8 | type Context (onChanged : unit -> unit) = 9 | let disposingEvent = Event<_>() 10 | let lastChanged = ref (DateTime.Now.AddSeconds -1.0) 11 | let sync = obj() 12 | 13 | let trigger() = 14 | let shouldTrigger = lock sync (fun _ -> 15 | match !lastChanged with 16 | | time when DateTime.Now - time <= TimeSpan.FromSeconds 1. -> false 17 | | _ -> 18 | lastChanged := DateTime.Now 19 | true 20 | ) 21 | if shouldTrigger then onChanged() 22 | 23 | member __.Disposing: IEvent = disposingEvent.Publish 24 | member __.Trigger = trigger 25 | interface IDisposable with 26 | member __.Dispose() = disposingEvent.Trigger() 27 | 28 | // Active patterns & operators for parsing strings 29 | let (@?) (s:string) i = if i >= s.Length then None else Some s.[i] 30 | 31 | let inline satisfies predicate (charOption:option) = 32 | match charOption with 33 | | Some c when predicate c -> charOption 34 | | _ -> None 35 | 36 | let (|EOF|_|) = function 37 | | Some _ -> None 38 | | _ -> Some () 39 | 40 | let (|LetterDigit|_|) = satisfies Char.IsLetterOrDigit 41 | let (|Upper|_|) = satisfies Char.IsUpper 42 | let (|Lower|_|) = satisfies Char.IsLower 43 | 44 | /// Turns a string into a nice PascalCase identifier 45 | let niceName (set:System.Collections.Generic.HashSet<_>) = 46 | fun (s: string) -> 47 | if s = s.ToUpper() then s else 48 | // Starting to parse a new segment 49 | let rec restart i = seq { 50 | match s @? i with 51 | | EOF -> () 52 | | LetterDigit _ & Upper _ -> yield! upperStart i (i + 1) 53 | | LetterDigit _ -> yield! consume i false (i + 1) 54 | | _ -> yield! restart (i + 1) } 55 | 56 | // Parsed first upper case letter, continue either all lower or all upper 57 | and upperStart from i = seq { 58 | match s @? i with 59 | | Upper _ -> yield! consume from true (i + 1) 60 | | Lower _ -> yield! consume from false (i + 1) 61 | | _ -> yield! restart (i + 1) } 62 | // Consume are letters of the same kind (either all lower or all upper) 63 | and consume from takeUpper i = seq { 64 | match s @? i with 65 | | Lower _ when not takeUpper -> yield! consume from takeUpper (i + 1) 66 | | Upper _ when takeUpper -> yield! consume from takeUpper (i + 1) 67 | | _ -> 68 | yield from, i 69 | yield! restart i } 70 | 71 | // Split string into segments and turn them to PascalCase 72 | let mutable name = 73 | seq { for i1, i2 in restart 0 do 74 | let sub = s.Substring(i1, i2 - i1) 75 | if Seq.forall Char.IsLetterOrDigit sub then 76 | yield sub.[0].ToString().ToUpper() + sub.ToLower().Substring(1) } 77 | |> String.concat "" 78 | 79 | while set.Contains name do 80 | let mutable lastLetterPos = String.length name - 1 81 | while Char.IsDigit name.[lastLetterPos] && lastLetterPos > 0 do 82 | lastLetterPos <- lastLetterPos - 1 83 | if lastLetterPos = name.Length - 1 then 84 | name <- name + "2" 85 | elif lastLetterPos = 0 then 86 | name <- (UInt64.Parse name + 1UL).ToString() 87 | else 88 | let number = name.Substring(lastLetterPos + 1) 89 | name <- name.Substring(0, lastLetterPos + 1) + (UInt64.Parse number + 1UL).ToString() 90 | set.Add name |> ignore 91 | name 92 | 93 | 94 | let findConfigFile resolutionFolder configFileName = 95 | if Path.IsPathRooted configFileName then 96 | configFileName 97 | else 98 | Path.Combine(resolutionFolder, configFileName) 99 | 100 | let erasedType<'T> assemblyName rootNamespace typeName = 101 | ProvidedTypeDefinition(assemblyName, rootNamespace, typeName, Some(typeof<'T>)) 102 | 103 | let generalTypeSet = System.Collections.Generic.HashSet() 104 | 105 | let runtimeType<'T> typeName = ProvidedTypeDefinition(niceName generalTypeSet typeName, Some typeof<'T>) 106 | 107 | let seqType ty = typedefof>.MakeGenericType[| ty |] 108 | let listType ty = typedefof>.MakeGenericType[| ty |] 109 | let optionType ty = typedefof>.MakeGenericType[| ty |] 110 | 111 | // Get the assembly and namespace used to house the provided types 112 | let thisAssembly = System.Reflection.Assembly.GetExecutingAssembly() 113 | let rootNamespace = "FSharp.Management" 114 | let missingValue = "@@@missingValue###" -------------------------------------------------------------------------------- /src/FSharp.Management/paket.references: -------------------------------------------------------------------------------- 1 | FSharp.Core 2 | File:ProvidedTypes.fsi 3 | File:ProvidedTypes.fs -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | True 10 | 11 | 12 | 13 | 14 | True 15 | 16 | 17 | 18 | 19 | True 20 | 21 | 22 | 23 | 24 | True 25 | 26 | 27 | 28 | 29 | True 30 | 31 | 32 | 33 | 34 | True 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/CommonFolders.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.CommonFoldersTests 2 | 3 | open FSharp.Management 4 | open Expecto 5 | 6 | let [] userDirectoryTests = 7 | testList "User Directory tests" [ 8 | test "User Roaming AppData path should match Environment.GetFolderPath" { 9 | let env = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) 10 | Expect.equal (CommonFolders.GetUser UserPath.RoamingApplicationData) env "" 11 | } 12 | test "User Local AppData path should match Environment.GetFolderPath" { 13 | let env = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData) 14 | Expect.equal (CommonFolders.GetUser UserPath.LocalApplicationData) env "" 15 | } 16 | test "User desktop folder should match Environment.GetFolderPath" { 17 | let env = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) 18 | Expect.equal (CommonFolders.GetUser UserPath.Desktop) env "" 19 | } 20 | ] 21 | 22 | let [] sharedUserTests = 23 | testList "Shared User Tests" [ 24 | test "Shared AppData path should match Environment.GetFolderPath" { 25 | let env = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) 26 | Expect.equal (CommonFolders.GetSharedUser SharedPath.ApplicationData) env "" 27 | } 28 | test "Shared music folder should match Environment.GetFolderPath" { 29 | let env = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonMusic) 30 | Expect.equal (CommonFolders.GetSharedUser SharedPath.Music) env "" 31 | } 32 | ] 33 | 34 | let [] systemTests = 35 | testList "System tests" [ 36 | test "System temp folder should match Path class" { 37 | let pathFolder = System.IO.Path.GetTempPath() 38 | Expect.equal (CommonFolders.GetSystem SystemPath.Temp) pathFolder "" 39 | } 40 | test "Windows system folder should contain kernel32.dll" { 41 | let sysFolder = CommonFolders.GetSystem SystemPath.System 42 | let file = System.IO.Path.Combine(sysFolder, "kernel32.dll") 43 | Expect.equal (System.IO.File.Exists file) true "" 44 | } 45 | ] 46 | 47 | let [] applicationTests = 48 | testList "Application Tests" [ 49 | test "FSharpManangement path should contain tests\\FSharp.Manangement.Tests\\bin" { 50 | let path = CommonFolders.GetApplication ApplicationPath.FSharpManagementLocation 51 | Expect.stringContains path "tests\\FSharp.Management.Tests\\bin" "" 52 | } 53 | test "FSharpManangement shadow copied path should contain FSharp.Manangement.Tests" { 54 | let path = CommonFolders.GetApplication ApplicationPath.FSharpManagementShadowCopiedLocation 55 | Expect.stringContains path "FSharp.Management.Tests" "" 56 | } 57 | ] 58 | 59 | // Unfortunatley, most test runners fail to load the entry point assembly properly. This may be VS, or nunit, etc, but requires 60 | // special care to test properly 61 | //[] 62 | //let ``Entry location should contain nunit.exe``() = 63 | // let path = CommonFolders.GetApplication ApplicationPath.EntryPointLocation 64 | // let file = System.IO.Path.Combine(path, "nunit.ee") 65 | // System.IO.File.Exists file |> should equal true 66 | -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/FSharp.Management.Tests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | e789c72a-5cfd-436b-8ef1-61aa2852a89f 9 | Exe 10 | FSharp.Management.Tests 11 | FSharp.Management.Tests 12 | v4.6.1 13 | 4.4.0.0 14 | FSharp.Management.Tests 15 | 16 | ..\..\ 17 | 18 | 19 | true 20 | full 21 | false 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | 3 26 | 27 | 28 | Project 29 | 30 | 31 | 32 | 33 | 34 | 35 | pdbonly 36 | true 37 | true 38 | bin\Release\ 39 | TRACE 40 | 3 41 | 42 | 43 | 44 | 45 | 11 46 | 47 | 48 | 49 | 50 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 51 | 52 | 53 | 54 | 55 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 56 | 57 | 58 | 59 | 60 | 61 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | ..\..\bin\FSharp.Management.dll 85 | 86 | 87 | ..\..\bin\FSharp.Management.PowerShell.dll 88 | 89 | 90 | ..\..\bin\FSharp.Management.WMI.dll 91 | 92 | 93 | ..\..\bin\FSharp.Management.WMI.DesignTime.dll 94 | 95 | 96 | 97 | 98 | 99 | C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 100 | 101 | 102 | 103 | 104 | 105 | 106 | ..\..\packages\test\Argu\lib\net40\Argu.dll 107 | True 108 | True 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | ..\..\packages\test\Expecto\lib\net461\Expecto.dll 118 | True 119 | True 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | ..\..\packages\test\FSharp.Core\lib\net45\FSharp.Core.dll 129 | True 130 | True 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | ..\..\packages\test\Mono.Cecil\lib\net40\Mono.Cecil.dll 140 | True 141 | True 142 | 143 | 144 | ..\..\packages\test\Mono.Cecil\lib\net40\Mono.Cecil.Mdb.dll 145 | True 146 | True 147 | 148 | 149 | ..\..\packages\test\Mono.Cecil\lib\net40\Mono.Cecil.Pdb.dll 150 | True 151 | True 152 | 153 | 154 | ..\..\packages\test\Mono.Cecil\lib\net40\Mono.Cecil.Rocks.dll 155 | True 156 | True 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/FileSystemProvider.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.FileSystemProviderTests 2 | 3 | open FSharp.Management 4 | open Expecto 5 | 6 | type Users = FileSystem<"C:\\Users"> 7 | type RelativeUsers = FileSystem<"C:\\Users", "C:\\Users"> 8 | 9 | type Relative = RelativePath<""> 10 | type RelativeToBin = RelativePath<"bin"> 11 | type RelativeToBuild = RelativePath<"bin\\Release"> 12 | 13 | let [] fileSystemTests = 14 | testList "FileSystemProvider Tests" [ 15 | test "Can create type for users path" { 16 | Expect.equal Users.Path @"C:\Users\" "" 17 | } 18 | test "Can access the default users path" { 19 | Expect.equal Users.Default.Path @"C:\Users\Default\" "" 20 | } 21 | test "Can access the users path via relative path" { 22 | Expect.equal RelativeUsers.Path "." "" 23 | } 24 | test "Can access the default users path via relative path" { 25 | Expect.equal RelativeUsers.Default.Path @"Default\" "" 26 | } 27 | test "Can access the bin folder within the project" { 28 | Expect.equal Relative.bin.Path @"bin\" "" 29 | } 30 | test "Can access the bin folder via \".\" in RelativePath provider" { 31 | Expect.equal RelativePath<".">.bin.Path @"bin\" "" 32 | } 33 | test "Can access a relative path" { 34 | Expect.equal Relative.Path @"." "" 35 | } 36 | test "Can access a relative subfolder" { 37 | Expect.equal Relative.bin.Path @"bin\" "" 38 | } 39 | test "Can access a relative subfolder relative to .\\bin" { 40 | Expect.equal RelativeToBin.Release.Path @"Release\" "" 41 | } 42 | test "Can access a relative file" { 43 | Expect.equal Relative.``WMI.Tests.fs`` @"WMI.Tests.fs" "" 44 | } 45 | test "Can access a parent dir" { 46 | Expect.equal Relative.``..``.Path @"..\" "" 47 | } 48 | test "Can access a parent's parent dir" { 49 | Expect.equal Relative.``..``.``..``.Path @"..\..\" "" 50 | } 51 | test "Can access solution files using RelativePath provider" { 52 | let fsDocPath = RelativeToBuild.``..``.``..``.``..``.``..``.docs.content.``FileSystemProvider.fsx`` 53 | let buildFolder = CommonFolders.GetApplication ApplicationPath.FSharpManagementLocation 54 | 55 | let path = System.IO.Path.GetFullPath(System.IO.Path.Combine(buildFolder, fsDocPath)) 56 | 57 | Expect.equal (System.IO.File.Exists(path)) true "" 58 | } 59 | ] -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/PowerShellProvider.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.PowerShellProvider 2 | 3 | open FSharp.Management 4 | open Expecto 5 | 6 | let []Modules = "Microsoft.PowerShell.Management;Microsoft.PowerShell.Core" 7 | 8 | type PS = PowerShellProvider< Modules > 9 | 10 | let [] psTest = 11 | testList "PoweShell TP Tests" [ 12 | test "Get system drive" { 13 | match PS.``Get-Item``(path=[|@"C:\"|]) with 14 | | Success(Choice5Of5 dirs) -> 15 | Expect.equal dirs.Length 1 "" 16 | Expect.equal ((Seq.head dirs).FullName) @"C:\" "" 17 | | _ -> failwith "Unexpected result" 18 | } 19 | test "Check that process `testtest` does not started" { 20 | match PS.``Get-Process``(name=[|"testtest"|]) with 21 | | Failure(_) -> ignore() 22 | | _ -> failwith "Unexpected result" 23 | } 24 | test "Get list of registered snapins" { 25 | match PS.``Get-PSSnapin``(registered = true) with 26 | | Success(snapins) -> 27 | Expect.equal (snapins.IsEmpty) false "" 28 | | _ -> failwith "Unexpected result" 29 | } 30 | test "Get random number from range" { 31 | match PS.``Get-Random``(minimum = 0, maximum = 10) with 32 | | Success(Choice1Of3 [value]) when value >=0 && value <= 10 -> () 33 | | _ -> failwith "Unexpected result" 34 | } 35 | test "Get events from event log" { 36 | match PS.``Get-EventLog``(logName="Application", entryType=[|"Error"|], newest=2) with 37 | | Success(Choice2Of3 entries) -> 38 | Expect.equal entries.Length 2 "" 39 | | _ -> failwith "Unexpected result" 40 | } 41 | test "Get help message" { // This Cmdlet has an empty OutputType 42 | match PS.``Get-Help``() with 43 | | Success(resultObj) -> 44 | Expect.equal (resultObj.GetType()) (typeof) "" 45 | | _ -> failwith "Unexpected result" 46 | } 47 | test "Get help message with custom runspace" { // Verify CustomRunspace existance and disposing 48 | let psCustom = new PS.CustomRunspace() 49 | 50 | match psCustom.``Get-Help``() with 51 | | Success(resultObj) -> 52 | Expect.equal (resultObj.GetType()) (typeof) "" 53 | | _ -> failwith "Unexpected result" 54 | 55 | Expect.equal psCustom.Runspace.RunspaceStateInfo.State 56 | System.Management.Automation.Runspaces.RunspaceState.Opened "" 57 | (psCustom :> System.IDisposable).Dispose() 58 | Expect.equal psCustom.Runspace.RunspaceStateInfo.State 59 | System.Management.Automation.Runspaces.RunspaceState.Closed "" 60 | } 61 | test "Change location" { // This Cmdlet has a typed OutputType, but doesn't actually return anything 62 | match PS.``Set-Location``(path="""""") with 63 | | Success (resultObj) -> 64 | match box resultObj with 65 | | null -> ignore() 66 | | _ -> failwith "Unexpected result" 67 | | _ -> failwith "Unexpected result" 68 | } 69 | ] 70 | 71 | let []ModuleFile = __SOURCE_DIRECTORY__ + @"\testModule.psm1" 72 | type PSFileModule = PowerShellProvider< ModuleFile > 73 | 74 | let [] psModuleTests = 75 | testCase "Call a function defined in a module file" <| fun _ -> 76 | let testString = "testString" 77 | match PSFileModule.doSomething(test=testString) with 78 | | Success(stringList) -> 79 | Expect.equal stringList.Length 1 "" 80 | Expect.equal (Seq.head stringList) testString "" 81 | | _ -> failwith "Unexpected result" 82 | 83 | type PS64 = PowerShellProvider< Modules, Is64BitRequired=true > 84 | 85 | let [] ps64tests = 86 | testList "PowerShell Type Provider 64 Tests" [ 87 | test "Get system drive x64" { 88 | match PS64.``Get-Item``(path=[|@"C:\"|]) with 89 | | Success(Choice5Of5 dirs) -> 90 | Expect.equal dirs.Length 1 "" 91 | Expect.equal ((Seq.head dirs).FullName) @"C:\" "" 92 | | _ -> failwith "Unexpected result" 93 | } 94 | test "Check that process `testtest` does not started x64" { 95 | match PS64.``Get-Process``(name=[|"testtest"|]) with 96 | | Failure(_) -> ignore() 97 | | _ -> failwith "Unexpected result" 98 | } 99 | test "Get list of registered snapins x64" { 100 | match PS64.``Get-PSSnapin``(registered = true) with 101 | | Success(snapins) -> 102 | Expect.equal snapins.IsEmpty false "" 103 | | _ -> failwith "Unexpected result" 104 | } 105 | ] 106 | 107 | //let modules = "ActiveDirectory;AppBackgroundTask;AppLocker;Appx;AssignedAccess;Azure;BestPractices;BitLocker;BranchCache;CimCmdlets;ClusterAwareUpdating;DFSN;DFSR;Defender;DhcpServer;DirectAccessClientComponents;Dism;DnsClient;DnsServer;FailoverClusters;GroupPolicy;Hyper-V;ISE;International;IpamServer;IscsiTarget;Kds;MMAgent;Microsoft.PowerShell.Core;Microsoft.PowerShell.Diagnostics;Microsoft.PowerShell.Host;Microsoft.PowerShell.Management;Microsoft.PowerShell.Security;Microsoft.PowerShell.Utility;Microsoft.WSMan.Management;MsDtc;NFS;NetAdapter;NetConnection;NetEventPacketCapture;NetLbfo;NetNat;NetQos;NetSecurity;NetSwitchTeam;NetTCPIP;NetWNV;NetworkConnectivityStatus;NetworkLoadBalancingClusters;NetworkTransition;PKI;PSDesiredStateConfiguration;PSDiagnostics;PSScheduledJob;PSWorkflow;PcsvDevice;PrintManagement;RemoteAccess;RemoteDesktop;ScheduledTasks;SecureBoot;ServerManager;ServerManagerTasks;SmbShare;SmbWitness;StartScreen;Storage;TLS;TroubleshootingPack;TrustedPlatformModule;UpdateServices;VpnClient;Wdac;WebAdministration;WindowsDeveloperLicense;WindowsErrorReporting;WindowsSearch;iSCSI".Split([|';'|]) -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/Program.fs: -------------------------------------------------------------------------------- 1 | module Program 2 | 3 | open Expecto 4 | 5 | [] 6 | let main args = 7 | let config = 8 | { defaultConfig with 9 | ``parallel`` = false 10 | verbosity = Logging.LogLevel.Verbose } 11 | runTestsInAssembly config args -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/RegistryProvider.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.RegistryProviderTests 2 | 3 | open FSharp.Management 4 | open Expecto 5 | 6 | let [] registryProviderTests = 7 | testList "RegistryProvider Tests" [ 8 | test "Can create type for HKEY_CURRENT_USER" { 9 | Expect.equal Registry.HKEY_CURRENT_USER.Path 10 | "HKEY_CURRENT_USER" "" 11 | } 12 | test "Can create subtype for HKEY_LOCAL_MACHINE" { 13 | Expect.equal Registry.HKEY_LOCAL_MACHINE.SOFTWARE.Path 14 | @"HKEY_LOCAL_MACHINE\SOFTWARE" "" 15 | } 16 | ] -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/StringReaderProvider.Tests.data: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam scelerisque leo ut mauris ullamcorper posuere. Aliquam quis nulla dolor. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque leo ipsum, imperdiet vehicula quam nec, egestas condimentum purus. Donec rutrum lacus ac turpis lacinia blandit. Cras sollicitudin dapibus interdum. Sed dapibus elementum turpis, at feugiat lectus interdum sed. Integer faucibus non turpis nec ullamcorper. Nam eget tincidunt ex. 2 | 3 | Quisque vitae nulla leo. Nunc ultricies facilisis tellus, et placerat libero pulvinar et. Phasellus mollis consectetur orci in vestibulum. Integer ultricies tortor vitae condimentum dictum. Mauris id mi ante. Ut congue dolor erat, pretium aliquam neque iaculis at. Sed dictum dolor vel tellus finibus, eget tempus ligula dignissim. Ut cursus nibh magna, a feugiat risus maximus eu. 4 | 5 | Cras accumsan vulputate neque, eu euismod tellus congue vitae. Donec at nunc est. Ut libero sapien, imperdiet nec sem vel, tincidunt feugiat turpis. Vestibulum lectus nunc, rhoncus eu tellus sed, egestas congue ex. Phasellus sed interdum lacus. Curabitur rutrum, lectus in mattis sodales, augue ex tristique enim, sit amet elementum est sem non erat. Integer sit amet libero augue. Nulla in suscipit dolor. Mauris ac porta orci, vitae varius tellus. Nunc nec consectetur dui. 6 | 7 | Vivamus rhoncus porta nibh, quis auctor sapien fermentum quis. Maecenas nunc lectus, efficitur vitae arcu sit amet, volutpat efficitur eros. Aenean pellentesque tellus et placerat mollis. Nullam nisl lectus, bibendum sit amet varius at, scelerisque in augue. Phasellus vehicula erat sed felis iaculis rutrum. Aenean elementum ullamcorper mauris, vel aliquam diam suscipit ac. Duis eget congue felis. Proin placerat lorem odio, luctus bibendum justo dapibus et. Sed in ornare mauris. Nulla facilisi. Fusce ultricies purus id augue cursus viverra. Donec maximus risus id metus suscipit volutpat. Duis eu lacinia odio. Nullam sit amet nunc arcu. 8 | 9 | Etiam pulvinar dui a eros ullamcorper luctus. Nam lobortis urna vitae lorem maximus, ac rhoncus felis ultricies. Morbi vestibulum ultricies urna, sed suscipit velit vehicula in. Sed iaculis velit nec ligula cursus semper. Nam sed felis vitae dui aliquet interdum sed sed eros. Donec porta ex a dolor blandit, non tempor purus molestie. Pellentesque viverra diam quis fringilla commodo. Praesent ut enim ac massa imperdiet pellentesque in eget nunc. Curabitur imperdiet erat sit amet condimentum maximus. Proin tincidunt sem sed lorem congue, nec scelerisque libero viverra. -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/StringReaderProvider.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.StringReaderProviderTests 2 | 3 | open FSharp.Management 4 | open Expecto 5 | 6 | type LoremIpsum = StringReader<"StringReaderProvider.Tests.data"> 7 | 8 | let [] stringReaderTest = 9 | testCase "StringReader provider reads the file correctly" <| fun () -> 10 | let expected = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam scelerisque leo ut mauris ullamcorper posuere. Aliquam quis nulla dolor. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque leo ipsum, imperdiet vehicula quam nec, egestas condimentum purus. Donec rutrum lacus ac turpis lacinia blandit. Cras sollicitudin dapibus interdum. Sed dapibus elementum turpis, at feugiat lectus interdum sed. Integer faucibus non turpis nec ullamcorper. Nam eget tincidunt ex. 11 | 12 | Quisque vitae nulla leo. Nunc ultricies facilisis tellus, et placerat libero pulvinar et. Phasellus mollis consectetur orci in vestibulum. Integer ultricies tortor vitae condimentum dictum. Mauris id mi ante. Ut congue dolor erat, pretium aliquam neque iaculis at. Sed dictum dolor vel tellus finibus, eget tempus ligula dignissim. Ut cursus nibh magna, a feugiat risus maximus eu. 13 | 14 | Cras accumsan vulputate neque, eu euismod tellus congue vitae. Donec at nunc est. Ut libero sapien, imperdiet nec sem vel, tincidunt feugiat turpis. Vestibulum lectus nunc, rhoncus eu tellus sed, egestas congue ex. Phasellus sed interdum lacus. Curabitur rutrum, lectus in mattis sodales, augue ex tristique enim, sit amet elementum est sem non erat. Integer sit amet libero augue. Nulla in suscipit dolor. Mauris ac porta orci, vitae varius tellus. Nunc nec consectetur dui. 15 | 16 | Vivamus rhoncus porta nibh, quis auctor sapien fermentum quis. Maecenas nunc lectus, efficitur vitae arcu sit amet, volutpat efficitur eros. Aenean pellentesque tellus et placerat mollis. Nullam nisl lectus, bibendum sit amet varius at, scelerisque in augue. Phasellus vehicula erat sed felis iaculis rutrum. Aenean elementum ullamcorper mauris, vel aliquam diam suscipit ac. Duis eget congue felis. Proin placerat lorem odio, luctus bibendum justo dapibus et. Sed in ornare mauris. Nulla facilisi. Fusce ultricies purus id augue cursus viverra. Donec maximus risus id metus suscipit volutpat. Duis eu lacinia odio. Nullam sit amet nunc arcu. 17 | 18 | Etiam pulvinar dui a eros ullamcorper luctus. Nam lobortis urna vitae lorem maximus, ac rhoncus felis ultricies. Morbi vestibulum ultricies urna, sed suscipit velit vehicula in. Sed iaculis velit nec ligula cursus semper. Nam sed felis vitae dui aliquet interdum sed sed eros. Donec porta ex a dolor blandit, non tempor purus molestie. Pellentesque viverra diam quis fringilla commodo. Praesent ut enim ac massa imperdiet pellentesque in eget nunc. Curabitur imperdiet erat sit amet condimentum maximus. Proin tincidunt sem sed lorem congue, nec scelerisque libero viverra.""" 19 | Expect.equal LoremIpsum.Content expected "" -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/SystemTimeZonesProvider.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.SystemTimeZonesProviderTests 2 | 3 | open FSharp.Management 4 | open Expecto 5 | open System 6 | 7 | let [] timezonesTest = 8 | testCase "SystemTimeZones provider has correct UTC zone" <| fun _ -> 9 | let expect = TimeZoneInfo.FindSystemTimeZoneById "UTC" 10 | let actual = SystemTimeZones.``(UTC) Coordinated Universal Time`` 11 | Expect.equal actual expect "" 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/WMI.Tests.fs: -------------------------------------------------------------------------------- 1 | module FSharp.Management.Tests.WMIProvider 2 | 3 | open System 4 | open System.Management 5 | open FSharp.Management 6 | 7 | type Local = WmiProvider<"localhost"> 8 | let data = Local.GetDataContext() 9 | 10 | // Add a handler to watch WMI queries getting executed 11 | data.QueryExecuted.Add(printfn "Query executed: %s") 12 | 13 | let data1 = [ for b in data.Win32_DiskDrive -> b.Name, b.Description] 14 | 15 | // Access some WMI data from the data connection 16 | let data2 = 17 | [for dd in data.CIM_DiskDrive -> 18 | [for c in dd.Capabilities -> c.Is_SMART_Notification]] -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/paket.references: -------------------------------------------------------------------------------- 1 | group Test 2 | Expecto -------------------------------------------------------------------------------- /tests/FSharp.Management.Tests/testModule.psm1: -------------------------------------------------------------------------------- 1 | function doSomething { 2 | [OutputType([string])] 3 | param ( 4 | [string] $test 5 | ) 6 | return $test 7 | } 8 | 9 | export-moduleMember -function doSomething --------------------------------------------------------------------------------