public NeoEmulator(Blockchain blockchain)
        {
            this.blockchain = blockchain;
            this.interop    = new InteropService();

            _pctx = new ProfilerContext();
        }
        ISession OpenSession(ISessionFactory factory, ShardId shardId, PartitionId partitionId)
        {
            var workbench = Workbench.Current;
            var session   = WorkbenchUtil <ShardId, ISession> .GetValue(SessionCacheKey, shardId);

            //检测同一个session是否有相同的逻辑表但真实表不一致的情况
            if (session != null)
            {
                var interceptor = (ShardInterceptor)((ISessionImplementor)session).Interceptor;
                if (!interceptor.Register(partitionId))
                {
                    session = null;
                }
            }

            if (session == null)
            {
                workbench.AttachDisposeHandler(DisposeSessions);
                using (var scope = ProfilerContext.Profile("open nhibernate inner session"))
                {
                    session = factory.OpenSession(new ShardInterceptor(partitionId));
                }
                WorkbenchUtil <ShardId, ISession> .SetValue(SessionCacheKey, shardId, session);
            }
            if (TransactionScope.IsScope && !TransactionScope.IsLinkWidhTranscation(session))
            {
                ProfilerContext.Current.Trace("platform", "open a transaction session");
                TransactionScope.Push(new NHibernateTranscation(session.BeginTransaction()), session);
            }
            return(session);
        }
Exemple #3
0
            /// <summary>
            /// Debug
            /// </summary>
            /// <param name="message"></param>
            public void Debug(object message)
            {
                if (ProfilerContext.Current.Enabled)
                {
                    ProfilerContext.Current.Trace("nhibernate", FormatSql((string)message));
                }
                using (var p = ProfilerContext.Profile((string)message))
                { }

                //_log.Debug(message);
            }
        void Trace <T>(string method, string query)
        {
            var message = String.Format("{0}@{1}\r\nquery:{2}", typeof(T).FullName, method, query);

            if (ProfilerContext.Current.Enabled)
            {
                ProfilerContext.Current.Trace("mongo", String.Format("{0}@{1}\r\nquery:{2}", typeof(T).FullName, method, Projects.Tool.Profiler.ProfilerUtil.JsonFormat(query)));
            }

            using (var p = ProfilerContext.Profile(message))
            { }
        }
Exemple #5
0
        public void Intercept(IInvocation invocation)
        {
            var  methodName = invocation.Method.Name;
            bool skip       = methodName == "OpenSession" || methodName == "GetShardParams" || methodName == "CreateSpecification";

            if (!skip && (methodName == "GetList" || methodName == "Get"))
            {
                var arguments = invocation.Method.GetParameters();
                skip = arguments.Length != 2 || arguments[0].ParameterType != typeof(ShardParams);
            }
            if (!skip)
            {
                ProfilerContext.BeginWatch(invocation.TargetType.FullName + "." + invocation.Method.Name);
            }

            try
            {
                var entityType = ReflectionHelper.GetEntityTypeFromRepositoryType(invocation.TargetType);
                var metadata   = RepositoryFramework.GetDefineMetadata(entityType);

                if (metadata != null)
                {
                    var mi = invocations.FirstOrDefault(o => o.IsMatch(invocation));
                    if (mi != null)
                    {
                        mi.Process(invocation, metadata);
                        ProxyEntity(invocation);
                        return;
                    }
                }
                if (skip)
                {
                    invocation.Proceed();
                }
                else
                {
                    using (MonitorContext.Repository(invocation.Method))
                        invocation.Proceed();
                }

                ProxyEntity(invocation);
            }
            finally
            {
                if (!skip)
                {
                    ProfilerContext.EndWatch();
                }
            }
        }
        public IShardSession <TEntity> OpenSession <TEntity>(ShardParams shardParams)
        {
            var strategy = RepositoryFramework.GetShardStrategy(typeof(TEntity));

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy", String.Format("无法找到类型 {0} 对应的分区策略信息。", typeof(TEntity).FullName));
            }

            var shardId     = strategy.GetShardId(shardParams);
            var partitionId = strategy.GetPartitionId(shardParams);

            using (var scope = ProfilerContext.Profile("open nhibernate session"))
            {
                var session = manager.OpenSession(shardId, partitionId);
                return(new NHibernateShardSession <TEntity>(session));
            }
        }
        ISessionFactory GetSessionFactory(ShardId shardId)
        {
            ISessionFactory factory = sessionFactories.TryGetValue(shardId);

            if (factory == null)
            {
                lock (syscRoot)
                {
                    factory = sessionFactories.TryGetValue(shardId);
                    if (factory == null)
                    {
                        using (var scope = ProfilerContext.Profile("create session factory"))
                        {
                            factory = CreateSessionFactory(shardId);
                        }
                        sessionFactories.Add(shardId, factory);
                    }
                }
            }
            return(factory);
        }
 public BlogPostsController(ProfilerContext context)
 {
     _context = context;
 }
 public AuthorsController(ProfilerContext context)
 {
     _context = context;
 }
Exemple #10
0
 public SocialsController(ProfilerContext context)
 {
     _context = context;
 }
Exemple #11
0
 public UsersController(ProfilerContext context)
 {
     _context = context;
 }