public IEnumerable <object> Enumerate(Type type)
{
if (type == typeof(object))
{
type = null;
}
else if (type != null)
{
AutoRegisterType(type);
}
ulong oid = 0;
ulong finalOid = _owner.GetLastAllocatedOid();
long prevProtectionCounter = 0;
while (true)
{
_keyValueTrProtector.Start();
if (oid == 0)
{
prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
_keyValueTr.SetKeyPrefix(ObjectDB.AllObjectsPrefix);
if (!_keyValueTr.FindFirstKey())
{
break;
}
}
else
{
if (_keyValueTrProtector.WasInterupted(prevProtectionCounter))
{
_keyValueTr.SetKeyPrefix(ObjectDB.AllObjectsPrefix);
oid++;
var key = BuildKeyFromOid(oid);
var result = _keyValueTr.Find(ByteBuffer.NewSync(key));
if (result == FindResult.Previous)
{
if (!_keyValueTr.FindNextKey())
{
result = FindResult.NotFound;
}
}
if (result == FindResult.NotFound)
{
oid--;
break;
}
}
else
{
if (!_keyValueTr.FindNextKey())
{
break;
}
}
prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
}
oid = ReadOidFromCurrentKeyInTransaction();
var o = GetObjFromObjCacheByOid(oid);
if (o != null)
{
if (type == null || type.IsInstanceOfType(o))
{
yield return(o);
}
continue;
}
TableInfo tableInfo;
var reader = ReadObjStart(oid, out tableInfo);
if (type != null && !type.IsAssignableFrom(tableInfo.ClientType))
{
continue;
}
var obj = ReadObjFinish(oid, tableInfo, reader);
yield return(obj);
}
if (_dirtyObjSet == null)
{
yield break;
}
var dirtyObjsToEnum = _dirtyObjSet.Where(p => p.Key > oid && p.Key <= finalOid).ToList();
dirtyObjsToEnum.Sort((p1, p2) =>
{
if (p1.Key < p2.Key)
{
return(-1);
}
if (p1.Key > p2.Key)
{
return(1);
}
return(0);
});
foreach (var dObjPair in dirtyObjsToEnum)
{
var obj = dObjPair.Value;
if (type != null && !type.IsInstanceOfType(obj))
{
continue;
}
yield return(obj);
}
}