public int CacheSql(DefaultParsingResult parsingResult)
        {
            var result = this.apiCache.put(parsingResult.Sql);

            parsingResult.Id = result.Id;

            if (result.NewValue)
            {
                var sqlMetaData = new TSqlMetaData();
                sqlMetaData.AgentId        = AgentId;
                sqlMetaData.AgentStartTime = AgentStartTime;

                sqlMetaData.SqlId = parsingResult.Id;
                sqlMetaData.Sql   = parsingResult.Sql;


                RequestPacket request = null;
                using (var serializer = new HeaderTBaseSerializer())
                {
                    request = new RequestPacket(IdGenerator.SequenceId(), serializer.serialize(sqlMetaData));
                    this.enhancedDataSender.Send(request.ToBuffer());
                }
            }

            return(result.Id);
        }
        public int CacheApi(MethodDescriptor methodDescriptor)
        {
            var fullName = methodDescriptor.GetFullName();
            var result   = this.apiCache.put(fullName);

            methodDescriptor.ApiId = result.Id;

            if (result.NewValue)
            {
                var apiMetadata = new TApiMetaData();
                apiMetadata.AgentId        = agentId;
                apiMetadata.AgentStartTime = agentStartTime;

                apiMetadata.ApiId   = result.Id;
                apiMetadata.ApiInfo = methodDescriptor.ApiDescriptor;
                apiMetadata.Line    = methodDescriptor.LineNumber;
                apiMetadata.Type    = methodDescriptor.Type;

                RequestPacket request = null;
                using (var serializer = new HeaderTBaseSerializer())
                {
                    request = new RequestPacket(IdGenerator.SequenceId(), serializer.serialize(apiMetadata));
                    this.enhancedDataSender.Send(request.ToBuffer());
                }
            }

            return(result.Id);
        }
        private void SendAgentInfo()
        {
            var agentConfig = TinyIoCContainer.Current.Resolve <AgentConfig>();

            while (true)
            {
                var agentInfo = new TAgentInfo
                {
                    AgentId         = agentConfig.AgentId,
                    Hostname        = agentConfig.HostName,
                    ApplicationName = agentConfig.ApplicationName,
                    AgentVersion    = agentConfig.AgentVersion,
                    VmVersion       = "1.8.0_121",
                    ServiceType     = 1010,
                    StartTimestamp  = agentConfig.AgentStartTime,
                    JvmInfo         = new TJvmInfo()
                    {
                        Version   = 0,
                        VmVersion = "1.8.0_121",
                        GcType    = TJvmGcType.PARALLEL
                    }
                };

                try
                {
                    using (var serializer = new HeaderTBaseSerializer())
                    {
                        var payload = serializer.serialize(agentInfo);
                        var request = new RequestPacket(IdGenerator.SequenceId(), payload);
                        tcpClient.Send(request.ToBuffer());
                    }
                }
                catch (Exception ex)
                {
                    Logger.Current.Error(ex.ToString());
                }

                Thread.Sleep(5 * 60 * 1000);
            }
        }