예제 #1
0
        private S3PlayerApiClient RefreshClient(S3PlayerApiClient clientObject, TokenResponse tokenResponse, CancellationToken ct)
        {
            // TODO: check for token expiration also
            if (clientObject == null)
            {
                clientObject = PlayerApiExtensions.GetPlayerApiClient(_httpClientFactory, _clientOptions.CurrentValue.urls.playerApi, tokenResponse);
            }

            return(clientObject);
        }
예제 #2
0
        public async Task <Event> EnlistAsync(string code, CancellationToken ct)
        {
            // user may not have access to the player api, so we get the resource owner token
            var token = await ApiClientsExtensions.GetToken(_serviceProvider);

            var playerApiClient      = PlayerApiExtensions.GetPlayerApiClient(_httpClientFactory, _clientOptions.urls.playerApi, token);
            var steamfitterApiClient = SteamfitterApiExtensions.GetSteamfitterApiClient(_httpClientFactory, _clientOptions.urls.steamfitterApi, token);

            var alloyEvent = await GetEventByShareCodeAsync(code, ct);

            if (alloyEvent.Status == EventStatus.Active || alloyEvent.Status == EventStatus.Paused)
            {
                if (alloyEvent != null)
                {
                    if (alloyEvent.ViewId.HasValue)
                    {
                        await PlayerApiExtensions.AddUserToViewTeamAsync(playerApiClient, alloyEvent.ViewId.Value, _user.GetId(), ct);
                    }

                    if (alloyEvent.ScenarioId.HasValue)
                    {
                        await steamfitterApiClient.AddUsersToScenarioAsync(alloyEvent.ScenarioId.Value, new List <Guid> {
                            _user.GetId()
                        }, ct);
                    }

                    try
                    {
                        var entity = await _context.EventUsers.Where(e => e.UserId == _user.GetId() && e.EventId == alloyEvent.Id).FirstOrDefaultAsync();

                        if (entity == null)
                        {
                            var eventUser = new EventUserEntity
                            {
                                EventId   = alloyEvent.Id,
                                UserId    = _user.GetId(),
                                CreatedBy = _user.GetId()
                            };

                            _context.EventUsers.Add(eventUser);
                            await _context.SaveChangesAsync();
                        }

                        return(alloyEvent);
                    }
                    catch (Exception)
                    {
                        throw new InviteException("Invite Failed, Accepted Already");
                    }
                }
            }
            throw new InviteException($"Invite Failed, Event Status: {Enum.GetName(typeof(EventStatus), alloyEvent.Status)}");
        }