示例#1
0
        public static BaseResponse Build(BaseRequest request)
        {
            if (request is ReceiveRequest)
            {
                return(ReceiveCommand.GetPendingMessages(request as ReceiveRequest));
            }
            if (request is LoginRequest)
            {
                return(LoginCommand.LogUserIn(request as LoginRequest));
            }
            if (request is LogoffRequest)
            {
                return(LogoffCommand.LogUserOff(request as LogoffRequest));
            }
            if (request is SendRequest)
            {
                return(SendCommand.Send(request as SendRequest));
            }

            return(null);
        }
示例#2
0
        private static void HandlePreviousJoke(SendRequest request)
        {
            TocTocJoke joke = AsyncListener.PendingJokes
                              .Where(j => j.UserId == request.UserId)
                              .FirstOrDefault();

            if (joke != null)
            {
                // If the interaction was correct:
                if (joke.ClientInteractions[joke.ClientInteractionIndex]
                    .Equals(request.Data, StringComparison.OrdinalIgnoreCase) == true)
                {
                    // Increments interaction from both client and server, and adds
                    // the new joke interaction to the pending messages container.
                    joke.ClientInteractionIndex++;

                    Message jokeMsg = new Message()
                    {
                        Data = joke.ServerInteractions[joke.ServerInteractionIndex],
                        DestinationUserId = request.UserId
                    };

                    joke.ServerInteractionIndex++;

                    AsyncListener.PendingMessages.Add(jokeMsg);

                    // If the joke is over, remove it from the bunch:
                    if (joke.ServerInteractionIndex >= joke.ServerInteractions.Length)
                    {
                        AsyncListener.PendingJokes.Remove(joke);
                    }
                }
                else
                {
                    SendCommand.HandleJokeError(request.UserId, joke);
                }
            }
        }