├── .gitignore ├── LICENSE ├── README.md ├── deploy ├── ClearScript.Manager.Http.ps1 ├── ClearScript.Manager.ps1 ├── Package.bat ├── Publish.bat ├── archive.ps1 ├── common.ps1 ├── extensions │ └── psake.psm1 ├── package.ps1 └── publish.ps1 ├── img └── clearscript.png └── src ├── ClearScript.Manager.Demo ├── App.config ├── ClearScript.Manager.Demo.csproj ├── ClearScriptV8-32.dll ├── ClearScriptV8-32.pdb ├── ClearScriptV8-64.dll ├── ClearScriptV8-64.pdb ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── packages.config ├── v8-ia32.dll ├── v8-ia32.pdb ├── v8-x64.dll └── v8-x64.pdb ├── ClearScript.Manager.Http.Test ├── ClearScript.Manager.Http.Test.csproj ├── Lib │ ├── ClearScriptV8-32.dll │ ├── ClearScriptV8-32.pdb │ ├── ClearScriptV8-64.dll │ ├── ClearScriptV8-64.pdb │ ├── v8-ia32.dll │ ├── v8-ia32.pdb │ ├── v8-x64.dll │ └── v8-x64.pdb ├── Properties │ └── AssemblyInfo.cs ├── TestIncludeScript.js ├── TestMainScript.js ├── WhenExecutingMainIncludeScript.cs ├── WhenExecutingScriptWithIncludeScripts.cs ├── WhenExecutingScriptWithRequire.cs ├── WhenMakingHttpCall.cs └── packages.config ├── ClearScript.Manager.Http ├── ClearScript.Manager.Http.csproj ├── ClearScript.Manager.Http.nuspec ├── Helpers │ ├── DynamicExtensions.cs │ ├── Node │ │ ├── NodeBuffer.cs │ │ ├── NodeHttp.cs │ │ ├── NodeHttpRequest.cs │ │ ├── NodeHttpRequestOptions.cs │ │ ├── NodeHttpResponse.cs │ │ └── NodeRequestModule.cs │ └── ScriptAwaiter.cs ├── Loaders │ └── HttpScriptLoader.cs ├── Packages │ ├── HttpPackage.cs │ ├── PackageHelpers.cs │ └── RequestPackage.cs ├── Properties │ └── AssemblyInfo.cs ├── Scripts │ └── request.js └── packages.config ├── ClearScript.Manager.Test ├── ClearScript.Manager.Test.csproj ├── Lib │ ├── ClearScriptV8-32.dll │ ├── ClearScriptV8-32.pdb │ ├── ClearScriptV8-64.dll │ ├── ClearScriptV8-64.pdb │ ├── v8-ia32.dll │ ├── v8-ia32.pdb │ ├── v8-x64.dll │ └── v8-x64.pdb ├── Properties │ └── AssemblyInfo.cs ├── ScriptSubject.cs ├── TestDiffNameRequire.js ├── TestIncludeScript.js ├── TestMainScript.js ├── TestParentRequire.js ├── TestRequire.js ├── TestRequire2.js ├── V8ScriptingTests.cs ├── WhenCachingScripts.cs ├── WhenExecutingBasicJavaScript.cs ├── WhenExecutingMainIncludeScript.cs ├── WhenExecutingScriptWithIncludeScripts.cs ├── WhenExecutingScriptWithRequire.cs ├── WhenExecutingScriptWithTimeout.cs ├── WhenExecutingWithHostObjects.cs ├── WhenExecutingWithHostTypes.cs ├── WhenUsingAManagerPool.cs ├── WhenUsingGetEngine.cs └── packages.config ├── ClearScript.Manager.WebDemo ├── App_Start │ ├── BundleConfig.cs │ ├── FilterConfig.cs │ ├── RouteConfig.cs │ └── WebApiConfig.cs ├── Areas │ └── HelpPage │ │ ├── ApiDescriptionExtensions.cs │ │ ├── App_Start │ │ └── HelpPageConfig.cs │ │ ├── Controllers │ │ └── HelpController.cs │ │ ├── HelpPage.css │ │ ├── HelpPageAreaRegistration.cs │ │ ├── HelpPageConfigurationExtensions.cs │ │ ├── ModelDescriptions │ │ ├── CollectionModelDescription.cs │ │ ├── ComplexTypeModelDescription.cs │ │ ├── DictionaryModelDescription.cs │ │ ├── EnumTypeModelDescription.cs │ │ ├── EnumValueDescription.cs │ │ ├── IModelDocumentationProvider.cs │ │ ├── KeyValuePairModelDescription.cs │ │ ├── ModelDescription.cs │ │ ├── ModelDescriptionGenerator.cs │ │ ├── ModelNameAttribute.cs │ │ ├── ModelNameHelper.cs │ │ ├── ParameterAnnotation.cs │ │ ├── ParameterDescription.cs │ │ └── SimpleTypeModelDescription.cs │ │ ├── Models │ │ └── HelpPageApiModel.cs │ │ ├── SampleGeneration │ │ ├── HelpPageSampleGenerator.cs │ │ ├── HelpPageSampleKey.cs │ │ ├── ImageSample.cs │ │ ├── InvalidSample.cs │ │ ├── ObjectGenerator.cs │ │ ├── SampleDirection.cs │ │ └── TextSample.cs │ │ ├── Views │ │ ├── Help │ │ │ ├── Api.cshtml │ │ │ ├── DisplayTemplates │ │ │ │ ├── ApiGroup.cshtml │ │ │ │ ├── CollectionModelDescription.cshtml │ │ │ │ ├── ComplexTypeModelDescription.cshtml │ │ │ │ ├── DictionaryModelDescription.cshtml │ │ │ │ ├── EnumTypeModelDescription.cshtml │ │ │ │ ├── HelpPageApiModel.cshtml │ │ │ │ ├── ImageSample.cshtml │ │ │ │ ├── InvalidSample.cshtml │ │ │ │ ├── KeyValuePairModelDescription.cshtml │ │ │ │ ├── ModelDescriptionLink.cshtml │ │ │ │ ├── Parameters.cshtml │ │ │ │ ├── Samples.cshtml │ │ │ │ ├── SimpleTypeModelDescription.cshtml │ │ │ │ └── TextSample.cshtml │ │ │ ├── Index.cshtml │ │ │ └── ResourceModel.cshtml │ │ ├── Shared │ │ │ └── _Layout.cshtml │ │ ├── Web.config │ │ └── _ViewStart.cshtml │ │ └── XmlDocumentationProvider.cs ├── ClearScript.Manager.WebDemo.csproj ├── ClearScriptV8-32.dll ├── ClearScriptV8-32.pdb ├── ClearScriptV8-64.dll ├── ClearScriptV8-64.pdb ├── Content │ ├── Site.css │ ├── bootstrap.css │ └── bootstrap.min.css ├── Controllers │ ├── HomeController.cs │ └── ValuesController.cs ├── Global.asax ├── Global.asax.cs ├── Models │ ├── Script.cs │ └── TestModel.cs ├── Project_Readme.html ├── Properties │ └── AssemblyInfo.cs ├── Scripts │ ├── _references.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-1.10.2.intellisense.js │ ├── jquery-1.10.2.js │ ├── jquery-1.10.2.min.js │ ├── jquery-1.10.2.min.map │ ├── modernizr-2.6.2.js │ ├── request.js │ ├── respond.js │ └── respond.min.js ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ └── _Layout.cshtml │ ├── Web.config │ └── _ViewStart.cshtml ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── favicon.ico ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff ├── packages.config ├── v8-ia32.dll ├── v8-ia32.pdb ├── v8-x64.dll └── v8-x64.pdb ├── ClearScript.Manager.sln └── ClearScript.Manager ├── Caching ├── CachedV8Runtime.cs ├── HashUtilities.cs ├── IConcurrentDictionary.cs ├── IDictionaryEx.cs ├── LruCache.cs └── LruCacheCorruptionException.cs ├── ClearScript.Manager.csproj ├── ClearScript.Manager.nuspec ├── ExecutionOptions.cs ├── Extensions ├── DynamicExtensions.cs ├── EngineExtensions.cs ├── EnumerableExtensions.cs └── StringExtensions.cs ├── HostObject.cs ├── HostType.cs ├── IncludeScript.cs ├── Loaders ├── FileScriptLoader.cs ├── IScriptLoader.cs ├── RequireManager.cs ├── RequiredPackage.cs ├── Requirer.cs └── ScriptLoadManager.cs ├── ManagerPool.cs ├── ManagerScope.cs ├── ManagerSettings.cs ├── Properties └── AssemblyInfo.cs ├── RuntimeManager.cs ├── ScriptCompiler.cs └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Eric Swann et. al. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /deploy/ClearScript.Manager.Http.ps1: -------------------------------------------------------------------------------- 1 | properties { 2 | $BaseDir = Resolve-Path "..\" 3 | $SolutionFile = "$BaseDir\src\ClearScript.Manager.sln" 4 | $ProjectPath = "$BaseDir\src\ClearScript.Manager.Http\ClearScript.Manager.Http.csproj" 5 | $ArchiveDir = "$BaseDir\Deploy\Archive" 6 | 7 | $NuGetPackageName = "ClearScript.Manager.Http" 8 | } 9 | 10 | . .\common.ps1 11 | -------------------------------------------------------------------------------- /deploy/ClearScript.Manager.ps1: -------------------------------------------------------------------------------- 1 | properties { 2 | $BaseDir = Resolve-Path "..\" 3 | $SolutionFile = "$BaseDir\src\ClearScript.Manager.sln" 4 | $ProjectPath = "$BaseDir\src\ClearScript.Manager\ClearScript.Manager.csproj" 5 | $ArchiveDir = "$BaseDir\Deploy\Archive" 6 | 7 | $NuGetPackageName = "ClearScript.Manager" 8 | } 9 | 10 | . .\common.ps1 11 | -------------------------------------------------------------------------------- /deploy/Package.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | powershell -NoProfile -ExecutionPolicy unrestricted -Command "& {.\archive.ps1; exit $error.Count}" 4 | 5 | 6 | powershell -NoProfile -ExecutionPolicy unrestricted -Command "& {.\package.ps1 -PackageName 'ClearScript.Manager'; exit $error.Count}" 7 | 8 | 9 | powershell -NoProfile -ExecutionPolicy unrestricted -Command "& {.\package.ps1 -PackageName 'ClearScript.Manager.Http'; exit $error.Count}" 10 | 11 | 12 | 13 | pause -------------------------------------------------------------------------------- /deploy/Publish.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | 4 | powershell -NoProfile -ExecutionPolicy unrestricted -Command "& {.\archive.ps1; exit $error.Count}" 5 | 6 | 7 | powershell -NoProfile -ExecutionPolicy unrestricted -Command "& {.\publish.ps1 -PackageName 'ClearScript.Manager'; exit $error.Count}" 8 | 9 | 10 | powershell -NoProfile -ExecutionPolicy unrestricted -Command "& {.\publish.ps1 -PackageName 'ClearScript.Manager.Http'; exit $error.Count}" 11 | 12 | 13 | 14 | 15 | pause -------------------------------------------------------------------------------- /deploy/archive.ps1: -------------------------------------------------------------------------------- 1 | $loadedPsake = $false; 2 | if ((Get-Module psake) -eq $null) { 3 | import-module .\extensions\psake.psm1 4 | $loadedPsake = $true; 5 | } 6 | 7 | invoke-psake "common.ps1" -taskList Archive 8 | 9 | if ($loadedPsake) { 10 | remove-module psake 11 | } -------------------------------------------------------------------------------- /deploy/common.ps1: -------------------------------------------------------------------------------- 1 | #Common NuGet/Archiving logic, not meant ot be executed directly. 2 | 3 | $framework = '4.5.1' 4 | $currentDate = Get-Date -format yyyyMMddhhmmss 5 | 6 | $archiveFolder = "run_$currentDate" 7 | 8 | task default -depends Pack 9 | 10 | task Init { 11 | cls 12 | } 13 | 14 | 15 | task Archive -depends Init { 16 | New-Item -ItemType Directory -Force -Path archive\$archiveFolder 17 | 18 | if (Test-Path output) { 19 | Move-Item output\* archive\$archiveFolder 20 | Remove-Item output\* 21 | } 22 | } 23 | 24 | task Build -depends Init{ 25 | exec { msbuild $SolutionFile /p:Configuration=Release } 26 | } 27 | 28 | 29 | task Pack -depends Build { 30 | exec { nuget pack "$ProjectPath" -OutputDirectory output -Properties Configuration=Release } 31 | } 32 | 33 | task Publish -depends Pack { 34 | $PackageName = gci output\$NuGetPackageName.*.nupkg 35 | exec { nuget push $PackageName } 36 | } -------------------------------------------------------------------------------- /deploy/package.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | $PackageName 3 | ) 4 | 5 | $loadedPsake = $false; 6 | if ((Get-Module psake) -eq $null) { 7 | import-module .\extensions\psake.psm1 8 | $loadedPsake = $true; 9 | } 10 | 11 | invoke-psake "$($PackageName).ps1" -taskList Pack 12 | 13 | if ($loadedPsake) { 14 | remove-module psake 15 | } -------------------------------------------------------------------------------- /deploy/publish.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | $PackageName 3 | ) 4 | 5 | $loadedPsake = $false; 6 | if ((Get-Module psake) -eq $null) { 7 | import-module .\extensions\psake.psm1 8 | $loadedPsake = $true; 9 | } 10 | 11 | invoke-psake "$($PackageName).ps1" -taskList Publish 12 | 13 | if ($loadedPsake) { 14 | remove-module psake 15 | } -------------------------------------------------------------------------------- /img/clearscript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/img/clearscript.png -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/ClearScript.Manager.Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {60385905-F78E-4933-9FB7-DD75D51CA2CD} 8 | Exe 9 | Properties 10 | ClearScript.Manager.Demo 11 | ClearScript.Manager.Demo 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\ClearScript.Installer.1.0.1.31662\lib\net45\ClearScript.dll 37 | 38 | 39 | ..\packages\ClearScript.Manager.1.0.0.32920\lib\net45\ClearScript.Manager.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Always 60 | 61 | 62 | Always 63 | 64 | 65 | Always 66 | 67 | 68 | Always 69 | 70 | 71 | Always 72 | 73 | 74 | Always 75 | 76 | 77 | Always 78 | 79 | 80 | Always 81 | 82 | 83 | 84 | 91 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/ClearScriptV8-32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/ClearScriptV8-32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/ClearScriptV8-32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/ClearScriptV8-32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/ClearScriptV8-64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/ClearScriptV8-64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/ClearScriptV8-64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/ClearScriptV8-64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ClearScript.Manager.Demo 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ClearScript.Manager.Demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ClearScript.Manager.Demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a1bdf813-2d8d-47b8-9c3c-6d2738436a2e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/v8-ia32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/v8-ia32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/v8-ia32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/v8-ia32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/v8-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/v8-x64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Demo/v8-x64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Demo/v8-x64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/ClearScriptV8-64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/v8-ia32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/v8-ia32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/v8-ia32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/v8-ia32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/v8-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/v8-x64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Lib/v8-x64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Http.Test/Lib/v8-x64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ClearScript.Manager.Http.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ClearScript.Manager.Http.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b0e102d5-4b69-4f2d-93e5-4b7bcefa899b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/TestIncludeScript.js: -------------------------------------------------------------------------------- 1 | var x = 'test string1'; -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/TestMainScript.js: -------------------------------------------------------------------------------- 1 | subject.Count = 10; subject.TestString = 'test string1'; -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/WhenExecutingMainIncludeScript.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ClearScript.Manager.Http.Loaders; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace ClearScript.Manager.Http.Test 7 | { 8 | [TestFixture] 9 | public class WhenExecutingMainIncludeScript 10 | { 11 | [SetUp] 12 | public void SetUp() 13 | { 14 | HttpScriptLoader.Register(); 15 | } 16 | 17 | [Test] 18 | public async void Script_With_Http_Reference_Is_Run() 19 | { 20 | var subject = new TestObject(); 21 | var manager = new RuntimeManager(new ManualManagerSettings()); 22 | 23 | await manager.ExecuteAsync(new List { new IncludeScript { Uri = "https://gist.githubusercontent.com/eswann/66796164c1904b6135ea/raw/5491642164a45ae34af2926137950de3249d1e91/gistfile1.txt", ScriptId = "testScript" } }, 24 | new ExecutionOptions 25 | { 26 | HostObjects = new List { new HostObject { Name = "subject", Target = subject } }, 27 | }); 28 | 29 | subject.Name.ShouldEqual("Name"); 30 | subject.Count.ShouldEqual(10); 31 | subject.TestString.ShouldEqual("test string1"); 32 | } 33 | 34 | [Test] 35 | public async void Multiple_Scripts_Types_Are_Run_First_To_Last() 36 | { 37 | var subject = new TestObject(); 38 | var manager = new RuntimeManager(new ManualManagerSettings()); 39 | 40 | await manager.ExecuteAsync(new List 41 | { 42 | new IncludeScript {Uri = ".\\TestMainScript.js", ScriptId = "testScript"}, 43 | new IncludeScript {Code = "subject.TestString = 'test string3';", ScriptId = "testScript3"}, 44 | new IncludeScript {Uri = "https://gist.githubusercontent.com/eswann/62fc90e542f7697263db/raw/026c42ef0043a70a8c3b720e3026ecee9c691a06/gistfile1.txt", ScriptId = "TestScript4"} 45 | }, 46 | new ExecutionOptions 47 | { 48 | HostObjects = new List {new HostObject {Name = "subject", Target = subject}}, 49 | }); 50 | 51 | subject.Name.ShouldEqual("Name"); 52 | subject.Count.ShouldEqual(20); 53 | subject.TestString.ShouldEqual("test string3"); 54 | } 55 | 56 | 57 | public class TestObject 58 | { 59 | private string _name = "Name"; 60 | 61 | public string Name 62 | { 63 | get { return _name; } 64 | set { _name = value; } 65 | } 66 | 67 | public string TestString { get; set; } 68 | 69 | public int Count { get; set; } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/WhenExecutingScriptWithIncludeScripts.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ClearScript.Manager.Http.Loaders; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace ClearScript.Manager.Http.Test 7 | { 8 | 9 | [TestFixture] 10 | public class WhenExecutingScriptWithIncludeScripts 11 | { 12 | [SetUp] 13 | public void SetUp() 14 | { 15 | HttpScriptLoader.Register(); 16 | } 17 | 18 | [Test] 19 | public async void Script_With_Http_Include_Is_Included() 20 | { 21 | var subject = new TestObject(); 22 | var manager = new RuntimeManager(new ManualManagerSettings()); 23 | 24 | await manager.ExecuteAsync("testscript", "subject.Count = 10; subject.TestString = x;", 25 | new ExecutionOptions 26 | { 27 | HostObjects = new List {new HostObject {Name = "subject", Target = subject}}, 28 | Scripts = new List { new IncludeScript { Uri = "https://gist.githubusercontent.com/eswann/3215f3afff3a602c0f3a/raw/a9ace53fca80fdcdefba60c4f7bf803bf5239905/gistfile1.txt", ScriptId = "testScript2" } } 29 | }); 30 | 31 | subject.Name.ShouldEqual("Name"); 32 | subject.Count.ShouldEqual(10); 33 | subject.TestString.ShouldEqual("test string1"); 34 | } 35 | 36 | public class TestObject 37 | { 38 | private string _name = "Name"; 39 | 40 | public string Name 41 | { 42 | get { return _name; } 43 | set { _name = value; } 44 | } 45 | 46 | public string TestString { get; set; } 47 | 48 | public int Count { get; set; } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/WhenExecutingScriptWithRequire.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ClearScript.Manager.Loaders; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace ClearScript.Manager.Http.Test 7 | { 8 | [TestFixture] 9 | public class WhenExecutingScriptWithRequire 10 | { 11 | [SetUp] 12 | public void Setup() 13 | { 14 | RequireManager.ClearPackages(); 15 | } 16 | 17 | [Test] 18 | public async void Script_With_Require_Is_Used() 19 | { 20 | var subject = new TestObject(); 21 | var manager = new RuntimeManager(new ManualManagerSettings {ScriptTimeoutMilliSeconds = 0}); 22 | 23 | RequireManager.RegisterPackage(new RequiredPackage { PackageId = "testRequire", ScriptUri = "https://gist.githubusercontent.com/eswann/76ecaba02dee33cf26b4/raw/bcafe0a389c84ba44d6ee1661e66b2213aa2ffa0/testRequire" }); 24 | 25 | await 26 | manager.ExecuteAsync("testscript", 27 | "var testObject = require('testRequire'); subject.Count = 10; subject.TestString = testObject.getText();", 28 | new ExecutionOptions 29 | { 30 | HostObjects = new List {new HostObject {Name = "subject", Target = subject}}, 31 | }); 32 | 33 | subject.Name.ShouldEqual("Name"); 34 | subject.Count.ShouldEqual(10); 35 | subject.TestString.ShouldEqual("testText"); 36 | } 37 | 38 | [Test] 39 | public async void Require_Specified_As_Script_HttpPath_Path_Is_Used() 40 | { 41 | var subject = new TestObject(); 42 | var manager = new RuntimeManager(new ManualManagerSettings {ScriptTimeoutMilliSeconds = 0}); 43 | 44 | await 45 | manager.ExecuteAsync("testscript", 46 | @"var testObject = require('https://gist.githubusercontent.com/eswann/76ecaba02dee33cf26b4/raw/bcafe0a389c84ba44d6ee1661e66b2213aa2ffa0/testRequire'); subject.Count = 10; subject.TestString = testObject.getText();", 47 | new ExecutionOptions 48 | { 49 | HostObjects = new List {new HostObject {Name = "subject", Target = subject}}, 50 | }); 51 | 52 | subject.Name.ShouldEqual("Name"); 53 | subject.Count.ShouldEqual(10); 54 | subject.TestString.ShouldEqual("testText"); 55 | } 56 | 57 | [Test] 58 | public async void Require_Named_With_Explicit_Name_Succeeds() 59 | { 60 | var subject = new TestObject(); 61 | var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 0 }); 62 | 63 | await 64 | manager.ExecuteAsync("testscript", 65 | @"var testObject = requireNamed('testRequire', 'https://gist.githubusercontent.com/eswann/3ff5ec2bcc63b7d2cdaa/raw/26e30f6a9761dbbe5634b2de1549c4a455b7a7d6/TestDiffNameRequire.js'); subject.Count = 10; subject.TestString = testObject.getText();", 66 | new ExecutionOptions 67 | { 68 | HostObjects = new List { new HostObject { Name = "subject", Target = subject } }, 69 | }); 70 | 71 | subject.Name.ShouldEqual("Name"); 72 | subject.Count.ShouldEqual(10); 73 | subject.TestString.ShouldEqual("testText"); 74 | } 75 | 76 | } 77 | 78 | 79 | public class TestObject 80 | { 81 | private string _name = "Name"; 82 | 83 | public string Name 84 | { 85 | get { return _name; } 86 | set { _name = value; } 87 | } 88 | 89 | public string TestString { get; set; } 90 | 91 | public int Count { get; set; } 92 | } 93 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/WhenMakingHttpCall.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using ClearScript.Manager.Http.Helpers; 3 | using ClearScript.Manager.Http.Packages; 4 | using ClearScript.Manager.Loaders; 5 | using Microsoft.ClearScript; 6 | using NUnit.Framework; 7 | using Should; 8 | 9 | namespace ClearScript.Manager.Http.Test 10 | { 11 | [TestFixture] 12 | public class WhenMakingHttpCall 13 | { 14 | [SetUp] 15 | public void Setup() 16 | { 17 | RequireManager.ClearPackages(); 18 | } 19 | 20 | [Test] 21 | public async void Basic_Http_Get_Succeeds() 22 | { 23 | var subject = new TestObject(); 24 | var manager = new RuntimeManager(new ManualManagerSettings{ScriptTimeoutMilliSeconds = 0}); 25 | 26 | PackageHelpers.RegisterRequestPackages(); 27 | 28 | manager.AddConsoleReference = true; 29 | var options = new ExecutionOptions(); 30 | options.HostObjects.Add(new HostObject {Name = "subject", Target = subject}); 31 | 32 | var scriptAwaiter = new ScriptAwaiter(); 33 | options.HostObjects.Add(new HostObject { Name = "scriptAwaiter", Target = scriptAwaiter }); 34 | 35 | var code = "var request = require('request');" + 36 | "request({url: 'http://api.icndb.com/jokes/random/1', json: true}," + 37 | " function (error, response, body) {subject.StatusCode = response.statusCode; subject.Response = response; scriptAwaiter.Callback();});"; 38 | 39 | await manager.ExecuteAsync("testScript", code, options); 40 | await scriptAwaiter.T; 41 | 42 | subject.StatusCode.ShouldEqual(200); 43 | } 44 | 45 | [Test] 46 | public async void Basic_Http_Get_Body_Is_Retrieved() 47 | { 48 | var subject = new TestObject(); 49 | var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 0 }); 50 | 51 | PackageHelpers.RegisterRequestPackages(); 52 | 53 | manager.AddConsoleReference = true; 54 | var options = new ExecutionOptions(); 55 | options.HostObjects.Add(new HostObject { Name = "subject", Target = subject }); 56 | 57 | var scriptAwaiter = new ScriptAwaiter(); 58 | options.HostObjects.Add(new HostObject { Name = "scriptAwaiter", Target = scriptAwaiter }); 59 | 60 | var code = "var request = require('request');" + 61 | "request({url: 'http://api.icndb.com/jokes/random/1', json: true}," + 62 | " function (error, response, body) {subject.Response = response; subject.Body = body; subject.Joke = body.value[0].joke; scriptAwaiter.Callback();});"; 63 | 64 | await manager.ExecuteAsync("testScript", code, options); 65 | await scriptAwaiter.T; 66 | 67 | subject.Joke.ShouldNotBeNull(); 68 | } 69 | 70 | [Test] 71 | public async void Basic_Http_Get_Headers_Are_Retrieved() 72 | { 73 | var subject = new TestObject(); 74 | var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 0 }); 75 | 76 | PackageHelpers.RegisterRequestPackages(); 77 | 78 | manager.AddConsoleReference = true; 79 | var options = new ExecutionOptions(); 80 | options.HostObjects.Add(new HostObject { Name = "subject", Target = subject }); 81 | 82 | var scriptAwaiter = new ScriptAwaiter(); 83 | options.HostObjects.Add(new HostObject { Name = "scriptAwaiter", Target = scriptAwaiter }); 84 | 85 | var code = "var request = require('request');" + 86 | "request({url: 'http://api.icndb.com/jokes/random/1', json: true}," + 87 | " function (error, response, body) {subject.Response = response; subject.Headers = response.headers; scriptAwaiter.Callback();});"; 88 | 89 | await manager.ExecuteAsync("testScript", code, options); 90 | await scriptAwaiter.T; 91 | 92 | subject.Headers.Count().ShouldBeGreaterThan(0); 93 | } 94 | 95 | public class TestObject 96 | { 97 | private string _name = "Name"; 98 | 99 | public string Name 100 | { 101 | get { return _name; } 102 | set { _name = value; } 103 | } 104 | 105 | public string Server { get; set; } 106 | 107 | public int StatusCode { get; set; } 108 | 109 | public string Joke { get; set; } 110 | 111 | public object Response { get; set; } 112 | 113 | public object Body { get; set; } 114 | 115 | public PropertyBag Headers { get; set; } 116 | 117 | public int Count { get; set; } 118 | } 119 | 120 | } 121 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/ClearScript.Manager.Http.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | $version$ 6 | $id$ 7 | eric_swann 8 | eric_swann 9 | https://github.com/eswann/ClearScript.Manager 10 | https://raw.githubusercontent.com/eswann/ClearScript.Manager/master/img/clearscript.png 11 | false 12 | $description$ 13 | $description$ 14 | Copyright 2014 Eric Swann, et. al. - All rights reserved. 15 | 16 | ClearScript V8 JavaScript 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/DynamicExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Dynamic; 4 | 5 | namespace ClearScript.Manager.Http.Helpers 6 | { 7 | public static class DynamicExtensions 8 | { 9 | public static bool TryGetMember(this DynamicObject source, string name, out object outField) 10 | { 11 | 12 | outField = ((dynamic)source).field; 13 | return !(outField is Microsoft.ClearScript.Undefined); 14 | } 15 | 16 | public static dynamic AsDynamic(this DynamicObject obj) 17 | { 18 | return obj; 19 | } 20 | 21 | public static IEnumerable> GetProperties(this DynamicObject obj) 22 | { 23 | if (obj == null) 24 | { 25 | yield break; 26 | } 27 | foreach (var varName in obj.GetDynamicMemberNames()) 28 | { 29 | object prop; 30 | if (obj.TryGetMember(varName, out prop)) 31 | { 32 | yield return new KeyValuePair(varName, prop); 33 | } 34 | } 35 | } 36 | 37 | public static T GetMember(this DynamicObject source, string name, T defaultValue = default(T)) 38 | { 39 | Object outField; 40 | 41 | if (source.TryGetMember(new SimpleGetMemberBinder(name), out outField)) 42 | { 43 | if (outField is Microsoft.ClearScript.Undefined) 44 | { 45 | return defaultValue; 46 | } 47 | return (T)outField; 48 | } 49 | 50 | return defaultValue; 51 | } 52 | 53 | public static T GetMember(this DynamicObject source, string name, Func converter, T defaultValue = default(T)) 54 | { 55 | Object outField; 56 | 57 | if (source.TryGetMember(new SimpleGetMemberBinder(name), out outField)) 58 | { 59 | if (outField is Microsoft.ClearScript.Undefined) 60 | { 61 | return defaultValue; 62 | } 63 | return converter(outField); 64 | } 65 | 66 | return defaultValue; 67 | } 68 | } 69 | 70 | internal class SimpleGetMemberBinder : GetMemberBinder 71 | { 72 | public SimpleGetMemberBinder(string name) 73 | : base(name, true) 74 | { 75 | } 76 | 77 | public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion) 78 | { 79 | return null; 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/Node/NodeBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ClearScript.Manager.Http.Helpers.Node 5 | { 6 | public class NodeBuffer 7 | { 8 | 9 | public NodeBuffer(int size) 10 | : this(new MemoryStream(size)) 11 | { 12 | 13 | } 14 | public NodeBuffer() 15 | : this(new MemoryStream()) 16 | { 17 | 18 | } 19 | public NodeBuffer(Stream innerStream) 20 | { 21 | this.InnerStream = innerStream; 22 | } 23 | 24 | public static bool isBuffer(object obj) 25 | { 26 | return obj is NodeBuffer; 27 | } 28 | 29 | 30 | public NodeBuffer slice(int? start = null, int? end = null) 31 | { 32 | if (start == null && end == null) 33 | { 34 | return this; 35 | } 36 | throw new NotImplementedException(); 37 | 38 | } 39 | 40 | protected Stream InnerStream { get; set; } 41 | 42 | 43 | public string asString(object enc = null, int? start = null, int? end = null) 44 | { 45 | string encoding = null; 46 | long pos = InnerStream.Position; 47 | InnerStream.Position = 0; 48 | string ret; 49 | 50 | if (string.IsNullOrWhiteSpace(encoding)) 51 | { 52 | ret = new StreamReader(InnerStream, true).ReadToEnd(); 53 | } 54 | else 55 | { 56 | ret = new StreamReader(InnerStream, System.Text.Encoding.GetEncoding(encoding)).ReadToEnd(); 57 | } 58 | 59 | InnerStream.Position = pos; 60 | return ret; 61 | 62 | } 63 | 64 | public void copy(NodeBuffer target, int? targetStart = null, int? sourceStart = null, int? sourceEnd = null) 65 | { 66 | InnerStream.CopyTo(target.InnerStream); 67 | 68 | } 69 | 70 | public long length 71 | { 72 | get { return InnerStream.Length; } 73 | } 74 | 75 | 76 | } 77 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/Node/NodeHttp.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | 3 | namespace ClearScript.Manager.Http.Helpers.Node 4 | { 5 | 6 | public class NodeHttp 7 | { 8 | public NodeHttpRequest request(dynamic options, dynamic callback) 9 | { 10 | var client = new HttpClient(); 11 | var requestMessage = new HttpRequestMessage(); 12 | var req = new NodeHttpRequest(client, requestMessage, options, callback); 13 | return req; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/Node/NodeHttpRequestOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Dynamic; 3 | 4 | namespace ClearScript.Manager.Http.Helpers.Node 5 | { 6 | public class NodeHttpRequestOptions 7 | { 8 | public NodeHttpRequestOptions(DynamicObject config) 9 | { 10 | host = config.GetMember("host"); 11 | scheme = config.GetMember("scheme", "http"); 12 | hostname = config.GetMember("hostname") ?? host; 13 | 14 | url = config.GetMember("uri") ?? config.GetMember("url"); 15 | method = config.GetMember("method"); 16 | headers = config.GetMember("headers"); 17 | 18 | port = config.GetMember("port", Convert.ToInt32, 80); 19 | } 20 | 21 | public string host 22 | { 23 | get { return hostname; } 24 | set { hostname = value; } 25 | } 26 | 27 | public string hostname { get; set; } 28 | 29 | public int? port { get; set; } 30 | 31 | public string method { get; set; } 32 | 33 | public string path { get; set; } 34 | 35 | public DynamicObject headers { get; set; } 36 | 37 | 38 | 39 | public DynamicObject auth { get; set; } 40 | public DynamicObject agent { get; set; } 41 | 42 | public string scheme { get; set; } 43 | 44 | public dynamic uri 45 | { 46 | get { return url; } 47 | set { url = value; } 48 | } 49 | 50 | public dynamic url 51 | { 52 | get 53 | { 54 | if (hostname != null) 55 | { 56 | try 57 | { 58 | return new UriBuilder(scheme, hostname, port.HasValue ? port.Value : 80, path).Uri; 59 | } 60 | catch 61 | { 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | set 68 | { 69 | if (value != null) 70 | { 71 | var uriString = value as string; 72 | if (uriString != null) 73 | { 74 | value = new Uri(uriString); 75 | 76 | } 77 | var valAsUri = value as Uri; 78 | if (valAsUri != null) 79 | { 80 | hostname = valAsUri.Host; 81 | port = valAsUri.Port; 82 | scheme = valAsUri.Scheme; 83 | path = valAsUri.PathAndQuery; 84 | return; 85 | } 86 | 87 | hostname = value.hostname; 88 | port = value.port; 89 | scheme = value.protocol; 90 | path = value.pathname + value.search; 91 | 92 | } 93 | } 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/Node/NodeHttpResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Threading.Tasks; 6 | using Microsoft.ClearScript; 7 | 8 | namespace ClearScript.Manager.Http.Helpers.Node 9 | { 10 | public class NodeHttpResponse : NodeBuffer 11 | { 12 | private NodeHttpRequest _nodeHttpRequest; 13 | private readonly Task _resp; 14 | private bool _dataFired; 15 | private readonly Dictionary> _listeners = new Dictionary>(); 16 | 17 | public NodeHttpResponse(NodeHttpRequest nodeHttpRequest, Task resp) 18 | : base(null) 19 | { 20 | // TODO: Complete member initialization 21 | _nodeHttpRequest = nodeHttpRequest; 22 | _resp = resp; 23 | 24 | if (!resp.IsFaulted) 25 | { 26 | statusCode = (int)resp.Result.StatusCode; 27 | 28 | headers = new PropertyBag(); 29 | 30 | foreach (var kvp in resp.Result.Headers) 31 | { 32 | headers[kvp.Key] = kvp.Value.FirstOrDefault(); 33 | } 34 | 35 | if (resp.Result.Content != null) 36 | { 37 | foreach (var kvp in resp.Result.Content.Headers) 38 | { 39 | headers[kvp.Key] = kvp.Value.FirstOrDefault(); 40 | } 41 | } 42 | } 43 | } 44 | 45 | public void InitEvents() 46 | { 47 | _resp.Result.Content.ReadAsStreamAsync().ContinueWith(x => 48 | { 49 | InnerStream = x.Result; 50 | OnData(); 51 | }); 52 | } 53 | public object body { get; set; } 54 | 55 | internal HttpResponseMessage GetHttpResponseMessage() 56 | { 57 | return _resp.Result; 58 | } 59 | 60 | public void on(string eventName, dynamic callbackFn) 61 | { 62 | 63 | List events; 64 | if (!_listeners.TryGetValue(eventName, out events)) 65 | { 66 | events = _listeners[eventName] = new List(); 67 | } 68 | 69 | events.Add(callbackFn); 70 | 71 | //close 72 | //readable 73 | //data 74 | //end 75 | //error 76 | } 77 | 78 | 79 | //todo .. rework as chunked 80 | private void OnData() 81 | { 82 | List listeners; 83 | if (_listeners.TryGetValue("data", out listeners)) 84 | { 85 | listeners.ForEach(listener => listener.call(null, this)); 86 | } 87 | if (_listeners.TryGetValue("end", out listeners)) 88 | { 89 | listeners.ForEach(listener => listener.call(null)); 90 | } 91 | } 92 | 93 | public string httpVersion { get; set; } 94 | 95 | public dynamic headers { get; set; } 96 | 97 | public int statusCode { get; set; } 98 | 99 | public byte[] read(int? size = null) 100 | { 101 | throw new NotImplementedException(); 102 | } 103 | 104 | public void pipe(dynamic destinationStream, dynamic options = null) 105 | { 106 | throw new NotImplementedException(); 107 | } 108 | 109 | public void unpipe(dynamic destinationStream = null) 110 | { 111 | throw new NotImplementedException(); 112 | } 113 | 114 | public void unshift(dynamic chunk = null) 115 | { 116 | throw new NotImplementedException(); 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/Node/NodeRequestModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Dynamic; 3 | using System.Net.Http; 4 | 5 | namespace ClearScript.Manager.Http.Helpers.Node 6 | { 7 | public class NodeRequestModule 8 | { 9 | public static void MakeRequest(string url, dynamic callback) 10 | { 11 | } 12 | 13 | internal static void MakeRequest(DynamicObject config, DynamicObject callback, Microsoft.ClearScript.V8.V8ScriptEngine engine) 14 | { 15 | var options = new NodeHttpRequestOptions(config); 16 | var uriObj = new Uri((config.GetMember("uri") ?? config.GetMember("url")).ToString()); 17 | options.url = (config.GetMember("uri") ?? config.GetMember("url")); 18 | options.host = uriObj.Host; 19 | options.hostname = uriObj.Host; 20 | options.scheme = uriObj.Scheme; 21 | options.path = uriObj.PathAndQuery; 22 | options.port = uriObj.Port; 23 | options.method = config.GetMember("method", "GET"); 24 | options.headers = config.GetMember("headers"); 25 | bool isJson = config.GetMember("json", false); 26 | 27 | var req = new NodeHttpRequest(new HttpClient(), new HttpRequestMessage(), options); 28 | Action wrapperCallback = resp => 29 | { 30 | if (callback == null) 31 | { 32 | return; 33 | } 34 | // string body = null; 35 | object body = null; 36 | var apiResp = resp.GetHttpResponseMessage(); 37 | if (apiResp.Content != null && apiResp.Content.Headers.ContentLength > 0) 38 | { 39 | if (isJson) 40 | { 41 | string xxx = apiResp.Content.ReadAsStringAsync().Result; 42 | var parser = (dynamic)engine.Evaluate("JSON.parse"); 43 | body = parser(xxx); 44 | } 45 | else 46 | { 47 | body = apiResp.Content.ReadAsStringAsync().Result; 48 | } 49 | } 50 | 51 | callback.AsDynamic().call(null, null, resp, body); 52 | }; 53 | req.@on("response", wrapperCallback); 54 | 55 | req.end(); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Helpers/ScriptAwaiter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace ClearScript.Manager.Http.Helpers 5 | { 6 | public class ScriptAwaiter 7 | { 8 | public Task T { get; set; } 9 | public Action Callback { get; set; } 10 | 11 | public ScriptAwaiter() 12 | { 13 | T = new Task(new Action(() => { })); 14 | Callback = CallbackImp; 15 | } 16 | 17 | void CallbackImp() 18 | { 19 | T.Start(); 20 | } 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Loaders/HttpScriptLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using ClearScript.Manager.Loaders; 4 | 5 | namespace ClearScript.Manager.Http.Loaders 6 | { 7 | /// 8 | /// Loads scripts if they are file-system based scripts. 9 | /// 10 | public class HttpScriptLoader : IScriptLoader 11 | { 12 | public string Name { get { return "FileScriptLoader"; } } 13 | 14 | public static void Register() 15 | { 16 | new HttpScriptLoader().RegisterLoader(); 17 | } 18 | 19 | public bool ShouldUse(IncludeScript script) 20 | { 21 | if (!string.IsNullOrEmpty(script.Code)) 22 | return false; 23 | 24 | if (Uri.IsWellFormedUriString(script.Uri, UriKind.RelativeOrAbsolute)) 25 | { 26 | var uri = new Uri(script.Uri); 27 | if (!uri.IsFile) 28 | return true; 29 | } 30 | 31 | return false; 32 | } 33 | 34 | public void LoadCode(IncludeScript script) 35 | { 36 | using (var httpClient = new HttpClient()) 37 | { 38 | script.Code = httpClient.GetStringAsync(script.Uri).Result; 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Packages/HttpPackage.cs: -------------------------------------------------------------------------------- 1 | using ClearScript.Manager.Http.Helpers.Node; 2 | using ClearScript.Manager.Loaders; 3 | 4 | namespace ClearScript.Manager.Http.Packages 5 | { 6 | public class HttpPackage : RequiredPackage 7 | { 8 | public HttpPackage() 9 | { 10 | PackageId = "http"; 11 | HostObjects.Add(new HostObject { Name = "http", Target = new NodeHttp() }); 12 | HostTypes.Add(new HostType{ Name="Buffer", Type = typeof(NodeBuffer)}); 13 | } 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Packages/PackageHelpers.cs: -------------------------------------------------------------------------------- 1 | using ClearScript.Manager.Loaders; 2 | 3 | namespace ClearScript.Manager.Http.Packages 4 | { 5 | /// 6 | /// Helpers for registering packages. 7 | /// 8 | public static class PackageHelpers 9 | { 10 | /// 11 | /// Registers packages needed for using the request include. 12 | /// 13 | public static void RegisterRequestPackages() 14 | { 15 | RequireManager.RegisterPackage(new HttpPackage()); 16 | RequireManager.RegisterPackage(new RequestPackage()); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Packages/RequestPackage.cs: -------------------------------------------------------------------------------- 1 | using ClearScript.Manager.Loaders; 2 | 3 | namespace ClearScript.Manager.Http.Packages 4 | { 5 | public class RequestPackage : RequiredPackage 6 | { 7 | public RequestPackage() 8 | { 9 | PackageId = "request"; 10 | ScriptUri = @".\Scripts\request.js"; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ClearScript.Manager.Http")] 9 | [assembly: AssemblyDescription("Http extension and helpers for ClearScript Manager")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ClearScript.Manager.Http")] 13 | [assembly: AssemblyCopyright("Copyright © 2014 Eric Swann et. al. - All rights reserved.")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7e4bb2b7-3368-4b82-8ada-45993b337d56")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.3.4.*")] 36 | [assembly: AssemblyFileVersion("1.3.4.*")] 37 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/Scripts/request.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | function requestFactory(options, callback) { 4 | 5 | var cfg = options; 6 | if (typeof options === 'string') { 7 | cfg = { uri: options }; 8 | } 9 | 10 | cfg.callback = callback || options.callback; 11 | 12 | return new requestFactory.Request(cfg); 13 | } 14 | 15 | 16 | function Request(options) { 17 | this.options = options; 18 | this.go(); 19 | 20 | } 21 | 22 | Request.prototype.go = function () { 23 | var me = this; 24 | var strings = []; 25 | var buffer; 26 | 27 | me.req = http.request(me.options, function (res) { 28 | if (me.options.callback) { 29 | res.on('data', function (chunk) { 30 | var me = this; 31 | if (Buffer.isBuffer(chunk)) { 32 | if (!buffer) { 33 | buffer = new Buffer(1024); 34 | } 35 | //hack till i get the right bla 36 | chunk.copy(buffer); 37 | } else { 38 | strings.push(chunk); 39 | } 40 | }); 41 | res.on('end', function () { 42 | me.onEnd(strings, buffer, res, me.options.callback); 43 | }); 44 | } 45 | }); 46 | 47 | me.req.end(); 48 | //todo sedn data on req. 49 | 50 | }; 51 | 52 | 53 | Request.prototype.onEnd = function (strings, buffer, response, callback) { 54 | var self = this; 55 | if (self._aborted) { 56 | return; 57 | } 58 | 59 | if (buffer.length) { 60 | if (self.encoding === null) { 61 | // response.body = buffer 62 | // can't move to this until https://github.com/rvagg/bl/issues/13 63 | response.body = buffer.slice(); 64 | } else { 65 | response.body = buffer.asString(self.encoding); 66 | } 67 | } else if (strings.length) { 68 | // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. 69 | // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse(). 70 | if (self.encoding === 'utf8' && strings[0].length > 0 && strings[0][0] === '\uFEFF') { 71 | strings[0] = strings[0].substring(1); 72 | } 73 | response.body = strings.join(''); 74 | } 75 | 76 | if (self.options.json) { 77 | try { 78 | response.body = JSON.parse(response.body); 79 | } catch (e) { } 80 | } 81 | 82 | if (typeof response.body === 'undefined' && !self._json) { 83 | response.body = ''; 84 | } 85 | callback.call(null, null, response, response.body); 86 | }; 87 | 88 | if (typeof module != 'undefined' && module != null) { 89 | module.exports = request; 90 | } 91 | 92 | requestFactory.Request = Request; 93 | 94 | request.exports = requestFactory; 95 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Http/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/ClearScriptV8-32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/ClearScriptV8-32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/ClearScriptV8-32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/ClearScriptV8-32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/ClearScriptV8-64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/ClearScriptV8-64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/ClearScriptV8-64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/ClearScriptV8-64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/v8-ia32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/v8-ia32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/v8-ia32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/v8-ia32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/v8-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/v8-x64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Lib/v8-x64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.Test/Lib/v8-x64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Stratoflow.ClearScript.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Stratoflow.ClearScript.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a0931039-f18d-4a94-a24a-3d533e6ab9e9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/ScriptSubject.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.Test 2 | { 3 | public class ScriptSubject 4 | { 5 | private bool _isSuccess = true; 6 | 7 | // ReSharper disable once InconsistentNaming 8 | public object data { get; set; } 9 | 10 | // ReSharper disable once InconsistentNaming 11 | public bool isSuccess 12 | { 13 | get { return _isSuccess; } 14 | set { _isSuccess = value; } 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/TestDiffNameRequire.js: -------------------------------------------------------------------------------- 1 |  2 | function TestType() {} 3 | 4 | TestType.prototype.getText = function() { return "testText"; }; 5 | 6 | testRequire.exports = new TestType(); -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/TestIncludeScript.js: -------------------------------------------------------------------------------- 1 | var x = 'test string1'; -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/TestMainScript.js: -------------------------------------------------------------------------------- 1 | subject.Count = 10; subject.TestString = 'test string1'; -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/TestParentRequire.js: -------------------------------------------------------------------------------- 1 |  2 | var testObject = require('testRequire'); 3 | 4 | function TestParentType() { 5 | 6 | } 7 | 8 | TestParentType.prototype.getText = testObject.getText; 9 | TestParentType.prototype.getNumber = function () { return 500; } 10 | 11 | testParentRequire.exports = new TestParentType(); -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/TestRequire.js: -------------------------------------------------------------------------------- 1 |  2 | function TestType() {} 3 | 4 | TestType.prototype.getText = function() { return "testText"; }; 5 | 6 | testRequire.exports = new TestType(); -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/TestRequire2.js: -------------------------------------------------------------------------------- 1 |  2 | function TestType2() {} 3 | 4 | TestType2.prototype.getNumber = function() { return 300; }; 5 | 6 | testRequire2.exports = new TestType2(); -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/V8ScriptingTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.ClearScript.V8; 3 | using NUnit.Framework; 4 | 5 | namespace ClearScript.Manager.Test 6 | { 7 | [TestFixture] 8 | public class V8ScriptingTests 9 | { 10 | [Test] 11 | public void Can_Perform_JS_Length_On_A_Passed_String() 12 | { 13 | using (var engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers)) 14 | { 15 | engine.Script.MyString = "Just a test string"; 16 | engine.AddHostType("Console", typeof(Console)); 17 | 18 | engine.Execute("Console.WriteLine ('Length of MyString = {0}', MyString.length)"); 19 | } 20 | } 21 | 22 | [Test] 23 | public void Can_Perform_JS_ToLower_On_A_Passed_String() 24 | { 25 | using (var engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers)) 26 | { 27 | engine.Script.MyString = "Just a test string"; 28 | engine.AddHostType("Console", typeof(Console)); 29 | 30 | engine.Execute("Console.WriteLine ('Length of MyString = {0}', MyString.toLowerCase())"); 31 | } 32 | } 33 | 34 | [Test] 35 | public void Can_Perform_JS_ToLower_On_An_Object_Property() 36 | { 37 | using (var engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers)) 38 | { 39 | var myObject = new {MyString = "Just a test string"}; 40 | 41 | engine.Script.MyString = "Just a test string"; 42 | engine.AddHostType("Console", typeof(Console)); 43 | engine.AddHostObject("myObject", myObject); 44 | 45 | engine.Execute("Console.WriteLine ('Length of MyString = {0}', myObject.MyString.toLowerCase())"); 46 | } 47 | } 48 | 49 | } 50 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenCachingScripts.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using ClearScript.Manager.Caching; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace ClearScript.Manager.Test 7 | { 8 | [TestFixture] 9 | public class WhenCachingScripts 10 | { 11 | [Test] 12 | public async void Compiled_Script_Is_Cached_By_Default() 13 | { 14 | var manager = new RuntimeManager(new ManualManagerSettings()); 15 | 16 | await manager.ExecuteAsync("test", "var i = 0; i++;"); 17 | 18 | CachedV8Script cached; 19 | manager.TryGetCached("test", out cached).ShouldBeTrue(); 20 | } 21 | 22 | [Test] 23 | public async void Cached_Script_Shows_Cache_Hits() 24 | { 25 | var manager = new RuntimeManager(new ManualManagerSettings()); 26 | 27 | await manager.ExecuteAsync("test", "var i = 0; i++;"); 28 | 29 | await manager.ExecuteAsync("test", "var i = 0; i++;"); 30 | 31 | CachedV8Script cached; 32 | manager.TryGetCached("test", out cached); 33 | 34 | cached.CacheHits.ShouldBeGreaterThan(1); 35 | } 36 | 37 | [Test] 38 | public void Zero_Expiration_Script_Is_Not_Cached() 39 | { 40 | var manager = new RuntimeManager(new ManualManagerSettings()); 41 | 42 | manager.Compile("test", "var i = 0; i++;", true, 0); 43 | 44 | CachedV8Script cached; 45 | manager.TryGetCached("test", out cached).ShouldBeFalse(); 46 | } 47 | 48 | [Test] 49 | public void Uncached_Script_Is_Not_Cached() 50 | { 51 | var manager = new RuntimeManager(new ManualManagerSettings()); 52 | 53 | manager.Compile("test", "var i = 0; i++;", false); 54 | 55 | CachedV8Script cached; 56 | manager.TryGetCached("test", out cached).ShouldBeFalse(); 57 | } 58 | 59 | [Test] 60 | public void Expired_Script_Is_Not_Returned() 61 | { 62 | var manager = new RuntimeManager(new ManualManagerSettings()); 63 | 64 | manager.Compile("test", "var i = 0; i++;", true, 1); 65 | 66 | Thread.Sleep(1000); 67 | 68 | CachedV8Script cached; 69 | manager.TryGetCached("test", out cached).ShouldBeFalse(); 70 | } 71 | 72 | 73 | } 74 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenExecutingBasicJavaScript.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ClearScript; 2 | using NUnit.Framework; 3 | 4 | namespace ClearScript.Manager.Test 5 | { 6 | [TestFixture] 7 | public class WhenExecutingBasicJavaScript 8 | { 9 | [SetUp] 10 | public void TestSetUp() 11 | { 12 | ManagerPool.InitializeCurrentPool(new ManualManagerSettings()); 13 | } 14 | 15 | [Test] 16 | public async void Script_With_No_Subject_Can_Be_Executed() 17 | { 18 | var manager = new RuntimeManager(new ManualManagerSettings()); 19 | 20 | await manager.ExecuteAsync("test", "var i = 0; i++;"); 21 | } 22 | 23 | [Test] 24 | public async void Script_Can_Write_To_Console() 25 | { 26 | var manager = new RuntimeManager(new ManualManagerSettings()) {AddConsoleReference = true}; 27 | 28 | await manager.ExecuteAsync("test", "Console.WriteLine('wrote this to the console');"); 29 | } 30 | 31 | [Test] 32 | public void Javascript_Error_Is_Raised() 33 | { 34 | var manager = new RuntimeManager(new ManualManagerSettings()); 35 | 36 | Assert.Throws(async () => 37 | await manager.ExecuteAsync("test", "Console.WriteLine('wrote this to the console');")); 38 | } 39 | 40 | [Test] 41 | public async void Script_Returns_Engine() 42 | { 43 | var manager = new RuntimeManager(new ManualManagerSettings()); 44 | 45 | var engine = await manager.ExecuteAsync("test", "var i = 0; i++;"); 46 | 47 | Assert.AreEqual(1, engine.Script.i); 48 | } 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenExecutingScriptWithIncludeScripts.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using Should; 4 | 5 | namespace ClearScript.Manager.Test 6 | { 7 | [TestFixture] 8 | public class WhenExecutingScriptWithIncludeScripts 9 | { 10 | [Test] 11 | public async void Script_With_String_Code_Include_Is_Included() 12 | { 13 | var preScript = "var x = 'test string1';"; 14 | 15 | var subject = new TestObject(); 16 | var manager = new RuntimeManager(new ManualManagerSettings()); 17 | 18 | await manager.ExecuteAsync("testscript", "subject.Count = 10; subject.TestString = x;", 19 | new ExecutionOptions 20 | { 21 | HostObjects = new List {new HostObject {Name = "subject", Target = subject}}, 22 | Scripts = new List {new IncludeScript {Code = preScript, ScriptId = "testScript2"}} 23 | }); 24 | 25 | subject.Name.ShouldEqual("Name"); 26 | subject.Count.ShouldEqual(10); 27 | subject.TestString.ShouldEqual("test string1"); 28 | } 29 | 30 | [Test] 31 | public async void Script_With_File_Include_Is_Included() 32 | { 33 | var subject = new TestObject(); 34 | var manager = new RuntimeManager(new ManualManagerSettings()); 35 | 36 | await manager.ExecuteAsync("testscript", "subject.Count = 10; subject.TestString = x;", 37 | new ExecutionOptions 38 | { 39 | HostObjects = new List {new HostObject {Name = "subject", Target = subject}}, 40 | Scripts = new List {new IncludeScript {Uri = ".\\TestIncludeScript.js", ScriptId = "testScript2"}} 41 | }); 42 | 43 | subject.Name.ShouldEqual("Name"); 44 | subject.Count.ShouldEqual(10); 45 | subject.TestString.ShouldEqual("test string1"); 46 | } 47 | 48 | [Test] 49 | public async void Included_Variables_Are_Accessible_Via_Script_Object() 50 | { 51 | var subject = new TestObject(); 52 | var manager = new RuntimeManager(new ManualManagerSettings()); 53 | 54 | var engine = await manager.ExecuteAsync("testscript", "subject.Count = 10; subject.TestString = x;", 55 | new ExecutionOptions 56 | { 57 | HostObjects = new List { new HostObject { Name = "subject", Target = subject } }, 58 | Scripts = new List { new IncludeScript { Uri = ".\\TestIncludeScript.js", ScriptId = "testScript2" } } 59 | }); 60 | 61 | subject.Name.ShouldEqual("Name"); 62 | subject.Count.ShouldEqual(10); 63 | subject.TestString.ShouldEqual("test string1"); 64 | engine.Script.x = "test string1"; 65 | } 66 | 67 | public class TestObject 68 | { 69 | private string _name = "Name"; 70 | 71 | public string Name 72 | { 73 | get { return _name; } 74 | set { _name = value; } 75 | } 76 | 77 | public string TestString { get; set; } 78 | 79 | public int Count { get; set; } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenExecutingScriptWithTimeout.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ClearScript; 2 | using NUnit.Framework; 3 | 4 | namespace ClearScript.Manager.Test 5 | { 6 | [TestFixture] 7 | public class WhenExecutingScriptWithTimeout 8 | { 9 | [Test] 10 | public void Script_Exceeding_Timeout_Errs() 11 | { 12 | var manager = new RuntimeManager(new ManualManagerSettings{ScriptTimeoutMilliSeconds = 500}) 13 | { 14 | AddConsoleReference = true 15 | }; 16 | 17 | var script = "Console.WriteLine('Started:' + new Date().toJSON()); " + 18 | "var now = new Date().getTime(); while(new Date().getTime() < now + 1000){{ /* do nothing */ }}; " + 19 | "Console.WriteLine('Finished:' + new Date().toJSON());"; 20 | 21 | 22 | Assert.Throws(async () => await manager.ExecuteAsync("test", script)); 23 | 24 | } 25 | 26 | 27 | [Test] 28 | public async void Script_Not_Exceeding_Timeout_Works() 29 | { 30 | var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 500 }) 31 | { 32 | AddConsoleReference = true 33 | }; 34 | 35 | var script = "Console.WriteLine('Started:' + new Date().toJSON()); " + 36 | "var now = new Date().getTime(); " + 37 | "Console.WriteLine('Finished:' + new Date().toJSON());"; 38 | 39 | 40 | await manager.ExecuteAsync("test", script); 41 | 42 | } 43 | 44 | [Test] 45 | public async void Script_With_0_Timeout_Works() 46 | { 47 | var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 0 }) 48 | { 49 | AddConsoleReference = true 50 | }; 51 | 52 | var script = "Console.WriteLine('Started:' + new Date().toJSON()); " + 53 | "var now = new Date().getTime(); " + 54 | "Console.WriteLine('Finished:' + new Date().toJSON());"; 55 | 56 | 57 | await manager.ExecuteAsync("test", script); 58 | 59 | } 60 | 61 | } 62 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenExecutingWithHostObjects.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Dynamic; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace ClearScript.Manager.Test 7 | { 8 | [TestFixture] 9 | public class WhenExecutingWithHostObjects 10 | { 11 | 12 | [Test] 13 | public async void Script_With_Typed_Subject_Can_Be_Executed() 14 | { 15 | var subject = new TestObject(); 16 | var manager = new RuntimeManager(new ManualManagerSettings()); 17 | 18 | await manager.ExecuteAsync("testscript", "subject.Count = 10;", 19 | new List {new HostObject {Name = "subject", Target = subject}}); 20 | 21 | subject.Name.ShouldEqual("Name"); 22 | subject.Count.ShouldEqual(10); 23 | } 24 | 25 | [Test] 26 | public async void Script_With_Dynamic_Subject_Can_Be_Executed() 27 | { 28 | dynamic subject = new ExpandoObject(); 29 | subject.Name = "Name"; 30 | subject.Count = 0; 31 | 32 | var manager = new RuntimeManager(new ManualManagerSettings()); 33 | 34 | await manager.ExecuteAsync("test", "subject.Count = 10;", 35 | new List { new HostObject { Name = "subject", Target = subject } }); 36 | 37 | //Should craps out on dynamics 38 | Assert.AreEqual(subject.Name, "Name"); 39 | Assert.AreEqual(subject.Count, 10); 40 | } 41 | 42 | 43 | public class TestObject 44 | { 45 | private string _name = "Name"; 46 | 47 | public string Name 48 | { 49 | get { return _name; } 50 | set { _name = value; } 51 | } 52 | 53 | public int Count { get; set; } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenExecutingWithHostTypes.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using Should; 4 | 5 | namespace ClearScript.Manager.Test 6 | { 7 | [TestFixture] 8 | public class WhenExecutingWithHostTypes 9 | { 10 | [Test] 11 | public async void Script_Referencing_Specific_Type_Executes() 12 | { 13 | 14 | var manager = new RuntimeManager(new ManualManagerSettings()); 15 | 16 | var hostType = new HostType 17 | { 18 | Name = "MathStuff", 19 | Type = typeof(System.Math) 20 | }; 21 | 22 | var subject = new TestObject(); 23 | 24 | await manager.ExecuteAsync("test", "subject.Result = MathStuff.Pow(10,2);", 25 | new List { new HostObject { Name = "subject", Target = subject } }, 26 | new List { hostType }); 27 | 28 | subject.Result.ShouldEqual(100); 29 | 30 | } 31 | 32 | public class TestObject 33 | { 34 | private string _name = "Name"; 35 | 36 | public string Name 37 | { 38 | get { return _name; } 39 | set { _name = value; } 40 | } 41 | 42 | public decimal Result { get; set; } 43 | } 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenUsingAManagerPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using NUnit.Framework; 4 | using Should; 5 | 6 | namespace ClearScript.Manager.Test 7 | { 8 | [TestFixture] 9 | public class WhenUsingAManagerPool 10 | { 11 | [Test] 12 | public async void Script_Exceeding_Pool_Count_Blocks_Until_Item_Available() 13 | { 14 | 15 | //Set the manager max count 16 | ManagerPool.InitializeCurrentPool(new ManualManagerSettings{ RuntimeMaxCount = 2 }); 17 | 18 | const string script = "Console.WriteLine('Started {0}:' + new Date().toJSON()); " + 19 | "var now = new Date().getTime(); while(new Date().getTime() < now + 1000){{ /* do nothing */ }}; " + 20 | "Console.WriteLine('finished {0}:' + new Date().toJSON());"; 21 | 22 | var startDate = DateTime.UtcNow; 23 | 24 | await Task.WhenAll( 25 | RunInScope("first", script), 26 | RunInScope("second", script), 27 | RunInScope("third", script)); 28 | 29 | DateTime.UtcNow.Subtract(startDate).ShouldBeGreaterThan(new TimeSpan(0, 0, 2)); 30 | } 31 | 32 | private static Task RunInScope(string name, string script) 33 | { 34 | return Task.Run(async () => 35 | { 36 | using (var scope = new ManagerScope()) 37 | { 38 | scope.RuntimeManager.AddConsoleReference = true; 39 | await scope.RuntimeManager.ExecuteAsync(name, script); 40 | } 41 | }); 42 | } 43 | 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/WhenUsingGetEngine.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Should; 3 | 4 | namespace ClearScript.Manager.Test 5 | { 6 | [TestFixture] 7 | public class WhenUsingEngine 8 | { 9 | [Test] 10 | public void Script_Engine_Is_Retrieved() 11 | { 12 | ManagerPool.InitializeCurrentPool(new ManualManagerSettings { RuntimeMaxCount = 2 }); 13 | 14 | using (var scope = new ManagerScope()) 15 | { 16 | var engine = scope.RuntimeManager.GetEngine(); 17 | 18 | engine.ShouldNotBeNull(); 19 | 20 | engine.Execute("var i = 200;"); 21 | 22 | Assert.AreEqual(200, engine.Script.i); 23 | } 24 | 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace ClearScript.Manager.WebDemo 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 15 | // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 16 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 17 | "~/Scripts/modernizr-*")); 18 | 19 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 20 | "~/Scripts/bootstrap.js", 21 | "~/Scripts/respond.js")); 22 | 23 | bundles.Add(new StyleBundle("~/Content/css").Include( 24 | "~/Content/bootstrap.css", 25 | "~/Content/site.css")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace ClearScript.Manager.WebDemo 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace ClearScript.Manager.WebDemo 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace ClearScript.Manager.WebDemo 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API configuration and services 13 | 14 | // Web API routes 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ApiDescriptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Web; 4 | using System.Web.Http.Description; 5 | 6 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage 7 | { 8 | public static class ApiDescriptionExtensions 9 | { 10 | /// 11 | /// Generates an URI-friendly ID for the . E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}" 12 | /// 13 | /// The . 14 | /// The ID as a string. 15 | public static string GetFriendlyId(this ApiDescription description) 16 | { 17 | string path = description.RelativePath; 18 | string[] urlParts = path.Split('?'); 19 | string localPath = urlParts[0]; 20 | string queryKeyString = null; 21 | if (urlParts.Length > 1) 22 | { 23 | string query = urlParts[1]; 24 | string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys; 25 | queryKeyString = String.Join("_", queryKeys); 26 | } 27 | 28 | StringBuilder friendlyPath = new StringBuilder(); 29 | friendlyPath.AppendFormat("{0}-{1}", 30 | description.HttpMethod.Method, 31 | localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty)); 32 | if (queryKeyString != null) 33 | { 34 | friendlyPath.AppendFormat("_{0}", queryKeyString.Replace('.', '-')); 35 | } 36 | return friendlyPath.ToString(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Controllers/HelpController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Http; 3 | using System.Web.Mvc; 4 | using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions; 5 | using ClearScript.Manager.WebDemo.Areas.HelpPage.Models; 6 | 7 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.Controllers 8 | { 9 | /// 10 | /// The controller that will handle requests for the help page. 11 | /// 12 | public class HelpController : Controller 13 | { 14 | private const string ErrorViewName = "Error"; 15 | 16 | public HelpController() 17 | : this(GlobalConfiguration.Configuration) 18 | { 19 | } 20 | 21 | public HelpController(HttpConfiguration config) 22 | { 23 | Configuration = config; 24 | } 25 | 26 | public HttpConfiguration Configuration { get; private set; } 27 | 28 | public ActionResult Index() 29 | { 30 | ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider(); 31 | return View(Configuration.Services.GetApiExplorer().ApiDescriptions); 32 | } 33 | 34 | public ActionResult Api(string apiId) 35 | { 36 | if (!String.IsNullOrEmpty(apiId)) 37 | { 38 | HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId); 39 | if (apiModel != null) 40 | { 41 | return View(apiModel); 42 | } 43 | } 44 | 45 | return View(ErrorViewName); 46 | } 47 | 48 | public ActionResult ResourceModel(string modelName) 49 | { 50 | if (!String.IsNullOrEmpty(modelName)) 51 | { 52 | ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator(); 53 | ModelDescription modelDescription; 54 | if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription)) 55 | { 56 | return View(modelDescription); 57 | } 58 | } 59 | 60 | return View(ErrorViewName); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/HelpPage.css: -------------------------------------------------------------------------------- 1 | .help-page h1, 2 | .help-page .h1, 3 | .help-page h2, 4 | .help-page .h2, 5 | .help-page h3, 6 | .help-page .h3, 7 | #body.help-page, 8 | .help-page-table th, 9 | .help-page-table pre, 10 | .help-page-table p { 11 | font-family: "Segoe UI Light", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; 12 | } 13 | 14 | .help-page pre.wrapped { 15 | white-space: -moz-pre-wrap; 16 | white-space: -pre-wrap; 17 | white-space: -o-pre-wrap; 18 | white-space: pre-wrap; 19 | } 20 | 21 | .help-page .warning-message-container { 22 | margin-top: 20px; 23 | padding: 0 10px; 24 | color: #525252; 25 | background: #EFDCA9; 26 | border: 1px solid #CCCCCC; 27 | } 28 | 29 | .help-page-table { 30 | width: 100%; 31 | border-collapse: collapse; 32 | text-align: left; 33 | margin: 0px 0px 20px 0px; 34 | border-top: 1px solid #D4D4D4; 35 | } 36 | 37 | .help-page-table th { 38 | text-align: left; 39 | font-weight: bold; 40 | border-bottom: 1px solid #D4D4D4; 41 | padding: 5px 6px 5px 6px; 42 | } 43 | 44 | .help-page-table td { 45 | border-bottom: 1px solid #D4D4D4; 46 | padding: 10px 8px 10px 8px; 47 | vertical-align: top; 48 | } 49 | 50 | .help-page-table pre, 51 | .help-page-table p { 52 | margin: 0px; 53 | padding: 0px; 54 | font-family: inherit; 55 | font-size: 100%; 56 | } 57 | 58 | .help-page-table tbody tr:hover td { 59 | background-color: #F3F3F3; 60 | } 61 | 62 | .help-page a:hover { 63 | background-color: transparent; 64 | } 65 | 66 | .help-page .sample-header { 67 | border: 2px solid #D4D4D4; 68 | background: #00497E; 69 | color: #FFFFFF; 70 | padding: 8px 15px; 71 | border-bottom: none; 72 | display: inline-block; 73 | margin: 10px 0px 0px 0px; 74 | } 75 | 76 | .help-page .sample-content { 77 | display: block; 78 | border-width: 0; 79 | padding: 15px 20px; 80 | background: #FFFFFF; 81 | border: 2px solid #D4D4D4; 82 | margin: 0px 0px 10px 0px; 83 | } 84 | 85 | .help-page .api-name { 86 | width: 40%; 87 | } 88 | 89 | .help-page .api-documentation { 90 | width: 60%; 91 | } 92 | 93 | .help-page .parameter-name { 94 | width: 20%; 95 | } 96 | 97 | .help-page .parameter-documentation { 98 | width: 40%; 99 | } 100 | 101 | .help-page .parameter-type { 102 | width: 20%; 103 | } 104 | 105 | .help-page .parameter-annotations { 106 | width: 20%; 107 | } 108 | 109 | .help-page h1, 110 | .help-page .h1 { 111 | font-size: 36px; 112 | line-height: normal; 113 | } 114 | 115 | .help-page h2, 116 | .help-page .h2 { 117 | font-size: 24px; 118 | } 119 | 120 | .help-page h3, 121 | .help-page .h3 { 122 | font-size: 20px; 123 | } 124 | 125 | #body.help-page { 126 | font-size: 14px; 127 | line-height: 143%; 128 | color: #333; 129 | } 130 | 131 | .help-page a { 132 | color: #0000EE; 133 | text-decoration: none; 134 | } 135 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/HelpPageAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using System.Web.Mvc; 3 | 4 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage 5 | { 6 | public class HelpPageAreaRegistration : AreaRegistration 7 | { 8 | public override string AreaName 9 | { 10 | get 11 | { 12 | return "HelpPage"; 13 | } 14 | } 15 | 16 | public override void RegisterArea(AreaRegistrationContext context) 17 | { 18 | context.MapRoute( 19 | "HelpPage_Default", 20 | "Help/{action}/{apiId}", 21 | new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); 22 | 23 | HelpPageConfig.Register(GlobalConfiguration.Configuration); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/CollectionModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class CollectionModelDescription : ModelDescription 4 | { 5 | public ModelDescription ElementDescription { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/ComplexTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ComplexTypeModelDescription : ModelDescription 6 | { 7 | public ComplexTypeModelDescription() 8 | { 9 | Properties = new Collection(); 10 | } 11 | 12 | public Collection Properties { get; private set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/DictionaryModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class DictionaryModelDescription : KeyValuePairModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/EnumTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class EnumTypeModelDescription : ModelDescription 7 | { 8 | public EnumTypeModelDescription() 9 | { 10 | Values = new Collection(); 11 | } 12 | 13 | public Collection Values { get; private set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/EnumValueDescription.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class EnumValueDescription 4 | { 5 | public string Documentation { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Value { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/IModelDocumentationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 5 | { 6 | public interface IModelDocumentationProvider 7 | { 8 | string GetDocumentation(MemberInfo member); 9 | 10 | string GetDocumentation(Type type); 11 | } 12 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/KeyValuePairModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class KeyValuePairModelDescription : ModelDescription 4 | { 5 | public ModelDescription KeyModelDescription { get; set; } 6 | 7 | public ModelDescription ValueModelDescription { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/ModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Describes a type model. 7 | /// 8 | public abstract class ModelDescription 9 | { 10 | public string Documentation { get; set; } 11 | 12 | public Type ModelType { get; set; } 13 | 14 | public string Name { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/ModelNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Use this attribute to change the name of the generated for a type. 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = false, Inherited = false)] 9 | public sealed class ModelNameAttribute : Attribute 10 | { 11 | public ModelNameAttribute(string name) 12 | { 13 | Name = name; 14 | } 15 | 16 | public string Name { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/ModelNameHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 7 | { 8 | internal static class ModelNameHelper 9 | { 10 | // Modify this to provide custom model name mapping. 11 | public static string GetModelName(Type type) 12 | { 13 | ModelNameAttribute modelNameAttribute = type.GetCustomAttribute(); 14 | if (modelNameAttribute != null && !String.IsNullOrEmpty(modelNameAttribute.Name)) 15 | { 16 | return modelNameAttribute.Name; 17 | } 18 | 19 | string modelName = type.Name; 20 | if (type.IsGenericType) 21 | { 22 | // Format the generic type name to something like: GenericOfAgurment1AndArgument2 23 | Type genericType = type.GetGenericTypeDefinition(); 24 | Type[] genericArguments = type.GetGenericArguments(); 25 | string genericTypeName = genericType.Name; 26 | 27 | // Trim the generic parameter counts from the name 28 | genericTypeName = genericTypeName.Substring(0, genericTypeName.IndexOf('`')); 29 | string[] argumentTypeNames = genericArguments.Select(t => GetModelName(t)).ToArray(); 30 | modelName = String.Format(CultureInfo.InvariantCulture, "{0}Of{1}", genericTypeName, String.Join("And", argumentTypeNames)); 31 | } 32 | 33 | return modelName; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/ParameterAnnotation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ParameterAnnotation 6 | { 7 | public Attribute AnnotationAttribute { get; set; } 8 | 9 | public string Documentation { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/ParameterDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class ParameterDescription 7 | { 8 | public ParameterDescription() 9 | { 10 | Annotations = new Collection(); 11 | } 12 | 13 | public Collection Annotations { get; private set; } 14 | 15 | public string Documentation { get; set; } 16 | 17 | public string Name { get; set; } 18 | 19 | public ModelDescription TypeDescription { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/ModelDescriptions/SimpleTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class SimpleTypeModelDescription : ModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Models/HelpPageApiModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | using System.Net.Http.Headers; 4 | using System.Web.Http.Description; 5 | using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions; 6 | 7 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage.Models 8 | { 9 | /// 10 | /// The model that represents an API displayed on the help page. 11 | /// 12 | public class HelpPageApiModel 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public HelpPageApiModel() 18 | { 19 | UriParameters = new Collection(); 20 | SampleRequests = new Dictionary(); 21 | SampleResponses = new Dictionary(); 22 | ErrorMessages = new Collection(); 23 | } 24 | 25 | /// 26 | /// Gets or sets the that describes the API. 27 | /// 28 | public ApiDescription ApiDescription { get; set; } 29 | 30 | /// 31 | /// Gets or sets the collection that describes the URI parameters for the API. 32 | /// 33 | public Collection UriParameters { get; private set; } 34 | 35 | /// 36 | /// Gets or sets the documentation for the request. 37 | /// 38 | public string RequestDocumentation { get; set; } 39 | 40 | /// 41 | /// Gets or sets the that describes the request body. 42 | /// 43 | public ModelDescription RequestModelDescription { get; set; } 44 | 45 | /// 46 | /// Gets the request body parameter descriptions. 47 | /// 48 | public IList RequestBodyParameters 49 | { 50 | get 51 | { 52 | return GetParameterDescriptions(RequestModelDescription); 53 | } 54 | } 55 | 56 | /// 57 | /// Gets or sets the that describes the resource. 58 | /// 59 | public ModelDescription ResourceDescription { get; set; } 60 | 61 | /// 62 | /// Gets the resource property descriptions. 63 | /// 64 | public IList ResourceProperties 65 | { 66 | get 67 | { 68 | return GetParameterDescriptions(ResourceDescription); 69 | } 70 | } 71 | 72 | /// 73 | /// Gets the sample requests associated with the API. 74 | /// 75 | public IDictionary SampleRequests { get; private set; } 76 | 77 | /// 78 | /// Gets the sample responses associated with the API. 79 | /// 80 | public IDictionary SampleResponses { get; private set; } 81 | 82 | /// 83 | /// Gets the error messages associated with this model. 84 | /// 85 | public Collection ErrorMessages { get; private set; } 86 | 87 | private static IList GetParameterDescriptions(ModelDescription modelDescription) 88 | { 89 | ComplexTypeModelDescription complexTypeModelDescription = modelDescription as ComplexTypeModelDescription; 90 | if (complexTypeModelDescription != null) 91 | { 92 | return complexTypeModelDescription.Properties; 93 | } 94 | 95 | CollectionModelDescription collectionModelDescription = modelDescription as CollectionModelDescription; 96 | if (collectionModelDescription != null) 97 | { 98 | complexTypeModelDescription = collectionModelDescription.ElementDescription as ComplexTypeModelDescription; 99 | if (complexTypeModelDescription != null) 100 | { 101 | return complexTypeModelDescription.Properties; 102 | } 103 | } 104 | 105 | return null; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/SampleGeneration/ImageSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an image sample on the help page. There's a display template named ImageSample associated with this class. 7 | /// 8 | public class ImageSample 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The URL of an image. 14 | public ImageSample(string src) 15 | { 16 | if (src == null) 17 | { 18 | throw new ArgumentNullException("src"); 19 | } 20 | Src = src; 21 | } 22 | 23 | public string Src { get; private set; } 24 | 25 | public override bool Equals(object obj) 26 | { 27 | ImageSample other = obj as ImageSample; 28 | return other != null && Src == other.Src; 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return Src.GetHashCode(); 34 | } 35 | 36 | public override string ToString() 37 | { 38 | return Src; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/SampleGeneration/InvalidSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an invalid sample on the help page. There's a display template named InvalidSample associated with this class. 7 | /// 8 | public class InvalidSample 9 | { 10 | public InvalidSample(string errorMessage) 11 | { 12 | if (errorMessage == null) 13 | { 14 | throw new ArgumentNullException("errorMessage"); 15 | } 16 | ErrorMessage = errorMessage; 17 | } 18 | 19 | public string ErrorMessage { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | InvalidSample other = obj as InvalidSample; 24 | return other != null && ErrorMessage == other.ErrorMessage; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return ErrorMessage.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return ErrorMessage; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/SampleGeneration/SampleDirection.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage 2 | { 3 | /// 4 | /// Indicates whether the sample is used for request or response 5 | /// 6 | public enum SampleDirection 7 | { 8 | Request = 0, 9 | Response 10 | } 11 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/SampleGeneration/TextSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.WebDemo.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents a preformatted text sample on the help page. There's a display template named TextSample associated with this class. 7 | /// 8 | public class TextSample 9 | { 10 | public TextSample(string text) 11 | { 12 | if (text == null) 13 | { 14 | throw new ArgumentNullException("text"); 15 | } 16 | Text = text; 17 | } 18 | 19 | public string Text { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | TextSample other = obj as TextSample; 24 | return other != null && Text == other.Text; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return Text.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return Text; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/Api.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.Models 3 | @model HelpPageApiModel 4 | 5 | @{ 6 | var description = Model.ApiDescription; 7 | ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath; 8 | } 9 | 10 | 11 |
12 | 19 |
20 | @Html.DisplayForModel() 21 |
22 |
23 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/ApiGroup.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using ClearScript.Manager.WebDemo.Areas.HelpPage 5 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.Models 6 | @model IGrouping 7 | 8 | @{ 9 | var controllerDocumentation = ViewBag.DocumentationProvider != null ? 10 | ViewBag.DocumentationProvider.GetDocumentation(Model.Key) : 11 | null; 12 | } 13 | 14 |

@Model.Key.ControllerName

15 | @if (!String.IsNullOrEmpty(controllerDocumentation)) 16 | { 17 |

@controllerDocumentation

18 | } 19 | 20 | 21 | 22 | 23 | 24 | @foreach (var api in Model) 25 | { 26 | 27 | 28 | 38 | 39 | } 40 | 41 |
APIDescription
@api.HttpMethod.Method @api.RelativePath 29 | @if (api.Documentation != null) 30 | { 31 |

@api.Documentation

32 | } 33 | else 34 | { 35 |

No documentation available.

36 | } 37 |
-------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/CollectionModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model CollectionModelDescription 3 | @if (Model.ElementDescription is ComplexTypeModelDescription) 4 | { 5 | @Html.DisplayFor(m => m.ElementDescription) 6 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/ComplexTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model ComplexTypeModelDescription 3 | @Html.DisplayFor(m => m.Properties, "Parameters") -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/DictionaryModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model DictionaryModelDescription 3 | Dictionary of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/EnumTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model EnumTypeModelDescription 3 | 4 |

Possible enumeration values:

5 | 6 | 7 | 8 | 9 | 10 | 11 | @foreach (EnumValueDescription value in Model.Values) 12 | { 13 | 14 | 15 | 18 | 21 | 22 | } 23 | 24 |
NameValueDescription
@value.Name 16 |

@value.Value

17 |
19 |

@value.Documentation

20 |
-------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/HelpPageApiModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Description 3 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.Models 4 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 5 | @model HelpPageApiModel 6 | 7 | @{ 8 | ApiDescription description = Model.ApiDescription; 9 | } 10 |

@description.HttpMethod.Method @description.RelativePath

11 |
12 |

@description.Documentation

13 | 14 |

Request Information

15 | 16 |

URI Parameters

17 | @Html.DisplayFor(m => m.UriParameters, "Parameters") 18 | 19 |

Body Parameters

20 | 21 |

@Model.RequestDocumentation

22 | 23 | @if (Model.RequestModelDescription != null) 24 | { 25 | @Html.DisplayFor(m => m.RequestModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.RequestModelDescription }) 26 | if (Model.RequestBodyParameters != null) 27 | { 28 | @Html.DisplayFor(m => m.RequestBodyParameters, "Parameters") 29 | } 30 | } 31 | else 32 | { 33 |

None.

34 | } 35 | 36 | @if (Model.SampleRequests.Count > 0) 37 | { 38 |

Request Formats

39 | @Html.DisplayFor(m => m.SampleRequests, "Samples") 40 | } 41 | 42 |

Response Information

43 | 44 |

Resource Description

45 | 46 |

@description.ResponseDescription.Documentation

47 | 48 | @if (Model.ResourceDescription != null) 49 | { 50 | @Html.DisplayFor(m => m.ResourceDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ResourceDescription }) 51 | if (Model.ResourceProperties != null) 52 | { 53 | @Html.DisplayFor(m => m.ResourceProperties, "Parameters") 54 | } 55 | } 56 | else 57 | { 58 |

None.

59 | } 60 | 61 | @if (Model.SampleResponses.Count > 0) 62 | { 63 |

Response Formats

64 | @Html.DisplayFor(m => m.SampleResponses, "Samples") 65 | } 66 | 67 |
-------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/ImageSample.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage 2 | @model ImageSample 3 | 4 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/InvalidSample.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage 2 | @model InvalidSample 3 | 4 | @if (HttpContext.Current.IsDebuggingEnabled) 5 | { 6 |
7 |

@Model.ErrorMessage

8 |
9 | } 10 | else 11 | { 12 |

Sample not available.

13 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/KeyValuePairModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model KeyValuePairModelDescription 3 | Pair of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/ModelDescriptionLink.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model Type 3 | @{ 4 | ModelDescription modelDescription = ViewBag.modelDescription; 5 | if (modelDescription is ComplexTypeModelDescription || modelDescription is EnumTypeModelDescription) 6 | { 7 | if (Model == typeof(Object)) 8 | { 9 | @:Object 10 | } 11 | else 12 | { 13 | @Html.ActionLink(modelDescription.Name, "ResourceModel", "Help", new { modelName = modelDescription.Name }, null) 14 | } 15 | } 16 | else if (modelDescription is CollectionModelDescription) 17 | { 18 | var collectionDescription = modelDescription as CollectionModelDescription; 19 | var elementDescription = collectionDescription.ElementDescription; 20 | @:Collection of @Html.DisplayFor(m => elementDescription.ModelType, "ModelDescriptionLink", new { modelDescription = elementDescription }) 21 | } 22 | else 23 | { 24 | @Html.DisplayFor(m => modelDescription) 25 | } 26 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/Parameters.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Collections.Generic 2 | @using System.Collections.ObjectModel 3 | @using System.Web.Http.Description 4 | @using System.Threading 5 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 6 | @model IList 7 | 8 | @if (Model.Count > 0) 9 | { 10 | 11 | 12 | 13 | 14 | 15 | @foreach (ParameterDescription parameter in Model) 16 | { 17 | ModelDescription modelDescription = parameter.TypeDescription; 18 | 19 | 20 | 23 | 26 | 39 | 40 | } 41 | 42 |
NameDescriptionTypeAdditional information
@parameter.Name 21 |

@parameter.Documentation

22 |
24 | @Html.DisplayFor(m => modelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = modelDescription }) 25 | 27 | @if (parameter.Annotations.Count > 0) 28 | { 29 | foreach (var annotation in parameter.Annotations) 30 | { 31 |

@annotation.Documentation

32 | } 33 | } 34 | else 35 | { 36 |

None.

37 | } 38 |
43 | } 44 | else 45 | { 46 |

None.

47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/Samples.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Net.Http.Headers 2 | @model Dictionary 3 | 4 | @{ 5 | // Group the samples into a single tab if they are the same. 6 | Dictionary samples = Model.GroupBy(pair => pair.Value).ToDictionary( 7 | pair => String.Join(", ", pair.Select(m => m.Key.ToString()).ToArray()), 8 | pair => pair.Key); 9 | var mediaTypes = samples.Keys; 10 | } 11 |
12 | @foreach (var mediaType in mediaTypes) 13 | { 14 |

@mediaType

15 |
16 | Sample: 17 | @{ 18 | var sample = samples[mediaType]; 19 | if (sample == null) 20 | { 21 |

Sample not available.

22 | } 23 | else 24 | { 25 | @Html.DisplayFor(s => sample); 26 | } 27 | } 28 |
29 | } 30 |
-------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/SimpleTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 2 | @model SimpleTypeModelDescription 3 | @Model.Documentation -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/DisplayTemplates/TextSample.cshtml: -------------------------------------------------------------------------------- 1 | @using ClearScript.Manager.WebDemo.Areas.HelpPage 2 | @model TextSample 3 | 4 |
5 | @Model.Text
6 | 
-------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using System.Collections.ObjectModel 5 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.Models 6 | @model Collection 7 | 8 | @{ 9 | ViewBag.Title = "ASP.NET Web API Help Page"; 10 | 11 | // Group APIs by controller 12 | ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); 13 | } 14 | 15 | 16 |
17 |
18 |
19 |

@ViewBag.Title

20 |
21 |
22 |
23 |
24 | 32 |
33 | @foreach (var group in apiGroups) 34 | { 35 | @Html.DisplayFor(m => group, "ApiGroup") 36 | } 37 |
38 |
39 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Help/ResourceModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using ClearScript.Manager.WebDemo.Areas.HelpPage.ModelDescriptions 3 | @model ModelDescription 4 | 5 | 6 |
7 | 14 |

@Model.Name

15 |

@Model.Documentation

16 |
17 | @Html.DisplayFor(m => Model) 18 |
19 |
20 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @RenderSection("scripts", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Areas/HelpPage/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | // Change the Layout path below to blend the look and feel of the help page with your existing web pages 3 | Layout = "~/Views/Shared/_Layout.cshtml"; 4 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/ClearScriptV8-32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/ClearScriptV8-32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/ClearScriptV8-32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/ClearScriptV8-32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/ClearScriptV8-64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/ClearScriptV8-64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/ClearScriptV8-64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/ClearScriptV8-64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Set width on the form input elements since they're 100% wide by default */ 13 | input, 14 | select, 15 | textarea { 16 | max-width: 280px; 17 | } 18 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace ClearScript.Manager.WebDemo.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public ActionResult Index() 12 | { 13 | ViewBag.Title = "Home Page"; 14 | 15 | return View(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Dynamic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Threading.Tasks; 8 | using System.Web.Http; 9 | using ClearScript.Manager.WebDemo.Models; 10 | using Microsoft.ClearScript; 11 | using Microsoft.ClearScript.V8; 12 | 13 | namespace ClearScript.Manager.WebDemo.Controllers 14 | { 15 | public class ValuesController : ApiController 16 | { 17 | // GET api/values 18 | public IEnumerable Get() 19 | { 20 | return new string[] { "value1", "value2" }; 21 | } 22 | 23 | // GET api/values/5 24 | public string Get(int id) 25 | { 26 | return "value"; 27 | } 28 | 29 | // POST api/values 30 | public async Task Post([FromBody]Script script) 31 | { 32 | var scriptId = Guid.NewGuid(); 33 | using (var scope = new ManagerScope()) 34 | { 35 | dynamic host = new ExpandoObject(); 36 | //var host = new TestModel(); 37 | var option = new ExecutionOptions 38 | { 39 | HostObjects = new List {new HostObject {Name = "host", Target = host}} 40 | }; 41 | 42 | //var engine = new V8ScriptEngine(); 43 | //engine.AddHostObject("host", HostItemFlags.None, host); 44 | //engine.Execute(script.Text); 45 | await scope.RuntimeManager.ExecuteAsync(scriptId.ToString(), script.Text, option); 46 | 47 | return host; 48 | } 49 | } 50 | 51 | // PUT api/values/5 52 | public void Put(int id, [FromBody]string value) 53 | { 54 | } 55 | 56 | // DELETE api/values/5 57 | public void Delete(int id) 58 | { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="ClearScript.Manager.WebDemo.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Mvc; 7 | using System.Web.Optimization; 8 | using System.Web.Routing; 9 | 10 | namespace ClearScript.Manager.WebDemo 11 | { 12 | public class WebApiApplication : System.Web.HttpApplication 13 | { 14 | protected void Application_Start() 15 | { 16 | AreaRegistration.RegisterAllAreas(); 17 | GlobalConfiguration.Configure(WebApiConfig.Register); 18 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 19 | RouteConfig.RegisterRoutes(RouteTable.Routes); 20 | BundleConfig.RegisterBundles(BundleTable.Bundles); 21 | 22 | ManagerPool.InitializeCurrentPool(new ManagerSettings()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Models/Script.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace ClearScript.Manager.WebDemo.Models 7 | { 8 | public class Script 9 | { 10 | public string Text { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Models/TestModel.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.WebDemo.Models 2 | { 3 | public class TestModel 4 | { 5 | public string Value { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ClearScript.Manager.WebDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ClearScript.Manager.WebDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("04016bfc-4c57-438c-acd7-7fd97974958c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Scripts/_references.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/Scripts/_references.js -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Scripts/request.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | function requestFactory(options, callback) { 4 | 5 | var cfg = options; 6 | if (typeof options === 'string') { 7 | cfg = { uri: options }; 8 | } 9 | 10 | cfg.callback = callback || options.callback; 11 | 12 | return new requestFactory.Request(cfg); 13 | } 14 | 15 | 16 | function Request(options) { 17 | this.options = options; 18 | this.go(); 19 | 20 | } 21 | 22 | Request.prototype.go = function () { 23 | var me = this; 24 | var strings = []; 25 | var buffer; 26 | 27 | me.req = http.request(me.options, function (res) { 28 | if (me.options.callback) { 29 | res.on('data', function (chunk) { 30 | var me = this; 31 | if (Buffer.isBuffer(chunk)) { 32 | if (!buffer) { 33 | buffer = new Buffer(1024); 34 | } 35 | //hack till i get the right bla 36 | chunk.copy(buffer); 37 | } else { 38 | strings.push(chunk); 39 | } 40 | }); 41 | res.on('end', function () { 42 | me.onEnd(strings, buffer, res, me.options.callback); 43 | }); 44 | } 45 | }); 46 | 47 | me.req.end(); 48 | //todo sedn data on req. 49 | 50 | }; 51 | 52 | 53 | Request.prototype.onEnd = function (strings, buffer, response, callback) { 54 | var self = this; 55 | if (self._aborted) { 56 | return; 57 | } 58 | 59 | if (buffer.length) { 60 | if (self.encoding === null) { 61 | // response.body = buffer 62 | // can't move to this until https://github.com/rvagg/bl/issues/13 63 | response.body = buffer.slice(); 64 | } else { 65 | response.body = buffer.toString(self.encoding); 66 | } 67 | } else if (strings.length) { 68 | // The UTF8 BOM [0xEF,0xBB,0xBF] is converted to [0xFE,0xFF] in the JS UTC16/UCS2 representation. 69 | // Strip this value out when the encoding is set to 'utf8', as upstream consumers won't expect it and it breaks JSON.parse(). 70 | if (self.encoding === 'utf8' && strings[0].length > 0 && strings[0][0] === '\uFEFF') { 71 | strings[0] = strings[0].substring(1); 72 | } 73 | response.body = strings.join(''); 74 | } 75 | 76 | if (self.options.json) { 77 | try { 78 | response.body = JSON.parse(response.body); 79 | } catch (e) { } 80 | } 81 | 82 | if (typeof response.body === 'undefined' && !self._json) { 83 | response.body = ''; 84 | } 85 | callback.call(null, null, response, response.body); 86 | // self.emit('complete', response, response.body) 87 | }; 88 | 89 | if (typeof module != 'undefined' && module != null) { 90 | module.exports = request; 91 | } 92 | 93 | requestFactory.Request = Request; 94 | 95 | request = requestFactory; 96 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Scripts/respond.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ 16 | /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ 17 | window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.style.background="none";d.appendChild(g);return function(h){g.innerHTML='­';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document); 18 | 19 | /*! Respond.js v1.2.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ 20 | (function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var w=e.document,s=w.documentElement,i=[],k=[],q=[],o={},h=30,f=w.getElementsByTagName("head")[0]||s,g=w.getElementsByTagName("base")[0],b=f.getElementsByTagName("link"),d=[],a=function(){var D=b,y=D.length,B=0,A,z,C,x;for(;B-1,minw:F.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:F.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}j()},l,r,v=function(){var z,A=w.createElement("div"),x=w.body,y=false;A.style.cssText="position:absolute;font-size:1em;width:1em";if(!x){x=y=w.createElement("body");x.style.background="none"}x.appendChild(A);s.insertBefore(x,s.firstChild);z=A.offsetWidth;if(y){s.removeChild(x)}else{x.removeChild(A)}z=p=parseFloat(z);return z},p,j=function(I){var x="clientWidth",B=s[x],H=w.compatMode==="CSS1Compat"&&B||w.body[x]||B,D={},G=b[b.length-1],z=(new Date()).getTime();if(I&&l&&z-l-1?(p||v()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||v()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===f){f.removeChild(q[E])}}for(var E in D){var M=w.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;f.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(w.createTextNode(F))}q.push(M)}},n=function(x,z){var y=c();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},c=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(){j(true)}if(e.addEventListener){e.addEventListener("resize",t,false)}else{if(e.attachEvent){e.attachEvent("onresize",t)}}})(this); -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | 
2 |

ASP.NET

3 |

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.

4 |

Learn more »

5 |
6 |
7 |
8 |

Getting started

9 |

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach 10 | a broad range of clients, including browsers and mobile devices. ASP.NET Web API 11 | is an ideal platform for building RESTful applications on the .NET Framework.

12 |

Learn more »

13 |
14 |
15 |

Get more libraries

16 |

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

17 |

Learn more »

18 |
19 |
20 |

Web Hosting

21 |

You can easily find a web hosting company that offers the right mix of features and price for your applications.

22 |

Learn more »

23 |
24 |
25 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 | 5 | 6 | 7 | 8 | 9 | Error 10 | 11 | 12 |
13 |

Error.

14 |

An error occurred while processing your request.

15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @Styles.Render("~/Content/css") 8 | @Scripts.Render("~/bundles/modernizr") 9 | 10 | 11 | 29 |
30 | @RenderBody() 31 |
32 |
33 |

© @DateTime.Now.Year - My ASP.NET Application

34 |
35 |
36 | 37 | @Scripts.Render("~/bundles/jquery") 38 | @Scripts.Render("~/bundles/bootstrap") 39 | @RenderSection("scripts", required: false) 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 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 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/favicon.ico -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/v8-ia32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/v8-ia32.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/v8-ia32.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/v8-ia32.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/v8-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/v8-x64.dll -------------------------------------------------------------------------------- /src/ClearScript.Manager.WebDemo/v8-x64.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eswann/ClearScript.Manager/8cd528d4096c96c7235cf0e931331a25b5d1fa92/src/ClearScript.Manager.WebDemo/v8-x64.pdb -------------------------------------------------------------------------------- /src/ClearScript.Manager.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearScript.Manager", "ClearScript.Manager\ClearScript.Manager.csproj", "{CFAB8382-B76F-4AA1-AB38-52674F932E52}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearScript.Manager.Test", "ClearScript.Manager.Test\ClearScript.Manager.Test.csproj", "{E7A8A86A-83AF-48CE-9266-E3094218F401}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Artifacts", "Artifacts", "{7667EE17-051A-434A-BB9F-1DC685B1A471}" 11 | ProjectSection(SolutionItems) = preProject 12 | ..\LICENSE = ..\LICENSE 13 | ..\README.md = ..\README.md 14 | EndProjectSection 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearScript.Manager.Demo", "ClearScript.Manager.Demo\ClearScript.Manager.Demo.csproj", "{60385905-F78E-4933-9FB7-DD75D51CA2CD}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearScript.Manager.Http", "ClearScript.Manager.Http\ClearScript.Manager.Http.csproj", "{190EF179-83F2-4091-AB95-A609D278ACCC}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearScript.Manager.Http.Test", "ClearScript.Manager.Http.Test\ClearScript.Manager.Http.Test.csproj", "{76F7C7E8-EB54-4840-989C-124DCC30128D}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearScript.Manager.WebDemo", "ClearScript.Manager.WebDemo\ClearScript.Manager.WebDemo.csproj", "{15DC9470-1862-4F28-B3D9-55EC94BBA695}" 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Any CPU = Debug|Any CPU 27 | Release|Any CPU = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {CFAB8382-B76F-4AA1-AB38-52674F932E52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {CFAB8382-B76F-4AA1-AB38-52674F932E52}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {CFAB8382-B76F-4AA1-AB38-52674F932E52}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {CFAB8382-B76F-4AA1-AB38-52674F932E52}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {E7A8A86A-83AF-48CE-9266-E3094218F401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {E7A8A86A-83AF-48CE-9266-E3094218F401}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {E7A8A86A-83AF-48CE-9266-E3094218F401}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {60385905-F78E-4933-9FB7-DD75D51CA2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {60385905-F78E-4933-9FB7-DD75D51CA2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {60385905-F78E-4933-9FB7-DD75D51CA2CD}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {190EF179-83F2-4091-AB95-A609D278ACCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {190EF179-83F2-4091-AB95-A609D278ACCC}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {190EF179-83F2-4091-AB95-A609D278ACCC}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {190EF179-83F2-4091-AB95-A609D278ACCC}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {76F7C7E8-EB54-4840-989C-124DCC30128D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {76F7C7E8-EB54-4840-989C-124DCC30128D}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {76F7C7E8-EB54-4840-989C-124DCC30128D}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {76F7C7E8-EB54-4840-989C-124DCC30128D}.Release|Any CPU.Build.0 = Release|Any CPU 48 | {15DC9470-1862-4F28-B3D9-55EC94BBA695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 49 | {15DC9470-1862-4F28-B3D9-55EC94BBA695}.Debug|Any CPU.Build.0 = Debug|Any CPU 50 | {15DC9470-1862-4F28-B3D9-55EC94BBA695}.Release|Any CPU.ActiveCfg = Release|Any CPU 51 | {15DC9470-1862-4F28-B3D9-55EC94BBA695}.Release|Any CPU.Build.0 = Release|Any CPU 52 | EndGlobalSection 53 | GlobalSection(SolutionProperties) = preSolution 54 | HideSolutionNode = FALSE 55 | EndGlobalSection 56 | EndGlobal 57 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/Caching/CachedV8Runtime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.ClearScript.V8; 3 | 4 | namespace ClearScript.Manager.Caching 5 | { 6 | public class CachedV8Script 7 | { 8 | public CachedV8Script () 9 | { 10 | } 11 | 12 | public CachedV8Script(V8Script script, int expirationSeconds = ManagerSettings.DefaultScriptTimeoutMilliSeconds) 13 | { 14 | CreatedOn = DateTime.UtcNow; 15 | ExpiresOn = CreatedOn.AddSeconds(expirationSeconds); 16 | Script = script; 17 | } 18 | 19 | public V8Script Script { get; set; } 20 | 21 | public DateTime CreatedOn { get; set; } 22 | 23 | public DateTime ExpiresOn { get; set; } 24 | 25 | public int CacheHits { get; internal set; } 26 | } 27 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Caching/HashUtilities.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2012-2014 by Roger Knapp, Licensed under the Apache License, Version 2.0 2 | /* Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | 18 | namespace ClearScript.Manager.Caching 19 | { 20 | internal class HashUtilities 21 | { 22 | private static readonly int[] _primeNumbers = 23 | new[] 24 | { 25 | 17, 37, 67, 131, 257, 521, // ROK - Added smaller primes 26 | 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, 27 | 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, 28 | 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 29 | 1395263, 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369 30 | }; 31 | 32 | internal static int SelectPrimeNumber(int hashSize) 33 | { 34 | int offset = Array.BinarySearch(_primeNumbers, hashSize); 35 | if (offset < 0) 36 | offset = ~offset; 37 | return _primeNumbers[Math.Min(offset, _primeNumbers.Length - 1)]; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/Caching/IDictionaryEx.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2012-2014 by Roger Knapp, Licensed under the Apache License, Version 2.0 2 | /* Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | 19 | namespace ClearScript.Manager.Caching 20 | { 21 | /// 22 | /// Extends the IDictionary interface to encompass the TryXxxx operations 23 | /// 24 | public interface IDictionaryEx : IDictionary, IDisposable 25 | { 26 | /// 27 | /// Adds a key/value pair to the if the key does not already exist. 28 | /// 29 | /// The key of the element to add. 30 | /// The value to be added, if the key does not already exist. 31 | /// The is read-only. 32 | TValue GetOrAdd(TKey key, TValue value); 33 | 34 | /// 35 | /// Adds an element with the provided key and value to the . 36 | /// 37 | /// The object to use as the key of the element to add. 38 | /// The object to use as the value of the element to add. 39 | /// The is read-only. 40 | bool TryAdd(TKey key, TValue value); 41 | 42 | /// 43 | /// Updates an element with the provided key to the value if it exists. 44 | /// 45 | /// Returns true if the key provided was found and updated to the value. 46 | /// The object to use as the key of the element to update. 47 | /// The new value for the key if found. 48 | /// The is read-only. 49 | bool TryUpdate(TKey key, TValue value); 50 | 51 | /// 52 | /// Updates an element with the provided key to the value if it exists. 53 | /// 54 | /// Returns true if the key provided was found and updated to the value. 55 | /// The object to use as the key of the element to update. 56 | /// The new value for the key if found. 57 | /// The value that is compared to the value of the element with key. 58 | /// The is read-only. 59 | bool TryUpdate(TKey key, TValue value, TValue comparisonValue); 60 | 61 | /// 62 | /// Removes the element with the specified key from the . 63 | /// 64 | /// 65 | /// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . 66 | /// 67 | /// The key of the element to remove. 68 | /// The value that was removed. 69 | /// The is read-only. 70 | bool TryRemove(TKey key, out TValue value); 71 | } 72 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Caching/LruCacheCorruptionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager.Caching 4 | { 5 | public class LruCacheCorruptionException : Exception 6 | { 7 | public override string Message 8 | { 9 | get { return "LRU Cache is corrupted."; } 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/ClearScript.Manager.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CFAB8382-B76F-4AA1-AB38-52674F932E52} 8 | Library 9 | Properties 10 | ClearScript.Manager 11 | ClearScript.Manager 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\ClearScript.Manager.XML 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\ClearScript.Manager.XML 34 | 35 | 36 | 37 | False 38 | ..\packages\ClearScript.Installer.1.0.1.31662\lib\net45\ClearScript.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | Code 64 | 65 | 66 | Code 67 | 68 | 69 | 70 | 71 | 72 | Code 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 101 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/ClearScript.Manager.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | $version$ 6 | $id$ 7 | eric_swann 8 | eric_swann 9 | https://github.com/eswann/ClearScript.Manager 10 | https://raw.githubusercontent.com/eswann/ClearScript.Manager/master/img/clearscript.png 11 | false 12 | $description$ 13 | $description$ 14 | Copyright 2014 Eric Swann, et. al. - All rights reserved. 15 | 16 | ClearScript V8 JavaScript 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/ExecutionOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ClearScript.Manager 4 | { 5 | /// 6 | /// Options for execution of of scripts by the Runtime Manager 7 | /// 8 | public class ExecutionOptions 9 | { 10 | private bool _addToCache = true; 11 | private IList _hostObjects; 12 | private IList _hostTypes; 13 | private IList _scripts; 14 | 15 | /// 16 | /// Objects to inject into the JavaScript runtime. 17 | /// 18 | public IList HostObjects 19 | { 20 | get { return _hostObjects ?? (_hostObjects = new List()); } 21 | set { _hostObjects = value; } 22 | } 23 | 24 | /// 25 | /// Types to make available to the JavaScript runtime. 26 | /// 27 | public IList HostTypes 28 | { 29 | get { return _hostTypes ?? (_hostTypes = new List()); } 30 | set { _hostTypes = value; } 31 | } 32 | 33 | /// 34 | /// Indicates that this script should be added to the script cache once compiled. Default is True. 35 | /// 36 | public bool AddToCache 37 | { 38 | get { return _addToCache; } 39 | set { _addToCache = value; } 40 | } 41 | 42 | /// 43 | /// Indicates the duration that a script should be cached. 44 | /// 45 | public int? CacheExpirationSeconds { get; set; } 46 | 47 | /// 48 | /// External JavaScripts to import before executing the current script. 49 | /// 50 | public IList Scripts 51 | { 52 | get { return _scripts ?? (_scripts = new List()); } 53 | set { _scripts = value; } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/Extensions/DynamicExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Dynamic; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CSharp.RuntimeBinder; 8 | using Binder = Microsoft.CSharp.RuntimeBinder.Binder; 9 | 10 | namespace ClearScript.Manager.Extensions 11 | { 12 | /// 13 | /// Extension methods to get properties of dynamic objects. 14 | /// 15 | internal static class DynamicExtensions 16 | { 17 | private static readonly ConcurrentDictionary _delegateCache = new ConcurrentDictionary(); 18 | 19 | /// 20 | /// Gets a property of the dynamic object. 21 | /// 22 | /// Source object. 23 | /// Member to retrieve. 24 | /// The requested property value. 25 | /// If source or member are null. 26 | public static object GetProperty(this object source, string member) 27 | { 28 | if (source == null) throw new ArgumentNullException("source"); 29 | if (member == null) throw new ArgumentNullException("member"); 30 | 31 | Type scope = source.GetType(); 32 | var provider = source as IDynamicMetaObjectProvider; 33 | if (provider != null) 34 | { 35 | var objectType = typeof (object); 36 | var cacheKey = objectType.FullName + member; 37 | Delegate del; 38 | 39 | if (!_delegateCache.TryGetValue(cacheKey, out del)) 40 | { 41 | ParameterExpression param = Expression.Parameter(typeof (object)); 42 | DynamicMetaObject mobj = provider.GetMetaObject(param); 43 | var binder = (GetMemberBinder) Binder.GetMember(0, member, scope, new[] {CSharpArgumentInfo.Create(0, null)}); 44 | DynamicMetaObject ret = mobj.BindGetMember(binder); 45 | BlockExpression final = Expression.Block(Expression.Label(CallSiteBinder.UpdateLabel), ret.Expression); 46 | LambdaExpression lambda = Expression.Lambda(final, param); 47 | del = lambda.Compile(); 48 | _delegateCache.TryAdd(cacheKey, del); 49 | } 50 | 51 | return del.DynamicInvoke(source); 52 | } 53 | return source.GetType().GetProperty(member, BindingFlags.Public | BindingFlags.Instance).GetValue(source, null); 54 | } 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Extensions/EngineExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ClearScript; 2 | 3 | namespace ClearScript.Manager.Extensions 4 | { 5 | internal static class EngineExtensions 6 | { 7 | public static ScriptEngine AddHostObject(this ScriptEngine engine, HostObject hostObject) 8 | { 9 | engine.AddHostObject(hostObject.Name, hostObject.Flags, hostObject.Target); 10 | 11 | return engine; 12 | } 13 | 14 | public static ScriptEngine AddHostType(this ScriptEngine engine, HostType hostType) 15 | { 16 | engine.AddHostType(hostType.Name, hostType.Flags, hostType.Type); 17 | 18 | return engine; 19 | } 20 | 21 | public static ScriptEngine ApplyOptions(this ScriptEngine engine, ExecutionOptions options) 22 | { 23 | if (options != null) 24 | { 25 | if (options.HostObjects != null) 26 | { 27 | foreach (HostObject hostObject in options.HostObjects) 28 | { 29 | engine.AddHostObject(hostObject); 30 | } 31 | } 32 | 33 | if (options.HostTypes != null) 34 | { 35 | foreach (HostType hostType in options.HostTypes) 36 | { 37 | engine.AddHostType(hostType); 38 | } 39 | } 40 | } 41 | 42 | return engine; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Extensions/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ClearScript.Manager.Extensions 4 | { 5 | internal static class EnumerableExtensions 6 | { 7 | internal static bool SafeAny(this IList list) 8 | { 9 | return list != null && list.Count > 0; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace ClearScript.Manager.Extensions 2 | { 3 | internal static class StringExtensions 4 | { 5 | public static string ToCamelCase(this string input) 6 | { 7 | if (string.IsNullOrEmpty(input)) 8 | return input; 9 | 10 | if (input.Length == 1) 11 | { 12 | return input.ToLowerInvariant(); 13 | } 14 | 15 | return input.Substring(0, 1).ToLowerInvariant() + input.Substring(1); 16 | } 17 | 18 | public static string ToPascalCase(this string input) 19 | { 20 | if (string.IsNullOrEmpty(input)) 21 | return input; 22 | 23 | if (input.Length == 1) 24 | { 25 | return input.ToUpperInvariant(); 26 | } 27 | 28 | return input.Substring(0, 1).ToUpperInvariant() + input.Substring(1); 29 | 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/HostObject.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ClearScript; 2 | 3 | namespace ClearScript.Manager 4 | { 5 | /// 6 | /// A specific object instance to inject into the javascript to execute. 7 | /// 8 | public class HostObject 9 | { 10 | /// 11 | /// Name of the object used to access the object in the JavaScript. 12 | /// 13 | public string Name { get; set; } 14 | 15 | /// 16 | /// HostItemFlags to apply to the HostType. Limits the scope of the type and which type members are available. 17 | /// See ClearScript documentation for more information. 18 | /// 19 | public HostItemFlags Flags { get; set; } 20 | 21 | /// 22 | /// The target object to inject into the JavaScript. 23 | /// 24 | public object Target { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/HostType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.ClearScript; 3 | 4 | namespace ClearScript.Manager 5 | { 6 | /// 7 | /// A type to make available in JavaScript. 8 | /// 9 | public class HostType 10 | { 11 | /// 12 | /// Name of the type that is used to reference the type within the JavaScript. 13 | /// 14 | public string Name { get; set; } 15 | 16 | /// 17 | /// HostItemFlags to apply to the HostType. Limits the scope of the type and which type members are available. 18 | /// See ClearScript documentation for more information. 19 | /// 20 | public HostItemFlags Flags { get; set; } 21 | 22 | /// 23 | /// Host type collections provide convenient scriptable access to all the types defined in one or more host assemblies. 24 | /// They are hierarchical collections where leaf nodes represent types and parent nodes represent namespaces. 25 | /// See ClearScript documentation for more information. 26 | /// 27 | public HostTypeCollection HostTypeCollection { get; set; } 28 | 29 | /// 30 | /// An individual type to make available to the script. 31 | /// 32 | public Type Type { get; set; } 33 | } 34 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/IncludeScript.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace ClearScript.Manager 4 | { 5 | /// 6 | /// Script to include in the execution of another script. This script is executed first. Can contain functions, libraries etc... 7 | /// 8 | public class IncludeScript 9 | { 10 | /// 11 | /// Unique name of the script to execute. 12 | /// 13 | public string ScriptId { get; set; } 14 | 15 | /// 16 | /// Uri (file or Url) of the script to execute. Need to include script code or script Url. 17 | /// 18 | public string Uri { get; set; } 19 | 20 | /// 21 | /// This code is prepended to the created code. 22 | /// 23 | public string PrependCode { get; set; } 24 | 25 | /// 26 | /// This code is appended to the created code. 27 | /// 28 | public string AppendCode { get; set; } 29 | 30 | /// 31 | /// Code of the script to include. Need to include script code or script Url. 32 | /// 33 | public string Code { get; set; } 34 | 35 | /// 36 | /// Sets the script Id if it is not set. 37 | /// 38 | internal void EnsureScriptId() 39 | { 40 | if (string.IsNullOrEmpty(ScriptId)) 41 | { 42 | if (!string.IsNullOrEmpty(Uri)) 43 | { 44 | ScriptId = Uri; 45 | } 46 | else if (!string.IsNullOrEmpty(Code)) 47 | { 48 | ScriptId = Code.GetHashCode().ToString(CultureInfo.InvariantCulture); 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Loaders/FileScriptLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ClearScript.Manager.Loaders 5 | { 6 | /// 7 | /// Loads scripts if they are file-system based scripts. 8 | /// 9 | public class FileScriptLoader : IScriptLoader 10 | { 11 | public string Name { get { return "FileScriptLoader"; } } 12 | 13 | public bool ShouldUse(IncludeScript script) 14 | { 15 | if (!string.IsNullOrEmpty(script.Code)) 16 | return false; 17 | 18 | if (Uri.IsWellFormedUriString(script.Uri, UriKind.RelativeOrAbsolute)) 19 | { 20 | var uri = new Uri(script.Uri); 21 | 22 | if (!uri.IsFile) 23 | return false; 24 | } 25 | 26 | return true; 27 | } 28 | 29 | public void LoadCode(IncludeScript script) 30 | { 31 | using (var reader = File.OpenText(script.Uri)) 32 | { 33 | script.Code = reader.ReadToEnd(); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Loaders/IScriptLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace ClearScript.Manager.Loaders 4 | { 5 | /// 6 | /// Interface for all classes that load scripts from a path or URI 7 | /// 8 | public interface IScriptLoader 9 | { 10 | /// 11 | /// Name of the script loader. 12 | /// 13 | string Name { get; } 14 | 15 | /// 16 | /// Determines if this script loader should be used at all. 17 | /// 18 | /// Script to evaluate. 19 | /// Bool indicating if this loader should be used. 20 | bool ShouldUse(IncludeScript script); 21 | 22 | /// 23 | /// Loads the scripts Code property from the other available properties of the IncludeScript, typically using hte Uri. 24 | /// 25 | /// Script to load 26 | void LoadCode(IncludeScript script); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/Loaders/RequireManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using Microsoft.ClearScript.V8; 4 | 5 | namespace ClearScript.Manager.Loaders 6 | { 7 | /// 8 | /// Manages Require packages. 9 | /// 10 | public class RequireManager 11 | { 12 | private static readonly ConcurrentDictionary _packages = new ConcurrentDictionary(); 13 | 14 | /// 15 | /// Register a packaged for potential requirement. 16 | /// 17 | /// The package to register. 18 | public static void RegisterPackage(RequiredPackage package) 19 | { 20 | _packages.TryAdd(package.PackageId, package); 21 | } 22 | 23 | /// 24 | /// Try to get the package from the registered packages. 25 | /// 26 | /// Id of the package to retrieve. 27 | /// Package to return. 28 | /// Bool indicating if package was found. 29 | public static bool TryGetPackage(string packageId, out RequiredPackage package) 30 | { 31 | return _packages.TryGetValue(packageId, out package); 32 | } 33 | 34 | /// 35 | /// Clears all registered packages. 36 | /// 37 | public static void ClearPackages() 38 | { 39 | _packages.Clear(); 40 | } 41 | 42 | /// 43 | /// Builds and returns a requirer to include with an engine. 44 | /// 45 | /// Compiles the required scripts if needed. 46 | /// The engine that will run the required script. 47 | /// 48 | internal static Requirer BuildRequirer(ScriptCompiler compiler, V8ScriptEngine engine) 49 | { 50 | var requirer = new Requirer 51 | { 52 | Compiler = compiler, 53 | Engine = engine 54 | }; 55 | 56 | //Need to add this as a host object to the script 57 | requirer.Engine.AddHostObject("require", new Func(requirer.Require)); 58 | requirer.Engine.AddHostObject("requireNamed", new Func(requirer.Require)); 59 | 60 | return requirer; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Loaders/RequiredPackage.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ClearScript.Manager.Loaders 4 | { 5 | /// 6 | /// Provides a definition for a required package. Must contain a script or a hostobject. 7 | /// 8 | public class RequiredPackage 9 | { 10 | private readonly IList _hostObjects = new List(); 11 | private readonly IList _hostTypes = new List(); 12 | 13 | /// 14 | /// The ID of the package. 15 | /// 16 | public string PackageId { get; set; } 17 | 18 | /// 19 | /// A script URI of a package javascript. The export from the package is returned from the require call. 20 | /// 21 | public string ScriptUri { get; set; } 22 | 23 | /// 24 | /// Host objects needed for the package. If a script is not included, the first host object is returned when the package is required. 25 | /// 26 | public IList HostObjects 27 | { 28 | get { return _hostObjects; } 29 | } 30 | 31 | /// 32 | /// Host types needed for the package. 33 | /// 34 | public IList HostTypes 35 | { 36 | get { return _hostTypes; } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Loaders/Requirer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using ClearScript.Manager.Extensions; 4 | using Microsoft.ClearScript; 5 | using Microsoft.ClearScript.V8; 6 | 7 | namespace ClearScript.Manager.Loaders 8 | { 9 | /// 10 | /// Used to register require packages and also provided to scripts to return required resources via the "require" call. 11 | /// 12 | public class Requirer 13 | { 14 | internal ScriptCompiler Compiler { get; set; } 15 | internal V8ScriptEngine Engine { get; set; } 16 | 17 | /// 18 | /// Called via a javascript to require and return the requested package. 19 | /// 20 | /// ID of the RequirePackage to require. 21 | /// The return object to use for the require. Either the export from the require script or the returned HostObject if not script is present. 22 | public object Require(string packageId) 23 | { 24 | return Require(packageId, null); 25 | } 26 | 27 | 28 | /// 29 | /// Called via a javascript to require and return the requested package. 30 | /// 31 | /// ID of the RequirePackage to require. 32 | /// A script uri. This is only needed if the packageId doesn't meet the script convention name and the package is not a registered package. 33 | /// The return object to use for the require. Either the export from the require script or the returned HostObject if not script is present. 34 | public object Require(string packageId, string scriptUri) 35 | { 36 | RequiredPackage package; 37 | bool hasUri = !String.IsNullOrEmpty(scriptUri); 38 | bool packageCreated = false; 39 | 40 | if (packageId.Contains("/") || packageId.Contains("\\")) 41 | { 42 | if (!hasUri) 43 | { 44 | scriptUri = packageId; 45 | hasUri = true; 46 | } 47 | 48 | packageId = DerivePackageIdFromUri(scriptUri); 49 | 50 | if (packageId.Length == 0) 51 | throw new ArgumentException( 52 | "The provided packageId is not a valid package name. The packageId must be a valid file path or uri if path characters are contained in the name."); 53 | } 54 | 55 | if (!RequireManager.TryGetPackage(packageId, out package)) 56 | { 57 | if (!hasUri) 58 | { 59 | throw new KeyNotFoundException(String.Format("The package with ID {0} was not found, did you register this package?", packageId)); 60 | } 61 | 62 | package = new RequiredPackage {PackageId = packageId, ScriptUri = scriptUri}; 63 | packageCreated = true; 64 | } 65 | 66 | var options = new ExecutionOptions 67 | { 68 | HostObjects = package.HostObjects, 69 | HostTypes = package.HostTypes 70 | }; 71 | 72 | Engine.ApplyOptions(options); 73 | 74 | if (!String.IsNullOrEmpty(package.ScriptUri)) 75 | { 76 | var compiledScript = Compiler.Compile(new IncludeScript {Uri = package.ScriptUri, PrependCode = "var " + packageId + " = {};"}); 77 | 78 | Engine.Execute(compiledScript); 79 | 80 | var outputObject = DynamicExtensions.GetProperty(Engine.Script, packageId); 81 | 82 | if (outputObject is Undefined) 83 | { 84 | //try to find pascal case if camel is not present. 85 | outputObject = DynamicExtensions.GetProperty(Engine.Script, packageId.ToPascalCase()); 86 | } 87 | 88 | if (packageCreated) 89 | { 90 | RequireManager.RegisterPackage(package); 91 | } 92 | 93 | return outputObject.exports; 94 | } 95 | 96 | if (options.HostObjects.SafeAny()) 97 | return options.HostObjects[0]; 98 | 99 | return null; 100 | } 101 | 102 | private string DerivePackageIdFromUri(string path) 103 | { 104 | string[] segments = path.Split(new []{'/','\\'}, StringSplitOptions.RemoveEmptyEntries); 105 | 106 | var resource = segments[segments.Length - 1]; 107 | 108 | var periodIndex = resource.IndexOfAny(new[]{'.','?'}); 109 | 110 | if (periodIndex > 0) 111 | { 112 | resource = resource.Substring(0, periodIndex); 113 | } 114 | 115 | return resource.ToCamelCase(); 116 | 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Loaders/ScriptLoadManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ClearScript.Manager.Loaders 5 | { 6 | /// 7 | /// Manages the loading of scripts for the runtime manager. 8 | /// 9 | public static class ScriptLoadManager 10 | { 11 | private static readonly List _loaders = new List {new FileScriptLoader()}; 12 | 13 | /// 14 | /// Register a script loader with the manager. 15 | /// 16 | /// The script loader to register. 17 | public static void RegisterLoader(this IScriptLoader loader) 18 | { 19 | _loaders.Add(loader); 20 | } 21 | 22 | /// 23 | /// Uses the manager to load a script. 24 | /// 25 | /// The script to load. 26 | public static void LoadScript(this IncludeScript script) 27 | { 28 | foreach (var scriptLoader in _loaders) 29 | { 30 | if (scriptLoader.ShouldUse(script)) 31 | { 32 | try { 33 | scriptLoader.LoadCode(script); 34 | return; 35 | } 36 | catch (Exception ex) 37 | { 38 | throw new ArgumentException(string.Format("{0} failed to load script with Script ID:{1} and Script Uri:{2}. Check InnerException for more info.", 39 | scriptLoader.Name, script.ScriptId, script.Uri), ex); 40 | } 41 | } 42 | } 43 | 44 | throw new ArgumentException( 45 | string.Format("The provided script could not be loaded with any of the available script loaders. Script ID:{0} Script Uri:{1}.", script.ScriptId, script.Uri)); 46 | } 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/ManagerPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | 4 | namespace ClearScript.Manager 5 | { 6 | /// 7 | /// Defines a pool from which Runtime Managers are requested. 8 | /// 9 | public interface IManagerPool 10 | { 11 | /// 12 | /// Gets a runtime from the pool. Blocks until a manager becomes available. 13 | /// 14 | /// The next available IRuntimeManager. 15 | IRuntimeManager GetRuntime(); 16 | 17 | /// 18 | /// Returns a Runtime Manager to the pool. 19 | /// 20 | /// The Runtime Manager to return to the pool. 21 | void ReturnToPool(IRuntimeManager runtimeManager); 22 | } 23 | 24 | /// 25 | /// Defines a pool from which Runtime Managers are requested. 26 | /// 27 | public class ManagerPool : IManagerPool 28 | { 29 | /// 30 | /// Static reference to the current pool of Runtime Managers. 31 | /// 32 | public static IManagerPool CurrentPool; 33 | 34 | private readonly object _addLock = new object(); 35 | 36 | /// 37 | /// Current count of Runtimes within the pool. 38 | /// 39 | public int RuntimeCurrentCount = 0; 40 | 41 | private readonly BlockingCollection _availableRuntimes = new BlockingCollection(); 42 | private readonly IManagerSettings _settings; 43 | 44 | /// 45 | /// Creates a new Runtime Manager Pool. 46 | /// 47 | /// Settings to apply to the Runtime Manager. 48 | public ManagerPool(IManagerSettings settings) 49 | { 50 | if(settings == null) 51 | throw new ArgumentNullException("settings", "Settings must be supplied to the RuntimePool."); 52 | 53 | _settings = settings; 54 | } 55 | 56 | /// 57 | /// Initializes the CurrentPool with the provided settings. 58 | /// 59 | /// Settings to apply. 60 | public static void InitializeCurrentPool(IManagerSettings settings) 61 | { 62 | CurrentPool = new ManagerPool(settings); 63 | } 64 | 65 | public IRuntimeManager GetRuntime() 66 | { 67 | IRuntimeManager manager; 68 | if (_availableRuntimes.TryTake(out manager)) 69 | return manager; 70 | 71 | int runtimeMaxCount = _settings.RuntimeMaxCount; 72 | if (RuntimeCurrentCount < runtimeMaxCount) 73 | { 74 | lock (_addLock) 75 | { 76 | if (RuntimeCurrentCount < runtimeMaxCount) 77 | { 78 | var runtime = new RuntimeManager(_settings); 79 | RuntimeCurrentCount++; 80 | return runtime; 81 | } 82 | } 83 | } 84 | return _availableRuntimes.Take(); 85 | } 86 | 87 | public void ReturnToPool(IRuntimeManager runtimeManager) 88 | { 89 | _availableRuntimes.Add(runtimeManager); 90 | } 91 | 92 | } 93 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/ManagerScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClearScript.Manager 4 | { 5 | /// 6 | /// Scope in which a Runtime Manager is requested from the pool and returned upon completion. 7 | /// 8 | public class ManagerScope : IDisposable 9 | { 10 | private bool _disposed; 11 | 12 | /// 13 | /// Creates a new ManagerScope and requests a RuntimeManager. 14 | /// 15 | public ManagerScope() 16 | { 17 | RuntimeManager = ManagerPool.CurrentPool.GetRuntime(); 18 | } 19 | 20 | /// 21 | /// Allows access to the allocated Runtime Manager from within this scope. 22 | /// 23 | public IRuntimeManager RuntimeManager { get; private set; } 24 | 25 | /// 26 | /// Disposed the object and returns the Runtime Manager to the pool. 27 | /// 28 | public void Dispose() 29 | { 30 | if (!_disposed) 31 | { 32 | RuntimeManager.Cleanup(); 33 | ManagerPool.CurrentPool.ReturnToPool(RuntimeManager); 34 | _disposed = true; 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("ClearScript.Manager")] 8 | [assembly: AssemblyDescription("ClearScript Manager encapsulates the use of the ClearScript V8 engine in multi-use scenarios. Newest version supports ClearScript 5.4 on .Net 4.5")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("ClearScript.Manager")] 12 | [assembly: AssemblyCopyright("Copyright © 2014, 2015 Eric Swann et. al. - All rights reserved.")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("e9b2e119-e4ec-4648-bed4-9609484f8356")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.3.5.*")] 35 | [assembly: AssemblyFileVersion("1.3.5.*")] 36 | -------------------------------------------------------------------------------- /src/ClearScript.Manager/ScriptCompiler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using ClearScript.Manager.Caching; 4 | using ClearScript.Manager.Loaders; 5 | using Microsoft.ClearScript.V8; 6 | 7 | namespace ClearScript.Manager 8 | { 9 | internal class ScriptCompiler 10 | { 11 | private readonly LruCache _scriptCache; 12 | private readonly IManagerSettings _settings; 13 | private readonly V8Runtime _v8Runtime; 14 | 15 | public ScriptCompiler(V8Runtime v8Runtime, IManagerSettings settings) 16 | { 17 | _settings = settings; 18 | _v8Runtime = v8Runtime; 19 | _scriptCache = new LruCache(LurchTableOrder.Access, settings.ScriptCacheMaxCount); 20 | } 21 | 22 | public V8Script Compile(string scriptId, string code, bool addToCache = true, int? cacheExpirationSeconds = null) 23 | { 24 | CachedV8Script cachedScript; 25 | if (TryGetCached(scriptId, out cachedScript)) 26 | { 27 | return cachedScript.Script; 28 | } 29 | 30 | V8Script compiledScript = _v8Runtime.Compile(scriptId, code); 31 | 32 | if (addToCache) 33 | { 34 | if (!cacheExpirationSeconds.HasValue) 35 | { 36 | cacheExpirationSeconds = _settings.ScriptCacheExpirationSeconds; 37 | } 38 | if (cacheExpirationSeconds > 0) 39 | { 40 | var cacheEntry = new CachedV8Script(compiledScript, cacheExpirationSeconds.Value); 41 | _scriptCache.AddOrUpdate(scriptId, cacheEntry, (key, original) => cacheEntry); 42 | } 43 | } 44 | 45 | return compiledScript; 46 | } 47 | 48 | public V8Script Compile(IncludeScript script, bool addToCache = true, int? cacheExpirationSeconds = null) 49 | { 50 | CachedV8Script cachedScript; 51 | 52 | script.EnsureScriptId(); 53 | 54 | if (TryGetCached(script.ScriptId, out cachedScript)) 55 | { 56 | return cachedScript.Script; 57 | } 58 | 59 | if (string.IsNullOrEmpty(script.Code) && !string.IsNullOrEmpty(script.Uri)) 60 | { 61 | script.LoadScript(); 62 | } 63 | if (!string.IsNullOrEmpty(script.Code)) 64 | { 65 | if (!string.IsNullOrEmpty(script.PrependCode) || !string.IsNullOrEmpty(script.AppendCode)) 66 | { 67 | var builder = new StringBuilder(); 68 | builder.Append(script.PrependCode).Append(script.Code).Append(script.AppendCode); 69 | return Compile(script.ScriptId, builder.ToString(), addToCache, cacheExpirationSeconds); 70 | } 71 | return Compile(script.ScriptId, script.Code, addToCache, cacheExpirationSeconds); 72 | } 73 | return null; 74 | } 75 | 76 | public bool TryGetCached(string scriptId, out CachedV8Script cachedScript) 77 | { 78 | if (_scriptCache.TryGetValue(scriptId, out cachedScript)) 79 | { 80 | if (cachedScript.ExpiresOn > DateTime.UtcNow) 81 | { 82 | cachedScript.CacheHits++; 83 | return true; 84 | } 85 | _scriptCache.TryRemove(scriptId, out cachedScript); 86 | } 87 | cachedScript = null; 88 | return false; 89 | } 90 | 91 | } 92 | } -------------------------------------------------------------------------------- /src/ClearScript.Manager/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------