Exemplo n.º 1
0
        public void Execute(EnableDatabaseTracingParameters parameters)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[schemaName];
            string connectionString           = settings.ConnectionString;

            if (parameters.IsTracingEnabled)
            {
                TraceContext context = TraceContext.CreateContext(
                    ApplicationContext.Current.UserId,
                    ApplicationContext.Current.TerminalId,
                    ApplicationContext.Current.SessionId);

                context.IsTracingEnabled = true;

                ITracingDao tracingDao = PolicyInjection.Create <TracingDao, ITracingDao>(connectionString);
                StartDatabaseTracingParameters startTracingParameters = new StartDatabaseTracingParameters();

                string userId = ApplicationContext.Current.UserId;

                if ((userId.Contains('\\') || userId.Contains('/')))
                {
                    string[] userIdParts = userId.Split(new char[] { '\\', '/' });
                    userId = userIdParts[1];
                }

                startTracingParameters.UserId      = userId;
                startTracingParameters.TerminalId  = ApplicationContext.Current.TerminalId;
                startTracingParameters.WriteHeader = true;
                tracingDao.StartDatabaseTracing(startTracingParameters);
            }
            else
            {
                TraceContext context = TraceContext.GetContext(
                    ApplicationContext.Current.UserId,
                    ApplicationContext.Current.TerminalId,
                    ApplicationContext.Current.SessionId);

                if (context != null)
                {
                    context.IsTracingEnabled = false;

                    ITracingDao tracingDao = PolicyInjection.Create <TracingDao, ITracingDao>(connectionString);
                    StopDatabaseTracingParameters stopTracingParameters = new StopDatabaseTracingParameters();
                    stopTracingParameters.WriteHeader = true;
                    tracingDao.StopDatabaseTracing(stopTracingParameters);
                }
            }
        }
Exemplo n.º 2
0
        public static TraceContext GetContext(string userId, string terminalId, string sessionId)
        {
            TraceContext context = null;
            string       key     = string.Format("{0}_{1}", userId, terminalId);

            syncLock.AcquireReaderLock(-1);

            try
            {
                contextDictionary.TryGetValue(key, out context);

                if ((context != null) && (context.SessionId != sessionId))
                {
                    context = null;
                }
            }
            finally
            {
                syncLock.ReleaseReaderLock();
            }

            return(context);
        }
Exemplo n.º 3
0
        public static TraceContext CreateContext(string userId, string terminalId, string sessionId)
        {
            string key = string.Format("{0}_{1}", userId, terminalId);

            TraceContext context = new TraceContext();

            context.TerminalId = terminalId;
            context.UserId     = userId;
            context.SessionId  = sessionId;

            syncLock.AcquireWriterLock(-1);

            try
            {
                contextDictionary[key] = context;
            }
            finally
            {
                syncLock.ReleaseWriterLock();
            }

            return(context);
        }
Exemplo n.º 4
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            IMethodReturn msg     = null;
            TraceContext  context = null;

            if (ApplicationContext.Current != null)
            {
                context = TraceContext.GetContext(
                    ApplicationContext.Current.UserId,
                    ApplicationContext.Current.TerminalId,
                    ApplicationContext.Current.SessionId);
            }

            if (context != null && context.IsTracingEnabled)
            {
                lock (context)
                {
                    using (ITransactionScope scope = new TransactionScope())
                    {
                        string userId = context.UserId;

                        if ((userId.Contains('\\') || userId.Contains('/')))
                        {
                            string[] userIdParts = userId.Split(new char[] { '\\', '/' });
                            userId = userIdParts[1];
                        }

                        ITracingDao tracingDao = new TracingDao(connectionString);

                        StartDatabaseTracingParameters startParameters = new StartDatabaseTracingParameters();
                        startParameters.TerminalId  = context.TerminalId;
                        startParameters.UserId      = userId;
                        startParameters.WriteHeader = false;

                        tracingDao.StartDatabaseTracing(startParameters);

                        try
                        {
                            msg = getNext()(input, getNext);
                        }
                        finally
                        {
                            StopDatabaseTracingParameters stopParameters = new StopDatabaseTracingParameters();
                            stopParameters.WriteHeader = false;
                            tracingDao.StopDatabaseTracing(stopParameters);
                        }

                        try
                        {
                            scope.Complete();
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
            }
            else
            {
                msg = getNext()(input, getNext);
            }

            return(msg);
        }