Пример #1
0
        public async Task <ActionResult <IEnumerable <NodeViewModel> > > Get()
        {
            NodeException[] nodeExps = await _nodeDataCache.GetNodeExceptionsAsync();

            Node[] sourceNodes = await _nodeDataCache.GetNodesAsync();

            NodeViewModel[] nodes = _mapper.Map <NodeViewModel[]>(sourceNodes);
            if (nodeExps.Length > 0)
            {
                foreach (var node in nodes)
                {
                    node.ExceptionCount = nodeExps.Count(ex => ex.Url == node.Url);
                }
            }
            else
            {
                foreach (var node in nodes)
                {
                    node.ExceptionCount = 0;
                }
            }
            return(Ok(nodes));
        }
        private async Task BroadcastToClientsAsync(CancellationToken cancelToken)
        {
            var nodes = await _nodeDataCache.GetNodesAsync();

            var nodeExps = await _nodeDataCache.GetNodeExceptionsAsync();

            var nodeViews = _mapper.Map <NodeViewModel[]>(nodes);

            foreach (var n in nodeViews)
            {
                n.ExceptionCount = nodeExps.Count(e => e.Url == n.Url);
            }
            await _nodeHub.Clients.Group(NodeHub.NodesInfo_GroupName).SendAsync(nameof(INodeHubClient.UpdateNodes), nodeViews, cancellationToken: cancelToken);
        }