Skip to content

Commit

Permalink
Merge branch 'release/v1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Ovsiankin committed Apr 29, 2021
2 parents 9673f28 + 01f3069 commit 9db0342
Show file tree
Hide file tree
Showing 42 changed files with 1,069 additions and 89 deletions.
3 changes: 1 addition & 2 deletions Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@
<CallTarget Targets="InstallStdLib" Condition="'$(StandardLibraryPacks)' != ''"/>
<DeleteTree Directories="$(LibFolder)/opm" />

<Exec Command="&quot;$(ToolFolder)/oscript.exe&quot; &quot;$(MSBuildProjectDirectory)\install\unicode-zipper.os&quot; unpack &quot;$(MSBuildProjectDirectory)\install\opm-0.16.2.ospx&quot; &quot;$(LibFolder)\tmp&quot;"/>
<Exec Command="&quot;$(ToolFolder)/oscript.exe&quot; &quot;$(MSBuildProjectDirectory)\install\unicode-zipper.os&quot; unpack &quot;$(MSBuildProjectDirectory)\install\opm-1.0.2.ospx&quot; &quot;$(LibFolder)\tmp&quot;"/>
<Exec Command="&quot;$(ToolFolder)/oscript.exe&quot; &quot;$(MSBuildProjectDirectory)\install\unicode-zipper.os&quot; unpack &quot;$(LibFolder)\tmp\content.zip&quot; &quot;$(LibFolder)/opm&quot;"/>

<Copy SourceFiles="$(MSBuildProjectDirectory)\install\oscript-config.exe" DestinationFolder="$(TempFolder)/%(PlatformItem.BinFolder)" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\install\package-loader.os" DestinationFolder="$(LibFolder)"/>

<DeleteTree Directories="$(LibFolder)\tmp"/>
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pipeline {
agent none

environment {
ReleaseNumber = '1.5.0'
ReleaseNumber = '1.6.0'
outputEnc = '65001'
}

Expand Down
Binary file removed install/opm-0.16.2.ospx
Binary file not shown.
Binary file added install/opm-1.0.2.ospx
Binary file not shown.
Binary file removed install/oscript-config.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ASPNETHandler/ASPNetApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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
2 changes: 1 addition & 1 deletion src/ASPNETHandler/ASPNetNullApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void ShowExceptionInfo(Exception exc)
// Непонятно что это, наверное аналог системного диалога, на сервере нет никаких диалогов
}

public bool InputString(out string result, int maxLen)
public bool InputString(out string result, string prompt, int maxLen, bool multiline)
{
// Мы не можем вводить никаких строк на сервере в 1С это недоступно
result = null;
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTests/EngineWrapperNUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public string[] GetCommandLineArguments()
return commandLineArgs;
}

public bool InputString(out string result, int maxLen)
public bool InputString(out string result, string prompt, int maxLen, bool multiline)
{
result = "";
return false;
Expand Down
18 changes: 11 additions & 7 deletions src/OneScript.DebugProtocol/EvaluatedVariableLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class EvaluatedVariableLocator : IVariableLocator
private int[] _path;
private readonly int _stackFrameIndex;
private readonly string _expression;
private readonly int _threadId;

private Variable[] _variables;

Expand All @@ -28,21 +29,24 @@ private EvaluatedVariableLocator(EvaluatedVariableLocator parent, int variableIn
Array.Copy(parent._path, _path, parent._path.Length);
_path[parent._path.Length] = variableIndex;
_expression = parent._expression;
}
_threadId = parent._threadId;
}

public EvaluatedVariableLocator(string expression, int stackFrameIndex)
public EvaluatedVariableLocator(string expression, int threadId, int stackFrameIndex)
{
_stackFrameIndex = stackFrameIndex;
_path = new int[0];
_expression = expression;
}
_threadId = threadId;
}

public EvaluatedVariableLocator(string expression, int stackFrameIndex, int variableIndex)
public EvaluatedVariableLocator(string expression, int threadId, int stackFrameIndex, int variableIndex)
{
_stackFrameIndex = stackFrameIndex;
_path = new int[] { variableIndex };
_expression = expression;
}
_threadId = threadId;
}

public Variable this[int index]
{
Expand All @@ -53,7 +57,7 @@ public EvaluatedVariableLocator(string expression, int stackFrameIndex, int vari
return _variables[index];
}
}

public int Count
{
get
Expand Down Expand Up @@ -85,7 +89,7 @@ void IVariableLocator.Hydrate(IDebuggerService process)
{
if(_variables != null)
return;
var variables = process.GetEvaluatedVariables(_expression, 1, _stackFrameIndex, _path);
var variables = process.GetEvaluatedVariables(_expression, _threadId, _stackFrameIndex, _path);
_variables = variables;
}

Expand Down
6 changes: 6 additions & 0 deletions src/OneScriptDocumenter/toc_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
* [КоллекцияСовпаденийРегулярногоВыражения]($base_url$/КоллекцияСовпаденийРегулярногоВыражения)
* [СовпадениеРегулярногоВыражения]($base_url$/СовпадениеРегулярногоВыражения)

### Работа с фоновыми заданиями

* [ФоновоеЗадание](/syntax/page/ФоновоеЗадание)
* [МенеджерФоновыхЗаданий](/syntax/page/МенеджерФоновыхЗаданий)
* [БлокировкаРесурса](/syntax/page/БлокировкаРесурса)

### Работа с форматами сериализации

* [ЧтениеXML]($base_url$/ЧтениеXML)
Expand Down
7 changes: 7 additions & 0 deletions src/ScriptEngine.HostedScript/HostedScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ScriptEngine.Machine;
using System.Collections.Generic;
using ScriptEngine.Compiler;
using ScriptEngine.HostedScript.Library.Tasks;
using ScriptEngine.Machine.Contexts;


Expand Down Expand Up @@ -90,6 +91,12 @@ public void Initialize()
{
InitializationCallback?.Invoke(_engine, _engine.Environment);
_engine.Initialize();

var taskManager = new BackgroundTasksManager(EngineInstance);
_engine.Environment.InjectGlobalProperty(taskManager, "ФоновыеЗадания", true);
_engine.Environment.InjectGlobalProperty(taskManager, "BackgroundTasks", true);


_isInitialized = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ScriptEngine.HostedScript/IHostApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IHostApplication
{
void Echo(string str, MessageStatusEnum status = MessageStatusEnum.Ordinary);
void ShowExceptionInfo(Exception exc);
bool InputString(out string result, int maxLen);
bool InputString(out string result, string prompt, int maxLen, bool multiline);
string[] GetCommandLineArguments();
}
}
38 changes: 34 additions & 4 deletions src/ScriptEngine.HostedScript/Library/SystemGlobalContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,46 @@ public void Quit(int exitCode)
/// Ввод строки пользователем. Позволяет запросить у пользователя информацию.
/// </summary>
/// <param name="resut">Выходной параметр. Введенные данные в виде строки.</param>
/// <param name="len">Максимальная длина вводимой строки.
/// Возможно указание неограниченной длины (длина=ноль), но данное поведение может не поддерживаться хост-приложением.</param>
/// <param name="prompt">Строка, выводимая в качестве подсказки. Необязательный, по умолчанию - пустая строка.</param>
/// <param name="len">Максимальная длина вводимой строки. Необязательный, по умолчанию - 0 (неограниченная длина).
/// Указание неограниченной длины может не поддерживаться хост-приложением.</param>
/// <param name="multiline">Булево, определяет режим ввода многострочного текста. Необязательный, по умолчанию - Ложь.</param>
/// <returns>Булево. Истина, если пользователь ввел данные, Ложь, если отказался.</returns>
[ContextMethod("ВвестиСтроку", "InputString")]
public bool InputString([ByRef] IVariable resut, int len = 0)
public bool InputString([ByRef] IVariable resut, IValue prompt = null, IValue len = null, IValue multiline = null)
{
string input;
bool inputIsDone;

string strPrompt = null;
int length = 0;
bool flagML = false;

if (prompt != null)
{
if (prompt.DataType != DataType.String)
throw RuntimeException.InvalidNthArgumentType(2);

strPrompt = prompt.AsString();
}

if (len != null)
{
if (len.DataType != DataType.Number)
throw RuntimeException.InvalidNthArgumentType(3);

length = (int)len.AsNumber();
}

if (multiline != null)
{
if (multiline.DataType != DataType.Boolean)
throw RuntimeException.InvalidNthArgumentType(4);

flagML = multiline.AsBoolean();
}

inputIsDone = ApplicationHost.InputString(out input, len);
inputIsDone = ApplicationHost.InputString(out input, strPrompt, length, flagML);

if (inputIsDone)
{
Expand Down
114 changes: 114 additions & 0 deletions src/ScriptEngine.HostedScript/Library/Tasks/BackgroundTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*----------------------------------------------------------
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;
using System.Threading.Tasks;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;

namespace ScriptEngine.HostedScript.Library.Tasks
{
[ContextClass("ФоновоеЗадание", "BackgroundTask")]
public class BackgroundTask : AutoContext<BackgroundTask>
{
private readonly MethodInfo _method;
private readonly int _methIndex;
private Task _workerTask;
private int _taskId;

public BackgroundTask(IRuntimeContextInstance target, string methodName, ArrayImpl parameters = default)
{
Target = target;
MethodName = methodName;
if(parameters != default)
Parameters = new ArrayImpl(parameters);

Identifier = new GuidWrapper();

_methIndex = Target.FindMethod(MethodName);
_method = Target.GetMethodInfo(_methIndex);
}

public Task WorkerTask
{
get => _workerTask;
set
{
_workerTask = value;
_taskId = _workerTask.Id;
}
}

public int TaskId => _taskId;

[ContextProperty("УникальныйИдентификатор","UUID")]
public GuidWrapper Identifier { get; private set; }

[ContextProperty("ИмяМетода","MethodName")]
public string MethodName { get; private set; }

[ContextProperty("Объект","Object")]
public IRuntimeContextInstance Target { get; private set; }

[ContextProperty("Состояние", "State")]
public TaskStateEnum State { get; private set; }

[ContextProperty("Параметры", "Parameters")]
public IValue Parameters { get; private set; } = ValueFactory.Create();

[ContextProperty("Результат", "Result")]
public IValue Result { get; private set; } = ValueFactory.Create();

[ContextProperty("ИнформацияОбОшибке", "ExceptionInfo")]
public ExceptionInfoContext ExceptionInfo { get; private set; }

/// <summary>
/// Ждать завершения задания указанное число миллисекунд
/// </summary>
/// <param name="timeout">Таймаут. Если ноль - ждать вечно</param>
/// <returns>Истина - дождались завершения. Ложь - сработал таймаут</returns>
[ContextMethod("ОжидатьЗавершения", "Wait")]
public bool Wait(int timeout = 0)
{
timeout = BackgroundTasksManager.ConvertTimeout(timeout);

return WorkerTask.Wait(timeout);
}

public void ExecuteOnCurrentThread()
{
if (State != TaskStateEnum.NotRunned)
throw new RuntimeException(Locale.NStr("ru = 'Неверное состояние задачи';en = 'Incorrect task status'"));

var parameters = Parameters is ArrayImpl array ?
array.ToArray() :
new IValue[0];

try
{
State = TaskStateEnum.Running;
if (_method.IsFunction)
{
Target.CallAsFunction(_methIndex, parameters, out var result);
Result = result;
}
else
{
Target.CallAsProcedure(_methIndex, parameters);
}

State = TaskStateEnum.Completed;
}
catch (RuntimeException exception)
{
State = TaskStateEnum.CompletedWithErrors;
ExceptionInfo = new ExceptionInfoContext(exception);
}
}
}
}

0 comments on commit 9db0342

Please sign in to comment.