Example #1
0
        QueueStatus SendSome(Action <IList <TraceMessage> > sendTraceMessagesTask)
        {
            TraceMessage tm;

            while ((totalEstimatedSize < Fonlow.TraceHub.Constants.TransportBufferSize) && pendingQueue.TryPeek(out tm))
            {
                var estimatedSize = GetTraceMessageSize(tm);
                if (totalEstimatedSize + estimatedSize >= Fonlow.TraceHub.Constants.TransportBufferSize)
                {
                    break;
                }

                pendingQueue.TryDequeue(out tm);
                sendingBuffer.Add(tm);
                totalEstimatedSize += GetTraceMessageSize(tm);
            }

            if (sendingBuffer.Count > 0)
            {
                try
                {
                    sendTraceMessagesTask(sendingBuffer);
                    sendingBuffer.Clear();
                }
                catch (AggregateException ex)
                {
                    Console.WriteLine(ex.ToString());
                    return(QueueStatus.Failed);
                }
            }
            else
            {
                return(QueueStatus.Empty);
            }

            totalEstimatedSize = 0;
            return(QueueStatus.Sent);
        }