/// <inheritdoc/> protected internal override void OnBeforeEnumerate(EnumerationContext context) { base.OnBeforeEnumerate(context); var parameterContext = ((Xtensive.Orm.Providers.EnumerationContext)context).ParameterContext; SetValue(context, CachedSourceName, Origin.CompiledSource.Invoke(parameterContext)); }
public async Task <IEnumerator <Tuple> > GetEnumeratorAsync(EnumerationContext context, CancellationToken token) { const string enumerationMarker = "Enumerated"; var enumerated = context.GetValue <bool>(this, enumerationMarker); bool onEnumerationExecuted = false; if (!enumerated) { OnBeforeEnumerate(context); } try { context.SetValue(this, enumerationMarker, true); var enumerator = (await OnEnumerateAsync(context, token).ConfigureAwait(false)) .ToEnumerator( () => { if (!enumerated) { OnAfterEnumerate(context); } }); onEnumerationExecuted = true; return(enumerator); } finally { if (!enumerated && !onEnumerationExecuted) { OnAfterEnumerate(context); } } }
private RecordSetReader(EnumerationContext context, ExecutableProvider provider, CancellationToken token = default) { this.context = context; this.provider = provider; this.token = token; isGreedy = context.CheckOptions(EnumerationContextOptions.GreedyEnumerator); }
/// <summary> /// Transforms current <see cref="ExecutableProvider"/> instance to <see cref="IEnumerable{T}"/> /// sequence of <see cref="Tuple"/>s. /// </summary> /// <param name="context">The <see cref="EnumerationContext"/> instance where to perform enumeration.</param> /// <returns>Sequence of <see cref="Tuple"/>s.</returns> public IEnumerable <Tuple> ToEnumerable(EnumerationContext context) { using var tupleReader = RecordSetReader.Create(context, this); while (tupleReader.MoveNext()) { yield return(tupleReader.Current); } }
/// <summary> /// Creates a <see cref="RecordSetReader"/> instance capable to read <paramref name="provider"/> /// execution results and bound to the specified <paramref name="context"/>. /// </summary> /// <param name="context">The <see cref="EnumerationContext"/> instance associated with the query execution.</param> /// <param name="provider">The <see cref="ExecutableProvider"/> to be processed.</param> /// <returns><see cref="RecordSetReader"/> instance ready for enumeration. /// This means query is already executed but no records have been read yet.</returns> public static RecordSetReader Create(EnumerationContext context, ExecutableProvider provider) { var recordSet = new RecordSetReader(context, provider); var task = recordSet.Prepare(false); task.GetAwaiter().GetResult(); // Ensure exception, if any, is being thrown return(recordSet); }
/// <summary> /// Asynchronously creates a <see cref="RecordSetReader"/> instance capable to read <paramref name="provider"/> /// execution results and bound to the specified <paramref name="context"/>. /// </summary> /// <param name="context">The <see cref="EnumerationContext"/> instance associated with the query execution.</param> /// <param name="provider">The <see cref="ExecutableProvider"/> to be processed.</param> /// <param name="token">The <see cref="CancellationToken"/> allowing to cancel query execution if necessary.</param> /// <returns><see cref="RecordSetReader"/> instance ready for enumeration. /// This means query is already executed but no records have been read yet.</returns> public static async ValueTask <RecordSetReader> CreateAsync( EnumerationContext context, ExecutableProvider provider, CancellationToken token) { var recordSet = new RecordSetReader(context, provider, token); await recordSet.Prepare(true).ConfigureAwait(false); return(recordSet); }
/// <summary> /// Called when enumeration is finished. /// </summary> /// <param name="context">The enumeration context.</param> protected internal virtual void OnAfterEnumerate(EnumerationContext context) { foreach (var source in Sources) { if (source is ExecutableProvider ep) { ep.OnAfterEnumerate(context); } } }
/// <summary> /// Called when enumeration is finished. /// </summary> /// <param name="context">The enumeration context.</param> protected virtual void OnAfterEnumerate(EnumerationContext context) { foreach (var source in Sources) { var ep = source as ExecutableProvider; if (ep != null) { ep.OnAfterEnumerate(context); } } }
protected virtual Task <IEnumerable <Tuple> > OnEnumerateAsync(EnumerationContext context, CancellationToken token) { //Default version is synchronous token.ThrowIfCancellationRequested(); return(Task.FromResult(OnEnumerate(context))); }
protected abstract IEnumerable <Tuple> OnEnumerate(EnumerationContext context);
/// <summary> /// Puts specified <paramref name="value"/> into the cache residing in the provided /// <see cref="EnumerationContext"/> instance using the <paramref name="name"/> as the key. /// </summary> /// <param name="context">The <see cref="EnumerationContext"/> where to cache <paramref name="value"/>.</param> /// <param name="name">The name of the <paramref name="value"/> to be cached.</param> /// <param name="value">The value of <typeparamref name="T"/> type to be cached.</param> /// <typeparam name="T">The type of the provided <paramref name="value"/>.</typeparam> protected void SetValue <T>(EnumerationContext context, string name, T value) where T : class => context.SetValue(this, name, value);
/// <inheritdoc/> protected internal override DataReader OnEnumerate(EnumerationContext context) { return(new DataReader(GetValue <IEnumerable <Tuple> >(context, CachedSourceName))); }
/// <inheritdoc/> protected override IEnumerable <Tuple> OnEnumerate(EnumerationContext context) { return(CachedSource); }
protected T GetValue <T>(EnumerationContext context, string name) where T : class { context.EnsureIsActive(); return(context.GetValue <T>(this, name)); }
// Constructors /// <inheritdoc/> public EnumerationScope(RseEnumerationContext context) : base(context) { }
/// <summary> /// Gets value of type <typeparamref name="T"/> previously cached in /// <see cref="EnumerationContext"/> by its <paramref name="name"/>. /// </summary> /// <param name="context"><see cref="EnumerationContext"/> instance where value cache resides.</param> /// <param name="name">The name of the required cached value.</param> /// <typeparam name="T">The type of the value in cache.</typeparam> /// <returns> Cached value with the specified key; /// or <see langword="null"/>, if no cached value is found, or it has already expired. /// </returns> protected T GetValue <T>(EnumerationContext context, string name) where T : class => context.GetValue <T>(this, name);
/// <summary> /// Asynchronously starts enumeration of the given <see cref="ExecutableProvider"/>. /// </summary> /// <param name="context">The enumeration context.</param> /// <param name="token">The <see cref="CancellationToken"/> to interrupt execution if necessary.</param> /// <returns><see cref="DataReader"/> ready to be iterated.</returns> protected internal virtual Task <DataReader> OnEnumerateAsync(EnumerationContext context, CancellationToken token) { //Default version is synchronous token.ThrowIfCancellationRequested(); return(Task.FromResult(OnEnumerate(context))); }
/// <summary> /// Starts enumeration of the given <see cref="ExecutableProvider"/>. /// </summary> /// <param name="context">The enumeration context.</param> /// <returns><see cref="DataReader"/> ready to be iterated.</returns> protected internal abstract DataReader OnEnumerate(EnumerationContext context);
protected void SetValue <T>(EnumerationContext context, string name, T value) where T : class { context.EnsureIsActive(); context.SetValue(this, name, value); }
/// <inheritdoc/> protected override void OnBeforeEnumerate(EnumerationContext context) { base.OnBeforeEnumerate(context); CachedSource = Origin.CompiledSource.Invoke(); }