Пример #1
0
        /// <inheritdoc/>
        public void Init(HttpApplication context)
        {
            context.BeginRequest += (sender, args) =>
            {
                TransactionInstance transactionInstance = TransactionInstance.GetInstance(context.Context);
                transactionInstance.BeginDetail                 += TransactionModule.BeginDetail;
                transactionInstance.BeginTransaction            += TransactionModule.BeginTransaction;
                transactionInstance.EndDetail                   += TransactionModule.EndDetail;
                transactionInstance.EndTransaction              += TransactionModule.EndTransaction;
                context.Context.Items[nameof(TransactionModule)] = transactionInstance.StartTransaction(
                    context.Context.Request.Url,
                    nameof(HttpApplication),
                    nameof(TransactionModule));
            };

            context.AcquireRequestState += (sender, args) =>
            {
                context.Context.Items[nameof(TransactionDetail)] = TransactionInstance.GetInstance(context.Context).StartDetail(
                    nameof(HttpApplication),
                    nameof(context.AcquireRequestState));
            };
            context.PostAcquireRequestState += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopDetail(context.Context.Items[nameof(TransactionDetail)] as TransactionDetail, true);
                context.Context.Items.Remove(nameof(TransactionDetail));
            };

            context.AuthenticateRequest += (sender, args) =>
            {
                context.Context.Items[nameof(TransactionDetail)] = TransactionInstance.GetInstance(context.Context).StartDetail(
                    nameof(HttpApplication),
                    nameof(context.AuthenticateRequest));
            };
            context.PostAuthenticateRequest += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopDetail(
                    context.Context.Items[nameof(TransactionDetail)] as TransactionDetail,
                    true);
                context.Context.Items.Remove(nameof(TransactionDetail));
            };

            context.AuthorizeRequest += (sender, args) =>
            {
                context.Context.Items[nameof(TransactionDetail)] = TransactionInstance.GetInstance(context.Context).StartDetail(
                    nameof(HttpApplication),
                    nameof(context.AuthorizeRequest));
            };
            context.PostAuthorizeRequest += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopDetail(
                    context.Context.Items[nameof(TransactionDetail)] as TransactionDetail,
                    true);
                context.Context.Items.Remove(nameof(TransactionDetail));
            };

            context.ResolveRequestCache += (sender, args) =>
            {
                context.Context.Items[nameof(TransactionDetail)] = TransactionInstance.GetInstance(context.Context).StartDetail(
                    nameof(HttpApplication),
                    nameof(context.ResolveRequestCache));
            };
            context.PostResolveRequestCache += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopDetail(
                    context.Context.Items[nameof(TransactionDetail)] as TransactionDetail,
                    true);
                context.Context.Items.Remove(nameof(TransactionDetail));
            };

            context.PreRequestHandlerExecute += (sender, args) =>
            {
                if (context.Context.Items[nameof(TransactionModule)] is TransactionDescription transactionDescription)
                {
                    KeyValuePair <string, string> fullMethodName = TransactionHelper.GetFullMethodName(context.Context);
                    transactionDescription.FullName   = fullMethodName.Key;
                    transactionDescription.MethodName = fullMethodName.Value;
                }

                context.Context.Items[nameof(TransactionDetail)] = TransactionInstance.GetInstance(context.Context).StartDetail(
                    nameof(HttpApplication),
                    nameof(context.Request));
            };
            context.PostRequestHandlerExecute += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopDetail(
                    context.Context.Items[nameof(TransactionDetail)] as TransactionDetail,
                    true);
                context.Context.Items.Remove(nameof(TransactionDetail));
            };

            context.UpdateRequestCache += (sender, args) =>
            {
                context.Context.Items[nameof(TransactionDetail)] = TransactionInstance.GetInstance(context.Context).StartDetail(
                    nameof(HttpApplication),
                    nameof(context.UpdateRequestCache));
            };
            context.PostUpdateRequestCache += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopDetail(
                    context.Context.Items[nameof(TransactionDetail)] as TransactionDetail,
                    true);
                context.Context.Items.Remove(nameof(TransactionDetail));
            };

            context.Error += (sender, args) =>
            {
                if (context.Context.Items[nameof(TransactionDetail)] is TransactionDetail transactionDetail)
                {
                    TransactionInstance.GetInstance(context.Context).StopDetail(
                        transactionDetail,
                        true);
                    context.Context.Items.Remove(nameof(TransactionDetail));
                }
            };

            context.EndRequest += (sender, args) =>
            {
                TransactionInstance.GetInstance(context.Context).StopTransaction();
            };
        }
Пример #2
0
 /// <summary>
 /// Gets the full name and the method name.
 /// The Key is FullName and the Value is MethodName
 /// </summary>
 /// <param name="httpContext">The context HTTP.</param>
 /// <returns>The full name and method name.</returns>
 public static KeyValuePair <string, string> GetFullMethodName(HttpContext httpContext)
 {
     return(TransactionHelper.GetFullMethodName(new HttpContextWrapper(httpContext)));
 }