public RequestTypeInvalidException(
     WebSocketRequestType requestType,
     WebSocket webSocket,
     HttpStatusCode returnStatusCode = HttpStatusCode.BadRequest)
 {
     _message = $"The request type - {requestType.AsString()} - is not valid";
     _isWebSocketException = true;
     _returnStatusCode     = returnStatusCode;
     _webSocket            = webSocket;
 }
        public async Task ProcessIncomingRequest(WebSocket webSocket, WebSocketRequestType requestType, BaseDto baseDtoParam = null, string jsonString = null)
        {
            if (requestType != WebSocketRequestType.REQUEST)
            {
                throw new RequestTypeInvalidException(requestType, webSocket);
            }

            BaseDto baseDto;
            string  jsonText;

            if (baseDtoParam != null)
            {
                baseDto  = baseDtoParam;
                jsonText = jsonString;
            }
            else
            {
                var(baseDtoTemp, jsonTextTemp) = await ReadWebSocketAsAsync <BaseDto>(webSocket);

                baseDto  = baseDtoTemp;
                jsonText = jsonTextTemp;
            }

            switch (baseDto.RequestType)
            {
            case WebSocketRequestType.AUTHENTICATION:

                _logger.LogDebug($"Incoming websocket request {baseDto.RequestType} from user {baseDto.Token1}");

                var authenticationDto = JsonConvert.DeserializeObject <AuthenticationDto>(jsonText);
                await ProcessAuthenticationAsync(authenticationDto, webSocket);

                break;

            case WebSocketRequestType.RECEIVED_COMFIRMATION:
                _logger.LogDebug($"Incoming websocket request {baseDto.RequestType} from user {baseDto.Token1}");

                var receiveConfirmationDto = JsonConvert.DeserializeObject <ReceivedConfirmationDto>(jsonText);
                await ProcessReceivedConfirmation(receiveConfirmationDto, webSocket);

                break;

            default:
                throw new RequestTypeInvalidException(requestType, webSocket);
            }
        }
 public static string AsString(this WebSocketRequestType type)
 {
     return(type.ToString());
 }