public DefaultSubscription(string identity,
IList<string> eventKeys,
TopicLookup topics,
string cursor,
Func<MessageResult, object, Task<bool>> callback,
int maxMessages,
IStringMinifier stringMinifier,
IPerformanceCounterManager counters,
object state) :
base(identity, eventKeys, callback, maxMessages, counters, state)
{
_stringMinifier = stringMinifier;
if (String.IsNullOrEmpty(cursor))
{
_cursors = GetCursorsFromEventKeys(EventKeys, topics);
}
else
{
// Ensure delegate continues to use the C# Compiler static delegate caching optimization.
_cursors = Cursor.GetCursors(cursor, _defaultCursorPrefix, (k, s) => UnminifyCursor(k, s), stringMinifier) ?? GetCursorsFromEventKeys(EventKeys, topics);
}
_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);
}
}