Пример #1
0
        /// <summary>
        ///      The method used to perform the logging of the dependency call
        /// </summary>
        /// <param name="work">The work that this coordinator will manage</param>
        /// <param name="metadata">The metadata related to this dependency call</param>
        /// <returns>an awaitable <see cref="Task"/></returns>
        public async Task ExecuteAsync(Func <Task> work, DependencyMetadata metadata)
        {
            try
            {
                metadata.Start();
                await work();

                metadata.Complete();
            }
            catch (Exception ex)
            {
                metadata.CompleteWithException(ex);
                throw;
            }
            finally
            {
                Write(metadata);
            }
        }
Пример #2
0
        /// <summary>
        ///      The method used to perform the logging of the dependency call
        /// </summary>
        /// <typeparam name="TResult">The type of the result to be returned asynchronously</typeparam>
        /// <param name="work">The work that this coordinator will manage</param>
        /// <param name="metadata">The metadata related to this dependency call</param>
        /// <returns>an awaitable <see cref="Task{TResult}"/></returns>
        public async Task <TResult> ExecuteAsync <TResult>(Func <Task <TResult> > work, DependencyMetadata <TResult> metadata)
        {
            try
            {
                metadata.Start();
                var result = await work();

                metadata.Complete(result);

                return(result);
            }
            catch (Exception ex)
            {
                metadata.CompleteWithException(ex);
                throw;
            }
            finally
            {
                Write(metadata);
            }
        }