Beispiel #1
0
            private void MigrateMessage(Stack <ITransaction> stack, ITransaction source, ITransaction target, int level)
            {
                // Note that stack.ToArray() gives an array reversed, which is the opposite of Java.
                ITransaction[] onStackTransactions = stack.ToArray();
                ITransaction   current             = (level < stack.Count ? onStackTransactions[stack.Count - 1 - level] : null);
                bool           shouldKeep          = false;

                foreach (IMessage child in source.Children)
                {
                    if (child != current)
                    {
                        target.AddChild(child);
                    }
                    else
                    {
                        DefaultTransaction cloned = new DefaultTransaction(current.Type, current.Name, _mManager);

                        cloned.Timestamp        = current.Timestamp;
                        cloned.DurationInMicros = current.DurationInMicros;
                        cloned.AddData(current.Data);
                        cloned.Status = CatConstants.SUCCESS;

                        target.AddChild(cloned);
                        MigrateMessage(stack, current, cloned, level + 1);
                        shouldKeep = true;
                    }
                }

                source.Children.Clear();

                if (shouldKeep)
                {
                    source.AddChild(current);
                }
            }
Beispiel #2
0
            private void MigrateMessage(Stack <ITransaction> stack, ITransaction source, ITransaction target, int level)
            {
                var current    = level < stack.Count ? stack.ToList()[level] : null;
                var shouldKeep = false;

                foreach (IMessage child in source.Children)
                {
                    if (child != current)
                    {
                        target.AddChild(child);
                    }
                    else
                    {
                        DefaultTransaction cloned = new DefaultTransaction(current.Type, current.Name, _manager);

                        cloned.Timestamp        = current.Timestamp;
                        cloned.DurationInMicros = current.DurationInMicros;
                        cloned.AddData(current.Data);
                        cloned.Status = PureCatConstants.SUCCESS;

                        target.AddChild(cloned);
                        MigrateMessage(stack, current, cloned, level + 1);

                        shouldKeep = true;
                    }
                }

                source.Children.Clear();
                if (shouldKeep)
                {
                    source.AddChild(current);
                }
            }
Beispiel #3
0
            //验证Transaction
            internal void ValidateTransaction(ITransaction transaction)
            {
                IList<IMessage> children = transaction.Children;
                int len = children.Count;
                for (int i = 0; i < len; i++)
                {
                    IMessage message = children[i];
                    var transaction1 = message as ITransaction;
                    if (transaction1 != null)
                    {
                        ValidateTransaction(transaction1);
                    }
                }

                if (!transaction.IsCompleted())
                {
                    // missing transaction end, log a BadInstrument event so that
                    // developer can fix the code
                    IMessage notCompleteEvent = new DefaultEvent("CAT", "BadInstrument")
                                                    {Status = "TransactionNotCompleted"};
                    notCompleteEvent.Complete();
                    transaction.AddChild(notCompleteEvent);
                    transaction.Complete();
                }
            }
            private void AdjustForTruncatedTransaction(ITransaction root)
            {
                DefaultEvent next = new DefaultEvent("TruncatedTransaction", "TotalDuration");
                long         actualDurationInMicros = _mTotalDurationInMicros + root.DurationInMicros;

                next.AddData(Convert.ToString(actualDurationInMicros));
                next.Status = CatConstants.SUCCESS;
                root.AddChild(next);

                _mTotalDurationInMicros = 0;
            }
            private void AddTransactionChild(DefaultMessageManager manager, IMessage message, ITransaction transaction)
            {
                long treePeriod    = TrimToHour(_mTree.Message.Timestamp);
                long messagePeriod = TrimToHour(message.Timestamp - 10 * 1000L); // 10 seconds extra time allowed

                if (treePeriod < messagePeriod)
                {
                    TruncateAndFlush(manager, message.Timestamp);
                }

                transaction.AddChild(message);
            }
Beispiel #6
0
            private void AddTransactionChild(IMessage message, ITransaction transaction)
            {
                var treePeriod    = TrimToHour(_mTree.Message.Timestamp);
                var messagePeriod = TrimToHour(message.Timestamp - 10 * 1000L); // 10 seconds extra time allowed

                if (treePeriod < messagePeriod)
                {
                    TruncateAndFlush(message.Timestamp);
                }

                transaction.AddChild(message);
            }
            private void AddTransactionChild(IMessage message, ITransaction transaction)
            {
                long treePeriod    = trimToHour(_mTree.Message.Timestamp);
                long messagePeriod = trimToHour(message.Timestamp - 10 * 1000L);

                if (treePeriod < messagePeriod || _mLength >= _mManager._mClientConfig.Domain.MaxMessageSize)
                {
                    _mManager._mValidator.TruncateAndFlush(this, message.Timestamp);
                }

                transaction.AddChild(message);
                _mLength++;
            }
Beispiel #8
0
 /// <summary>
 ///   添加Event和Heartbeat
 /// </summary>
 /// <param name="manager"> </param>
 /// <param name="message"> </param>
 public void Add(DefaultMessageManager manager, IMessage message)
 {
     if ((_mStack.Count == 0))
     {
         IMessageTree tree = _mTree.Copy();
         tree.MessageId = manager.NextMessageId();
         tree.Message = message;
         manager.Flush(tree);
     }
     else
     {
         ITransaction entry = _mStack.Peek();
         entry.AddChild(message);
     }
 }
Beispiel #9
0
            /// <summary>
            ///   添加transaction
            /// </summary>
            /// <param name="manager"> </param>
            /// <param name="transaction"> </param>
            public void Start(DefaultMessageManager manager, ITransaction transaction)
            {
                if (_mStack.Count != 0)
                {
                    transaction.Standalone = false;
                    ITransaction entry = _mStack.Peek();
                    entry.AddChild(transaction);
                }
                else
                {
                    _mTree.MessageId = manager.NextMessageId();
                    _mTree.Message = transaction;
                }

                _mStack.Push(transaction);
            }
        public virtual ITransaction NewTransaction(ITransaction parent, string type, string name)
        {
            // this enable CAT client logging cat message without explicit setup
            if (!_mManager.HasContext())
            {
                _mManager.Setup();
            }

            if (_mManager.CatEnabled && parent != null)
            {
                ITransaction transaction = new DefaultTransaction(type, name, _mManager);

                parent.AddChild(transaction);
                transaction.Standalone = false;
                return(transaction);
            }
            return(NullMessage.TRANSACTION);
        }
            //验证Transaction
            internal void ValidateTransaction(ITransaction transaction)
            {
                IList<IMessage> children = transaction.Children;
                int len = children.Count;
                for (int i = 0; i < len; i++)
                {
                    IMessage message = children[i];
                    var transaction1 = message as ITransaction;
                    if (transaction1 != null)
                    {
                        ValidateTransaction(transaction1);
                    }
                }

                if (!transaction.IsCompleted())
                {
                    // missing transaction end, log a BadInstrument event so that
                    // developer can fix the code
                    IMessage notCompleteEvent = new DefaultEvent("CAT", "BadInstrument")
                                                    {Status = "TransactionNotCompleted"};
                    notCompleteEvent.Complete();
                    transaction.AddChild(notCompleteEvent);
                    transaction.Complete();
                }
            }
            private void MigrateMessage(DefaultMessageManager manager, Stack<ITransaction> stack, ITransaction source, ITransaction target, int level)
            {
                ITransaction current = level < stack.Count ? stack.ToList()[level] : null;
                bool shouldKeep = false;

                foreach (IMessage child in source.Children)
                {
                    if (child != current)
                    {
                        target.AddChild(child);
                    }
                    else
                    {
                        DefaultTransaction cloned = new DefaultTransaction(current.Type, current.Name, manager);

                        cloned.Timestamp = current.Timestamp;
                        cloned.DurationInMicros = current.DurationInMicros;
                        cloned.AddData(current.Data);
                        cloned.Status = PureCatConstants.SUCCESS;

                        target.AddChild(cloned);
                        MigrateMessage(manager, stack, current, cloned, level + 1);

                        shouldKeep = true;
                    }
                }

                source.Children.Clear();
                if (shouldKeep)
                {
                    source.AddChild(current);
                }
            }
            private void AddTransactionChild(DefaultMessageManager manager, IMessage message, ITransaction transaction)
            {
                long treePeriod = TrimToHour(_mTree.Message.Timestamp);
                long messagePeriod = TrimToHour(message.Timestamp - 10 * 1000L); // 10 seconds extra time allowed

                if (treePeriod < messagePeriod)
                {
                    TruncateAndFlush(manager, message.Timestamp);
                }

                transaction.AddChild(message);
            }
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack <ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper     = _mBufferHelper;
            char         identifier = (char)buf.ReadByte();
            string       timestamp  = helper.Read(buf, TAB);
            string       type       = helper.Read(buf, TAB);
            string       name       = helper.Read(buf, TAB);

            switch (identifier)
            {
            case 't':
                IMessage transaction = new DefaultTransaction(type, name, null);

                helper.Read(buf, LF);     // get rid of line feed
                transaction.Timestamp = _mDateHelper.Parse(timestamp);

                if (parent != null)
                {
                    parent.AddChild(transaction);
                }

                stack.Push(parent);
                return(transaction);

            case 'A':
                DefaultTransaction tran     = new DefaultTransaction(type, name, null);
                string             status   = helper.Read(buf, TAB);
                string             duration = helper.Read(buf, TAB);
                string             data     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                tran.Timestamp = _mDateHelper.Parse(timestamp);
                tran.Status    = status;
                tran.AddData(data);

                long d = long.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);

                tran.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(tran);
                    return(parent);
                }
                return(tran);

            case 'T':
                string transactionStatus   = helper.Read(buf, TAB);
                string transactionDuration = helper.Read(buf, TAB);
                string transactionData     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                parent.Status = transactionStatus;
                parent.AddData(transactionData);

                long transactionD = long.Parse(transactionDuration.Substring(0, transactionDuration.Length - 2), NumberStyles.Integer);

                parent.DurationInMicros = transactionD;

                return(stack.Pop());

            case 'E':
                DefaultEvent evt         = new DefaultEvent(type, name);
                string       eventStatus = helper.Read(buf, TAB);
                string       eventData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status    = eventStatus;
                evt.AddData(eventData);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    return(parent);
                }
                return(evt);

            case 'M':
                DefaultMetric metric       = new DefaultMetric(type, name);
                string        metricStatus = helper.Read(buf, TAB);
                string        metricData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status    = metricStatus;
                metric.AddData(metricData);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    return(parent);
                }
                return(metric);

            case 'L':
                DefaultTrace trace       = new DefaultTrace(type, name);
                string       traceStatus = helper.Read(buf, TAB);
                string       traceData   = helper.Read(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                trace.Timestamp = _mDateHelper.Parse(timestamp);
                trace.Status    = traceStatus;
                trace.AddData(traceData);

                if (parent != null)
                {
                    parent.AddChild(trace);
                    return(parent);
                }
                return(trace);

            case 'H':
                DefaultHeartbeat heartbeat       = new DefaultHeartbeat(type, name);
                string           heartbeatStatus = helper.Read(buf, TAB);
                string           heartbeatData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status    = heartbeatStatus;
                heartbeat.AddData(heartbeatData);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    return(parent);
                }
                return(heartbeat);
            }

            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);
            //throw new Exception("Unknown identifier int name"); //java版的抛出异常

            // unknown message, ignore it
            return(parent);
        }
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack<ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper = _mBufferHelper;
            byte identifier = buf.ReadByte();
            String timestamp = helper.Read(buf, TAB);
            String type = helper.Read(buf, TAB);
            String name = helper.Read(buf, TAB);

            if (identifier == 'E')
            {
                IMessage evt = new DefaultEvent(type, name);
                String status = helper.Read(buf, TAB);
                String data = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status = status;
                evt.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    tree.EstimatedByteSize += evt.EstimateByteSize();
                    return parent;
                }
                return evt;
            }
            if (identifier == 'M')
            {
                DefaultMetric metric = new DefaultMetric(type, name);
                String status = helper.Read(buf, TAB);
                String data = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status = status;
                metric.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    tree.EstimatedByteSize += metric.EstimateByteSize();
                    return parent;
                }
                return metric;
            }
            if (identifier == 'H')
            {
                IMessage heartbeat = new DefaultHeartbeat(type, name);
                String status0 = helper.Read(buf, TAB);
                String data1 = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status = status0;
                heartbeat.AddData(data1);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    tree.EstimatedByteSize += heartbeat.EstimateByteSize();
                    return parent;
                }
                return heartbeat;
            }
            if (identifier == 't')
            {
                IMessage transaction = new DefaultTransaction(type, name,
                                                              null);

                helper.Read(buf, LF); // get rid of line feed
                transaction.Timestamp = _mDateHelper.Parse(timestamp);

                if (parent != null)
                {
                    parent.AddChild(transaction);
                }

                stack.Push(parent);
                return transaction;
            }
            if (identifier == 'A')
            {
                ITransaction transaction2 = new DefaultTransaction(type, name, null);
                String status3 = helper.Read(buf, TAB);
                String duration = helper.Read(buf, TAB);
                String data4 = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                transaction2.Timestamp = _mDateHelper.Parse(timestamp);
                transaction2.Status = status3;
                transaction2.AddData(data4);

                long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);
                transaction2.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(transaction2);
                    tree.EstimatedByteSize += transaction2.EstimateByteSize();
                    return parent;
                }
                return transaction2;
            }
            if (identifier == 'T')
            {
                String status5 = helper.Read(buf, TAB);
                String duration6 = helper.Read(buf, TAB);
                String data7 = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                parent.Status = status5;
                parent.AddData(data7);

                long d8 = Int64.Parse(
                    duration6.Substring(0, duration6.Length - 2),
                    NumberStyles.Integer);
                parent.DurationInMicros = d8;
                tree.EstimatedByteSize += parent.EstimateByteSize();
                return stack.Pop();
            }
            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);

            // unknown message, ignore it
            return parent;
        }
            private void AddTransactionChild(IMessage message, ITransaction transaction)
            {
                long treePeriod = trimToHour(_mTree.Message.Timestamp);
                long messagePeriod = trimToHour(message.Timestamp - 10 * 1000L);

                if (treePeriod < messagePeriod || _mLength >= _mManager._mClientConfig.Domain.MaxMessageSize)
                {
                    _mManager._mValidator.TruncateAndFlush(this, message.Timestamp);
                }

                transaction.AddChild(message);
                _mLength++;
            }
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack<ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper = _mBufferHelper;
            char identifier = (char)buf.ReadByte();
            string timestamp = helper.Read(buf, TAB);
            string type = helper.Read(buf, TAB);
            string name = helper.Read(buf, TAB);
            switch (identifier)
            {
                case 't':
                    IMessage transaction = new DefaultTransaction(type, name, null);

                    helper.Read(buf, LF); // get rid of line feed
                    transaction.Timestamp = _mDateHelper.Parse(timestamp);

                    if (parent != null)
                    {
                        parent.AddChild(transaction);
                    }

                    stack.Push(parent);
                    return transaction;
                case 'A':
                    DefaultTransaction tran = new DefaultTransaction(type, name, null);
                    string status = helper.Read(buf, TAB);
                    string duration = helper.Read(buf, TAB);
                    string data = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    tran.Timestamp = _mDateHelper.Parse(timestamp);
                    tran.Status = status;
                    tran.AddData(data);

                    long d = long.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);

                    tran.DurationInMicros = d;

                    if (parent != null)
                    {
                        parent.AddChild(tran);
                        return parent;
                    }
                    return tran;
                case 'T':
                    string transactionStatus = helper.Read(buf, TAB);
                    string transactionDuration = helper.Read(buf, TAB);
                    string transactionData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    parent.Status = transactionStatus;
                    parent.AddData(transactionData);

                    long transactionD = long.Parse(transactionDuration.Substring(0, transactionDuration.Length - 2), NumberStyles.Integer);

                    parent.DurationInMicros = transactionD;

                    return stack.Pop();
                case 'E':
                    DefaultEvent evt = new DefaultEvent(type, name);
                    string eventStatus = helper.Read(buf, TAB);
                    string eventData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    evt.Timestamp = _mDateHelper.Parse(timestamp);
                    evt.Status = eventStatus;
                    evt.AddData(eventData);

                    if (parent != null)
                    {
                        parent.AddChild(evt);
                        return parent;
                    }
                    return evt;
                case 'M':
                    DefaultMetric metric = new DefaultMetric(type, name);
                    string metricStatus = helper.Read(buf, TAB);
                    string metricData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF);
                    metric.Timestamp = _mDateHelper.Parse(timestamp);
                    metric.Status = metricStatus;
                    metric.AddData(metricData);

                    if (parent != null)
                    {
                        parent.AddChild(metric);
                        return parent;
                    }
                    return metric;
                case 'L':
                    DefaultTrace trace = new DefaultTrace(type, name);
                    string traceStatus = helper.Read(buf, TAB);
                    string traceData = helper.Read(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    trace.Timestamp = _mDateHelper.Parse(timestamp);
                    trace.Status = traceStatus;
                    trace.AddData(traceData);

                    if (parent != null)
                    {
                        parent.AddChild(trace);
                        return parent;
                    }
                    return trace;
                case 'H':
                    DefaultHeartbeat heartbeat = new DefaultHeartbeat(type, name);
                    string heartbeatStatus = helper.Read(buf, TAB);
                    string heartbeatData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                    heartbeat.Status = heartbeatStatus;
                    heartbeat.AddData(heartbeatData);

                    if (parent != null)
                    {
                        parent.AddChild(heartbeat);
                        return parent;
                    }
                    return heartbeat;
            }

            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);
            //throw new Exception("Unknown identifier int name"); //java版的抛出异常

            // unknown message, ignore it
            return parent;
        }
Beispiel #18
0
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack <ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper     = _mBufferHelper;
            byte         identifier = buf.ReadByte();
            String       timestamp  = helper.Read(buf, TAB);
            String       type       = helper.Read(buf, TAB);
            String       name       = helper.Read(buf, TAB);

            if (identifier == 'E')
            {
                IMessage evt    = new DefaultEvent(type, name);
                String   status = helper.Read(buf, TAB);
                String   data   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status    = status;
                evt.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    tree.EstimatedByteSize += evt.EstimateByteSize();
                    return(parent);
                }
                return(evt);
            }
            if (identifier == 'M')
            {
                DefaultMetric metric = new DefaultMetric(type, name);
                String        status = helper.Read(buf, TAB);
                String        data   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status    = status;
                metric.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    tree.EstimatedByteSize += metric.EstimateByteSize();
                    return(parent);
                }
                return(metric);
            }
            if (identifier == 'H')
            {
                IMessage heartbeat = new DefaultHeartbeat(type, name);
                String   status0   = helper.Read(buf, TAB);
                String   data1     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status    = status0;
                heartbeat.AddData(data1);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    tree.EstimatedByteSize += heartbeat.EstimateByteSize();
                    return(parent);
                }
                return(heartbeat);
            }
            if (identifier == 't')
            {
                IMessage transaction = new DefaultTransaction(type, name,
                                                              null);

                helper.Read(buf, LF); // get rid of line feed
                transaction.Timestamp = _mDateHelper.Parse(timestamp);

                if (parent != null)
                {
                    parent.AddChild(transaction);
                    tree.EstimatedByteSize += transaction.EstimateByteSize();
                }

                stack.Push(parent);
                return(transaction);
            }
            if (identifier == 'A')
            {
                ITransaction transaction2 = new DefaultTransaction(type, name, null);
                String       status3      = helper.Read(buf, TAB);
                String       duration     = helper.Read(buf, TAB);
                String       data4        = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                transaction2.Timestamp = _mDateHelper.Parse(timestamp);
                transaction2.Status    = status3;
                transaction2.AddData(data4);

                long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);
                transaction2.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(transaction2);
                    tree.EstimatedByteSize += transaction2.EstimateByteSize();
                    return(parent);
                }
                return(transaction2);
            }
            if (identifier == 'T')
            {
                String status5   = helper.Read(buf, TAB);
                String duration6 = helper.Read(buf, TAB);
                String data7     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                parent.Status = status5;
                parent.AddData(data7);

                long d8 = Int64.Parse(
                    duration6.Substring(0, duration6.Length - 2),
                    NumberStyles.Integer);
                parent.DurationInMicros = d8;

                return(stack.Pop());
            }
            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);

            // unknown message, ignore it
            return(parent);
        }
            private void AdjustForTruncatedTransaction(ITransaction root)
            {
                DefaultEvent next = new DefaultEvent("TruncatedTransaction", "TotalDuration");
                long actualDurationInMicros = _mTotalDurationInMicros + root.DurationInMicros;

                next.AddData(Convert.ToString(actualDurationInMicros));
                next.Status = CatConstants.SUCCESS;
                root.AddChild(next);

                _mTotalDurationInMicros = 0;
            }
        public virtual ITransaction NewTransaction(ITransaction parent, string type, string name)
        {
            // this enable CAT client logging cat message without explicit setup
            if (!_manager.HasContext())
            {
                _manager.Setup();
            }

            if (_manager.CatEnabled && parent != null)
            {
                ITransaction transaction = new DefaultTransaction(type, name, _manager);

                parent.AddChild(transaction);
                transaction.Standalone = false;
                return transaction;
            }
            return NullMessage.TRANSACTION;
        }
            private void MigrateMessage(Stack<ITransaction> stack, ITransaction source, ITransaction target, int level)
            {
                // Note that stack.ToArray() gives an array reversed, which is the opposite of Java.
                ITransaction[] onStackTransactions = stack.ToArray();
                ITransaction current = (level < stack.Count ? onStackTransactions[stack.Count - 1 - level] : null);
                bool shouldKeep = false;

                foreach (IMessage child in source.Children)
                {
                    if (child != current)
                    {
                        target.AddChild(child);
                    }
                    else
                    {
                        DefaultTransaction cloned = new DefaultTransaction(current.Type, current.Name, _mManager);

                        cloned.Timestamp = current.Timestamp;
                        cloned.DurationInMicros = current.DurationInMicros;
                        cloned.AddData(current.Data);
                        cloned.Status = CatConstants.SUCCESS;

                        target.AddChild(cloned);
                        MigrateMessage(stack, current, cloned, level + 1);
                        shouldKeep = true;
                    }
                }

                source.Children.Clear();

                if (shouldKeep)
                {
                    source.AddChild(current);
                }
            }