Skip to content

Commit 6330667

Browse files
author
Andrey Ovsiankin
committed
Merge branch 'develop'
2 parents af78290 + be0768b commit 6330667

File tree

11 files changed

+61
-126
lines changed

11 files changed

+61
-126
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pipeline {
33
agent none
44

55
environment {
6-
ReleaseNumber = '0.8.2'
6+
ReleaseNumber = '0.9.0'
77
}
88
stages {
99

examples/backgroundjobs/src/main.os

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Процедура НастроитьФоновыеЗадания()
1818

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

2222
ЗадержкаВыполнения = Новый ПараметрыОжиданияФоновыхЗаданий();
2323
ЗадержкаВыполнения.ОжиданиеВСекундах(30);

src/OneScript/Application/HttpRequestImpl.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This Source Code Form is subject to the terms of the
55
at http://mozilla.org/MPL/2.0/.
66
----------------------------------------------------------*/
77

8+
using System.Linq;
89
using Microsoft.AspNetCore.Http;
910
using ScriptEngine.HostedScript.Library;
1011
using ScriptEngine.HostedScript.Library.Binary;
@@ -122,11 +123,16 @@ public FormDataCollectionContext FormData
122123
[ContextMethod("ПараметрыЗапроса")]
123124
public MapImpl QueryParameters()
124125
{
125-
MapImpl result = new MapImpl();
126-
foreach (var kv in _realObject.Query)
126+
var result = new MapImpl();
127+
foreach (var (key, value) in _realObject.Query)
127128
{
128-
result.Insert(ValueFactory.Create(kv.Key),
129-
ValueFactory.Create(kv.Value));
129+
var valueToInsert = value.Count > 1 ?
130+
new ArrayImpl(value.Select(ValueFactory.Create)) :
131+
ValueFactory.Create(value);
132+
133+
result.Insert(
134+
ValueFactory.Create(key),
135+
valueToInsert);
130136
}
131137

132138
return result;

src/OneScript/Application/ScriptedMiddleware.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This Source Code Form is subject to the terms of the
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Http;
1010
using Microsoft.AspNetCore.Mvc;
11+
using OneScript.WebHost.Infrastructure;
1112
using ScriptEngine.HostedScript.Library;
1213
using ScriptEngine.Machine;
1314
using ScriptEngine.Machine.Contexts;
@@ -22,6 +23,7 @@ namespace OneScript.WebHost.Application
2223
public class ScriptedMiddleware : AutoScriptDrivenObject<ScriptedMiddleware>
2324
{
2425
private readonly RequestDelegate _next;
26+
private readonly IApplicationRuntime _runtime;
2527
private HttpContext _context;
2628

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

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

58-
var parameters = new IValue[] { new ArrayImpl() };
59-
await Task.Run(() => CallScriptMethod(mId, parameters));
61+
await RunMethodInAsync(context, mId);
62+
}
63+
64+
private Task RunMethodInAsync(HttpContext context, int methodId)
65+
{
66+
return Task.Run(() =>
67+
{
68+
var engine = _runtime.Engine;
69+
var machine = MachineInstance.Current;
70+
machine.PrepareThread(engine.Environment);
71+
try
72+
{
73+
_runtime.DebugCurrentThread();
74+
engine.InitializeSDO(this);
75+
CallScriptMethod(methodId, new [] {ValueFactory.Create()});
76+
}
77+
finally
78+
{
79+
_runtime.StopDebugCurrentThread();
80+
}
81+
});
6082
}
6183

6284
/// <summary>

src/OneScript/BackgroundJobs/BackgroundJobContext.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/OneScript/BackgroundJobs/BackgroundJobsExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This Source Code Form is subject to the terms of the
1515
using OneScript.WebHost.Database;
1616
using OneScript.WebHost.Infrastructure;
1717
using ScriptEngine;
18+
using ScriptEngine.HostedScript.Library.Tasks;
1819

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

85-
var bgJobsManager = new BackgroundJobsManagerContext(environment);
86+
var runtime = services.GetService<IApplicationRuntime>();
87+
88+
var bgJobsManager = new BackgroundTasksManager(runtime.Engine);
8689
environment.InjectGlobalProperty(bgJobsManager, "ФоновыеЗадания", true);
8790
environment.InjectGlobalProperty(bgJobsManager, "BackgroundJobs", true);
8891
}

src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/OneScript/Database/QueryResult.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,47 @@ public QueryResult(DbDataReader reader)
4242
row.Set(ColIdx, ValueFactory.Create());
4343
continue;
4444
}
45-
46-
if (record.GetFieldType(ColIdx) == typeof(Int32))
45+
46+
var fieldType = record.GetFieldType(ColIdx);
47+
if (fieldType == typeof(Int32))
4748
{
4849
row.Set(ColIdx, ValueFactory.Create((int)record.GetValue(ColIdx)));
4950
}
50-
if (record.GetFieldType(ColIdx) == typeof(Int64))
51+
else if (fieldType == typeof(Int64))
5152
{
5253
row.Set(ColIdx, ValueFactory.Create(record.GetInt64(ColIdx)));
5354
}
54-
if (record.GetFieldType(ColIdx) == typeof(Boolean))
55+
else if (fieldType == typeof(Boolean))
5556
{
5657
row.Set(ColIdx, ValueFactory.Create(record.GetBoolean(ColIdx)));
5758
}
58-
if (record.GetFieldType(ColIdx) == typeof(UInt64))
59+
else if (fieldType == typeof(UInt64))
5960
{
6061
row.Set(ColIdx, ValueFactory.Create(record.GetValue(ColIdx).ToString()));
6162
}
62-
63-
if (record.GetFieldType(ColIdx) == typeof(System.Double))
63+
else if (fieldType == typeof(System.Double))
6464
{
6565
double val = record.GetDouble(ColIdx);
6666
row.Set(ColIdx, ValueFactory.Create(val.ToString()));
6767
}
68-
if (record.GetFieldType(ColIdx) == typeof(Single))
68+
else if (fieldType == typeof(Single))
6969
{
7070
float val = record.GetFloat(ColIdx);
7171
row.Set(ColIdx, ValueFactory.Create(val.ToString()));
7272
}
73-
if (record.GetFieldType(ColIdx) == typeof(Decimal))
73+
else if (fieldType == typeof(Decimal))
7474
{
7575
row.Set(ColIdx, ValueFactory.Create(record.GetDecimal(ColIdx)));
7676
}
77-
if (record.GetFieldType(ColIdx) == typeof(System.String))
77+
else if (fieldType == typeof(System.DateTime))
7878
{
79-
row.Set(ColIdx, ValueFactory.Create(record.GetString(ColIdx)));
79+
row.Set(ColIdx, ValueFactory.Create(record.GetDateTime(ColIdx)));
8080
}
81-
if (record.GetFieldType(ColIdx) == typeof(System.DateTime))
81+
else if (fieldType == typeof(System.String))
8282
{
83-
row.Set(ColIdx, ValueFactory.Create(record.GetDateTime(ColIdx)));
83+
row.Set(ColIdx, ValueFactory.Create(record.GetString(ColIdx)));
8484
}
85-
if (record.GetFieldType(ColIdx) == typeof(System.Byte[]))
85+
else if (fieldType == typeof(System.Byte[]))
8686
{
8787
var data = (byte[])record[ColIdx];
8888
var newData = new BinaryDataContext(data);

src/OneScript/Infrastructure/AppStarter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void ShowExceptionInfo(Exception exc)
9898
throw new NotImplementedException();
9999
}
100100

101-
public bool InputString(out string result, int maxLen)
101+
public bool InputString(out string result, string prompt, int maxLen, bool multiline)
102102
{
103103
throw new NotImplementedException();
104104
}

src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,8 @@ public ScriptedMiddlewareActivator(
3434

3535
public async Task InvokeAsync(HttpContext context)
3636
{
37-
var engine = _runtime.Engine;
38-
var instance = new ScriptedMiddleware(_next, _module);
39-
var machine = MachineInstance.Current;
40-
machine.PrepareThread(engine.Environment);
41-
try
42-
{
43-
_runtime.DebugCurrentThread();
44-
engine.InitializeSDO(instance);
45-
await instance.InvokeAsync(context);
46-
}
47-
finally
48-
{
49-
_runtime.StopDebugCurrentThread();
50-
}
51-
37+
var instance = new ScriptedMiddleware(_next, _module, _runtime);
38+
await instance.InvokeAsync(context);
5239
}
5340
}
5441
}

0 commit comments

Comments
 (0)