/
krasninja
/
querycat
Обзор
Документация
Войти
/
krasninja
/
querycat
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/QueryCat.IntegrationTests/Plugins/SamplePluginRowsIterator.cs
69 строк
2 KB
Ivan Kozhin
Refactor execution thread creation and initialization
27 дек 2023, 07:45
27 дек 2023, 07:45
d832b07
Код
Авторство
О чём код?
using System.ComponentModel; using System.Diagnostics; using QueryCat.Backend; using QueryCat.Backend.Core.Data; using QueryCat.Backend.Core.Functions; using QueryCat.Backend.Core.Types; namespace QueryCat.IntegrationTests.Plugins; /// <summary> /// Example simple rows input iterator. /// </summary> public class SamplePluginRowsIterator : IRowsIterator { private const long MaxValue = 9; [Description("Sample iterator.")] [FunctionSignature("plugin(start: integer = 0): object<IRowsIterator>")] public static VariantValue SamplePlugin(FunctionCallInfo args) { var startValue = args.GetAt(0).AsInteger; var rowsSource = new SamplePluginRowsIterator(startValue); return VariantValue.CreateFromObject(rowsSource); } private long _currentState; /// <inheritdoc /> public Column[] Columns { get; } = { new("id", DataType.Integer, "Key.") }; /// <inheritdoc /> public Row Current { get; } public SamplePluginRowsIterator(long initialValue) { Current = new Row(Columns); _currentState = initialValue; } /// <inheritdoc /> public bool MoveNext() { Trace.WriteLine(nameof(MoveNext)); if (_currentState >= MaxValue) { return false; } _currentState++; Current["id"] = new VariantValue(_currentState); return true; } /// <inheritdoc /> public void Reset() { Trace.WriteLine(nameof(Reset)); _currentState = 0; } /// <inheritdoc /> public void Explain(IndentedStringBuilder stringBuilder) { Trace.WriteLine(nameof(Explain)); stringBuilder.AppendRowsIteratorsWithIndent("Sample Plugin"); } }