Exemple #1
0
        protected override ValueTask OnDisconnectAsync()
        {
            lock (_tablesSubscribed)
            {
                foreach (var tableName in _tablesSubscribed)
                {
                    TableSubscribers.Unsubscribe(tableName, this);
                }
            }

            return(new ValueTask());
        }
Exemple #2
0
        private void HandleSubscribe(SubscribeContract subscribeContract)
        {
            if (string.IsNullOrEmpty(subscribeContract.TableName))
            {
                return;
            }

            var table = DbInstance.GetTable(subscribeContract.TableName);

            if (table == null)
            {
                return;
            }


            var tables = new List <string>();

            if (_tablesSubscribed.Count > 0)
            {
                tables.AddRange(_tablesSubscribed);
            }

            tables.Add(subscribeContract.TableName);


            _tablesSubscribed = tables;


            TableSubscribers.Subscribe(subscribeContract.TableName, this);

            var rows = table.GetAllRecords(null);

            Console.WriteLine($"Socket {Id} is subscribed to the table {subscribeContract.TableName}. Initialized records: {rows.Count}");

            var initContract = new InitTableContract
            {
                TableName = subscribeContract.TableName,
                Data      = rows.ToHubUpdateContract()
            };

            SendPacket(initContract);
        }
Exemple #3
0
        public static void BroadcastRowsUpdate(DbTable dbTable, IReadOnlyList <DbRow> entities)
        {
            var connections = TableSubscribers.GetConnections(dbTable.Name);

            if (connections == null)
            {
                return;
            }

            var packetToBroadcast = new UpdateRowsContract
            {
                TableName = dbTable.Name,
                Data      = entities.ToHubUpdateContract()
            };

            foreach (var connection in connections)
            {
                connection.SendPacket(packetToBroadcast);
            }
        }
Exemple #4
0
        public static void BroadcastInitTable(DbTable dbTable)
        {
            var connections = TableSubscribers.GetConnections(dbTable.Name);

            if (connections == null)
            {
                return;
            }

            var packetToBroadcast = new InitTableContract
            {
                TableName = dbTable.Name,
                Data      = dbTable.GetAllRecords(null).ToHubUpdateContract()
            };

            foreach (var connection in connections)
            {
                connection.SendPacket(packetToBroadcast);
            }
        }
Exemple #5
0
        public static void BroadcastRowsDelete(DbTable dbTable, IReadOnlyList <DbRow> dbRows)
        {
            var connections = TableSubscribers.GetConnections(dbTable.Name);

            if (connections == null)
            {
                return;
            }

            var packetToBroadcast = new DeleteRowsContract
            {
                TableName    = dbTable.Name,
                RowsToDelete = dbRows.Select(row => (row.PartitionKey, row.RowKey)).ToList()
            };

            foreach (var connection in connections)
            {
                connection.SendPacket(packetToBroadcast);
            }
        }
Exemple #6
0
        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);
            }
        }