Example #1
0
            public override async Task Invoke(OperationContext operationContext, Func <Task> next)
            {
                var filterName     = originalFilter.GetType().Name;
                var executingStart = timer.Start();
                var executedStart  = default(TimeSpan);
                var firstPhase     = true;

                try
                {
                    await originalFilter.Invoke(operationContext, async() =>
                    {
                        firstPhase = false;
                        var executingTimerResult = timer.Stop(executingStart);
                        var msg = new LightNodeFilterResultMessage()
                        {
                            ContractName     = operationContext.ContractName,
                            OperationName    = operationContext.OperationName,
                            FilterName       = filterName,
                            Order            = originalFilter.Order,
                            Phase            = OperationPhase.Before,
                            FromRequestStart = timer.Point().Offset
                        }
                        .AsTimelineMessage(filterName, FilterCategory, "Before")
                        .AsTimedMessage(executingTimerResult);
                        messageBroker.Publish(msg);
                        try
                        {
                            await next();
                        }
                        finally
                        {
                            executedStart = timer.Start();
                        }
                    });
                }
                catch (Exception ex)
                {
                    var msg = new LightNodeFilterResultMessage()
                    {
                        ContractName     = operationContext.ContractName,
                        OperationName    = operationContext.OperationName,
                        FilterName       = filterName,
                        Order            = originalFilter.Order,
                        Phase            = (ex is ReturnStatusCodeException) ? OperationPhase.ReturnStatusCode : OperationPhase.Exception,
                        FromRequestStart = timer.Point().Offset
                    }
                    .AsTimelineMessage(filterName, FilterCategory, "Exception")
                    .AsTimedMessage((firstPhase) ? timer.Stop(executingStart) : timer.Stop(executedStart));
                    messageBroker.Publish(msg);
                    throw;
                }

                var executedTimerResult = timer.Stop(executedStart);
                var msgFinish           = new LightNodeFilterResultMessage()
                {
                    ContractName     = operationContext.ContractName,
                    OperationName    = operationContext.OperationName,
                    FilterName       = originalFilter.GetType().Name,
                    Order            = originalFilter.Order,
                    Phase            = OperationPhase.After,
                    FromRequestStart = timer.Point().Offset
                }
                .AsTimelineMessage(filterName, FilterCategory, "After")
                .AsTimedMessage(executedTimerResult);

                messageBroker.Publish(msgFinish);
            }
            public override async Task Invoke(OperationContext operationContext, Func<Task> next)
            {
                var filterName = originalFilter.GetType().Name;
                var executingStart = timer.Start();
                var executedStart = default(TimeSpan);
                var firstPhase = true;
                try
                {
                    await originalFilter.Invoke(operationContext, async () =>
                    {
                        firstPhase = false;
                        var executingTimerResult = timer.Stop(executingStart);
                        var msg = new LightNodeFilterResultMessage()
                            {
                                ContractName = operationContext.ContractName,
                                OperationName = operationContext.OperationName,
                                FilterName = filterName,
                                Order = originalFilter.Order,
                                Phase = OperationPhase.Before,
                                FromRequestStart = timer.Point().Offset
                            }
                            .AsTimelineMessage(filterName, FilterCategory, "Before")
                            .AsTimedMessage(executingTimerResult);
                        messageBroker.Publish(msg);
                        try
                        {
                            await next();
                        }
                        finally
                        {
                            executedStart = timer.Start();
                        }
                    });
                }
                catch (Exception ex)
                {
                    var msg = new LightNodeFilterResultMessage()
                        {
                            ContractName = operationContext.ContractName,
                            OperationName = operationContext.OperationName,
                            FilterName = filterName,
                            Order = originalFilter.Order,
                            Phase = (ex is ReturnStatusCodeException) ? OperationPhase.ReturnStatusCode : OperationPhase.Exception,
                            FromRequestStart = timer.Point().Offset
                        }
                        .AsTimelineMessage(filterName, FilterCategory, "Exception")
                        .AsTimedMessage((firstPhase) ? timer.Stop(executingStart) : timer.Stop(executedStart));
                    messageBroker.Publish(msg);
                    throw;
                }

                var executedTimerResult = timer.Stop(executedStart);
                var msgFinish = new LightNodeFilterResultMessage()
                    {
                        ContractName = operationContext.ContractName,
                        OperationName = operationContext.OperationName,
                        FilterName = originalFilter.GetType().Name,
                        Order = originalFilter.Order,
                        Phase = OperationPhase.After,
                        FromRequestStart = timer.Point().Offset
                    }
                    .AsTimelineMessage(filterName, FilterCategory, "After")
                    .AsTimedMessage(executedTimerResult);
                messageBroker.Publish(msgFinish);
            }