diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml new file mode 100644 index 0000000..bf199fd --- /dev/null +++ b/.github/workflows/dotnet-core.yml @@ -0,0 +1,59 @@ +name: Build .NET Core + +on: + push: + branches: + - master + - develop + - GA-* + +env: + MAIN_PROJECT: OneScript/OneScriptWeb.csproj + TEST_PROJECT: OneScriptWeb.Tests/OneScriptWeb.Tests.csproj + SOLUTION: OneScript.sln + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest] + dotnet-version: [3.1.301] + include: + - os: windows-latest + RID: win-x64 + target: netcoreapp3.1 + - os: ubuntu-latest + RID: linux-x64 + target: netcoreapp3.1 + defaults: + run: + working-directory: src + steps: + + # актуализация с сабмодулями + - uses: actions/checkout@v2 + with: + submodules: true + + # установка дотнет + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + # Сборка + - name: Build + run: dotnet build ${{env.MAIN_PROJECT}} -c Release -r ${{matrix.RID}} -f ${{ matrix.target }} -o ../artifact/${{matrix.target}}/${{matrix.RID}} + + # Тесты + - name: Test + run: dotnet test ${{env.TEST_PROJECT}} -c Release --runtime=${{matrix.RID}} -f ${{ matrix.target }} --logger="trx;LogFileName=${{matrix.RID}}.trx" --results-directory=testResults + + # Заливка в артефакты + - name: Artifact + uses: actions/upload-artifact@v2 + with: + name: oscript.web-${{matrix.RID}}.zip + path: ./artifact/${{matrix.target}}/${{matrix.RID}} diff --git a/Dockerfile b/Dockerfile index 7c398bc..fc04205 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env -WORKDIR /app - -# Copy everything else and build - -COPY . ./ -RUN dotnet restore OneScript/OneScriptWeb.csproj -RUN dotnet publish OneScript/OneScriptWeb.csproj -c Release -o /app/out -f netcoreapp2.2 -r debian-x64 - -# RUNTIME -#FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 -FROM ubuntu:18.04 - -RUN apt update -RUN apt install -y --no-install-recommends liblttng-ust0 libcurl4 libssl1.0.0 libkrb5-3 zlib1g libicu60 && \ - rm -rf /var/lib/apt/lists/* +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 ENV LANG ru_RU.UTF-8 @@ -22,7 +7,7 @@ ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_URLS=http://0.0.0.0:5000 WORKDIR /app -COPY --from=build-env /app/out /var/osp.net +COPY . /var/osp.net ENTRYPOINT ["/var/osp.net/OneScript.WebHost"] EXPOSE 5000 \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 96a5423..7fcaa41 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,17 +1,25 @@ pipeline { agent none - environment { - ReleaseNumber = '0.7.0' + + environment { + ReleaseNumber = '0.8.0' } stages { - stage('Build everything') - { + + stage('Build and test'){ options { skipDefaultCheckout() } - agent { - label 'windows' - } + agent { + docker { + image 'mcr.microsoft.com/dotnet/core/sdk:3.1' + label 'linux' + } + } + environment { + DOTNET_CLI_HOME = "/tmp/DOTNET_CLI_HOME" + } steps { + checkout( [$class: 'GitSCM', branches: [[name: "${env.BRANCH_NAME}"]], doGenerateSubmoduleConfigurations: false, @@ -24,39 +32,54 @@ pipeline { trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/EvilBeaver/OneScript.Web.git']]]) + + sh "dotnet build src/OneScript/OneScriptWeb.csproj -r linux-x64 /p:ReleaseNumber=${ReleaseNumber} -c Release -f netcoreapp3.1" + sh "dotnet build src/OneScript/OneScriptWeb.csproj -r win-x64 /p:ReleaseNumber=${ReleaseNumber} -c Release -f netcoreapp3.1" + sh ''' + rm -rf testResults + dotnet test src/OneScriptWeb.Tests/OneScriptWeb.Tests.csproj \ + -c Release \ + -f netcoreapp3.1 \ + --runtime win-x64 --logger="trx;LogFileName=win.trx" --results-directory=testResults - /*dir('src/OneScriptWeb.Tests'){ - bat ''' - @echo off - dotnet restore - dotnet xunit -nunit testresult.xml -configuration Release - ''' - - nunit testResultsPattern: 'testresult.xml' - }*/ + src/OneScriptWeb.Tests/OneScriptWeb.Tests.csproj \ + -c Release \ + -f netcoreapp3.1 \ + --runtime linux-x64 --logger="trx;LogFileName=linux.trx" --results-directory=testResults + '''.stripIndent() - dir('artifact'){ - deleteDir() - } - - dir('src'){ - bat ''' - @echo off - dotnet publish OneScript/OneScriptWeb.csproj -c Release -f net461 -o ../artifact/net461/win7-x64 -r win7-x64 - dotnet publish OneScript/OneScriptWeb.csproj -c Release -f net461 -o ../artifact/net461/debian-x64 -r debian-x64 - dotnet publish OneScript/OneScriptWeb.csproj -c Release -f netcoreapp2.2 -o ../artifact/core22/debian-x64 -r debian-x64 - ''' - } + mstest testResultsFile: 'testResults/*.trx' + + sh '''dotnet publish src/OneScript/OneScriptWeb.csproj \ + --no-build \ + -c Release + -f netcoreapp3.1 + -r win-x64 + -o artifact/core/win-x64 + + '''.stripIndent() + + sh '''dotnet publish src/OneScript/OneScriptWeb.csproj \ + --no-build \ + -c Release + -f netcoreapp3.1 + -r linux-x64 + -o artifact/core/linux-x64 + + '''.stripIndent() + + stash includes: 'artifact/**', name: 'buildResults' // новые версии дженкинса падают, если есть ранее зипованый артефакт fileOperations([fileDeleteOperation(excludes: '', includes: '*.zip')]) - zip archive: true, dir: 'artifact/net461/win7-x64', glob: '', zipFile: 'oscript.web-win7-x64.zip' - zip archive: true, dir: 'artifact/net461/debian-x64', glob: '', zipFile: 'oscript.web-debian-x64.zip' - zip archive: true, dir: 'artifact/core22/debian-x64', glob: '', zipFile: 'oscript.web-debian-x64-core.zip' + zip archive: true, dir: 'artifact/core/win-x64', glob: '', zipFile: 'oscript.web-win-x64.zip' + zip archive: true, dir: 'artifact/core/linux-x64', glob: '', zipFile: 'oscript.web-linux-x64.zip' } } - stage('Create docker image'){ + + stage('Create docker image') { + when { branch 'master' } options { skipDefaultCheckout() } agent { label 'linux' @@ -75,9 +98,11 @@ pipeline { submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/EvilBeaver/OneScript.Web.git']]]) + unstash 'buildResults' + withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'dockerpassword', usernameVariable: 'dockeruser')]) { - sh "docker build -t evilbeaver/oscript-web:${ReleaseNumber} --file Dockerfile src" - sh "docker login -p $dockerpassword -u $dockeruser && docker push evilbeaver/oscript-web:${ReleaseNumber}" + sh "docker build -t evilbeaver/oscript-web:${ReleaseNumber} --file Dockerfile src" + sh "docker login -p $dockerpassword -u $dockeruser && docker push evilbeaver/oscript-web:${ReleaseNumber}" } } } diff --git a/src/Include/OneScript b/src/Include/OneScript index 474406e..9673f28 160000 --- a/src/Include/OneScript +++ b/src/Include/OneScript @@ -1 +1 @@ -Subproject commit 474406e7b2b78766d53f53e9f4e4248c23c9b975 +Subproject commit 9673f2811b4fe51479034fcf65ba323f2030b7ce diff --git a/src/OneScript.sln b/src/OneScript.sln index 8d2cf3e..b3a471e 100644 --- a/src/OneScript.sln +++ b/src/OneScript.sln @@ -21,51 +21,36 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU - ReleaseNetStandard|Any CPU = ReleaseNetStandard|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {082351A7-DB5F-41F3-8337-CBAA7C877EC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {082351A7-DB5F-41F3-8337-CBAA7C877EC6}.Debug|Any CPU.Build.0 = Debug|Any CPU {082351A7-DB5F-41F3-8337-CBAA7C877EC6}.Release|Any CPU.ActiveCfg = Release|Any CPU {082351A7-DB5F-41F3-8337-CBAA7C877EC6}.Release|Any CPU.Build.0 = Release|Any CPU - {082351A7-DB5F-41F3-8337-CBAA7C877EC6}.ReleaseNetStandard|Any CPU.ActiveCfg = Release|Any CPU - {082351A7-DB5F-41F3-8337-CBAA7C877EC6}.ReleaseNetStandard|Any CPU.Build.0 = Release|Any CPU {894A3A1B-D6FC-4FA2-8712-953A1CA96875}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {894A3A1B-D6FC-4FA2-8712-953A1CA96875}.Debug|Any CPU.Build.0 = Debug|Any CPU {894A3A1B-D6FC-4FA2-8712-953A1CA96875}.Release|Any CPU.ActiveCfg = Release|Any CPU {894A3A1B-D6FC-4FA2-8712-953A1CA96875}.Release|Any CPU.Build.0 = Release|Any CPU - {894A3A1B-D6FC-4FA2-8712-953A1CA96875}.ReleaseNetStandard|Any CPU.ActiveCfg = Release|Any CPU - {894A3A1B-D6FC-4FA2-8712-953A1CA96875}.ReleaseNetStandard|Any CPU.Build.0 = Release|Any CPU {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Release|Any CPU.Build.0 = Release|Any CPU - {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.ReleaseNetStandard|Any CPU.ActiveCfg = ReleaseNetStandard|Any CPU - {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.ReleaseNetStandard|Any CPU.Build.0 = ReleaseNetStandard|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Release|Any CPU.Build.0 = Release|Any CPU - {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.ReleaseNetStandard|Any CPU.ActiveCfg = ReleaseNetStandard|Any CPU - {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.ReleaseNetStandard|Any CPU.Build.0 = ReleaseNetStandard|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Release|Any CPU.ActiveCfg = Release|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Release|Any CPU.Build.0 = Release|Any CPU - {778596E5-05C4-4775-A88B-34B3B48B56BA}.ReleaseNetStandard|Any CPU.ActiveCfg = Debug|Any CPU - {778596E5-05C4-4775-A88B-34B3B48B56BA}.ReleaseNetStandard|Any CPU.Build.0 = Debug|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Debug|Any CPU.Build.0 = Debug|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Release|Any CPU.ActiveCfg = Release|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Release|Any CPU.Build.0 = Release|Any CPU - {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.ReleaseNetStandard|Any CPU.ActiveCfg = Debug|Any CPU - {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.ReleaseNetStandard|Any CPU.Build.0 = Debug|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Release|Any CPU.Build.0 = Release|Any CPU - {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.ReleaseNetStandard|Any CPU.ActiveCfg = Debug|Any CPU - {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.ReleaseNetStandard|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/OneScript/Application/ApplicationInstance.cs b/src/OneScript/Application/ApplicationInstance.cs index 4e32c07..4769e47 100644 --- a/src/OneScript/Application/ApplicationInstance.cs +++ b/src/OneScript/Application/ApplicationInstance.cs @@ -1,18 +1,20 @@ -using ScriptEngine.Environment; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using ScriptEngine.Environment; using ScriptEngine.Machine.Contexts; using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Hangfire; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Routing; using OneScript.WebHost.BackgroundJobs; using OneScript.WebHost.Infrastructure; -using ScriptEngine; using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; -using Microsoft.Extensions.FileProviders; namespace OneScript.WebHost.Application { @@ -145,10 +147,15 @@ public void UseStaticFiles() [ContextMethod("ИспользоватьМаршруты")] public void UseMvcRoutes(string handler = null) { - if (handler == null) - _startupBuilder.UseMvcWithDefaultRoute(); + _startupBuilder.UseRouting(); + if (handler == default) + { + _startupBuilder.UseEndpoints(x => x.MapDefaultControllerRoute()); + } else + { CallRoutesRegistrationHandler(handler); + } } /// @@ -219,14 +226,13 @@ private void CallRoutesRegistrationHandler(string handler) var handlerIndex = GetScriptMethod(handler); var routesCol = new RoutesCollectionContext(); - CallScriptMethod(handlerIndex, new IValue[]{routesCol}); - _startupBuilder.UseMvc(routes => + _startupBuilder.UseEndpoints(routes => { foreach (var route in routesCol) { - routes.MapRoute(route.Name, route.Template, route.Defaults?.Select(x=> + routes.MapControllerRoute(route.Name, route.Template, route.Defaults?.Select(x=> { var kv = new KeyValuePair(x.Key.AsString(),ContextValuesMarshaller.ConvertToCLRObject(x.Value)); return kv; @@ -258,15 +264,10 @@ public static ApplicationInstance Create(ICodeSource src, IApplicationRuntime we var bc = compiler.Compile(src); var app = new ApplicationInstance(new LoadedModule(bc)); var machine = MachineInstance.Current; - webApp.Environment.LoadMemory(machine); + machine.PrepareThread(webApp.Environment); webApp.Engine.InitializeSDO(app); return app; } - - public void UseServices(IServiceProvider services) - { - //throw new NotImplementedException(); - } } } diff --git a/src/OneScript/Application/ContentActionResult.cs b/src/OneScript/Application/ContentActionResult.cs index cb2c236..5441c74 100644 --- a/src/OneScript/Application/ContentActionResult.cs +++ b/src/OneScript/Application/ContentActionResult.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Mvc; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/CookieOptionsWraper.cs b/src/OneScript/Application/CookieOptionsWraper.cs index e48eb7f..73f2d88 100644 --- a/src/OneScript/Application/CookieOptionsWraper.cs +++ b/src/OneScript/Application/CookieOptionsWraper.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using Microsoft.AspNetCore.Http; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/FileActionResult.cs b/src/OneScript/Application/FileActionResult.cs index 5bd2646..4df4b6b 100644 --- a/src/OneScript/Application/FileActionResult.cs +++ b/src/OneScript/Application/FileActionResult.cs @@ -1,7 +1,11 @@ -using System; -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.IO; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using ScriptEngine.HostedScript.Library.Binary; diff --git a/src/OneScript/Application/FormDataCollectionContext.cs b/src/OneScript/Application/FormDataCollectionContext.cs index d5eb0c3..11334be 100644 --- a/src/OneScript/Application/FormDataCollectionContext.cs +++ b/src/OneScript/Application/FormDataCollectionContext.cs @@ -1,8 +1,12 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; diff --git a/src/OneScript/Application/FormFileContext.cs b/src/OneScript/Application/FormFileContext.cs index 3cfbab1..4803d29 100644 --- a/src/OneScript/Application/FormFileContext.cs +++ b/src/OneScript/Application/FormFileContext.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using Microsoft.AspNetCore.Http; using ScriptEngine.HostedScript.Library; using ScriptEngine.HostedScript.Library.Binary; diff --git a/src/OneScript/Application/FormFilesCollectionContext.cs b/src/OneScript/Application/FormFilesCollectionContext.cs index 352020f..35e31de 100644 --- a/src/OneScript/Application/FormFilesCollectionContext.cs +++ b/src/OneScript/Application/FormFilesCollectionContext.cs @@ -1,8 +1,13 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections; using System.Collections.Generic; using Microsoft.AspNetCore.Http; -using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; @@ -73,4 +78,4 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/OneScript/Application/HttpRequestImpl.cs b/src/OneScript/Application/HttpRequestImpl.cs index ebdc0e8..0e7b74c 100644 --- a/src/OneScript/Application/HttpRequestImpl.cs +++ b/src/OneScript/Application/HttpRequestImpl.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Http; using ScriptEngine.HostedScript.Library; using ScriptEngine.HostedScript.Library.Binary; diff --git a/src/OneScript/Application/HttpResponseImpl.cs b/src/OneScript/Application/HttpResponseImpl.cs index de248d5..8c7e622 100644 --- a/src/OneScript/Application/HttpResponseImpl.cs +++ b/src/OneScript/Application/HttpResponseImpl.cs @@ -1,9 +1,12 @@ -using System; -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using ScriptEngine.HostedScript.Library; using ScriptEngine.HostedScript.Library.Binary; diff --git a/src/OneScript/Application/ModelStateDictionaryWrapper.cs b/src/OneScript/Application/ModelStateDictionaryWrapper.cs index f67e822..b95b7d7 100644 --- a/src/OneScript/Application/ModelStateDictionaryWrapper.cs +++ b/src/OneScript/Application/ModelStateDictionaryWrapper.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Mvc.ModelBinding; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/RedirectActionResult.cs b/src/OneScript/Application/RedirectActionResult.cs index d0ab8fd..97a186d 100644 --- a/src/OneScript/Application/RedirectActionResult.cs +++ b/src/OneScript/Application/RedirectActionResult.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Mvc; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/RouteDescriptionContext.cs b/src/OneScript/Application/RouteDescriptionContext.cs index 018860e..33d809e 100644 --- a/src/OneScript/Application/RouteDescriptionContext.cs +++ b/src/OneScript/Application/RouteDescriptionContext.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/RoutesCollectionContext.cs b/src/OneScript/Application/RoutesCollectionContext.cs index 1dc7fae..f32e04a 100644 --- a/src/OneScript/Application/RoutesCollectionContext.cs +++ b/src/OneScript/Application/RoutesCollectionContext.cs @@ -1,8 +1,12 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/ScriptedController.cs b/src/OneScript/Application/ScriptedController.cs index 51310e7..6c291b2 100644 --- a/src/OneScript/Application/ScriptedController.cs +++ b/src/OneScript/Application/ScriptedController.cs @@ -1,3 +1,9 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; @@ -382,11 +388,5 @@ private ViewActionResult DefaultViewResult() { return new ViewActionResult() { ViewData = ViewData }; } - - // TODO: Костыль вызванный ошибкой https://github.com/EvilBeaver/OneScript/issues/660 - internal static int GetOwnMethodsRelectionOffset() - { - return _ownMethods.Count; - } } } diff --git a/src/OneScript/Application/ScriptedMiddleware.cs b/src/OneScript/Application/ScriptedMiddleware.cs index c382dcd..ed97397 100644 --- a/src/OneScript/Application/ScriptedMiddleware.cs +++ b/src/OneScript/Application/ScriptedMiddleware.cs @@ -1,6 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/src/OneScript/Application/ScriptedViewComponent.cs b/src/OneScript/Application/ScriptedViewComponent.cs index acd2b6d..34d906b 100644 --- a/src/OneScript/Application/ScriptedViewComponent.cs +++ b/src/OneScript/Application/ScriptedViewComponent.cs @@ -1,14 +1,16 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.Extensions.DependencyInjection; using OneScript.WebHost.Infrastructure; -using ScriptEngine; -using ScriptEngine.Environment; using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/SessionImpl.cs b/src/OneScript/Application/SessionImpl.cs index 5e5bc74..0594437 100644 --- a/src/OneScript/Application/SessionImpl.cs +++ b/src/OneScript/Application/SessionImpl.cs @@ -1,4 +1,10 @@ -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Linq; using Microsoft.AspNetCore.Http; using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; @@ -106,4 +112,4 @@ public void Remove(string key) public object UnderlyingObject => _requestSession; } -} \ No newline at end of file +} diff --git a/src/OneScript/Application/StatusCodeActionResult.cs b/src/OneScript/Application/StatusCodeActionResult.cs index 9f39414..b324609 100644 --- a/src/OneScript/Application/StatusCodeActionResult.cs +++ b/src/OneScript/Application/StatusCodeActionResult.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Mvc; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Application/ViewActionResult.cs b/src/OneScript/Application/ViewActionResult.cs index 2b50217..89d4d34 100644 --- a/src/OneScript/Application/ViewActionResult.cs +++ b/src/OneScript/Application/ViewActionResult.cs @@ -1,13 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ViewFeatures; -using OneScript.WebHost.Infrastructure; -using ScriptEngine.HostedScript.Library; -using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; namespace OneScript.WebHost.Application diff --git a/src/OneScript/Application/ViewComponentContentResult.cs b/src/OneScript/Application/ViewComponentContentResult.cs index e398f73..78e5b64 100644 --- a/src/OneScript/Application/ViewComponentContentResult.cs +++ b/src/OneScript/Application/ViewComponentContentResult.cs @@ -1,6 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewComponents; diff --git a/src/OneScript/Application/ViewComponentViewResult.cs b/src/OneScript/Application/ViewComponentViewResult.cs index 77f2d95..4b72fd2 100644 --- a/src/OneScript/Application/ViewComponentViewResult.cs +++ b/src/OneScript/Application/ViewComponentViewResult.cs @@ -1,6 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewComponents; diff --git a/src/OneScript/Application/ViewDataDictionaryWrapper.cs b/src/OneScript/Application/ViewDataDictionaryWrapper.cs index 6a5e5ea..8fd6820 100644 --- a/src/OneScript/Application/ViewDataDictionaryWrapper.cs +++ b/src/OneScript/Application/ViewDataDictionaryWrapper.cs @@ -1,10 +1,15 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Collections; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ViewFeatures; using OneScript.WebHost.Infrastructure; -using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; @@ -94,4 +99,4 @@ public ViewDataDictionary GetDictionary() return realDict; } } -} \ No newline at end of file +} diff --git a/src/OneScript/Application/WebGlobalContext.cs b/src/OneScript/Application/WebGlobalContext.cs index 2fefd6e..f30bb1a 100644 --- a/src/OneScript/Application/WebGlobalContext.cs +++ b/src/OneScript/Application/WebGlobalContext.cs @@ -1,10 +1,14 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Reflection; using OneScript.WebHost.Infrastructure; -using ScriptEngine; using ScriptEngine.Environment; using ScriptEngine.HostedScript; using ScriptEngine.HostedScript.Library; diff --git a/src/OneScript/Authorization/AuthorizationModule.cs b/src/OneScript/Authorization/AuthorizationModule.cs index af22685..899e154 100644 --- a/src/OneScript/Authorization/AuthorizationModule.cs +++ b/src/OneScript/Authorization/AuthorizationModule.cs @@ -1,7 +1,12 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.FileProviders; using OneScript.WebHost.Infrastructure; diff --git a/src/OneScript/Authorization/CustomAuthExtensions.cs b/src/OneScript/Authorization/CustomAuthExtensions.cs index 59b0e19..675ba2a 100644 --- a/src/OneScript/Authorization/CustomAuthExtensions.cs +++ b/src/OneScript/Authorization/CustomAuthExtensions.cs @@ -1,11 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; namespace OneScript.WebHost.Authorization { diff --git a/src/OneScript/Authorization/CustomAuthRequirement.cs b/src/OneScript/Authorization/CustomAuthRequirement.cs index 3f86c0b..c7bf020 100644 --- a/src/OneScript/Authorization/CustomAuthRequirement.cs +++ b/src/OneScript/Authorization/CustomAuthRequirement.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using Microsoft.AspNetCore.Authorization; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs b/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs index 5064775..1c428af 100644 --- a/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs +++ b/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs @@ -1,6 +1,11 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.FileProviders; @@ -26,7 +31,7 @@ private void AppendScriptedHandlers(IApplicationRuntime runtime, IFileProvider f if(!authFile.Exists || authFile.IsDirectory) return; - runtime.Environment.LoadMemory(MachineInstance.Current); + MachineInstance.Current.PrepareThread(runtime.Environment); var codeSource = new FileInfoCodeSource(authFile); runtime.DebugCurrentThread(); diff --git a/src/OneScript/Authorization/ScriptedAuthorizationHandler.cs b/src/OneScript/Authorization/ScriptedAuthorizationHandler.cs index a425705..8315429 100644 --- a/src/OneScript/Authorization/ScriptedAuthorizationHandler.cs +++ b/src/OneScript/Authorization/ScriptedAuthorizationHandler.cs @@ -1,5 +1,10 @@ -using System; -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; diff --git a/src/OneScript/BackgroundJobs/BackgroundJobContext.cs b/src/OneScript/BackgroundJobs/BackgroundJobContext.cs index 607fe61..d9a9d58 100644 --- a/src/OneScript/BackgroundJobs/BackgroundJobContext.cs +++ b/src/OneScript/BackgroundJobs/BackgroundJobContext.cs @@ -1,4 +1,10 @@ -using ScriptEngine.Machine.Contexts; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using ScriptEngine.Machine.Contexts; namespace OneScript.WebHost.BackgroundJobs { @@ -12,4 +18,4 @@ public BackgroundJobContext(string jobId) _jobId = jobId; } } -} \ No newline at end of file +} diff --git a/src/OneScript/BackgroundJobs/BackgroundJobsExtensions.cs b/src/OneScript/BackgroundJobs/BackgroundJobsExtensions.cs index 9d2258a..4fe3c01 100644 --- a/src/OneScript/BackgroundJobs/BackgroundJobsExtensions.cs +++ b/src/OneScript/BackgroundJobs/BackgroundJobsExtensions.cs @@ -1,12 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Configuration; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Linq; -using System.Threading.Tasks; using Hangfire; using Hangfire.MemoryStorage; using Hangfire.PostgreSql; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; diff --git a/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs b/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs index 2df07f7..10eee55 100644 --- a/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs +++ b/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs @@ -1,8 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using Hangfire; +using OneScript.WebHost.Infrastructure; using ScriptEngine; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; @@ -48,8 +52,7 @@ public void WaitForCompletion() // должен быть public, т.к. hangfire не умеет вызывать private public static void PerformAction(string module, string method) { - var machine = MachineInstance.Current; - _globalEnv.LoadMemory(machine); + MachineInstance.Current.PrepareThread(_globalEnv); var scriptObject = (IRuntimeContextInstance)_globalEnv.GetGlobalProperty(module); var methodId = scriptObject.FindMethod(method); diff --git a/src/OneScript/BackgroundJobs/CronWrapper.cs b/src/OneScript/BackgroundJobs/CronWrapper.cs index 3f6eaa1..0450468 100644 --- a/src/OneScript/BackgroundJobs/CronWrapper.cs +++ b/src/OneScript/BackgroundJobs/CronWrapper.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Hangfire; using ScriptEngine.Machine.Contexts; @@ -84,4 +90,4 @@ public static CronWrapper Constructor() } -} \ No newline at end of file +} diff --git a/src/OneScript/BackgroundJobs/DashboardAutorizationFilter.cs b/src/OneScript/BackgroundJobs/DashboardAutorizationFilter.cs index a754f5e..91bafa9 100644 --- a/src/OneScript/BackgroundJobs/DashboardAutorizationFilter.cs +++ b/src/OneScript/BackgroundJobs/DashboardAutorizationFilter.cs @@ -1,4 +1,10 @@ -using Hangfire.Dashboard; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Hangfire.Dashboard; namespace OneScript.WebHost.BackgroundJobs { @@ -12,4 +18,4 @@ public bool Authorize(DashboardContext context) return httpContext.User.Identity.IsAuthenticated; } } -} \ No newline at end of file +} diff --git a/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs b/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs index 7b09bea..40d3cfc 100644 --- a/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs +++ b/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs @@ -1,13 +1,17 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Collections.Generic; -using System.Linq; using ScriptEngine.Machine.Contexts; using ScriptEngine.Machine; using Hangfire; using Hangfire.Storage; -using Microsoft.Extensions.DependencyInjection; using OneScript.WebHost.Database; using OneScript.WebHost.Infrastructure; using ScriptEngine; @@ -94,7 +98,7 @@ public void RunContinuationsTask(string TaskIDFrom, string module, string method public static void PerformAction(string module, string method) { - _globalEnv.LoadMemory(MachineInstance.Current); + MachineInstance.Current.PrepareThread(_globalEnv); ApplicationDbContext dbContext = null; try @@ -121,4 +125,4 @@ public static void PerformAction(string module, string method) } } } -} \ No newline at end of file +} diff --git a/src/OneScript/BackgroundJobs/TimeSpanWrapper.cs b/src/OneScript/BackgroundJobs/TimeSpanWrapper.cs index a571530..5213c52 100644 --- a/src/OneScript/BackgroundJobs/TimeSpanWrapper.cs +++ b/src/OneScript/BackgroundJobs/TimeSpanWrapper.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using ScriptEngine.Machine.Contexts; namespace OneScript.WebHost.BackgroundJobs @@ -59,4 +65,4 @@ public static TimeSpanWrapper Constructor() } } -} \ No newline at end of file +} diff --git a/src/OneScript/Database/ApplicationDbContext.cs b/src/OneScript/Database/ApplicationDbContext.cs index ee44943..f3eb42c 100644 --- a/src/OneScript/Database/ApplicationDbContext.cs +++ b/src/OneScript/Database/ApplicationDbContext.cs @@ -1,4 +1,10 @@ -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using OneScript.WebHost.Identity; using OneScript.WebHost.Infrastructure; diff --git a/src/OneScript/Database/DatabaseExtensions.cs b/src/OneScript/Database/DatabaseExtensions.cs index 927ed1e..d98c841 100644 --- a/src/OneScript/Database/DatabaseExtensions.cs +++ b/src/OneScript/Database/DatabaseExtensions.cs @@ -1,8 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Configuration; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; diff --git a/src/OneScript/Database/DbQueryContext.cs b/src/OneScript/Database/DbQueryContext.cs index ef8b2ed..08309b9 100644 --- a/src/OneScript/Database/DbQueryContext.cs +++ b/src/OneScript/Database/DbQueryContext.cs @@ -1,4 +1,10 @@ -using System.Data.Common; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Data.Common; using Microsoft.EntityFrameworkCore; using ScriptEngine.HostedScript.Library; using ScriptEngine.Machine; diff --git a/src/OneScript/Database/InfobaseContext.cs b/src/OneScript/Database/InfobaseContext.cs index 5a73b28..55f0646 100644 --- a/src/OneScript/Database/InfobaseContext.cs +++ b/src/OneScript/Database/InfobaseContext.cs @@ -1,5 +1,10 @@ -using System; -using Microsoft.Extensions.DependencyInjection; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using ScriptEngine.Machine.Contexts; namespace OneScript.WebHost.Database diff --git a/src/OneScript/Database/InfobaseUserContext.cs b/src/OneScript/Database/InfobaseUserContext.cs index feb8720..5941452 100644 --- a/src/OneScript/Database/InfobaseUserContext.cs +++ b/src/OneScript/Database/InfobaseUserContext.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using Microsoft.AspNetCore.Identity; using OneScript.WebHost.Identity; using ScriptEngine.HostedScript.Library; diff --git a/src/OneScript/Database/InfobaseUsersManagerContext.cs b/src/OneScript/Database/InfobaseUsersManagerContext.cs index 2731a96..852f629 100644 --- a/src/OneScript/Database/InfobaseUsersManagerContext.cs +++ b/src/OneScript/Database/InfobaseUsersManagerContext.cs @@ -1,10 +1,13 @@ -using System; -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using OneScript.WebHost.Identity; using ScriptEngine.HostedScript.Library; diff --git a/src/OneScript/Database/QueryResult.cs b/src/OneScript/Database/QueryResult.cs index a20f940..80eb0de 100644 --- a/src/OneScript/Database/QueryResult.cs +++ b/src/OneScript/Database/QueryResult.cs @@ -1,4 +1,10 @@ - +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using ScriptEngine.HostedScript.Library.Binary; using ScriptEngine.HostedScript.Library.ValueTable; using ScriptEngine.Machine; @@ -107,4 +113,4 @@ public Boolean IsEmpty() return _resultTable.Count() == 0; } } -} \ No newline at end of file +} diff --git a/src/OneScript/Identity/ApplicationRole.cs b/src/OneScript/Identity/ApplicationRole.cs index b8d43e3..bb31c70 100644 --- a/src/OneScript/Identity/ApplicationRole.cs +++ b/src/OneScript/Identity/ApplicationRole.cs @@ -1,9 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; namespace OneScript.WebHost.Identity { diff --git a/src/OneScript/Identity/ApplicationUser.cs b/src/OneScript/Identity/ApplicationUser.cs index 6dd142e..7eec5ad 100644 --- a/src/OneScript/Identity/ApplicationUser.cs +++ b/src/OneScript/Identity/ApplicationUser.cs @@ -1,9 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; namespace OneScript.WebHost.Identity { diff --git a/src/OneScript/Identity/IdentityExtensions.cs b/src/OneScript/Identity/IdentityExtensions.cs index 8b009c4..a113b47 100644 --- a/src/OneScript/Identity/IdentityExtensions.cs +++ b/src/OneScript/Identity/IdentityExtensions.cs @@ -1,15 +1,14 @@ -using System; -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; -using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.Extensions.Configuration; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using OneScript.WebHost.Database; namespace OneScript.WebHost.Identity @@ -40,14 +39,11 @@ public static void AddIdentityByConfiguration(this IServiceCollection services, options.AccessDeniedPath = cookieOpts["AccessDeniedPath"] ?? options.AccessDeniedPath; options.ExpireTimeSpan = cookieOpts["ExpireTimeSpan"] == null? options.ExpireTimeSpan : TimeSpan.Parse(cookieOpts["ExpireTimeSpan"]); options.ReturnUrlParameter = cookieOpts["ReturnUrlParameter"] ?? options.ReturnUrlParameter; - options.CookieName = cookieOpts["CookieName"] ?? "OscriptWeb.Identity.Application"; + options.Cookie.Name = cookieOpts["CookieName"] ?? "OscriptWeb.Identity.Application"; cookieOpts.Bind("Cookie", options.Cookie); }); } - - services.TryAddScoped(); - } private static void ProcessSecurityOptions(IdentityOptions options, IConfigurationSection security) diff --git a/src/OneScript/Infrastructure/AnnotationAttributeMapper.cs b/src/OneScript/Infrastructure/AnnotationAttributeMapper.cs index b74d8dc..c5a293b 100644 --- a/src/OneScript/Infrastructure/AnnotationAttributeMapper.cs +++ b/src/OneScript/Infrastructure/AnnotationAttributeMapper.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using OneScript.WebHost.Infrastructure.Implementations; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using ScriptEngine.Machine; namespace OneScript.WebHost.Infrastructure diff --git a/src/OneScript/Infrastructure/AnnotationException.cs b/src/OneScript/Infrastructure/AnnotationException.cs index 0c58126..5df9fa4 100644 --- a/src/OneScript/Infrastructure/AnnotationException.cs +++ b/src/OneScript/Infrastructure/AnnotationException.cs @@ -1,8 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ScriptEngine; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using ScriptEngine.Machine; namespace OneScript.WebHost.Infrastructure diff --git a/src/OneScript/Infrastructure/AppStarter.cs b/src/OneScript/Infrastructure/AppStarter.cs index 1cc304d..f21cd47 100644 --- a/src/OneScript/Infrastructure/AppStarter.cs +++ b/src/OneScript/Infrastructure/AppStarter.cs @@ -1,8 +1,13 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.IO; using System.Linq; using System.Reflection; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; @@ -103,4 +108,4 @@ public string[] GetCommandLineArguments() throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/src/OneScript/Infrastructure/CustomMarshaller.cs b/src/OneScript/Infrastructure/CustomMarshaller.cs index 61eb841..087f7b8 100644 --- a/src/OneScript/Infrastructure/CustomMarshaller.cs +++ b/src/OneScript/Infrastructure/CustomMarshaller.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; @@ -106,4 +112,4 @@ public static object ConvertToCLRObject(IValue value) } } } -} \ No newline at end of file +} diff --git a/src/OneScript/Infrastructure/DbContextProvider.cs b/src/OneScript/Infrastructure/DbContextProvider.cs index 52c7fc1..2fb00bb 100644 --- a/src/OneScript/Infrastructure/DbContextProvider.cs +++ b/src/OneScript/Infrastructure/DbContextProvider.cs @@ -1,9 +1,9 @@ -// /*---------------------------------------------------------- -// This Source Code Form is subject to the terms of the -// Mozilla Public License, v.2.0. If a copy of the MPL -// was not distributed with this file, You can obtain one -// at http://mozilla.org/MPL/2.0/. -// ----------------------------------------------------------*/ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ using Microsoft.EntityFrameworkCore; using OneScript.WebHost.Database; diff --git a/src/OneScript/Infrastructure/DynamicContextWrapper.cs b/src/OneScript/Infrastructure/DynamicContextWrapper.cs index 07f0691..330d9ab 100644 --- a/src/OneScript/Infrastructure/DynamicContextWrapper.cs +++ b/src/OneScript/Infrastructure/DynamicContextWrapper.cs @@ -1,10 +1,14 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections; using System.Collections.Generic; using System.Dynamic; using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; diff --git a/src/OneScript/Infrastructure/ExtensionsCompiler.cs b/src/OneScript/Infrastructure/ExtensionsCompiler.cs index b6f90e9..b63e6d9 100644 --- a/src/OneScript/Infrastructure/ExtensionsCompiler.cs +++ b/src/OneScript/Infrastructure/ExtensionsCompiler.cs @@ -1,4 +1,10 @@ -#if NET461 +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +#if NET461 using System; using System.CodeDom.Compiler; using System.Collections.Generic; @@ -70,4 +76,4 @@ public void AddSource(string code) } } } -#endif \ No newline at end of file +#endif diff --git a/src/OneScript/Infrastructure/FileInfoCodeSource.cs b/src/OneScript/Infrastructure/FileInfoCodeSource.cs index bcb36ea..5d56d5e 100644 --- a/src/OneScript/Infrastructure/FileInfoCodeSource.cs +++ b/src/OneScript/Infrastructure/FileInfoCodeSource.cs @@ -1,8 +1,11 @@ -using System; -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.IO; -using System.Linq; -using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; using ScriptEngine.Environment; diff --git a/src/OneScript/Infrastructure/IApplicationFactory.cs b/src/OneScript/Infrastructure/IApplicationFactory.cs index b25c53c..3b8a5a9 100644 --- a/src/OneScript/Infrastructure/IApplicationFactory.cs +++ b/src/OneScript/Infrastructure/IApplicationFactory.cs @@ -1,6 +1,11 @@ -using Microsoft.AspNetCore.Hosting; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using OneScript.WebHost.Application; -using ScriptEngine.Machine; namespace OneScript.WebHost.Infrastructure { diff --git a/src/OneScript/Infrastructure/IApplicationRuntime.cs b/src/OneScript/Infrastructure/IApplicationRuntime.cs index 4b345a7..79ffe41 100644 --- a/src/OneScript/Infrastructure/IApplicationRuntime.cs +++ b/src/OneScript/Infrastructure/IApplicationRuntime.cs @@ -1,5 +1,10 @@ -using ScriptEngine; -using ScriptEngine.Environment; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using ScriptEngine; namespace OneScript.WebHost.Infrastructure { @@ -7,5 +12,7 @@ public interface IApplicationRuntime { ScriptingEngine Engine { get; } RuntimeEnvironment Environment { get; } + + CompilerService GetCompilerService(); } -} \ No newline at end of file +} diff --git a/src/OneScript/Infrastructure/Implementations/ClassAttributeResolver.cs b/src/OneScript/Infrastructure/Implementations/ClassAttributeResolver.cs index 01b1c87..44b18ff 100644 --- a/src/OneScript/Infrastructure/Implementations/ClassAttributeResolver.cs +++ b/src/OneScript/Infrastructure/Implementations/ClassAttributeResolver.cs @@ -1,6 +1,11 @@ -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Collections.Generic; using System.Linq; -using ScriptEngine; using ScriptEngine.Compiler; using ScriptEngine.Environment; using ScriptEngine.Machine; @@ -61,4 +66,4 @@ public void AfterCompilation() { } } -} \ No newline at end of file +} diff --git a/src/OneScript/Infrastructure/Implementations/CustomHttpMethodAttribute.cs b/src/OneScript/Infrastructure/Implementations/CustomHttpMethodAttribute.cs index a5fc59b..0ccd9db 100644 --- a/src/OneScript/Infrastructure/Implementations/CustomHttpMethodAttribute.cs +++ b/src/OneScript/Infrastructure/Implementations/CustomHttpMethodAttribute.cs @@ -1,7 +1,11 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Routing; namespace OneScript.WebHost.Infrastructure.Implementations diff --git a/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs b/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs index 0668302..1cfc209 100644 --- a/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs +++ b/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs @@ -1,15 +1,20 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Threading; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Authorization; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders.Physical; @@ -17,7 +22,6 @@ using Microsoft.Extensions.Primitives; using OneScript.WebHost.Application; using ScriptEngine.Environment; -using ScriptEngine.HostedScript; using ScriptEngine.Machine.Contexts; using ScriptEngine.Machine; using ScriptEngine.Machine.Reflection; @@ -31,7 +35,6 @@ public class OscriptApplicationModelProvider : IApplicationModelProvider private readonly IApplicationRuntime _fw; private readonly IFileProvider _scriptsProvider; - private readonly int _controllersMethodOffset; private readonly ApplicationInstance _app; private readonly IAuthorizationPolicyProvider _policyProvider; private readonly ClassAttributeResolver _classAttribResolver; @@ -46,7 +49,6 @@ public OscriptApplicationModelProvider(ApplicationInstance appObject, _fw = framework; _app = appObject; _scriptsProvider = sourceProvider; - _controllersMethodOffset = ScriptedController.GetOwnMethodsRelectionOffset(); _policyProvider = authPolicyProvider; _classAttribResolver = new ClassAttributeResolver(); @@ -97,7 +99,7 @@ public void OnProvidersExecuting(ApplicationModelProviderContext context) private void FillContext(IEnumerable sources, ApplicationModelProviderContext context) { var reflector = new TypeReflectionEngine(); - _fw.Environment.LoadMemory(MachineInstance.Current); + MachineInstance.Current.PrepareThread(_fw.Environment); foreach (var virtualPath in sources) { LoadedModule module; @@ -254,7 +256,7 @@ public static AuthorizeFilter GetFilter(IAuthorizationPolicyProvider policyProvi private LoadedModule LoadControllerCode(ICodeSource src) { - var compiler = _fw.Engine.GetCompilerService(); + var compiler = _fw.GetCompilerService(); var byteCode = ScriptedController.CompileModule(compiler, src); return _fw.Engine.LoadModuleImage(byteCode); } @@ -535,11 +537,11 @@ private void MapDirect(string name, string alias, Type attrType) private void FillDefaultMappers() { - MapDirect("Authorize", "Авторизовать", typeof(AuthorizeAttribute)); MapDirect("HttpPost", null, typeof(HttpPostAttribute)); MapDirect("HttpGet", null, typeof(HttpGetAttribute)); _annotationMapper.AddMapper("HttpMethod", MapHttpMethod); + _annotationMapper.AddMapper("Authorize", "Авторизовать", MapAuthorizationAttribute); _annotationMapper.AddMapper("Action", "Действие", (annotation) => { if (annotation.ParamCount != 1) @@ -582,5 +584,33 @@ private static object MapHttpMethod(AnnotationDefinition anno) throw new AnnotationException(anno, "Too many parameters"); } + + private static object MapAuthorizationAttribute(AnnotationDefinition anno) + { + var instance = new AuthorizeAttribute(); + if (anno.ParamCount == 0) + return instance; + + foreach (var parameter in anno.Parameters) + { + if (BiLingualEquals(parameter.Name, "roles", "роли")) + { + instance.Roles = parameter.RuntimeValue.AsString(); + } + else if (BiLingualEquals(parameter.Name, "policy", "политика")) + { + instance.Policy = parameter.RuntimeValue.AsString(); + } + } + + return instance; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool BiLingualEquals(string src, string en, string ru) + { + return src.Equals(en, StringComparison.OrdinalIgnoreCase) || + src.Equals(ru, StringComparison.OrdinalIgnoreCase); + } } } diff --git a/src/OneScript/Infrastructure/Implementations/OscriptViewComponentActivator.cs b/src/OneScript/Infrastructure/Implementations/OscriptViewComponentActivator.cs index 8149556..e0ed8da 100644 --- a/src/OneScript/Infrastructure/Implementations/OscriptViewComponentActivator.cs +++ b/src/OneScript/Infrastructure/Implementations/OscriptViewComponentActivator.cs @@ -1,11 +1,14 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; -using System.Linq.Expressions; using System.Reflection; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.Extensions.DependencyInjection; using ScriptEngine.Machine; using ScriptEngine.Machine.Reflection; diff --git a/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvoker.cs b/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvoker.cs index 9f2c5a9..00f8f3f 100644 --- a/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvoker.cs +++ b/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvoker.cs @@ -1,10 +1,14 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Diagnostics; using System.Threading.Tasks; -using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.AspNetCore.Mvc.ViewFeatures; using OneScript.WebHost.Application; namespace OneScript.WebHost.Infrastructure.Implementations @@ -45,4 +49,4 @@ private static IViewComponentResult CoerceToViewComponentResult(object value) throw new InvalidOperationException($"Can't use type {value.GetType()} as the result of view component"); } } -} \ No newline at end of file +} diff --git a/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvokerFactory.cs b/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvokerFactory.cs index d0380b2..77cae99 100644 --- a/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvokerFactory.cs +++ b/src/OneScript/Infrastructure/Implementations/OscriptViewComponentInvokerFactory.cs @@ -1,9 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; -using Microsoft.Extensions.Logging; namespace OneScript.WebHost.Infrastructure.Implementations { diff --git a/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs b/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs index c2f9992..4ffe6b1 100644 --- a/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs +++ b/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs @@ -1,13 +1,13 @@ -using Microsoft.AspNetCore.Mvc.Controllers; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc; using OneScript.WebHost.Application; using OneScript.WebHost.Database; -using ScriptEngine; -using ScriptEngine.Environment; using ScriptEngine.Machine; namespace OneScript.WebHost.Infrastructure.Implementations @@ -39,8 +39,8 @@ public object Create(ControllerContext context) var module = info.Module; var instance = new ScriptedController(context, module); var machine = MachineInstance.Current; - engine.Environment.LoadMemory(machine); - + machine.PrepareThread(engine.Environment); + _runtime.DebugCurrentThread(); engine.InitializeSDO(instance); return instance; diff --git a/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs b/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs index 1c8e390..3589c74 100644 --- a/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs +++ b/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs @@ -1,11 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using OneScript.WebHost.Application; -using ScriptEngine; -using ScriptEngine.Environment; using ScriptEngine.Machine; using Microsoft.Extensions.FileProviders; @@ -17,13 +19,17 @@ public class ScriptedMiddlewareActivator private readonly LoadedModule _module; private readonly IApplicationRuntime _runtime; - public ScriptedMiddlewareActivator(RequestDelegate next, IFileProvider scripts, IApplicationRuntime runtime, string scriptName) + public ScriptedMiddlewareActivator( + RequestDelegate next, + IFileProvider scripts, + IApplicationRuntime runtime, + string scriptName) { _next = next; _runtime = runtime; var codeSrc = new FileInfoCodeSource(scripts.GetFileInfo(scriptName)); - var image = ScriptedMiddleware.CompileModule(runtime.Engine.GetCompilerService(), codeSrc); - _module = new LoadedModule(image); + var image = ScriptedMiddleware.CompileModule(_runtime.GetCompilerService(), codeSrc); + _module = _runtime.Engine.LoadModuleImage(image); } public async Task InvokeAsync(HttpContext context) @@ -31,9 +37,18 @@ public async Task InvokeAsync(HttpContext context) var engine = _runtime.Engine; var instance = new ScriptedMiddleware(_next, _module); var machine = MachineInstance.Current; - engine.Environment.LoadMemory(machine); - engine.InitializeSDO(instance); - await instance.InvokeAsync(context); + machine.PrepareThread(engine.Environment); + try + { + _runtime.DebugCurrentThread(); + engine.InitializeSDO(instance); + await instance.InvokeAsync(context); + } + finally + { + _runtime.StopDebugCurrentThread(); + } + } } } diff --git a/src/OneScript/Infrastructure/Implementations/ScriptedViewComponentFeatureProvider.cs b/src/OneScript/Infrastructure/Implementations/ScriptedViewComponentFeatureProvider.cs index a277c55..cd24af2 100644 --- a/src/OneScript/Infrastructure/Implementations/ScriptedViewComponentFeatureProvider.cs +++ b/src/OneScript/Infrastructure/Implementations/ScriptedViewComponentFeatureProvider.cs @@ -1,17 +1,20 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders.Physical; using OneScript.WebHost.Application; -using ScriptEngine; using ScriptEngine.Machine.Reflection; namespace OneScript.WebHost.Infrastructure.Implementations @@ -20,7 +23,7 @@ public class ScriptedViewComponentFeatureProvider : IApplicationFeatureProvider< { public ApplicationInstance Application { get; set; } public IFileProvider ScriptsProvider { get; set; } - public ScriptingEngine Engine { get; set; } + public IApplicationRuntime Runtime { get; set; } private TypeInfo[] _discoveredTypes; @@ -29,7 +32,7 @@ public void Configure(IServiceProvider services) // в режиме тестирования app-instance может быть null Application = services.GetService(); ScriptsProvider = services.GetRequiredService(); - Engine = services.GetRequiredService().Engine; + Runtime = services.GetRequiredService(); } public void PopulateFeature(IEnumerable parts, ViewComponentFeature feature) @@ -69,7 +72,7 @@ private void FillFeature(List sources) foreach (var virtualPath in sources) { var code = new FileInfoCodeSource(virtualPath); - var compiler = Engine.GetCompilerService(); + var compiler = Runtime.GetCompilerService(); var img = ScriptedViewComponent.CompileModule(compiler,code); var invokatorExist = img.Methods.Any(x => StringComparer.OrdinalIgnoreCase.Compare(ScriptedViewComponent.InvokeMethodNameRu, x.Signature.Name) == 0 @@ -78,8 +81,8 @@ private void FillFeature(List sources) if(!invokatorExist) continue; - var module = Engine.LoadModuleImage(img); - var baseFileName = System.IO.Path.GetFileNameWithoutExtension(code.SourceDescription); + var module = Runtime.Engine.LoadModuleImage(img); + var baseFileName = Path.GetFileNameWithoutExtension(code.SourceDescription); var builder = new ClassBuilder(); var type = builder.SetModule(module) diff --git a/src/OneScript/Infrastructure/OneScriptServicePlugin.cs b/src/OneScript/Infrastructure/OneScriptServicePlugin.cs index f129d47..5b59e26 100644 --- a/src/OneScript/Infrastructure/OneScriptServicePlugin.cs +++ b/src/OneScript/Infrastructure/OneScriptServicePlugin.cs @@ -1,8 +1,12 @@ -#if NETCOREAPP +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +#if NETCOREAPP using System.Text; #endif - -using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -16,7 +20,6 @@ using OneScript.DebugServices; using OneScript.WebHost.Authorization; using OneScript.WebHost.Infrastructure.Implementations; -using ScriptEngine.Machine; namespace OneScript.WebHost.Infrastructure { @@ -28,7 +31,7 @@ public static void AddOneScript(this IServiceCollection services) ServiceDescriptor.Transient()); services.TryAddTransient(svc => - new PhysicalFileProvider(svc.GetService().ContentRootPath)); + new PhysicalFileProvider(svc.GetService().ContentRootPath)); services.AddTransient(); InitializeScriptedLayer(services); diff --git a/src/OneScript/Infrastructure/OscriptViewsOverride.cs b/src/OneScript/Infrastructure/OscriptViewsOverride.cs index b52811e..38914df 100644 --- a/src/OneScript/Infrastructure/OscriptViewsOverride.cs +++ b/src/OneScript/Infrastructure/OscriptViewsOverride.cs @@ -1,4 +1,10 @@ -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Razor; diff --git a/src/OneScript/Infrastructure/RuntimeExtensions.cs b/src/OneScript/Infrastructure/RuntimeExtensions.cs new file mode 100644 index 0000000..b1656ed --- /dev/null +++ b/src/OneScript/Infrastructure/RuntimeExtensions.cs @@ -0,0 +1,21 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + +using ScriptEngine; +using ScriptEngine.Machine; + +namespace OneScript.WebHost.Infrastructure +{ + public static class RuntimeExtensions + { + public static void PrepareThread(this MachineInstance machine, RuntimeEnvironment env) + { + if (!machine.IsRunning) + env.LoadMemory(machine); + } + } +} \ No newline at end of file diff --git a/src/OneScript/Infrastructure/ScriptedMiddlewareExtension.cs b/src/OneScript/Infrastructure/ScriptedMiddlewareExtension.cs index 06e6718..56f186c 100644 --- a/src/OneScript/Infrastructure/ScriptedMiddlewareExtension.cs +++ b/src/OneScript/Infrastructure/ScriptedMiddlewareExtension.cs @@ -1,12 +1,11 @@ -using Microsoft.AspNetCore.Builder; -using OneScript.WebHost.Application; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Microsoft.AspNetCore.Builder; using OneScript.WebHost.Infrastructure.Implementations; -using ScriptEngine.Environment; -using ScriptEngine.Machine; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace OneScript.WebHost.Infrastructure { diff --git a/src/OneScript/Infrastructure/TypeReflectionEngine.cs b/src/OneScript/Infrastructure/TypeReflectionEngine.cs index e6955eb..9856399 100644 --- a/src/OneScript/Infrastructure/TypeReflectionEngine.cs +++ b/src/OneScript/Infrastructure/TypeReflectionEngine.cs @@ -1,9 +1,12 @@ -using ScriptEngine.Environment; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using ScriptEngine.Machine.Contexts; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using ScriptEngine.Machine; using ScriptEngine.Machine.Reflection; diff --git a/src/OneScript/Infrastructure/WebApplicationEngine.cs b/src/OneScript/Infrastructure/WebApplicationEngine.cs index 5638870..0bdd144 100644 --- a/src/OneScript/Infrastructure/WebApplicationEngine.cs +++ b/src/OneScript/Infrastructure/WebApplicationEngine.cs @@ -1,15 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + using System.Reflection; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using OneScript.WebHost.Application; using ScriptEngine; using ScriptEngine.HostedScript.Library; -using ScriptEngine.HostedScript; -using ScriptEngine.Machine; -using ScriptEngine.Machine.Contexts; namespace OneScript.WebHost.Infrastructure { @@ -28,7 +26,13 @@ public WebApplicationEngine() public ScriptingEngine Engine { get; } public RuntimeEnvironment Environment { get; } + public CompilerService GetCompilerService() + { + var compilerSvc = Engine.GetCompilerService(); + compilerSvc.DefinePreprocessorValue("ВебСервер"); + compilerSvc.DefinePreprocessorValue("WebServer"); - + return compilerSvc; + } } } diff --git a/src/OneScript/OneScriptWeb.csproj b/src/OneScript/OneScriptWeb.csproj index 7b442ec..2b71f66 100644 --- a/src/OneScript/OneScriptWeb.csproj +++ b/src/OneScript/OneScriptWeb.csproj @@ -1,15 +1,27 @@ + - net461;netcoreapp2.2 + 0.7.0 + $(BUILD_NUMBER) + 0 + OneScript.WebHost OneScript.WebHost OneScript.WebHost.Program - 0.7.0.0 - 0.7.0.0 + $(ReleaseNumber).$(BuildNumber) + $(ReleaseNumber).$(BuildNumber) false false + netcoreapp3.1 + + 1Script Server Pages + Copyright (c) 2018 EvilBeaver + Debug;Release + AnyCPU + + AnyCPU win7-x64;debian-x64;fedora-x64 @@ -17,6 +29,8 @@ AnyCPU bin\Release\$(TargetFramework)\OneScript.WebHost.xml + false + 2 @@ -33,22 +47,19 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/src/OneScript/Program.cs b/src/OneScript/Program.cs index 48c144d..2dad41b 100644 --- a/src/OneScript/Program.cs +++ b/src/OneScript/Program.cs @@ -1,4 +1,10 @@ -using System.Collections.Generic; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; diff --git a/src/OneScript/Startup.cs b/src/OneScript/Startup.cs index e3a31fd..a5787ac 100644 --- a/src/OneScript/Startup.cs +++ b/src/OneScript/Startup.cs @@ -1,20 +1,20 @@ -using System; -using System.IO; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.IO.Compression; using System.Linq; -using System.Net.Mime; -using System.Reflection; -using Hangfire; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor; -using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.ResponseCompression; -using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OneScript.WebHost.Application; @@ -49,6 +49,7 @@ public void ConfigureServices(IServiceCollection services) services.AddMemoryCache(); services.AddSession(); + services.AddHttpContextAccessor(); services.AddDatabaseByConfiguration(Configuration); services.AddIdentityByConfiguration(Configuration); services.AddBackgroundJobsByConfiguration(Configuration); @@ -70,15 +71,15 @@ public void ConfigureServices(IServiceCollection services) //TODO подумать как вывести данную конструкцию в конфигурацю доступную для разработчика 1С services.AddAntiforgery(options => options.Cookie.Name = "OScriptWeb.Antiforgery"); - services.AddMvc() + services.AddControllersWithViews(mvcopts => mvcopts.EnableEndpointRouting = false) + .AddRazorRuntimeCompilation() .ConfigureApplicationPartManager(pm=>pm.FeatureProviders.Add(new ScriptedViewComponentFeatureProvider())); - services.AddOneScript(); services.AddOneScriptDebug(Configuration); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider services) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services) { if (env.IsDevelopment()) { @@ -105,9 +106,10 @@ private static void StartOneScriptApp(IApplicationBuilder app, IServiceProvider try { var oscriptApp = services.GetService(); + + MachineInstance.Current.PrepareThread(appRuntime.Environment); + appRuntime.Engine.DebugController = services.GetService(); - oscriptApp.UseServices(services); - if (appRuntime.DebugEnabled()) { var logger = services.GetService>(); diff --git a/src/OneScriptWeb.Tests/ActionResultTests.cs b/src/OneScriptWeb.Tests/ActionResultTests.cs index ae1b739..62f69cb 100644 --- a/src/OneScriptWeb.Tests/ActionResultTests.cs +++ b/src/OneScriptWeb.Tests/ActionResultTests.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/OneScriptWeb.Tests/AppModelTests.cs b/src/OneScriptWeb.Tests/AppModelTests.cs index 1c62664..c56abe5 100644 --- a/src/OneScriptWeb.Tests/AppModelTests.cs +++ b/src/OneScriptWeb.Tests/AppModelTests.cs @@ -1,9 +1,14 @@ -using System.Linq; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Linq; using System.Reflection; using Dazinator.AspNet.Extensions.FileProviders; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -15,9 +20,6 @@ using OneScript.WebHost.Infrastructure; using OneScript.WebHost.Infrastructure.Implementations; using ScriptEngine; -using ScriptEngine.HostedScript; -using ScriptEngine.Machine; -using ScriptEngine.Machine.Reflection; using Xunit; namespace OneScriptWeb.Tests @@ -155,6 +157,7 @@ private static IApplicationRuntime CreateWebEngineMock() webAppMoq.SetupGet(x => x.Engine).Returns(engine); webAppMoq.SetupGet(x => x.Environment).Returns(engine.Environment); + webAppMoq.Setup(x => x.GetCompilerService()).Returns(() => engine.GetCompilerService()); return webAppMoq.Object; } @@ -165,11 +168,8 @@ private static ApplicationModel CreateApplicationModel(IFileProvider scriptsProv services.TryAddSingleton(Mock.Of()); services.TryAddSingleton(Mock.Of>()); services.TryAddSingleton(Mock.Of()); - services.TryAddScoped(x=>new HostingEnvironment() - { - ContentRootPath = "/" - }); - + services.TryAddScoped(x => Mock.Of()); + services.AddSingleton(CreateWebEngineMock()); services.AddOneScript(); diff --git a/src/OneScriptWeb.Tests/ApplicationStartupTests.cs b/src/OneScriptWeb.Tests/ApplicationStartupTests.cs index 3f34150..ebc8e59 100644 --- a/src/OneScriptWeb.Tests/ApplicationStartupTests.cs +++ b/src/OneScriptWeb.Tests/ApplicationStartupTests.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -8,12 +14,10 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -43,7 +47,7 @@ public void CheckThatApplicationInstanceIsCreatedOnMain() cfgBuilder.AddInMemoryCollection(memData); services.TryAddSingleton(cfgBuilder.Build()); services.TryAddSingleton(); - services.AddSingleton(new HostingEnvironment()); + services.AddSingleton(Mock.Of()); services.AddSingleton(Mock.Of>()); services.AddMvcCore(); services.AddOneScript(); @@ -97,7 +101,7 @@ private static ServiceCollection MockMvcServices() { var services = new ServiceCollection(); services.TryAddSingleton(); - services.AddSingleton(Mock.Of()); + services.AddSingleton(Mock.Of()); services.AddSingleton(Mock.Of()); services.AddTransient(typeof(IActionInvokerFactory), (s) => Mock.Of()); services.AddTransient(typeof(IActionSelector), (s) => Mock.Of()); @@ -126,7 +130,7 @@ private static ServiceCollection MockMvcServices() return services; } - //[Fact] + [Fact(Skip = "Skipped for some reasons")] public void CheckThatRoutesAreRegisteredInHandler() { var services = MockMvcServices(); @@ -174,14 +178,14 @@ public void MethodEchoWritesLog() var provider = services.BuildServiceProvider(); var starter = provider.GetService(); - var app = starter.CreateApp(); + starter.CreateApp(); loggerMock.Verify(x => x.Log( LogLevel.Information, It.IsAny(), - It.IsAny(), + It.Is((v, t) => true), null, - It.IsAny>()), + It.Is>((v, t) => true)), Times.Once); } diff --git a/src/OneScriptWeb.Tests/AuthHandlerTests.cs b/src/OneScriptWeb.Tests/AuthHandlerTests.cs index 528f9da..b423678 100644 --- a/src/OneScriptWeb.Tests/AuthHandlerTests.cs +++ b/src/OneScriptWeb.Tests/AuthHandlerTests.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; diff --git a/src/OneScriptWeb.Tests/ControllerCreationTest.cs b/src/OneScriptWeb.Tests/ControllerCreationTest.cs index 97f1879..c4526a1 100644 --- a/src/OneScriptWeb.Tests/ControllerCreationTest.cs +++ b/src/OneScriptWeb.Tests/ControllerCreationTest.cs @@ -1,4 +1,10 @@ -using System.Reflection; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System.Reflection; using Dazinator.AspNet.Extensions.FileProviders; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; diff --git a/src/OneScriptWeb.Tests/DbModelCreatorTests.cs b/src/OneScriptWeb.Tests/DbModelCreatorTests.cs index 670e7f3..5044573 100644 --- a/src/OneScriptWeb.Tests/DbModelCreatorTests.cs +++ b/src/OneScriptWeb.Tests/DbModelCreatorTests.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,6 +14,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using OneScript.WebHost.Database; @@ -69,13 +76,17 @@ public void CanCreateInfobaseUsers() { var opts = new DbContextOptionsBuilder(); var services = new ServiceCollection(); - services.AddTransient>((svc) => opts.UseInMemoryDatabase("usersManagerTest").Options); + services.AddTransient(_ => opts.UseInMemoryDatabase("usersManagerTest").Options); + services.AddTransient(_ => Mock.Of>>()); + services.AddTransient(_ => Mock.Of>>()); var cfgBuilder = new ConfigurationBuilder(); - Dictionary keys = new Dictionary(); - keys["Security:Password:RequireDigit"] = "false"; - keys["Security:Password:RequireUppercase"] = "false"; - keys["Security:Password:RequireLowercase"] = "false"; + var keys = new Dictionary + { + ["Security:Password:RequireDigit"] = "false", + ["Security:Password:RequireUppercase"] = "false", + ["Security:Password:RequireLowercase"] = "false" + }; cfgBuilder.AddInMemoryCollection(keys); services.AddIdentityByConfiguration(cfgBuilder.Build()); diff --git a/src/OneScriptWeb.Tests/DynamicContextWrapperTest.cs b/src/OneScriptWeb.Tests/DynamicContextWrapperTest.cs index 51f7051..c5b422e 100644 --- a/src/OneScriptWeb.Tests/DynamicContextWrapperTest.cs +++ b/src/OneScriptWeb.Tests/DynamicContextWrapperTest.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/src/OneScriptWeb.Tests/DynamicExtensionTest.cs b/src/OneScriptWeb.Tests/DynamicExtensionTest.cs index 7ae895b..1d6989b 100644 --- a/src/OneScriptWeb.Tests/DynamicExtensionTest.cs +++ b/src/OneScriptWeb.Tests/DynamicExtensionTest.cs @@ -1,4 +1,10 @@ -#if NETFRAMEWORK +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +#if NETFRAMEWORK using System; using System.CodeDom.Compiler; diff --git a/src/OneScriptWeb.Tests/FakeFileInfo.cs b/src/OneScriptWeb.Tests/FakeFileInfo.cs index 5d2e64f..9cc1dbb 100644 --- a/src/OneScriptWeb.Tests/FakeFileInfo.cs +++ b/src/OneScriptWeb.Tests/FakeFileInfo.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/OneScriptWeb.Tests/FileProviderExtensions.cs b/src/OneScriptWeb.Tests/FileProviderExtensions.cs index f12183d..55446b9 100644 --- a/src/OneScriptWeb.Tests/FileProviderExtensions.cs +++ b/src/OneScriptWeb.Tests/FileProviderExtensions.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/OneScriptWeb.Tests/HttpRequestResponseTests.cs b/src/OneScriptWeb.Tests/HttpRequestResponseTests.cs index b2fc03a..a210141 100644 --- a/src/OneScriptWeb.Tests/HttpRequestResponseTests.cs +++ b/src/OneScriptWeb.Tests/HttpRequestResponseTests.cs @@ -1,11 +1,16 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Internal; using Xunit; using Moq; using OneScript.WebHost.Application; @@ -55,8 +60,7 @@ public void ResponseHeadersCanBeSetFrom_MapImpl() [Fact] public void ContentTypeIsReflectedInHeadersAfterAssignment() { - var context = new DefaultHttpContext(); - var response = new DefaultHttpResponse(context); + var response = MockRequestClass(); var scriptRequest = new HttpResponseImpl(response); scriptRequest.ContentType = "text/plain"; @@ -68,8 +72,7 @@ public void ContentTypeIsReflectedInHeadersAfterAssignment() [Fact] public void ContentTypeIsReflectedInHeadersAfterSetHeaders() { - var context = new DefaultHttpContext(); - var response = new DefaultHttpResponse(context); + var response = MockRequestClass(); var headers = new MapImpl(); headers.SetIndexedValue(ValueFactory.Create("Content-Type"), ValueFactory.Create("text/plain")); @@ -132,5 +135,17 @@ public void CookiesAreAccessible() Assert.Equal("test", request.Cookies.GetIndexedValue(ValueFactory.Create("test")).AsString()); } + + private HttpResponse MockRequestClass() + { + var mock = new Mock(); + + var dict = new HeaderDictionary(); + mock.SetupGet(x => x.Headers).Returns(dict); + mock.SetupGet(x => x.ContentType).Returns(() => dict["Content-Type"].ToString()); + mock.SetupSet(x => x.ContentType).Callback(x => dict["Content-Type"] = x); + + return mock.Object; + } } } diff --git a/src/OneScriptWeb.Tests/OneScriptWeb.Tests.csproj b/src/OneScriptWeb.Tests/OneScriptWeb.Tests.csproj index af09f6e..68b639d 100644 --- a/src/OneScriptWeb.Tests/OneScriptWeb.Tests.csproj +++ b/src/OneScriptWeb.Tests/OneScriptWeb.Tests.csproj @@ -1,33 +1,22 @@  - false - - net461;netcoreapp2.2 - - - - 1 - $(BUILD_NUMBER) - 0 - 0 + netcoreapp3.1 + Debug;Release + AnyCPU - - - 1.$(ReleaseNumber).$(PatchNumber).$(BuildNumber) - $(Version) - 1Script Server Pages - Copyright (c) 2018 EvilBeaver - - + - - + + - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/OneScriptWeb.Tests/SessionsTest.cs b/src/OneScriptWeb.Tests/SessionsTest.cs index 7ff3198..3406f78 100644 --- a/src/OneScriptWeb.Tests/SessionsTest.cs +++ b/src/OneScriptWeb.Tests/SessionsTest.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/OneScriptWeb.Tests/TestOrderingLock.cs b/src/OneScriptWeb.Tests/TestOrderingLock.cs index a313202..eac51de 100644 --- a/src/OneScriptWeb.Tests/TestOrderingLock.cs +++ b/src/OneScriptWeb.Tests/TestOrderingLock.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Collections.Generic; using System.Text; diff --git a/src/OneScriptWeb.Tests/TypeReflectionTest.cs b/src/OneScriptWeb.Tests/TypeReflectionTest.cs index a2a3bdd..1e33553 100644 --- a/src/OneScriptWeb.Tests/TypeReflectionTest.cs +++ b/src/OneScriptWeb.Tests/TypeReflectionTest.cs @@ -1,4 +1,10 @@ -using System; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Threading; using OneScript.WebHost.Infrastructure; using OneScript.WebHost.Infrastructure.Implementations; diff --git a/src/OneScriptWeb.Tests/ViewComponentDiscoveryTest.cs b/src/OneScriptWeb.Tests/ViewComponentDiscoveryTest.cs index df53085..1b86002 100644 --- a/src/OneScriptWeb.Tests/ViewComponentDiscoveryTest.cs +++ b/src/OneScriptWeb.Tests/ViewComponentDiscoveryTest.cs @@ -1,17 +1,16 @@ -using System; -using System.Collections.Generic; -using System.IO; +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using System; using System.Linq; using System.Reflection; -using System.Text; -using System.Text.Encodings.Web; -using System.Threading.Tasks; using Dazinator.AspNet.Extensions.FileProviders; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -29,6 +28,17 @@ namespace OneScriptWeb.Tests { public class ViewComponentDiscoveryTest { + private IApplicationRuntime MakeRuntime() + { + var rtMock = new Mock(); + var engine = new ScriptingEngine {Environment = new RuntimeEnvironment()}; + rtMock.SetupGet(x => x.Engine).Returns(engine); + rtMock.SetupGet(x => x.Environment).Returns(engine.Environment); + rtMock.Setup(x => x.GetCompilerService()).Returns(() => engine.GetCompilerService()); + + return rtMock.Object; + } + [Fact] public void CanPopulateViewComponentFeature() { @@ -42,8 +52,8 @@ public void CanPopulateViewComponentFeature() var serviceProvider = services.BuildServiceProvider(); var cp = new ScriptedViewComponentFeatureProvider(); - cp.Engine = new ScriptingEngine(); - cp.Engine.Environment = new RuntimeEnvironment(); + + cp.Runtime = MakeRuntime(); cp.ScriptsProvider = serviceProvider.GetService(); var feature = new ViewComponentFeature(); @@ -67,8 +77,7 @@ public void CanIgnoreModulesWithoutInvokator() var serviceProvider = services.BuildServiceProvider(); var cp = new ScriptedViewComponentFeatureProvider(); - cp.Engine = new ScriptingEngine(); - cp.Engine.Environment = new RuntimeEnvironment(); + cp.Runtime = MakeRuntime(); cp.ScriptsProvider = serviceProvider.GetService(); var feature = new ViewComponentFeature(); @@ -91,8 +100,7 @@ public void CanActivateVC_Through_Activator() var serviceProvider = services.BuildServiceProvider(); var cp = new ScriptedViewComponentFeatureProvider(); - cp.Engine = new ScriptingEngine(); - cp.Engine.Environment = new RuntimeEnvironment(); + cp.Runtime = MakeRuntime(); cp.ScriptsProvider = serviceProvider.GetService(); var feature = new ViewComponentFeature(); @@ -137,10 +145,7 @@ public void CanDiscoverVCThroughAllPipeline() services.TryAddSingleton(Mock.Of()); services.TryAddSingleton(Mock.Of>()); services.TryAddSingleton(Mock.Of()); - services.TryAddScoped(x => new HostingEnvironment() - { - ContentRootPath = "/" - }); + services.TryAddScoped(x => Mock.Of()); var webAppMoq = new Mock(); var engine = new ScriptingEngine() @@ -150,6 +155,8 @@ public void CanDiscoverVCThroughAllPipeline() webAppMoq.SetupGet(x => x.Engine).Returns(engine); webAppMoq.SetupGet(x => x.Environment).Returns(engine.Environment); + webAppMoq.Setup(x => x.GetCompilerService()).Returns(engine.GetCompilerService()); + services.AddSingleton(webAppMoq.Object); services.AddMvc() .ConfigureApplicationPartManager(pm => pm.FeatureProviders.Add(new ScriptedViewComponentFeatureProvider()));