コード例 #1
0
ファイル: ClusterScannerTests.cs プロジェクト: ahives/HareDu1
        public void Verify_empty_result_returned_when_snapshot_null()
        {
            ClusterSnapshot snapshot = null;

            var result = new ClusterScanner(_probes)
                         .Scan(snapshot);

            result.ShouldBeEmpty();
        }
コード例 #2
0
ファイル: ClusterScannerTests.cs プロジェクト: ahives/HareDu3
        public void Verify_empty_result_returned_when_snapshot_null()
        {
            ClusterSnapshot snapshot = null;

            var result = new ClusterScanner(_probes)
                         .Scan(snapshot);

            Assert.IsEmpty(result);
        }
コード例 #3
0
ファイル: AtlasScraper.cs プロジェクト: mmichaels01/atlasinfo
        public async Task <ClusterSnapshot> ScrapeAsync(Cluster cluster)
        {
            var serverColumns = _mapContext.Server
                                .Include(x => x.Cluster)
                                .Include(x => x.GridCell)
                                .Where(x => x.Cluster == cluster)
                                .GroupBy(x => x.GridCell.Column)
                                .ToArray();

            if (serverColumns == null || !serverColumns.Any())
            {
                throw new Exception($"No servers found for specified {nameof(cluster)}");
            }

            var clusterSnapshot = new ClusterSnapshot(cluster)
            {
                Id              = Guid.NewGuid(),
                Timestamp       = DateTime.UtcNow,
                PlayerCount     = -1,
                ServerSnapshots = new ServerSnapshot[cluster.RowCount * cluster.ColumnCount]
            };

            var tasks = new List <Task <ServerSnapshot> >();

            foreach (var serverColumn in serverColumns)
            {
                foreach (var server in serverColumn)
                {
                    tasks.Add(Task.Run(async() => await GetServerSnapshotAsync(server)));
                }
            }

            await Task.WhenAll(tasks);

            for (var i = 0; i < tasks.Count; i++)
            {
                clusterSnapshot.ServerSnapshots[i] = tasks[i].Result;
            }

            clusterSnapshot.EndTimestamp = DateTime.UtcNow;
            clusterSnapshot.PlayerCount  = clusterSnapshot.ServerSnapshots.Sum(x => x.PlayerCount);
            clusterSnapshot.PlayerMax    = clusterSnapshot.ServerSnapshots.Max(x => x.PlayerCount);

            return(clusterSnapshot);
        }