private async Task <object> UpdateGuestSessionAsync(dynamic input, CancellationToken cancellationToken)
        {
            GuestSession guestSessionModel;

            try
            {
                guestSessionModel = this.Bind <GuestSession>();
            }
            catch (Exception ex)
            {
                Logger.Error("Binding failed while attempting to update a GuestSession resource.", ex);
                return(Response.BadRequestBindingException(ResponseReasons.FailedToBindToRequest));
            }

            await RequiresAccess()
            .WithProjectIdExpansion(ctx => guestSessionModel.ProjectId)
            .ExecuteAsync(cancellationToken);

            try
            {
                return(await _guestSessionController.UpdateGuestSessionAsync(guestSessionModel, PrincipalId));
            }
            catch (Exception ex)
            {
                Logger.Error("Unhandled exception encountered while attempting to update a GuestSession resource", ex);
                return(Response.InternalServerError(ResponseReasons.InternalServerErrorUpdateGuestSession));
            }
        }
Exemplo n.º 2
0
        public async void HandleEvent(SessionEnded payload)
        {
            try
            {
                var guestSession = await _guestSessionController.GetGuestSessionBySessionIdAsync(payload.SessionId);

                if (guestSession == null)
                {
                    return;
                }

                if (guestSession.GuestSessionState == GuestState.Ended)
                {
                    return;
                }

                guestSession.GuestSessionState = GuestState.Ended;
                await _guestSessionController.UpdateGuestSessionAsync(guestSession, guestSession.UserId);

                // Recalc lobby state after guest session is ended.
                await _projectLobbyStateController.RecalculateProjectLobbyStateAsync(guestSession.ProjectId);
            }
            catch (Exception ex)
            {
                _logger.Error($"Unexpected exception while ending the guest session for session ID {payload.SessionId}", ex);
            }
        }