Exemple #1
0
        public async Task <object> ExecuteOperation(ILightNodeOptions options, OperationContext context, Func <ILightNodeOptions, OperationContext, Task <object> > originalOperation)
        {
            if (MessageBroker == null || Timer == null)
            {
                return(await originalOperation(options, context));
            }
            var timer = Timer;

            object result;
            var    start = timer.Start();

            try
            {
                result = await originalOperation(options, context);

                var stop = timer.Stop(start);

                var message = new LightNodeExecuteResultMessage()
                {
                    ContractName         = context.ContractName,
                    OperationName        = context.OperationName,
                    Result               = result,
                    Environment          = context.Environment,
                    UsedContentFormatter = context.ContentFormatter,
                    Options              = options,
                    FromRequestStart     = timer.Point().Offset,
                    Phase = OperationPhase.Operation
                }
                .AsTimelineMessage(context.ToString(), OperationCategory)
                .AsTimedMessage(stop);
                MessageBroker.Publish(message);
                return(result);
            }
            catch (Exception ex)
            {
                var stop = timer.Stop(start);

                var message = new LightNodeExecuteResultMessage()
                {
                    ContractName         = context.ContractName,
                    OperationName        = context.OperationName,
                    Result               = ex.ToString(),
                    Environment          = context.Environment,
                    UsedContentFormatter = context.ContentFormatter,
                    Options              = options,
                    FromRequestStart     = timer.Point().Offset,
                    Phase = (ex is ReturnStatusCodeException) ? OperationPhase.ReturnStatusCode : OperationPhase.Exception
                }
                .AsTimelineMessage(context.ToString(), OperationCategory)
                .AsTimedMessage(stop);
                MessageBroker.Publish(message);

                throw;
            }
        }
        public async Task<object> ExecuteOperation(ILightNodeOptions options, OperationContext context, Func<ILightNodeOptions, OperationContext, Task<object>> originalOperation)
        {
            if (MessageBroker == null || Timer == null) return await originalOperation(options, context);
            var timer = Timer;

            object result;
            var start = timer.Start();
            try
            {
                result = await originalOperation(options, context);

                var stop = timer.Stop(start);

                var message = new LightNodeExecuteResultMessage()
                    {
                        ContractName = context.ContractName,
                        OperationName = context.OperationName,
                        Result = result,
                        Environment = context.Environment,
                        UsedContentFormatter = context.ContentFormatter,
                        Options = options,
                        FromRequestStart = timer.Point().Offset,
                        Phase = OperationPhase.Operation
                    }
                    .AsTimelineMessage(context.ToString(), OperationCategory)
                    .AsTimedMessage(stop);
                MessageBroker.Publish(message);
                return result;
            }
            catch (Exception ex)
            {
                var stop = timer.Stop(start);

                var message = new LightNodeExecuteResultMessage()
                    {
                        ContractName = context.ContractName,
                        OperationName = context.OperationName,
                        Result = ex.ToString(),
                        Environment = context.Environment,
                        UsedContentFormatter = context.ContentFormatter,
                        Options = options,
                        FromRequestStart = timer.Point().Offset,
                        Phase = (ex is ReturnStatusCodeException) ? OperationPhase.ReturnStatusCode : OperationPhase.Exception
                    }
                    .AsTimelineMessage(context.ToString(), OperationCategory)
                    .AsTimedMessage(stop);
                MessageBroker.Publish(message);

                throw;
            }
        }