Ejemplo n.º 1
0
        public async Task AddNodePendingMessage()
        {
            var content        = Guid.NewGuid();
            var pendingMessage = await pendingMessagesService.AddNodePendingMessageAsync(2, content, TimeSpan.FromSeconds(10));

            Assert.True(pendingMessage.NodeId == 2 && Convert.FromBase64String(pendingMessage.Content).SequenceEqual(ObjectSerializer.ObjectToByteArray(content)));
        }
Ejemplo n.º 2
0
        private async Task SendNoticeToNodesAsync(NodeNotice notice, IEnumerable <long> nodesIds = null)
        {
            List <NodeConnection> nodesConnections;

            if (nodesIds == null || !nodesIds.Any())
            {
                var nodes = await _nodesService.GetAllNodesInfoAsync().ConfigureAwait(false);

                nodesIds = nodes.Select(opt => opt.Id);
            }
            if (nodesIds != null && nodesIds.Any())
            {
                nodesConnections = _connectionsService.GetNodeConnections(nodesIds);
                IEnumerable <long> notConnectedNodesIds;
                if (nodesConnections != null && nodesConnections.Any())
                {
                    notConnectedNodesIds = nodesIds.Where(id => !nodesConnections.Any(node => node?.Node?.Id == id));
                }
                else
                {
                    notConnectedNodesIds = nodesIds;
                }

                if (notConnectedNodesIds != null && notConnectedNodesIds.Any())
                {
                    foreach (var nodeId in notConnectedNodesIds)
                    {
                        await _pendingMessagesService.AddNodePendingMessageAsync(nodeId, notice, TimeSpan.FromDays(10)).ConfigureAwait(false);
                    }
                }
            }
            else
            {
                nodesConnections = _connectionsService.GetNodeConnections();
            }
            await SendNoticeToNodesAsync(nodesConnections, notice).ConfigureAwait(false);
        }