public IReadOnlyList <DbRow> GetAllRecords(int?limit) { var result = new List <DbRow>(); _readerWriterLockSlim.EnterReadLock(); try { if (limit == null) { foreach (var partition in _partitions.Values) { result.AddRange(partition.GetAllRows()); } } else { foreach (var partition in _partitions.Values) { foreach (var dbRow in partition.GetAllRows()) { result.Add(dbRow); if (result.Count >= limit.Value) { return(result); } } } } } finally { _readerWriterLockSlim.ExitReadLock(); } return(result); }
public static void BroadCastInit(DbTable dbTable, DbPartition partition) { var clientsToSend = Connections.Get(itm => itm.SubscribedToTable(dbTable.Name)).Select(itm => itm.Client); byte[] packetToBroadcast = null; foreach (var clientProxy in clientsToSend) { if (packetToBroadcast == null) { packetToBroadcast = partition.GetAllRows().ToHubUpdateContract(); } clientProxy.SendAsync(dbTable.Name, "i:" + partition.PartitionKey, packetToBroadcast); } }
public static void BroadcastInitPartition(DbTable dbTable, DbPartition partition) { var connections = TableSubscribers.GetConnections(dbTable.Name); if (connections == null) { return; } var packetToBroadcast = new InitPartitionContract { TableName = dbTable.Name, PartitionKey = partition.PartitionKey, Data = partition.GetAllRows().ToHubUpdateContract() }; foreach (var connection in connections) { connection.SendPacket(packetToBroadcast); } }
public static PartitionSnapshot Create(DbTable table, DbPartition partition) { var dbRowsAsByteArray = partition.GetAllRows().ToJsonArray().AsArray(); return(Create(table.Name, partition.PartitionKey, dbRowsAsByteArray)); }