/// <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));
        }
Beispiel #2
0
        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);
 }
Beispiel #4
0
 /// <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);
        }
Beispiel #7
0
 /// <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);
         }
     }
 }
Beispiel #8
0
 /// <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);
         }
     }
 }
Beispiel #9
0
 protected virtual Task <IEnumerable <Tuple> > OnEnumerateAsync(EnumerationContext context, CancellationToken token)
 {
     //Default version is synchronous
     token.ThrowIfCancellationRequested();
     return(Task.FromResult(OnEnumerate(context)));
 }
Beispiel #10
0
 protected abstract IEnumerable <Tuple> OnEnumerate(EnumerationContext context);
Beispiel #11
0
 /// <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);
 }
Beispiel #14
0
 protected T GetValue <T>(EnumerationContext context, string name)
     where T : class
 {
     context.EnsureIsActive();
     return(context.GetValue <T>(this, name));
 }
Beispiel #15
0
        // Constructors

        /// <inheritdoc/>
        public EnumerationScope(RseEnumerationContext context)
            : base(context)
        {
        }
Beispiel #16
0
 /// <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);
Beispiel #17
0
 /// <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)));
 }
Beispiel #18
0
 /// <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);
Beispiel #19
0
 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();
 }