Exemple #1
0
        private void AddDataSourceEnumeratorToList(int index)
        {
            Enumerators.Add(DataSources[index].GetEnumerator());

            if (Enumerators[index].MoveNext())
            {
                ITimestampedDatum current = Enumerators[index].Current;
                if (!DataQueue.ContainsKey(current.Timestamp))
                {
                    DataQueue.Add(current.Timestamp, new List <int>());
                }

                DataQueue[current.Timestamp].Add(index);
            }
        }
Exemple #2
0
        public ITimestampedDatum GetNextDatum()
        {
            if (DataQueue.Count > 0)
            {
                KeyValuePair <DateTimeOffset, List <int> > firstTime = DataQueue.First();

                int sourceId = firstTime.Value.First();

                // Get the datum and advance the source's enumerator to see what the next timestamp it has is.
                ITimestampedDatum datum = Enumerators[sourceId].Current;

                // Remove the datum we've just retrieved from the queue.
                if (DataQueue[firstTime.Key].Count == 1)
                {
                    DataQueue.Remove(firstTime.Key);
                }
                else
                {
                    DataQueue[firstTime.Key].RemoveAt(0);                   // Since sourceId is retrieved by First(), this makes sense.
                }

                // We want to stop adding to the data queue if the only data being served are the epoch heartbeats.
                if (FinishedEnumerators != nDataSources - 1)
                {
                    // Add the source's next timestamp to the data queue.
                    if (Enumerators[sourceId].MoveNext())
                    {
                        DateTimeOffset nextDate = Enumerators[sourceId].Current.Timestamp;

                        if (!DataQueue.ContainsKey(nextDate))
                        {
                            DataQueue.Add(nextDate, new List <int>());
                        }

                        DataQueue[nextDate].Add(sourceId);
                    }
                    else
                    {
                        FinishedEnumerators++;
                    }
                }

                return(datum);
            }

            return(null);
        }