コード例 #1
0
        /// <summary>
        /// Add a decorator to the enumerable for additional processing
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="enumerator">The enumerator.</param>
        protected override IEnumerable <Row> DecorateEnumerableForExecution(IOperation operation, IEnumerable <Row> enumerator)
        {
            ThreadSafeEnumerator <Row> threadedEnumerator = new ThreadSafeEnumerator <Row>();

            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    foreach (Row t in new EventRaisingEnumerator(operation, enumerator))
                    {
                        threadedEnumerator.AddItem(t);
                    }
                }
                catch (Exception e)
                {
                    Error(e, "Failed to execute operation {0}", operation);
                    threadedEnumerator.MarkAsFinished();
#if DEBUG
                    throw e;
#endif
                }
                finally
                {
                    threadedEnumerator.MarkAsFinished();
                }
            });
            return(threadedEnumerator);
        }
コード例 #2
0
 /// <summary>
 /// Add a decorator to the enumerable for additional processing
 /// </summary>
 /// <param name="operation">The operation.</param>
 /// <param name="enumerator">The enumerator.</param>
 protected override IEnumerable<Row> DecorateEnumerableForExecution(IOperation operation, IEnumerable<Row> enumerator)
 {
     ThreadSafeEnumerator<Row> threadedEnumerator = new ThreadSafeEnumerator<Row>();
     ThreadPool.QueueUserWorkItem(delegate
     {
         try
         {
             foreach (Row t in new EventRaisingEnumerator(operation, enumerator))
             {
                 threadedEnumerator.AddItem(t);
             }
         }
         catch (Exception e)
         {
             Error(e, "Failed to execute operation {0}", operation);
             threadedEnumerator.MarkAsFinished();
             throw;
         }
         finally
         {
             threadedEnumerator.MarkAsFinished();
         }
     });
     return threadedEnumerator;
 }
コード例 #3
0
        /// <summary>
        ///     Add a decorator to the enumerable for additional processing
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="enumerator">The enumerator.</param>
        protected override IEnumerable <Row> DecorateEnumerableForExecution(IOperation operation, IEnumerable <Row> enumerator)
        {
            var threadedEnumerator = new ThreadSafeEnumerator <Row>();

            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    foreach (Row t in new EventRaisingEnumerator(operation, enumerator))
                    {
                        threadedEnumerator.AddItem(t);
                    }
                } catch (Exception e) {
                    foreach (var inner in e.FlattenHierarchy())
                    {
                        Error(inner, "Failed to execute {0}. {1}", operation.Name, inner.Message);
                        Debug(inner.StackTrace);
                    }
                    threadedEnumerator.MarkAsFinished();
#if DEBUG
                    throw new TransformalizeException(Logger, e.Message);
#endif
                } finally {
                    threadedEnumerator.MarkAsFinished();
                }
            });
            return(threadedEnumerator);
        }
コード例 #4
0
        /// <summary>
        /// Add a decorator to the enumerable for additional processing
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="enumerator">The enumerator.</param>
        /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> that may be used to cancel the asynchronous iteration.</param>
        protected override AsyncEnumerableTask <Row> DecorateEnumerableForExecution(
            IOperation operation,
            IAsyncEnumerable <Row> enumerator,
            CancellationToken cancellationToken = default)
        {
            ThreadSafeEnumerator <Row> threadedEnumerator = new ThreadSafeEnumerator <Row>();
            Task task = Task.Run(async() =>
            {
                try
                {
                    IAsyncEnumerable <Row> eventRaisingEnumerator = new EventRaisingEnumerator(operation, enumerator);
                    await eventRaisingEnumerator
                    .ForEachAsync(async t => { await threadedEnumerator.AddItem(t); },
                                  cancellationToken: cancellationToken);
                }
                catch (Exception e)
                {
                    Error(e, "Failed to execute operation {0}", new Tuple <string, object>("Operation", operation));
                }
                finally
                {
                    await threadedEnumerator.MarkAsFinished();
                }
            }, cancellationToken);

            return(new AsyncEnumerableTask <Row>
            {
                Enumerable = threadedEnumerator,
                Task = task,
            });
        }
コード例 #5
0
        /// <summary>
        ///     Add a decorator to the enumerable for additional processing
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="enumerator">The enumerator.</param>
        protected override IEnumerable<Row> DecorateEnumerableForExecution(IOperation operation, IEnumerable<Row> enumerator) {
            var threadedEnumerator = new ThreadSafeEnumerator<Row>();
            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    foreach (Row t in new EventRaisingEnumerator(operation, enumerator)) {
                        threadedEnumerator.AddItem(t);
                    }
                } catch (Exception e) {
                    foreach (var inner in e.FlattenHierarchy()) {
                        Error(inner, "Failed to execute {0}. {1}", operation.Name, inner.Message);
                        Debug(inner.StackTrace);
                    }
                    threadedEnumerator.MarkAsFinished();
#if DEBUG
                    throw new TransformalizeException(Logger, e.Message);
#endif

                } finally {
                    threadedEnumerator.MarkAsFinished();
                }
            });
            return threadedEnumerator;
        }