Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Ovsiankin committed Jun 15, 2021
2 parents af78290 + be0768b commit 6330667
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pipeline {
agent none

environment {
ReleaseNumber = '0.8.2'
ReleaseNumber = '0.9.0'
}
stages {

Expand Down
2 changes: 1 addition & 1 deletion examples/backgroundjobs/src/main.os
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Процедура НастроитьФоновыеЗадания()

//
ИД1 = ФоновыеЗадания.Выполнить("ОбработчикиФоновых.АсинхронноеЗадание");
ИД1 = ФоновыеЗадания.Выполнить(ОбработчикиФоновых, "АсинхронноеЗадание");

ЗадержкаВыполнения = Новый ПараметрыОжиданияФоновыхЗаданий();
ЗадержкаВыполнения.ОжиданиеВСекундах(30);
Expand Down
14 changes: 10 additions & 4 deletions src/OneScript/Application/HttpRequestImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/

using System.Linq;
using Microsoft.AspNetCore.Http;
using ScriptEngine.HostedScript.Library;
using ScriptEngine.HostedScript.Library.Binary;
Expand Down Expand Up @@ -122,11 +123,16 @@ public FormDataCollectionContext FormData
[ContextMethod("ПараметрыЗапроса")]
public MapImpl QueryParameters()
{
MapImpl result = new MapImpl();
foreach (var kv in _realObject.Query)
var result = new MapImpl();
foreach (var (key, value) in _realObject.Query)
{
result.Insert(ValueFactory.Create(kv.Key),
ValueFactory.Create(kv.Value));
var valueToInsert = value.Count > 1 ?
new ArrayImpl(value.Select(ValueFactory.Create)) :
ValueFactory.Create(value);

result.Insert(
ValueFactory.Create(key),
valueToInsert);
}

return result;
Expand Down
28 changes: 25 additions & 3 deletions src/OneScript/Application/ScriptedMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OneScript.WebHost.Infrastructure;
using ScriptEngine.HostedScript.Library;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;
Expand All @@ -22,6 +23,7 @@ namespace OneScript.WebHost.Application
public class ScriptedMiddleware : AutoScriptDrivenObject<ScriptedMiddleware>
{
private readonly RequestDelegate _next;
private readonly IApplicationRuntime _runtime;
private HttpContext _context;

#region Construction
Expand All @@ -31,9 +33,10 @@ public class ScriptedMiddleware : AutoScriptDrivenObject<ScriptedMiddleware>
/// </summary>
/// <param name="next">Следующий обработчик в конвейере</param>
/// <param name="module">Скомпилированный модуль посредника</param>
public ScriptedMiddleware(RequestDelegate next, LoadedModule module) : base(module, true)
public ScriptedMiddleware(RequestDelegate next, LoadedModule module, IApplicationRuntime runtime) : base(module, true)
{
_next = next;
_runtime = runtime;
InitOwnData();
}

Expand All @@ -55,8 +58,27 @@ public async Task InvokeAsync(HttpContext context)
HttpRequest = new HttpRequestImpl(_context.Request);
HttpResponse = new HttpResponseImpl(_context.Response);

var parameters = new IValue[] { new ArrayImpl() };
await Task.Run(() => CallScriptMethod(mId, parameters));
await RunMethodInAsync(context, mId);
}

private Task RunMethodInAsync(HttpContext context, int methodId)
{
return Task.Run(() =>
{
var engine = _runtime.Engine;
var machine = MachineInstance.Current;
machine.PrepareThread(engine.Environment);
try
{
_runtime.DebugCurrentThread();
engine.InitializeSDO(this);
CallScriptMethod(methodId, new [] {ValueFactory.Create()});
}
finally
{
_runtime.StopDebugCurrentThread();
}
});
}

/// <summary>
Expand Down
21 changes: 0 additions & 21 deletions src/OneScript/BackgroundJobs/BackgroundJobContext.cs

This file was deleted.

5 changes: 4 additions & 1 deletion src/OneScript/BackgroundJobs/BackgroundJobsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using OneScript.WebHost.Database;
using OneScript.WebHost.Infrastructure;
using ScriptEngine;
using ScriptEngine.HostedScript.Library.Tasks;

namespace OneScript.WebHost.BackgroundJobs
{
Expand Down Expand Up @@ -82,7 +83,9 @@ public static void PrepareBgJobsEnvironment(IServiceProvider services, RuntimeEn
environment.InjectGlobalProperty(jobsManager, "РегламентныеЗадания", true);
environment.InjectGlobalProperty(jobsManager, "ScheduledJobs", true);

var bgJobsManager = new BackgroundJobsManagerContext(environment);
var runtime = services.GetService<IApplicationRuntime>();

var bgJobsManager = new BackgroundTasksManager(runtime.Engine);
environment.InjectGlobalProperty(bgJobsManager, "ФоновыеЗадания", true);
environment.InjectGlobalProperty(bgJobsManager, "BackgroundJobs", true);
}
Expand Down
62 changes: 0 additions & 62 deletions src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs

This file was deleted.

28 changes: 14 additions & 14 deletions src/OneScript/Database/QueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,47 @@ public QueryResult(DbDataReader reader)
row.Set(ColIdx, ValueFactory.Create());
continue;
}

if (record.GetFieldType(ColIdx) == typeof(Int32))

var fieldType = record.GetFieldType(ColIdx);
if (fieldType == typeof(Int32))
{
row.Set(ColIdx, ValueFactory.Create((int)record.GetValue(ColIdx)));
}
if (record.GetFieldType(ColIdx) == typeof(Int64))
else if (fieldType == typeof(Int64))
{
row.Set(ColIdx, ValueFactory.Create(record.GetInt64(ColIdx)));
}
if (record.GetFieldType(ColIdx) == typeof(Boolean))
else if (fieldType == typeof(Boolean))
{
row.Set(ColIdx, ValueFactory.Create(record.GetBoolean(ColIdx)));
}
if (record.GetFieldType(ColIdx) == typeof(UInt64))
else if (fieldType == typeof(UInt64))
{
row.Set(ColIdx, ValueFactory.Create(record.GetValue(ColIdx).ToString()));
}

if (record.GetFieldType(ColIdx) == typeof(System.Double))
else if (fieldType == typeof(System.Double))
{
double val = record.GetDouble(ColIdx);
row.Set(ColIdx, ValueFactory.Create(val.ToString()));
}
if (record.GetFieldType(ColIdx) == typeof(Single))
else if (fieldType == typeof(Single))
{
float val = record.GetFloat(ColIdx);
row.Set(ColIdx, ValueFactory.Create(val.ToString()));
}
if (record.GetFieldType(ColIdx) == typeof(Decimal))
else if (fieldType == typeof(Decimal))
{
row.Set(ColIdx, ValueFactory.Create(record.GetDecimal(ColIdx)));
}
if (record.GetFieldType(ColIdx) == typeof(System.String))
else if (fieldType == typeof(System.DateTime))
{
row.Set(ColIdx, ValueFactory.Create(record.GetString(ColIdx)));
row.Set(ColIdx, ValueFactory.Create(record.GetDateTime(ColIdx)));
}
if (record.GetFieldType(ColIdx) == typeof(System.DateTime))
else if (fieldType == typeof(System.String))
{
row.Set(ColIdx, ValueFactory.Create(record.GetDateTime(ColIdx)));
row.Set(ColIdx, ValueFactory.Create(record.GetString(ColIdx)));
}
if (record.GetFieldType(ColIdx) == typeof(System.Byte[]))
else if (fieldType == typeof(System.Byte[]))
{
var data = (byte[])record[ColIdx];
var newData = new BinaryDataContext(data);
Expand Down
2 changes: 1 addition & 1 deletion src/OneScript/Infrastructure/AppStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ShowExceptionInfo(Exception exc)
throw new NotImplementedException();
}

public bool InputString(out string result, int maxLen)
public bool InputString(out string result, string prompt, int maxLen, bool multiline)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,8 @@ public class ScriptedMiddlewareActivator

public async Task InvokeAsync(HttpContext context)
{
var engine = _runtime.Engine;
var instance = new ScriptedMiddleware(_next, _module);
var machine = MachineInstance.Current;
machine.PrepareThread(engine.Environment);
try
{
_runtime.DebugCurrentThread();
engine.InitializeSDO(instance);
await instance.InvokeAsync(context);
}
finally
{
_runtime.StopDebugCurrentThread();
}

var instance = new ScriptedMiddleware(_next, _module, _runtime);
await instance.InvokeAsync(context);
}
}
}
6 changes: 3 additions & 3 deletions src/OneScript/OneScriptWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="OneScript" Version="1.5.0" />
<PackageReference Include="OneScript.DebugServices" Version="1.5.0" />
<PackageReference Include="OneScript.StandardLibrary" Version="1.5.0" />
<PackageReference Include="OneScript" Version="1.6.0" />
<PackageReference Include="OneScript.DebugServices" Version="1.6.0" />
<PackageReference Include="OneScript.StandardLibrary" Version="1.6.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" ExcludeAssets="All" />

Expand Down

0 comments on commit 6330667

Please sign in to comment.