public DefaultSubscription(string identity,
IEnumerable<string> eventKeys,
IDictionary<string, Topic> topics,
string cursor,
Func<MessageResult, Task<bool>> callback,
int maxMessages,
IPerformanceCounterWriter counters)
: base(identity, eventKeys, callback, maxMessages, counters)
{
IEnumerable<Cursor> cursors = null;
if (cursor == null)
{
cursors = from key in eventKeys
select new Cursor
{
Key = key,
Id = GetMessageId(topics, key)
};
}
else
{
cursors = Cursor.GetCursors(cursor);
}
_cursors = new List<Cursor>(cursors);
_cursorTopics = new List<Topic>();
if (!String.IsNullOrEmpty(cursor))
{
// Update all of the cursors so we're within the range
for (int i = _cursors.Count - 1; i >= 0; i--)
{
Cursor c = _cursors[i];
Topic topic;
if (!eventKeys.Contains(c.Key))
{
_cursors.Remove(c);
}
else if (topics.TryGetValue(_cursors[i].Key, out topic) && _cursors[i].Id > topic.Store.GetMessageCount())
{
UpdateCursor(c.Key, 0);
}
}
}
// Add dummy entries so they can be filled in
for (int i = 0; i < _cursors.Count; i++)
{
_cursorTopics.Add(null);
}
}