├── .gitattributes ├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe ├── NuGet.targets └── packages.config ├── GraphProvider.Tests.sln ├── GraphProvider.nuspec ├── GraphProvider.sln ├── LICENSE.txt ├── README.md ├── RELEASE_NOTES.md ├── build.cmd ├── build.fsx ├── build.sh ├── docs ├── content │ ├── Actors.dgml │ ├── Turnstile.dgml │ └── index.fsx ├── files │ └── img │ │ ├── Actors.png │ │ ├── Intellisense.png │ │ └── Turnstile.png └── tools │ ├── generate.fsx │ ├── packages.config │ └── templates │ └── template.cshtml ├── lib └── README.md ├── src └── GraphProvider │ ├── AssemblyInfo.fs │ ├── GraphProvider.fsproj │ ├── ProvidedTypes.fs │ ├── ProvidedTypes.fsi │ ├── StateMachine.fs │ ├── StateMachineProvider.fs │ └── TypeProviders.Helper.fs └── tests └── GraphProvider.Tests ├── Actors.dgml ├── AsyncStateMachine.Tests.fs ├── Binary.dgml ├── BinaryGraph.Tests.fs ├── BorderGatewayProtocol.dgml ├── BorderGatewayProtocolGraph.Tests.fs ├── FindPathTo.Tests.fs ├── FsUnit.fs ├── Graph1.dgml ├── GraphProvider.Tests.fsproj ├── StateMachine.Tests.fs ├── StateNetwork.Tests.fs ├── Turnstile.dgml ├── TurnstileGraph.Tests.fs └── packages.config /.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 | -------------------------------------------------------------------------------- /.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 | 164 | # Generated documentation folder 165 | docs/output/ 166 | 167 | # Temp folder used for publishing docs 168 | temp/ 169 | 170 | # Test results produced by build 171 | TestResults.xml 172 | release.cmd 173 | nuget/ 174 | 175 | # Nuget outputs 176 | nuget/*.nupkg 177 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/GraphProvider/9253d897117630a73fce53a20f8d5e21b742ebbd/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 32 | 33 | 34 | 35 | 36 | $(SolutionDir).nuget 37 | packages.config 38 | 39 | 40 | 41 | 42 | $(NuGetToolsPath)\NuGet.exe 43 | @(PackageSource) 44 | 45 | "$(NuGetExePath)" 46 | mono --runtime=v4.0.30319 $(NuGetExePath) 47 | 48 | $(TargetDir.Trim('\\')) 49 | 50 | -RequireConsent 51 | -NonInteractive 52 | 53 | "$(SolutionDir) " 54 | "$(SolutionDir)" 55 | 56 | 57 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) 58 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols 59 | 60 | 61 | 62 | RestorePackages; 63 | $(BuildDependsOn); 64 | 65 | 66 | 67 | 68 | $(BuildDependsOn); 69 | BuildPackage; 70 | 71 | 72 | 73 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | 98 | 100 | 101 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /GraphProvider.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("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GraphProvider.Tests", "tests\GraphProvider.Tests\GraphProvider.Tests.fsproj", "{E789C72A-5CFD-436B-8EF1-61AA2852A89F}" 6 | EndProject 7 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{0EA85019-C099-4A33-8E34-FEB132D17C02}" 8 | ProjectSection(SolutionItems) = preProject 9 | .nuget\packages.config = .nuget\packages.config 10 | EndProjectSection 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {E789C72A-5CFD-436B-8EF1-61AA2852A89F}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /GraphProvider.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @build.number@ 6 | @authors@ 7 | @authors@ 8 | http://github.com/fsprojects/GraphProvider/blob/master/LICENSE.txt 9 | http://fsprojects.github.com/GraphProvider 10 | false 11 | @summary@ 12 | @description@ 13 | @releaseNotes@ 14 | Copyright 2014 15 | @tags@ 16 | https://raw2.github.com/fsprojects/GraphProvider/master/docs/files/img/logo.png 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /GraphProvider.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}") = ".nuget", ".nuget", "{1F1B4F0F-2998-4D74-865B-9122611C2B14}" 6 | ProjectSection(SolutionItems) = preProject 7 | .nuget\NuGet.Config = .nuget\NuGet.Config 8 | .nuget\NuGet.exe = .nuget\NuGet.exe 9 | .nuget\NuGet.targets = .nuget\NuGet.targets 10 | EndProjectSection 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1}" 13 | EndProject 14 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GraphProvider", "src\GraphProvider\GraphProvider.fsproj", "{7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{BF60BC93-E09B-4E5F-9D85-95A519479D54}" 17 | ProjectSection(SolutionItems) = preProject 18 | build.fsx = build.fsx 19 | nuget\GraphProvider.nuspec = nuget\GraphProvider.nuspec 20 | README.md = README.md 21 | RELEASE_NOTES.md = RELEASE_NOTES.md 22 | EndProjectSection 23 | EndProject 24 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{83F16175-43B1-4C90-A1EE-8E351C33435D}" 25 | ProjectSection(SolutionItems) = preProject 26 | docs\tools\generate.fsx = docs\tools\generate.fsx 27 | docs\tools\templates\template.cshtml = docs\tools\templates\template.cshtml 28 | EndProjectSection 29 | EndProject 30 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D5255-776D-4B61-85F9-73C37AA1FB9A}" 31 | ProjectSection(SolutionItems) = preProject 32 | docs\content\Actors.dgml = docs\content\Actors.dgml 33 | docs\content\index.fsx = docs\content\index.fsx 34 | docs\content\Turnstile.dgml = docs\content\Turnstile.dgml 35 | EndProjectSection 36 | EndProject 37 | Global 38 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 39 | Debug|Any CPU = Debug|Any CPU 40 | Release|Any CPU = Release|Any CPU 41 | EndGlobalSection 42 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 43 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}.Release|Any CPU.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | GlobalSection(SolutionProperties) = preSolution 49 | HideSolutionNode = FALSE 50 | EndGlobalSection 51 | GlobalSection(NestedProjects) = preSolution 52 | {83F16175-43B1-4C90-A1EE-8E351C33435D} = {A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1} 53 | {8E6D5255-776D-4B61-85F9-73C37AA1FB9A} = {A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /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/GraphProvider/badge/issue)](http://issuestats.com/github/fsprojects/GraphProvider) 2 | [![Issue Stats](http://issuestats.com/github/fsprojects/GraphProvider/badge/pr)](http://issuestats.com/github/fsprojects/GraphProvider) 3 | 4 | 5 | GraphProvider [![NuGet Status](http://img.shields.io/nuget/v/GraphProvider.svg?style=flat)](https://www.nuget.org/packages/GraphProvider/) 6 | =========================== 7 | 8 | The GraphProvider project contains a state machine type provider. 9 | 10 | Documentation available here. 11 | 12 | ## Building 13 | 14 | * Run build.cmd 15 | 16 | ## Maintainer(s) 17 | 18 | - We are seeking a primary active maintainer for this stable repo. Please record your interest by [adding an admin issue](https://github.com/fsprojects/FsProjectsAdmin/issues) 19 | 20 | The default maintainer account for projects under "fsprojects" is [@fsprojectsgit](https://github.com/fsprojectsgit) - F# Community Project Incubation Space (repo management) 21 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | #### 0.0.1 - 27.02.2014 2 | * Initial release of GraphProvider -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | if not exist packages\FAKE\tools\Fake.exe ( 4 | .nuget\nuget.exe install FAKE -OutputDirectory packages -ExcludeVersion -Prerelease 5 | ) 6 | packages\FAKE\tools\FAKE.exe build.fsx %* 7 | -------------------------------------------------------------------------------- /build.fsx: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------- 2 | // FAKE build script 3 | // -------------------------------------------------------------------------------------- 4 | 5 | #r @"packages/FAKE/tools/FakeLib.dll" 6 | open Fake 7 | open Fake.Git 8 | open Fake.AssemblyInfoFile 9 | open Fake.ReleaseNotesHelper 10 | open System 11 | 12 | let projects = [|"GraphProvider" |] 13 | 14 | let summary = "This library is for the .NET platform implementing a state machine type provider." 15 | let description = "This library is for the .NET platform implementing a state machine type provider." 16 | let authors = ["Steffen Forkmann"; "Sergey Tihon"; "Daniel Mohl"; "Tomas Petricek"; "Ryan Riley"; "Mauricio Scheffer"; "Phil Trelford"; "Vasily Kirichenko"; "Reed Copsey, Jr."] 17 | let tags = "F# fsharp typeproviders Management PowerShell" 18 | 19 | let solutionFile = "GraphProvider" 20 | 21 | let testAssemblies = "tests/**/bin/Release/*.Tests*.dll" 22 | let gitHome = "https://github.com/fsprojects" 23 | let gitName = "GraphProvider" 24 | let cloneUrl = "git@github.com:fsprojects/GraphProvider.git" 25 | let nugetDir = "./nuget/" 26 | 27 | // Read additional information from the release notes document 28 | Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ 29 | let release = parseReleaseNotes (IO.File.ReadAllLines "RELEASE_NOTES.md") 30 | 31 | // Generate assembly info files with the right version & up-to-date information 32 | Target "AssemblyInfo" (fun _ -> 33 | for project in projects do 34 | let fileName = "src/" + project + "/AssemblyInfo.fs" 35 | CreateFSharpAssemblyInfo fileName 36 | [ Attribute.Title project 37 | Attribute.Product project 38 | Attribute.Description summary 39 | Attribute.Version release.AssemblyVersion 40 | Attribute.FileVersion release.AssemblyVersion ] 41 | ) 42 | 43 | // -------------------------------------------------------------------------------------- 44 | // Clean build results & restore NuGet packages 45 | 46 | Target "RestorePackages" RestorePackages 47 | 48 | Target "Clean" (fun _ -> 49 | CleanDirs ["bin"; "temp"; nugetDir] 50 | ) 51 | 52 | Target "CleanDocs" (fun _ -> 53 | CleanDirs ["docs/output"] 54 | ) 55 | 56 | // -------------------------------------------------------------------------------------- 57 | // Build library & test project 58 | 59 | Target "Build" (fun _ -> 60 | !! (solutionFile + ".sln") 61 | |> MSBuildRelease "" "Rebuild" 62 | |> ignore 63 | 64 | !! (solutionFile + ".Tests.sln") 65 | |> MSBuildRelease "" "Rebuild" 66 | |> ignore 67 | ) 68 | 69 | // -------------------------------------------------------------------------------------- 70 | // Run the unit tests using test runner & kill test runner when complete 71 | 72 | Target "RunTests" (fun _ -> 73 | ActivateFinalTarget "CloseTestRunner" 74 | 75 | !! testAssemblies 76 | |> NUnit (fun p -> 77 | { p with 78 | DisableShadowCopy = true 79 | TimeOut = TimeSpan.FromMinutes 20. 80 | OutputFile = "TestResults.xml" }) 81 | ) 82 | 83 | FinalTarget "CloseTestRunner" (fun _ -> 84 | ProcessHelper.killProcess "nunit-agent.exe" 85 | ) 86 | 87 | // -------------------------------------------------------------------------------------- 88 | // Build a NuGet package 89 | 90 | Target "NuGet" (fun _ -> 91 | // Format the description to fit on a single line (remove \r\n and double-spaces) 92 | let description = description.Replace("\r", "") 93 | .Replace("\n", "") 94 | .Replace(" ", " ") 95 | let project = projects.[0] 96 | 97 | let nugetDocsDir = nugetDir @@ "docs" 98 | let nugetlibDir = nugetDir @@ "lib/net40" 99 | 100 | CleanDir nugetDocsDir 101 | CleanDir nugetlibDir 102 | 103 | CopyDir nugetlibDir "bin" (fun file -> file.Contains "FSharp.Core." |> not) 104 | CopyDir nugetDocsDir "./docs/output" allFiles 105 | 106 | NuGet (fun p -> 107 | { p with 108 | Authors = authors 109 | Project = project 110 | Summary = summary 111 | Description = description 112 | Version = release.NugetVersion 113 | ReleaseNotes = release.Notes |> toLines 114 | Tags = tags 115 | OutputPath = nugetDir 116 | AccessKey = getBuildParamOrDefault "nugetkey" "" 117 | Publish = hasBuildParam "nugetkey" 118 | Dependencies = [] }) 119 | (project + ".nuspec") 120 | ) 121 | 122 | // -------------------------------------------------------------------------------------- 123 | // Generate the documentation 124 | 125 | Target "GenerateDocs" (fun _ -> 126 | executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore 127 | ) 128 | 129 | // -------------------------------------------------------------------------------------- 130 | // Release Scripts 131 | 132 | Target "ReleaseDocs" (fun _ -> 133 | let ghPages = "gh-pages" 134 | let ghPagesLocal = "temp/gh-pages" 135 | Repository.clone "temp" (cloneUrl) ghPages 136 | Branches.checkoutBranch ghPagesLocal ghPages 137 | fullclean "temp/gh-pages" 138 | CopyRecursive "docs/output" ghPagesLocal true |> printfn "%A" 139 | CommandHelper.runSimpleGitCommand ghPagesLocal "add ." |> printfn "%s" 140 | let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion 141 | CommandHelper.runSimpleGitCommand ghPagesLocal cmd |> printfn "%s" 142 | Branches.push ghPagesLocal 143 | ) 144 | 145 | Target "Release" DoNothing 146 | 147 | // -------------------------------------------------------------------------------------- 148 | // Run all targets by default. Invoke 'build ' to override 149 | 150 | Target "All" DoNothing 151 | 152 | "Clean" 153 | ==> "RestorePackages" 154 | ==> "AssemblyInfo" 155 | ==> "Build" 156 | ==> "RunTests" 157 | ==> "All" 158 | 159 | "All" 160 | ==> "CleanDocs" 161 | ==> "GenerateDocs" 162 | ==> "ReleaseDocs" 163 | ==> "NuGet" 164 | ==> "Release" 165 | 166 | RunTargetOrDefault "All" 167 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ ! -f packages/FAKE/tools/Fake.exe ]; then 3 | mono .NuGet/NuGet.exe install FAKE -OutputDirectory packages -ExcludeVersion -Prerelease 4 | fi 5 | mono packages/FAKE/tools/FAKE.exe build.fsx $@ 6 | -------------------------------------------------------------------------------- /docs/content/Actors.dgml: -------------------------------------------------------------------------------- 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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 56 | 57 | -------------------------------------------------------------------------------- /docs/content/Turnstile.dgml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/content/index.fsx: -------------------------------------------------------------------------------- 1 | (*** hide ***) 2 | #I "../../bin" 3 | 4 | (** 5 | GraphProvider 6 | =========================== 7 | 8 | The GraphProvider project implements a state machine type provider.. 9 | 10 |
11 |
12 |
13 |
14 | The library can be installed from NuGet: 15 |
PM> Install-Package GraphProvider
16 |
17 |
18 |
19 |
20 | 21 | Example 22 | ------- 23 | 24 | This example demonstrates the use of the GraphProvider: 25 | 26 | ![alt text](img/Turnstile.png "Turnstile") 27 | 28 | *) 29 | // reference the type provider dll 30 | #r "GraphProvider.dll" 31 | open GraphProvider 32 | 33 | // Let the type provider do it's work 34 | type Turnstile = Graph<"Turnstile.dgml"> 35 | 36 | (** 37 | 38 | Now we have full intellisense for the DGML file: 39 | ![alt text](img/Intellisense.png "Intellisense for DGML files") 40 | 41 | *) 42 | 43 | // Turnstile is locked initially 44 | Turnstile.StartFromLocked() 45 | // [fsi:val it : GraphProvider.Graph<...>.Locked2 = {Name = "Locked";}] 46 | 47 | // Insert a coin and the turnstile is unlocked 48 | Turnstile.StartFromLocked().Coin() 49 | // [fsi:val it : Graph<...>.Unlocked2 = {Name = "Unlocked";}] 50 | 51 | (** 52 | 53 | Finding shortest paths 54 | ---------------------- 55 | 56 | Consider the following DGML file: 57 | 58 | ![alt text](img/Actors.png "Actors") 59 | 60 | *) 61 | 62 | type Actors = Graph<"Actors.dgml"> 63 | 64 | // find the shortest path between Keanu Reeves and Kevin Bacon 65 | Actors.StartFromKeanuReeves().ShortestPathToKevinBacon() 66 | // [fsi:val it : List = ["The Matrix"; "Laurence Fishburne"; "Mystic River"]] 67 | 68 | (** 69 | 70 | Contributing and copyright 71 | -------------------------- 72 | 73 | The project is hosted on [GitHub][gh] where you can [report issues][issues], fork 74 | the project and submit pull requests. If you're adding new public API, please also 75 | consider adding [samples][content] that can be turned into a documentation. You might 76 | also want to read [library design notes][readme] to understand how it works. 77 | 78 | The library is available under Public Domain license, which allows modification and 79 | redistribution for both commercial and non-commercial purposes. For more information see the 80 | [License file][license] in the GitHub repository. 81 | 82 | [content]: https://github.com/fsprojects/GraphProvider/tree/master/docs/content 83 | [gh]: https://github.com/fsprojects/GraphProvider 84 | [issues]: https://github.com/fsprojects/GraphProvider/issues 85 | [readme]: https://github.com/fsprojects/GraphProvider/blob/master/README.md 86 | [license]: https://github.com/fsprojects/GraphProvider/blob/master/LICENSE.txt 87 | *) 88 | -------------------------------------------------------------------------------- /docs/files/img/Actors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/GraphProvider/9253d897117630a73fce53a20f8d5e21b742ebbd/docs/files/img/Actors.png -------------------------------------------------------------------------------- /docs/files/img/Intellisense.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/GraphProvider/9253d897117630a73fce53a20f8d5e21b742ebbd/docs/files/img/Intellisense.png -------------------------------------------------------------------------------- /docs/files/img/Turnstile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/GraphProvider/9253d897117630a73fce53a20f8d5e21b742ebbd/docs/files/img/Turnstile.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 = [ "GraphProvider.dll" ] 8 | // Web site location for the generated documentation 9 | let website = "/GraphProvider" 10 | 11 | // Specify more information about your project 12 | let info = 13 | [ "project-name", "GraphProvider" 14 | "project-author", "Steffen Forkmann" 15 | "project-summary", "This library is for the .NET platform implementing a state machine type provider." 16 | "project-github", "http://github.com/fsprojects/GraphProvider" 17 | "project-nuget", "https://www.nuget.org/packages/GraphProvider" ] 18 | 19 | // -------------------------------------------------------------------------------------- 20 | // For typical project, no changes are needed below 21 | // -------------------------------------------------------------------------------------- 22 | 23 | #I "../../packages/FSharp.Formatting.2.2.11-beta/lib/net40" 24 | #I "../../packages/RazorEngine.3.3.0/lib/net40/" 25 | #r "../../packages/Microsoft.AspNet.Razor.2.0.30506.0/lib/net40/System.Web.Razor.dll" 26 | #r "../../packages/FAKE/tools/FakeLib.dll" 27 | #r "RazorEngine.dll" 28 | #r "FSharp.Literate.dll" 29 | #r "FSharp.CodeFormat.dll" 30 | #r "FSharp.MetadataFormat.dll" 31 | open Fake 32 | open System.IO 33 | open Fake.FileHelper 34 | open FSharp.Literate 35 | open FSharp.MetadataFormat 36 | 37 | // When called from 'build.fsx', use the public project URL as 38 | // otherwise, use the current 'output' directory. 39 | #if RELEASE 40 | let root = website 41 | #else 42 | let root = "file://" + (__SOURCE_DIRECTORY__ @@ "../output") 43 | #endif 44 | 45 | // Paths with template/source/output locations 46 | let bin = __SOURCE_DIRECTORY__ @@ "../../bin" 47 | let content = __SOURCE_DIRECTORY__ @@ "../content" 48 | let output = __SOURCE_DIRECTORY__ @@ "../output" 49 | let files = __SOURCE_DIRECTORY__ @@ "../files" 50 | let templates = __SOURCE_DIRECTORY__ @@ "templates" 51 | let formatting = __SOURCE_DIRECTORY__ @@ "../../packages/FSharp.Formatting.2.2.11-beta/" 52 | let docTemplate = formatting @@ "templates/docpage.cshtml" 53 | 54 | // Where to look for *.csproj templates (in this order) 55 | let layoutRoots = 56 | [ templates; formatting @@ "templates" 57 | formatting @@ "templates/reference" ] 58 | 59 | // Copy static files and CSS + JS from F# Formatting 60 | let copyFiles () = 61 | CopyRecursive files output true |> Log "Copying file: " 62 | ensureDirectory (output @@ "content") 63 | CopyRecursive (formatting @@ "styles") (output @@ "content") true 64 | |> Log "Copying styles and scripts: " 65 | 66 | // Build API reference from XML comments 67 | let buildReference () = 68 | CleanDir (output @@ "reference") 69 | for lib in referenceBinaries do 70 | MetadataFormat.Generate 71 | ( bin @@ lib, output @@ "reference", layoutRoots, 72 | parameters = ("root", root)::info ) 73 | 74 | // Build documentation from `fsx` and `md` files in `docs/content` 75 | let buildDocumentation () = 76 | let subdirs = Directory.EnumerateDirectories(content, "*", SearchOption.AllDirectories) 77 | for dir in Seq.append [content] subdirs do 78 | let sub = if dir.Length > content.Length then dir.Substring(content.Length + 1) else "." 79 | Literate.ProcessDirectory 80 | ( dir, docTemplate, output @@ sub, replacements = ("root", root)::info, 81 | layoutRoots = layoutRoots ) 82 | 83 | // Generate 84 | copyFiles() 85 | buildDocumentation() 86 | buildReference() 87 | -------------------------------------------------------------------------------- /docs/tools/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | 47 |
48 |
49 |
50 | Fork me on GitHub 51 | 52 | 53 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/GraphProvider/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | namespace System 2 | open System.Reflection 3 | 4 | [] 5 | [] 6 | [] 7 | [] 8 | [] 9 | do () 10 | 11 | module internal AssemblyVersionInformation = 12 | let [] Version = "0.0.1" 13 | -------------------------------------------------------------------------------- /src/GraphProvider/GraphProvider.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 7e90d6ce-a10b-4858-a5bc-41df7250cbca 9 | Library 10 | GraphProvider 11 | GraphProvider 12 | v4.0 13 | 4.3.1.0 14 | GraphProvider 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 | c:\code\GraphProvider\GraphProvider.Tests.sln 30 | 31 | 32 | pdbonly 33 | true 34 | true 35 | ..\..\bin 36 | TRACE 37 | 3 38 | ..\..\bin\GraphProvider.XML 39 | 40 | 41 | 42 | 43 | False 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 11 61 | 62 | 63 | 64 | 65 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 66 | 67 | 68 | 69 | 70 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 71 | 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /src/GraphProvider/ProvidedTypes.fsi: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2005-2012. 2 | // This sample code is provided "as is" without warranty of any kind. 3 | // We disclaim all warranties, either express or implied, including the 4 | // warranties of merchantability and fitness for a particular purpose. 5 | 6 | // This file contains a set of helper types and methods for providing types in an implementation 7 | // of ITypeProvider. 8 | // 9 | // This code is a sample for use in conjunction with the F# 3.0 Developer Preview release of September 2011. 10 | 11 | 12 | namespace Samples.FSharp.ProvidedTypes 13 | 14 | open System 15 | open System.Reflection 16 | open System.Linq.Expressions 17 | open Microsoft.FSharp.Core.CompilerServices 18 | 19 | /// Represents an erased provided parameter 20 | type internal ProvidedParameter = 21 | inherit System.Reflection.ParameterInfo 22 | new : parameterName: string * parameterType: Type * ?isOut:bool * ?optionalValue:obj -> ProvidedParameter 23 | member IsParamArray : bool with get,set 24 | 25 | /// Represents an erased provided constructor. 26 | type internal ProvidedConstructor = 27 | inherit System.Reflection.ConstructorInfo 28 | 29 | /// Create a new provided constructor. It is not initially associated with any specific provided type definition. 30 | new : parameters: ProvidedParameter list -> ProvidedConstructor 31 | 32 | /// Add a 'System.Obsolete' attribute to this provided constructor 33 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 34 | 35 | /// Add XML documentation information to this provided constructor 36 | member AddXmlDoc : xmlDoc: string -> unit 37 | 38 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 39 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 40 | 41 | /// Add XML documentation information to this provided constructor, where the documentation is re-computed every time it is required. 42 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 43 | 44 | /// Set the quotation used to compute the implementation of invocations of this constructor. 45 | member InvokeCode : (Quotations.Expr list -> Quotations.Expr) with set 46 | 47 | /// Set the target and arguments of the base constructor call. Only used for generated types. 48 | member BaseConstructorCall : (Quotations.Expr list -> ConstructorInfo * Quotations.Expr list) with set 49 | 50 | /// Set a flag indicating that the constructor acts like an F# implicit constructor, so the 51 | /// parameters of the constructor become fields and can be accessed using Expr.GlobalVar with the 52 | /// same name. 53 | member IsImplicitCtor : bool with set 54 | 55 | /// Add definition location information to the provided constructor. 56 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 57 | 58 | member IsTypeInitializer : bool with get,set 59 | 60 | type internal ProvidedMethod = 61 | inherit System.Reflection.MethodInfo 62 | 63 | /// Create a new provided method. It is not initially associated with any specific provided type definition. 64 | new : methodName:string * parameters: ProvidedParameter list * returnType: Type -> ProvidedMethod 65 | 66 | /// Add XML documentation information to this provided method 67 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 68 | 69 | /// Add XML documentation information to this provided constructor 70 | member AddXmlDoc : xmlDoc: string -> unit 71 | 72 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 73 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 74 | 75 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 76 | /// The documentation is re-computed every time it is required. 77 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 78 | 79 | member AddMethodAttrs : attributes:MethodAttributes -> unit 80 | 81 | /// Set the method attributes of the method. By default these are simple 'MethodAttributes.Public' 82 | member SetMethodAttrs : attributes:MethodAttributes -> unit 83 | 84 | /// Get or set a flag indicating if the property is static. 85 | member IsStaticMethod : bool with get, set 86 | 87 | /// Set the quotation used to compute the implementation of invocations of this method. 88 | member InvokeCode : (Quotations.Expr list -> Quotations.Expr) with set 89 | 90 | 91 | /// Add definition location information to the provided type definition. 92 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 93 | 94 | 95 | 96 | /// Represents an erased provided property. 97 | type internal ProvidedProperty = 98 | inherit System.Reflection.PropertyInfo 99 | 100 | /// Create a new provided type. It is not initially associated with any specific provided type definition. 101 | new : propertyName: string * propertyType: Type * ?parameters:ProvidedParameter list -> ProvidedProperty 102 | 103 | /// Add a 'System.Obsolete' attribute to this provided property 104 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 105 | 106 | /// Add XML documentation information to this provided constructor 107 | member AddXmlDoc : xmlDoc: string -> unit 108 | 109 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 110 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 111 | 112 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 113 | /// The documentation is re-computed every time it is required. 114 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 115 | 116 | /// Get or set a flag indicating if the property is static. 117 | member IsStatic : bool with get,set 118 | 119 | /// Set the quotation used to compute the implementation of gets of this property. 120 | member GetterCode : (Quotations.Expr list -> Quotations.Expr) with set 121 | 122 | /// Set the function used to compute the implementation of sets of this property. 123 | member SetterCode : (Quotations.Expr list -> Quotations.Expr) with set 124 | 125 | /// Add definition location information to the provided type definition. 126 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 127 | 128 | /// Represents an erased provided property. 129 | type internal ProvidedEvent = 130 | inherit System.Reflection.EventInfo 131 | 132 | /// Create a new provided type. It is not initially associated with any specific provided type definition. 133 | new : propertyName: string * eventHandlerType: Type -> ProvidedEvent 134 | 135 | /// Add XML documentation information to this provided constructor 136 | member AddXmlDoc : xmlDoc: string -> unit 137 | 138 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 139 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 140 | 141 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 142 | /// The documentation is re-computed every time it is required. 143 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 144 | 145 | /// Get or set a flag indicating if the property is static. 146 | member IsStatic : bool with set 147 | 148 | /// Set the quotation used to compute the implementation of gets of this property. 149 | member AdderCode : (Quotations.Expr list -> Quotations.Expr) with set 150 | 151 | /// Set the function used to compute the implementation of sets of this property. 152 | member RemoverCode : (Quotations.Expr list -> Quotations.Expr) with set 153 | 154 | /// Add definition location information to the provided type definition. 155 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 156 | 157 | /// Represents an erased provided field. 158 | type internal ProvidedLiteralField = 159 | inherit System.Reflection.FieldInfo 160 | 161 | /// Create a new provided field. It is not initially associated with any specific provided type definition. 162 | new : fieldName: string * fieldType: Type * literalValue: obj -> ProvidedLiteralField 163 | 164 | /// Add a 'System.Obsolete' attribute to this provided field 165 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 166 | 167 | /// Add XML documentation information to this provided field 168 | member AddXmlDoc : xmlDoc: string -> unit 169 | 170 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 171 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 172 | 173 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 174 | /// The documentation is re-computed every time it is required. 175 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 176 | 177 | /// Add definition location information to the provided field. 178 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 179 | 180 | /// Represents an erased provided field. 181 | type internal ProvidedField = 182 | inherit System.Reflection.FieldInfo 183 | 184 | /// Create a new provided field. It is not initially associated with any specific provided type definition. 185 | new : fieldName: string * fieldType: Type -> ProvidedField 186 | 187 | /// Add a 'System.Obsolete' attribute to this provided field 188 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 189 | 190 | /// Add XML documentation information to this provided field 191 | member AddXmlDoc : xmlDoc: string -> unit 192 | 193 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 194 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 195 | 196 | /// Add XML documentation information to this provided field, where the computation of the documentation is delayed until necessary 197 | /// The documentation is re-computed every time it is required. 198 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 199 | 200 | /// Add definition location information to the provided field definition. 201 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 202 | 203 | member SetFieldAttributes : attributes : FieldAttributes -> unit 204 | 205 | /// Provides symbolic provided types 206 | [] 207 | type internal ProvidedTypeBuilder = 208 | /// Like typ.MakeGenericType, but will also work with unit-annotated types 209 | static member MakeGenericType: genericTypeDefinition: System.Type * genericArguments: System.Type list -> System.Type 210 | /// Like methodInfo.MakeGenericMethod, but will also work with unit-annotated types and provided types 211 | static member MakeGenericMethod: genericMethodDefinition: System.Reflection.MethodInfo * genericArguments: System.Type list -> MethodInfo 212 | 213 | /// Helps create erased provided unit-of-measure annotations. 214 | [] 215 | type internal ProvidedMeasureBuilder = 216 | 217 | /// The ProvidedMeasureBuilder for building measures. 218 | static member Default : ProvidedMeasureBuilder 219 | 220 | /// e.g. 1 221 | member One : System.Type 222 | /// e.g. m * kg 223 | member Product : measure1: System.Type * measure1: System.Type -> System.Type 224 | /// e.g. 1 / kg 225 | member Inverse : denominator: System.Type -> System.Type 226 | 227 | /// e.g. kg / m 228 | member Ratio : numerator: System.Type * denominator: System.Type -> System.Type 229 | 230 | /// e.g. m * m 231 | member Square : ``measure``: System.Type -> System.Type 232 | 233 | /// the SI unit from the F# core library, where the string is in capitals and US spelling, e.g. Meter 234 | member SI : string -> System.Type 235 | 236 | /// e.g. float, Vector 237 | member AnnotateType : basic: System.Type * argument: System.Type list -> System.Type 238 | 239 | 240 | /// Represents a provided static parameter. 241 | type internal ProvidedStaticParameter = 242 | inherit System.Reflection.ParameterInfo 243 | new : parameterName: string * parameterType:Type * ?parameterDefaultValue:obj -> ProvidedStaticParameter 244 | 245 | /// Add XML documentation information to this provided constructor 246 | member AddXmlDoc : xmlDoc: string -> unit 247 | 248 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 249 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 250 | 251 | /// Represents a provided type definition. 252 | type internal ProvidedTypeDefinition = 253 | inherit System.Type 254 | 255 | /// Create a new provided type definition in a namespace. 256 | new : assembly: Assembly * namespaceName: string * className: string * baseType: Type option -> ProvidedTypeDefinition 257 | 258 | /// Create a new provided type definition, to be located as a nested type in some type definition. 259 | new : className : string * baseType: Type option -> ProvidedTypeDefinition 260 | 261 | /// Add the given type as an implemented interface. 262 | member AddInterfaceImplementation : interfaceType: Type -> unit 263 | 264 | /// Add the given function as a set of on-demand computed interfaces. 265 | member AddInterfaceImplementationsDelayed : interfacesFunction:(unit -> Type list)-> unit 266 | 267 | /// Specifies that the given method body implements the given method declaration. 268 | member DefineMethodOverride : methodInfoBody: ProvidedMethod * methodInfoDeclaration: MethodInfo -> unit 269 | 270 | /// Add a 'System.Obsolete' attribute to this provided type definition 271 | member AddObsoleteAttribute : message: string * ?isError: bool -> unit 272 | 273 | /// Add XML documentation information to this provided constructor 274 | member AddXmlDoc : xmlDoc: string -> unit 275 | 276 | /// Set the base type 277 | member SetBaseType : Type -> unit 278 | 279 | /// Set the base type to a lazily evaluated value 280 | member SetBaseTypeDelayed : Lazy -> unit 281 | 282 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary. 283 | /// The documentation is only computed once. 284 | member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit 285 | 286 | /// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary 287 | /// The documentation is re-computed every time it is required. 288 | member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit 289 | 290 | /// Set the attributes on the provided type. This fully replaces the default TypeAttributes. 291 | member SetAttributes : System.Reflection.TypeAttributes -> unit 292 | 293 | /// Reset the enclosing type (for generated nested types) 294 | member ResetEnclosingType: enclosingType:System.Type -> unit 295 | 296 | /// Add a method, property, nested type or other member to a ProvidedTypeDefinition 297 | member AddMember : memberInfo:MemberInfo -> unit 298 | /// Add a set of members to a ProvidedTypeDefinition 299 | member AddMembers : memberInfos:list<#MemberInfo> -> unit 300 | 301 | /// Add a member to a ProvidedTypeDefinition, delaying computation of the members until required by the compilation context. 302 | member AddMemberDelayed : memberFunction:(unit -> #MemberInfo) -> unit 303 | 304 | /// Add a set of members to a ProvidedTypeDefinition, delaying computation of the members until required by the compilation context. 305 | member AddMembersDelayed : (unit -> list<#MemberInfo>) -> unit 306 | 307 | /// Add the types of the generated assembly as generative types, where types in namespaces get hierarchically positioned as nested types. 308 | member AddAssemblyTypesAsNestedTypesDelayed : assemblyFunction:(unit -> System.Reflection.Assembly) -> unit 309 | 310 | // Parametric types 311 | member DefineStaticParameters : parameters: ProvidedStaticParameter list * instantiationFunction: (string -> obj[] -> ProvidedTypeDefinition) -> unit 312 | 313 | /// Add definition location information to the provided type definition. 314 | member AddDefinitionLocation : line:int * column:int * filePath:string -> unit 315 | 316 | /// Suppress System.Object entries in intellisense menus in instances of this provided type 317 | member HideObjectMethods : bool with set 318 | 319 | /// Get or set a flag indicating if the ProvidedTypeDefinition is erased 320 | member IsErased : bool with get,set 321 | 322 | /// Get or set a flag indicating if the ProvidedTypeDefinition has type-relocation suppressed 323 | [] 324 | member SuppressRelocation : bool with get,set 325 | 326 | member MakeParametricType : name:string * args:obj[] -> ProvidedTypeDefinition 327 | 328 | /// A provided generated assembly 329 | type ProvidedAssembly = 330 | new : assemblyFileName:string -> ProvidedAssembly 331 | /// 332 | /// Emit the given provided type definitions as part of the assembly 333 | /// and adjust the 'Assembly' property of all provided type definitions to return that 334 | /// assembly. 335 | /// 336 | /// The assembly is only emitted when the Assembly property on the root type is accessed for the first time. 337 | /// The host F# compiler does this when processing a generative type declaration for the type. 338 | /// 339 | /// An optional path of type names to wrap the generated types. The generated types are then generated as nested types. 340 | member AddTypes : types : ProvidedTypeDefinition list -> unit 341 | member AddNestedTypes : types : ProvidedTypeDefinition list * enclosingGeneratedTypeNames: string list -> unit 342 | 343 | #if FX_NO_LOCAL_FILESYSTEM 344 | #else 345 | /// Register that a given file is a provided generated assembly 346 | static member RegisterGenerated : fileName:string -> Assembly 347 | #endif 348 | 349 | 350 | /// A base type providing default implementations of type provider functionality when all provided 351 | /// types are of type ProvidedTypeDefinition. 352 | type TypeProviderForNamespaces = 353 | 354 | /// Initializes a type provider to provide the types in the given namespace. 355 | internal new : namespaceName:string * types: ProvidedTypeDefinition list -> TypeProviderForNamespaces 356 | 357 | /// Initializes a type provider 358 | internal new : unit -> TypeProviderForNamespaces 359 | 360 | /// Add a namespace of provided types. 361 | member internal AddNamespace : namespaceName:string * types: ProvidedTypeDefinition list -> unit 362 | 363 | /// Invalidate the information provided by the provider 364 | member Invalidate : unit -> unit 365 | 366 | #if FX_NO_LOCAL_FILESYSTEM 367 | #else 368 | /// AssemblyResolve handler. Default implementation searches .dll file in registered folders 369 | abstract ResolveAssembly : System.ResolveEventArgs -> Assembly 370 | default ResolveAssembly : System.ResolveEventArgs -> Assembly 371 | 372 | /// Registers custom probing path that can be used for probing assemblies 373 | member RegisterProbingFolder : folder : string -> unit 374 | /// Registers location of RuntimeAssembly (from TypeProviderConfig) as probing folder 375 | member RegisterRuntimeAssemblyLocationAsProbingFolder : cfg : Core.CompilerServices.TypeProviderConfig -> unit 376 | #endif 377 | 378 | interface ITypeProvider 379 | -------------------------------------------------------------------------------- /src/GraphProvider/StateMachine.fs: -------------------------------------------------------------------------------- 1 | // Originally ported from http://fsharp3sample.codeplex.com 2 | module GraphProvider.StateMachine 3 | 4 | open System.Xml 5 | open System.Xml.Linq 6 | 7 | type IState = 8 | abstract member EnterFunction : unit -> unit 9 | abstract member ExitFunction : unit->unit 10 | 11 | // define a node record 12 | type Node = { Name : string; NextNodes : (string option * Node) list} 13 | 14 | // define DGML DU 15 | type DGML = 16 | | Node of string 17 | | Link of string * string * string option 18 | 19 | 20 | // define DGML class 21 | type DGMLClass() = class 22 | let mutable nodes = Unchecked.defaultof 23 | let mutable links = Unchecked.defaultof 24 | let mutable currentState = System.String.Empty 25 | 26 | // current state 27 | member this.CurrentState 28 | with get() = currentState 29 | and private set(v) = currentState <- v 30 | 31 | // all links in the DGML file 32 | member this.Links 33 | with get() = links 34 | and private set(v) = links <- v 35 | 36 | // all nodes in the DGML file 37 | member this.Nodes 38 | with get() = nodes 39 | and private set(v) = nodes <- v 40 | 41 | // initialize the state machien from fileName and set the initial state to initState 42 | member this.Init(fileName:string, initState) = 43 | let file = XDocument.Load(fileName, LoadOptions.None) 44 | this.Links <- 45 | file.Descendants() 46 | |> Seq.filter (fun node -> node.Name.LocalName = "Link") 47 | |> Seq.map (fun node -> 48 | let sourceName = node.Attribute(XName.Get("Source")).Value 49 | let targetName = node.Attribute(XName.Get("Target")).Value 50 | let label = 51 | let attr = node.Attribute(XName.Get("Label")) 52 | if attr = null then None else Some(attr.Value) 53 | DGML.Link(sourceName, targetName,label)) 54 | |> Seq.toList 55 | 56 | let getNextNodes fromNodeName= 57 | this.Links 58 | |> Seq.choose (function 59 | | Link(a, b, l) when a = fromNodeName -> 60 | match this.FindNode(b) with 61 | | Some(x) -> Some(l,x) 62 | | None -> None 63 | | _ -> None) 64 | |> Seq.toList 65 | 66 | this.Nodes <- 67 | file.Descendants() 68 | |> Seq.filter (fun node -> node.Name.LocalName = "Node") 69 | |> Seq.map (fun node -> node.Attribute(XName.Get("Id")).Value ) 70 | |> Seq.map (fun n -> { Node.Name=n; NextNodes = [] }) 71 | |> Seq.toList 72 | 73 | this.Nodes <- 74 | this.Nodes 75 | |> Seq.map (fun n -> { n with NextNodes = (getNextNodes n.Name) } ) 76 | |> Seq.toList 77 | 78 | this.CurrentState <- initState 79 | 80 | // fine the node by given nodeName 81 | member this.FindNode(nodeName) : Node option= 82 | let result = 83 | this.Nodes 84 | |> Seq.filter (fun n -> n.Name = nodeName) 85 | if result |> Seq.isEmpty then None 86 | else result |> Seq.head |> Some 87 | 88 | // current node 89 | member this.CurrentNode 90 | with get() = 91 | this.Nodes 92 | |> Seq.filter (fun n -> n.Name = this.CurrentState) 93 | |> Seq.head 94 | 95 | // determine if can transit to a node represented by the nodeName 96 | member this.CanTransitTo(nodeName:string) = 97 | this.CurrentNode.NextNodes |> Seq.exists (fun (_,n) -> n.Name = nodeName) 98 | 99 | // force current state to a new state 100 | member this.ForceStateTo(args) = 101 | this.CurrentState <- args 102 | end 103 | 104 | // state machine class which inherit the DGML class 105 | // and use a MailboxProcessor to perform asynchronous message processing (if makeAsync = true) 106 | type StateMachine(makeAsync) as this = 107 | inherit DGMLClass() 108 | 109 | let functions = System.Collections.Generic.Dictionary() 110 | let transit newState = 111 | if this.CanTransitTo newState then 112 | this.InvokeExit(this.CurrentNode.Name) 113 | this.ForceStateTo newState 114 | this.InvokeEnter newState 115 | 116 | let processor = new MailboxProcessor(fun inbox -> 117 | let rec loop () = 118 | async { 119 | let! newState = inbox.Receive() 120 | transit newState 121 | return! loop () 122 | } 123 | loop ()) 124 | 125 | do 126 | if makeAsync then processor.Start() 127 | 128 | // define the second constructor taking the file name and initial state name 129 | new(fileName, makeAsync, initState) as secondCtor = 130 | new StateMachine(makeAsync) 131 | then 132 | secondCtor.Init(fileName, initState) 133 | 134 | // asynchronously or synchronously transit to a new state 135 | member this.TransitTo(state) = 136 | if makeAsync then processor.Post state else transit state 137 | 138 | // FindPath - Slow version 139 | member this.FindShortestPathTo(startNode,targetNode) = 140 | let findIndex name = this.Nodes |> Seq.findIndex (fun x -> x.Name = name) 141 | 142 | let dist = 143 | this.Nodes 144 | |> Seq.map (fun x -> (System.Int32.MaxValue, x)) 145 | |> Array.ofSeq 146 | 147 | let prev = Array.create (this.Nodes.Length) Option.None 148 | let startIndex = findIndex startNode 149 | dist.[startIndex] <- (0, dist.[startIndex] |> snd) 150 | 151 | let rec processNode visitedNodes = 152 | let (act, u) = 153 | dist 154 | |> Seq.filter (fun x -> 155 | visitedNodes 156 | |> Seq.tryFind ((=) (snd x)) 157 | |> Option.isNone) 158 | |> Seq.minBy fst 159 | if u.Name = targetNode then 160 | let rec path (node : Node) = 161 | let index = findIndex node.Name 162 | match prev.[index] with 163 | | Some n -> n.Name :: path n 164 | | None -> [] 165 | 166 | match path u with 167 | | [] -> None 168 | | x -> Some x 169 | else 170 | let uIndex = findIndex u.Name 171 | let neighbors = u.NextNodes |> Seq.map snd 172 | let alt = act + 1 173 | for n in neighbors do 174 | let nIndex = findIndex n.Name 175 | let curDist = dist.[nIndex] |> fst 176 | if alt < curDist then 177 | dist.[nIndex] <- (alt, dist.[nIndex] |> snd) 178 | prev.[nIndex] <- Some this.Nodes.[uIndex] 179 | processNode (u :: visitedNodes) 180 | 181 | processNode [] 182 | 183 | // set the transition function 184 | member this.SetFunction(name:string, state:IState) = 185 | if functions.ContainsKey(name) then 186 | functions.[name] <- state 187 | else 188 | functions.Add(name, state) 189 | 190 | // invoke the Exit function 191 | member private this.InvokeExit(name:string) = 192 | if functions.ContainsKey(name) then 193 | functions.[name].ExitFunction() 194 | 195 | // invoke the Enter function 196 | member private this.InvokeEnter(name:string) = 197 | if functions.ContainsKey(name) then 198 | functions.[name].EnterFunction() 199 | 200 | type State = { Name:string } -------------------------------------------------------------------------------- /src/GraphProvider/StateMachineProvider.fs: -------------------------------------------------------------------------------- 1 | // Originally ported from http://fsharp3sample.codeplex.com 2 | module GraphProvider.StateMachineProvider 3 | 4 | open GraphProvider.Helper 5 | open GraphProvider.StateMachine 6 | open Samples.FSharp.ProvidedTypes 7 | open Microsoft.FSharp.Core.CompilerServices 8 | open System.Collections.Generic 9 | 10 | let internal stateMachineTy ownerType makeAsync (cfg:TypeProviderConfig) = 11 | let stateMachineType = erasedType thisAssembly rootNamespace (if makeAsync then "AsyncStateMachine" else "StateMachine") 12 | stateMachineType.DefineStaticParameters( 13 | parameters = [ProvidedStaticParameter("dgml file name", typeof) 14 | ProvidedStaticParameter("init state", typeof)], 15 | instantiationFunction = (fun typeName parameterValues -> 16 | match parameterValues with 17 | | [| :? string as fileName; :? string as initState |] -> 18 | 19 | let dgml = System.IO.Path.Combine(cfg.ResolutionFolder, fileName) 20 | 21 | let stateMachine = StateMachine(makeAsync) 22 | stateMachine.Init(dgml, initState) 23 | 24 | // TODO: watchForChanges ownerType dgml 25 | 26 | let stateMachineType = erasedType thisAssembly rootNamespace typeName 27 | stateMachineType.HideObjectMethods <- true 28 | stateMachineType.AddXmlDoc (sprintf "A strongly typed interface to the state machine described in '%s'" fileName) 29 | 30 | for n in stateMachine.Nodes do 31 | let name = n.Name 32 | let property = 33 | ProvidedProperty( 34 | propertyName = niceName (new HashSet<_>()) name, 35 | propertyType = typeof, 36 | GetterCode = (fun args -> <@@ name @@>)) 37 | property.AddXmlDoc("Status " + n.Name) 38 | stateMachineType.AddMember property 39 | 40 | let transitMethod = 41 | ProvidedMethod( 42 | methodName = niceName (new HashSet<_>()) (sprintf "TransitTo%s" name), 43 | parameters = [], 44 | returnType = typeof, 45 | InvokeCode = (fun args -> <@@ (%%args.[0] :> StateMachine).TransitTo(name) @@>)) 46 | stateMachineType.AddMember transitMethod 47 | 48 | let setTransitionFunctionMethod = 49 | ProvidedMethod( 50 | methodName = "SetTransitionFunction", 51 | parameters = [ProvidedParameter("Name", typeof) 52 | ProvidedParameter("StateClass", typeof)], 53 | returnType = typeof, 54 | InvokeCode = (fun args -> <@@ (%%args.[0] :> StateMachine).SetFunction(%%args.[1] :> string, %%args.[2] :> IState) @@>)) 55 | 56 | setTransitionFunctionMethod.AddXmlDoc "Sets the functions for status changes" 57 | stateMachineType.AddMember setTransitionFunctionMethod 58 | 59 | let defaultConstructor = 60 | ProvidedConstructor( 61 | parameters = [], 62 | InvokeCode = (fun _ -> <@@ StateMachine(dgml,makeAsync,initState) @@>)) 63 | defaultConstructor.AddXmlDoc "Initializes a state machine instance" 64 | 65 | stateMachineType.AddMember defaultConstructor 66 | stateMachineType)) 67 | stateMachineType 68 | 69 | let internal graph ownerType (cfg:TypeProviderConfig) = 70 | let graphType = erasedType thisAssembly rootNamespace ("Graph") 71 | graphType.DefineStaticParameters( 72 | parameters = [ProvidedStaticParameter("dgml file name", typeof)], 73 | instantiationFunction = (fun typeName parameterValues -> 74 | match parameterValues with 75 | | [| :? string as fileName |] -> 76 | let dgml = System.IO.Path.Combine(cfg.ResolutionFolder, fileName) 77 | // TODO: watchForChanges ownerType dgml 78 | 79 | let ownerType = erasedType thisAssembly rootNamespace typeName 80 | 81 | let stateMachine = StateMachine(false) 82 | stateMachine.Init(dgml, null) 83 | let states = System.Collections.Generic.Dictionary<_,_>() 84 | 85 | stateMachine.Nodes 86 | |> List.iter (fun node -> states.Add(node.Name,runtimeType node.Name)) 87 | 88 | states 89 | |> Seq.iter (fun state -> 90 | let s = state.Value 91 | ownerType.AddMember s) 92 | 93 | for node in stateMachine.Nodes do 94 | for node2 in node.NextNodes do 95 | let label,targetNode = node2 96 | let name = targetNode.Name 97 | let trasitionName = 98 | match label with 99 | | Some l -> l 100 | | _ -> "TransitTo" + name 101 | 102 | let transitionMethod = 103 | ProvidedMethod( 104 | methodName = niceName (new HashSet<_>()) trasitionName, 105 | parameters = [], 106 | returnType = states.[name], 107 | InvokeCode = (fun args -> <@@ { Name = name } @@>)) 108 | states.[node.Name].AddMember transitionMethod 109 | 110 | for node1 in stateMachine.Nodes do 111 | for targetNode in stateMachine.Nodes do 112 | if node1 <> targetNode then 113 | match stateMachine.FindShortestPathTo(node1.Name,targetNode.Name) with 114 | | Some path -> 115 | let name = targetNode.Name 116 | let path = path |> List.rev |> List.tail 117 | 118 | let shortestPathMethod = 119 | ProvidedMethod( 120 | methodName = niceName (new HashSet<_>()) ("ShortestPathTo" + name), 121 | parameters = [], 122 | returnType = listType typeof, 123 | InvokeCode = (fun args -> <@@ path @@>)) 124 | states.[node1.Name].AddMember shortestPathMethod 125 | | None -> () 126 | 127 | for node in stateMachine.Nodes do 128 | let name = node.Name 129 | 130 | let startFromMethod = 131 | ProvidedMethod( 132 | methodName = niceName (new HashSet<_>()) ("StartFrom" + name), 133 | parameters = [], 134 | returnType = states.[name], 135 | InvokeCode = (fun args -> <@@ { Name = name } @@>), 136 | IsStaticMethod = true) 137 | ownerType.AddMember startFromMethod 138 | 139 | ownerType)) 140 | graphType 141 | 142 | [] 143 | type public GraphProvider(cfg:TypeProviderConfig) as this = 144 | inherit TypeProviderForNamespaces() 145 | 146 | do this.AddNamespace( 147 | rootNamespace, 148 | [stateMachineTy this true cfg 149 | stateMachineTy this false cfg 150 | graph this cfg]) 151 | 152 | [] 153 | do () -------------------------------------------------------------------------------- /src/GraphProvider/TypeProviders.Helper.fs: -------------------------------------------------------------------------------- 1 | /// Starting to implement some helpers on top of ProvidedTypes API 2 | module internal GraphProvider.Helper 3 | open System 4 | open System.IO 5 | open Samples.FSharp.ProvidedTypes 6 | 7 | type Context (onChanged : unit -> unit) = 8 | let disposingEvent = Event<_>() 9 | let lastChanged = ref (DateTime.Now.AddSeconds -1.0) 10 | let sync = obj() 11 | 12 | let trigger() = 13 | let shouldTrigger = lock sync (fun _ -> 14 | match !lastChanged with 15 | | time when DateTime.Now - time <= TimeSpan.FromSeconds 1. -> false 16 | | _ -> 17 | lastChanged := DateTime.Now 18 | true 19 | ) 20 | if shouldTrigger then onChanged() 21 | 22 | member this.Disposing: IEvent = disposingEvent.Publish 23 | member this.Trigger = trigger 24 | interface IDisposable with 25 | member x.Dispose() = disposingEvent.Trigger() 26 | 27 | // Active patterns & operators for parsing strings 28 | let (@?) (s:string) i = if i >= s.Length then None else Some s.[i] 29 | 30 | let inline satisfies predicate (charOption:option) = 31 | match charOption with 32 | | Some c when predicate c -> charOption 33 | | _ -> None 34 | 35 | let (|EOF|_|) = function 36 | | Some _ -> None 37 | | _ -> Some () 38 | 39 | let (|LetterDigit|_|) = satisfies Char.IsLetterOrDigit 40 | let (|Upper|_|) = satisfies Char.IsUpper 41 | let (|Lower|_|) = satisfies Char.IsLower 42 | 43 | /// Turns a string into a nice PascalCase identifier 44 | let niceName (set:System.Collections.Generic.HashSet<_>) = 45 | fun (s: string) -> 46 | if s = s.ToUpper() then s else 47 | // Starting to parse a new segment 48 | let rec restart i = seq { 49 | match s @? i with 50 | | EOF -> () 51 | | LetterDigit _ & Upper _ -> yield! upperStart i (i + 1) 52 | | LetterDigit _ -> yield! consume i false (i + 1) 53 | | _ -> yield! restart (i + 1) } 54 | 55 | // Parsed first upper case letter, continue either all lower or all upper 56 | and upperStart from i = seq { 57 | match s @? i with 58 | | Upper _ -> yield! consume from true (i + 1) 59 | | Lower _ -> yield! consume from false (i + 1) 60 | | _ -> yield! restart (i + 1) } 61 | // Consume are letters of the same kind (either all lower or all upper) 62 | and consume from takeUpper i = seq { 63 | match s @? i with 64 | | Lower _ when not takeUpper -> yield! consume from takeUpper (i + 1) 65 | | Upper _ when takeUpper -> yield! consume from takeUpper (i + 1) 66 | | _ -> 67 | yield from, i 68 | yield! restart i } 69 | 70 | // Split string into segments and turn them to PascalCase 71 | let mutable name = 72 | seq { for i1, i2 in restart 0 do 73 | let sub = s.Substring(i1, i2 - i1) 74 | if Seq.forall Char.IsLetterOrDigit sub then 75 | yield sub.[0].ToString().ToUpper() + sub.ToLower().Substring(1) } 76 | |> String.concat "" 77 | 78 | while set.Contains name do 79 | let mutable lastLetterPos = String.length name - 1 80 | while Char.IsDigit name.[lastLetterPos] && lastLetterPos > 0 do 81 | lastLetterPos <- lastLetterPos - 1 82 | if lastLetterPos = name.Length - 1 then 83 | name <- name + "2" 84 | elif lastLetterPos = 0 then 85 | name <- (UInt64.Parse name + 1UL).ToString() 86 | else 87 | let number = name.Substring(lastLetterPos + 1) 88 | name <- name.Substring(0, lastLetterPos + 1) + (UInt64.Parse number + 1UL).ToString() 89 | set.Add name |> ignore 90 | name 91 | 92 | 93 | let findConfigFile resolutionFolder configFileName = 94 | if Path.IsPathRooted configFileName then 95 | configFileName 96 | else 97 | Path.Combine(resolutionFolder, configFileName) 98 | 99 | let erasedType<'T> assemblyName rootNamespace typeName = 100 | ProvidedTypeDefinition(assemblyName, rootNamespace, typeName, Some(typeof<'T>)) 101 | 102 | let generalTypeSet = System.Collections.Generic.HashSet() 103 | 104 | let runtimeType<'T> typeName = ProvidedTypeDefinition(niceName generalTypeSet typeName, Some typeof<'T>) 105 | 106 | let seqType ty = typedefof>.MakeGenericType[| ty |] 107 | let listType ty = typedefof>.MakeGenericType[| ty |] 108 | let optionType ty = typedefof>.MakeGenericType[| ty |] 109 | 110 | // Get the assembly and namespace used to house the provided types 111 | let thisAssembly = System.Reflection.Assembly.GetExecutingAssembly() 112 | let rootNamespace = "GraphProvider" 113 | let missingValue = "@@@missingValue###" -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/Actors.dgml: -------------------------------------------------------------------------------- 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 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 56 | 57 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/AsyncStateMachine.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.AsyncStateMachineTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | open GraphProvider.TypeProviders 6 | open System.Threading 7 | 8 | type SM1 = AsyncStateMachine<"Graph1.dgml", "State0"> 9 | 10 | let sleep() = Thread.Sleep 500 11 | 12 | [] 13 | let ``Can access valid states``() = 14 | let workflow1 = SM1() 15 | Assert.AreEqual("State0",workflow1.CurrentState) 16 | 17 | workflow1.TransitToState1() 18 | sleep() 19 | Assert.AreEqual("State1",workflow1.CurrentState) 20 | 21 | workflow1.TransitToState2() 22 | sleep() 23 | Assert.AreEqual("State2",workflow1.CurrentState) 24 | 25 | workflow1.TransitToState3() 26 | sleep() 27 | Assert.AreEqual("State3",workflow1.CurrentState) 28 | 29 | [] 30 | let ``Can't access invalid states``() = 31 | let workflow1 = SM1() 32 | workflow1.TransitToState1() 33 | workflow1.TransitToState2() 34 | workflow1.TransitToState3() 35 | sleep() 36 | Assert.AreEqual("State3",workflow1.CurrentState) 37 | 38 | workflow1.TransitToState2() 39 | sleep() 40 | Assert.AreEqual("State3",workflow1.CurrentState) 41 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/Binary.dgml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/BinaryGraph.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.BinaryGraphTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | open GraphProvider.TypeProviders 6 | 7 | type BinaryGraph = Graph<"Binary.dgml"> 8 | 9 | [] 10 | let ``Empty string should be even``() = 11 | let state = BinaryGraph.StartFromEven() 12 | Assert.AreEqual(state.Name,"Even") 13 | 14 | [] 15 | let ``Single 1 should be even``() = 16 | let state = BinaryGraph.StartFromEven().``1``() 17 | Assert.AreEqual(state.Name,"Even") 18 | 19 | [] 20 | let ``10 should be odd``() = 21 | let state = BinaryGraph.StartFromEven().``1``().``0``() 22 | Assert.AreEqual(state.Name,"Odd") 23 | 24 | [] 25 | let ``101010 should be odd``() = 26 | let state = 27 | BinaryGraph.StartFromEven() 28 | .``1``().``0``().``1``().``0``().``1``().``0``() 29 | Assert.AreEqual(state.Name,"Odd") 30 | 31 | [] 32 | let ``101011 should be even``() = 33 | let state = 34 | BinaryGraph.StartFromEven() 35 | .``1``().``0``().``1``().``0``().``1``().``1``() 36 | Assert.AreEqual(state.Name,"Even") -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/BorderGatewayProtocol.dgml: -------------------------------------------------------------------------------- 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 | 35 | 36 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/BorderGatewayProtocolGraph.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.BorderGatewayProtocolGraphTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | open GraphProvider.TypeProviders 6 | 7 | type BGP = Graph<"BorderGatewayProtocol.dgml"> 8 | 9 | [] 10 | let ``Initially everything is idle``() = 11 | let state = BGP.StartFromIdle() 12 | Assert.AreEqual(state.Name,"Idle") 13 | 14 | [] 15 | let ``Connection can be established``() = 16 | let state = 17 | BGP.StartFromIdle() 18 | .TransitToConnect() 19 | .TransitToOpenSent() 20 | .TransitToOpenConfirm() 21 | .TransitToEstablished() 22 | Assert.AreEqual(state.Name,"Established") -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/FindPathTo.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.FindPathToTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | open GraphProvider.TypeProviders 6 | 7 | type Actors = Graph<"Actors.dgml"> 8 | 9 | [] 10 | let ``Can find path between Keanu Reeves and Kevin Bacon``() = 11 | let path = Actors.StartFromKeanuReeves().ShortestPathToKevinBacon() 12 | Assert.AreEqual(["The Matrix"; "Laurence Fishburne"; "Mystic River"],path) -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/FsUnit.fs: -------------------------------------------------------------------------------- 1 | module FsUnit 2 | open NUnit.Framework 3 | open NUnit.Framework.Constraints 4 | 5 | let should (f : 'a -> #Constraint) x (y : obj) = 6 | let c = f x 7 | let y = 8 | match y with 9 | | :? (unit -> unit) -> box (new TestDelegate(y :?> unit -> unit)) 10 | | _ -> y 11 | Assert.That(y, c) 12 | 13 | let equal x = new EqualConstraint(x) 14 | 15 | // like "should equal", but validates same-type 16 | let shouldEqual (x: 'a) (y: 'a) = Assert.AreEqual(x, y, sprintf "Expected: %A\nActual: %A" x y) 17 | 18 | // overriding a standard language function is not cool 19 | //let not x = new NotConstraint(x) 20 | 21 | let contain x = new ContainsConstraint(x) 22 | 23 | let haveLength n = Has.Length.EqualTo(n) 24 | 25 | let haveCount n = Has.Count.EqualTo(n) 26 | 27 | let be = id 28 | 29 | let Null = new NullConstraint() 30 | 31 | let Empty = new EmptyConstraint() 32 | 33 | let EmptyString = new EmptyStringConstraint() 34 | 35 | let NullOrEmptyString = new NullOrEmptyStringConstraint() 36 | 37 | let True = new TrueConstraint() 38 | 39 | let False = new FalseConstraint() 40 | 41 | let sameAs x = new SameAsConstraint(x) 42 | 43 | let throw = Throws.TypeOf 44 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/Graph1.dgml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/GraphProvider.Tests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | e789c72a-5cfd-436b-8ef1-61aa2852a89f 9 | Library 10 | GraphProvider.Tests 11 | GraphProvider.Tests 12 | v4.0 13 | 4.3.1.0 14 | GraphProvider.Tests 15 | 16 | ..\..\ 17 | true 18 | 19 | 20 | true 21 | full 22 | false 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | 3 27 | 28 | 29 | Project 30 | 31 | 32 | 33 | 34 | 35 | 36 | pdbonly 37 | true 38 | true 39 | bin\Release\ 40 | TRACE 41 | 3 42 | 43 | 44 | 45 | 46 | 11 47 | 48 | 49 | 50 | 51 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 52 | 53 | 54 | 55 | 56 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | PreserveNewest 66 | 67 | 68 | PreserveNewest 69 | 70 | 71 | PreserveNewest 72 | 73 | 74 | PreserveNewest 75 | 76 | 77 | PreserveNewest 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | ..\..\bin\GraphProvider.dll 91 | 92 | 93 | ..\..\packages\FsUnit.1.2.1.0\Lib\Net40\FsUnit.NUnit.dll 94 | True 95 | 96 | 97 | 98 | True 99 | 100 | 101 | ..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll 102 | True 103 | 104 | 105 | 106 | 107 | C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 108 | 109 | 110 | 117 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/StateMachine.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.StateMachineTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | open GraphProvider.TypeProviders 6 | 7 | type SM1 = StateMachine<"Graph1.dgml", "State0"> 8 | 9 | [] 10 | let ``Can access valid states``() = 11 | let workflow1 = SM1() 12 | Assert.AreEqual("State0",workflow1.CurrentState) 13 | 14 | workflow1.TransitToState1() 15 | Assert.AreEqual("State1",workflow1.CurrentState) 16 | 17 | workflow1.TransitToState2() 18 | Assert.AreEqual("State2",workflow1.CurrentState) 19 | 20 | workflow1.TransitToState3() 21 | Assert.AreEqual("State3",workflow1.CurrentState) 22 | 23 | [] 24 | let ``Can't access invalid states``() = 25 | let workflow1 = SM1() 26 | workflow1.TransitToState1() 27 | workflow1.TransitToState2() 28 | workflow1.TransitToState3() 29 | Assert.AreEqual("State3",workflow1.CurrentState) 30 | 31 | workflow1.TransitToState2() 32 | Assert.AreEqual("State3",workflow1.CurrentState) 33 | 34 | 35 | [] 36 | let ``Executes the transition functions``() = 37 | let workflow1 = SM1() 38 | 39 | let entered1 = ref false 40 | let left1 = ref false 41 | let entered2 = ref false 42 | let left2 = ref false 43 | 44 | let trans1 = { new StateMachine.IState with 45 | member this.EnterFunction() = entered1 := true 46 | member this.ExitFunction() = left1 := true } 47 | 48 | let trans2 = { new StateMachine.IState with 49 | member this.EnterFunction() = entered2 := true 50 | member this.ExitFunction() = left2 := true } 51 | 52 | workflow1.SetTransitionFunction(workflow1.State1, trans1) 53 | workflow1.SetTransitionFunction(workflow1.State2, trans2) 54 | 55 | workflow1.TransitToState1() 56 | Assert.IsTrue(!entered1) 57 | Assert.IsFalse(!left1) 58 | Assert.IsFalse(!entered2) 59 | Assert.IsFalse(!left2) 60 | 61 | workflow1.TransitToState2() 62 | Assert.IsTrue(!entered1) 63 | Assert.IsTrue(!left1) 64 | Assert.IsTrue(!entered2) 65 | Assert.IsFalse(!left2) 66 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/StateNetwork.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.StateNetworkTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | open GraphProvider.TypeProviders 6 | 7 | type Graph1 = Graph<"Graph1.dgml"> 8 | 9 | [] 10 | let ``Can access initial state``() = 11 | let state = Graph1.StartFromState0() 12 | Assert.AreEqual(state.Name,"State0") 13 | 14 | [] 15 | let ``Can access states``() = 16 | let state2 = 17 | Graph1.StartFromState0() 18 | .TransitToState1() 19 | .TransitToState2() 20 | 21 | Assert.AreEqual(state2.Name,"State2") -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/Turnstile.dgml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/TurnstileGraph.Tests.fs: -------------------------------------------------------------------------------- 1 | module GraphProvider.TypeProviders.Graph.Tests.TurnstileGraphTests 2 | 3 | open NUnit.Framework 4 | open GraphProvider 5 | 6 | type Turnstile = Graph<"Turnstile.dgml"> 7 | 8 | [] 9 | let ``Turnstile should be locked initially``() = 10 | let state = Turnstile.StartFromLocked() 11 | Assert.AreEqual(state.Name,"Locked") 12 | 13 | [] 14 | let ``Pushing doesn't unlock the turnstile``() = 15 | let state = Turnstile.StartFromLocked().Push() 16 | Assert.AreEqual(state.Name,"Locked") 17 | 18 | [] 19 | let ``Insert a coin and the turnstile is unlocked``() = 20 | let state = Turnstile.StartFromLocked().Coin() 21 | Assert.AreEqual(state.Name,"Unlocked") 22 | 23 | [] 24 | let ``Insert a coin and push then the turnstile is locked``() = 25 | let state = 26 | Turnstile.StartFromLocked().Coin().Push() 27 | Assert.AreEqual(state.Name,"Locked") 28 | 29 | [] 30 | let ``Insert two coins and push then the turnstile is locked``() = 31 | let state = 32 | Turnstile.StartFromLocked().Coin().Coin().Push() 33 | Assert.AreEqual(state.Name,"Locked") -------------------------------------------------------------------------------- /tests/GraphProvider.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------