Exemplo n.º 1
0
        internal IBlockResult Execute(bool measureTime = true)
        {
            if (IsEmptyEventBlock)
            {
                return new BlockResultVoid()
                       {
                           Target = new BlockResultTarget
                           {
                               FlowTarget    = BlockFlowTarget.Return,
                               OverrideInput = Input
                           },
                       }
            }
            ;

            System.Diagnostics.Stopwatch sw = null;
            if (measureTime)
            {
                sw = new System.Diagnostics.Stopwatch();

                sw.Start();
            }

            try
            {
                var result = IsAsync ? AsyncHelper.RunSync(executorAsync) : executor();
                if (measureTime)
                {
                    sw.Stop();
                    result.ExecutionTime = new ExecutionTime(DateTime.Now, sw.Elapsed);
                }
                return(result);
            }
            catch (Exception e)
            {
                this.Events.Throw(e);
                var result = new BlockResultVoid()
                {
                    Target = new BlockResultTarget
                    {
                        FlowTarget = BlockFlowTarget.Return
                    },
                };
                if (measureTime)
                {
                    result.ExecutionTime = new ExecutionTime(DateTime.Now, sw.Elapsed);
                }

                return(result);
            }
        }
Exemplo n.º 2
0
        internal async Task <IBlockResult> ExecuteAsync(bool measureTime = true)
        {
            if (IsEmptyEventBlock)
            {
                return new BlockResultVoid()
                       {
                           Target = new BlockResultTarget
                           {
                               FlowTarget    = BlockFlowTarget.Return,
                               OverrideInput = Input
                           },
                       }
            }
            ;
            //Run with configure await false if no stopwatch (context) needed
            if (!measureTime && IsAsync)
            {
                try
                {
                    return(await executorAsync().ConfigureAwait(false));
                }
                catch (Exception e)
                {
                    this.Events.Throw(e);
                    return(new BlockResultVoid()
                    {
                        Target = new BlockResultTarget
                        {
                            FlowTarget = BlockFlowTarget.Return
                        },
                    });
                }
            }

            //If measure time execute without configure await
            System.Diagnostics.Stopwatch sw = null;
            if (measureTime)
            {
                sw = new System.Diagnostics.Stopwatch();

                sw.Start();
            }

            try
            {
                var result = IsAsync ? await executorAsync() : executor();

                if (measureTime)
                {
                    sw.Stop();
                    ((IBlockResult)result).ExecutionTime = new ExecutionTime(DateTime.Now, sw.Elapsed);
                }
                return(result);
            }
            catch (Exception e)
            {
                this.Events.Throw(e);
                var result = new BlockResultVoid()
                {
                    Target = new BlockResultTarget
                    {
                        FlowTarget = BlockFlowTarget.Return
                    },
                };
                if (measureTime)
                {
                    result.ExecutionTime = new ExecutionTime(DateTime.Now, sw.Elapsed);
                }

                return(result);
            }
        }
    }