Пример #1
0
        public override void AnnounceServer(string serverId, ServerContext context)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException(nameof(serverId));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var data = new ServerDataDto
            {
                WorkerCount = context.WorkerCount,
                Queues      = context.Queues,
                StartedAt   = DateTime.UtcNow
            };

            Database.Server.UpdateMany(Builders <ServerDto> .Filter.Eq(_ => _.Id, serverId),
                                       Builders <ServerDto> .Update.Combine(Builders <ServerDto> .Update.Set(_ => _.Data, JobHelper.ToJson(data)),
                                                                            Builders <ServerDto> .Update.Set(_ => _.LastHeartbeat, DateTime.UtcNow)),
                                       new UpdateOptions {
                IsUpsert = true
            });
        }
Пример #2
0
        public void GetServers_ShouldCallService()
        {
            var mockData = new ServerDataDto();

            _service.Setup(x => x.GetServerData(It.IsAny <int>(), It.IsAny <IChatDtoFactory <Server, ServerDataDto> >(), It.IsAny <ChatEntityRepositoryProxy <Server, ChatDbContext> >()))
            .Returns(mockData);

            _controller.GetServer(1, null, null);

            _service.Verify(x => x.GetServerData(It.IsAny <int>(),
                                                 It.IsAny <IChatDtoFactory <Server, ServerDataDto> >(),
                                                 It.IsAny <ChatEntityRepositoryProxy <Server, ChatDbContext> >()),
                            Times.Once);
        }
Пример #3
0
        public void AnnounceServer(string serverId, ServerContext context)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException("serverId");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var data = new ServerDataDto
            {
                WorkerCount = context.WorkerCount,
                Queues      = context.Queues,
                StartedAt   = _database.GetServerTimeUtc(),
            };

            _database.Server.Update(Query <ServerDto> .EQ(_ => _.Id, serverId),
                                    Update.Combine(Update <ServerDto> .Set(_ => _.Data, JobHelper.ToJson(data)), Update <ServerDto> .Set(_ => _.LastHeartbeat, _database.GetServerTimeUtc())),
                                    UpdateFlags.Upsert);
        }