Beispiel #1
0
        public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context)
        {
            ChatDatabase           db       = ChatDatabase.getInstance();
            GetChatHistoryResponse response = db.retrieveChatHistory(message.getCommand);

            return(context.Reply(response));
        }
        /// <summary>
        /// Saves the echo to the database, reverses the data, and returns it back to the calling endpoint.
        /// </summary>
        /// <param name="message">Information about the echo</param>
        /// <param name="context">Used to access information regarding the endpoints used for this handle</param>
        /// <returns>The response to be sent back to the calling process</returns>
        public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context)
        {
            //Save the echo to the database
            GetChatHistoryResponse responseData = ChatServiceDatabase.getInstance().getChatHistory(message);

            //The context is used to give a reply back to the endpoint that sent the request
            return(context.Reply(responseData));
        }
Beispiel #3
0
        public ActionResult Conversation(string otherUser = "")
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(otherUser))
            {
                throw new System.Exception("Did not supply all required arguments.");
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            GetChatHistory getCommand = new GetChatHistory()
            {
                history = new ChatHistory()
                {
                    user1 = Globals.getUser(),
                    user2 = otherUser
                }
            };

            GetChatHistoryRequest request = new GetChatHistoryRequest(getCommand);

            GetChatHistoryResponse response = connection.getChatHistory(request);

            string newConvoHtml = "";

            foreach (ChatMessage msg in response.responseData.history.messages)
            {
                if (msg.sender.Equals(Globals.getUser()))
                {
                    newConvoHtml +=
                        "<p class=\"message\">" +
                        "<span class=\"username\">You: </span>" +
                        msg.messageContents +
                        "</p>";
                }
                else
                {
                    newConvoHtml +=
                        "<p class=\"message\">" +
                        "<span class=\"username\" style=\"color:aqua;\">" + msg.sender + ": </span>" +
                        msg.messageContents +
                        "</p>";
                }
            }

            return(Content(newConvoHtml));
        }
        /// <summary>
        /// Asks the database to retrieve all chat messages passed between the 2 users specified in the command object.
        /// </summary>
        /// <param name="message">The command containg the message information</param>
        /// <param name="context">The receiving endpoint</param>
        /// <returns>The command object with the history property filled</returns>
        public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context)
        {
            GetChatHistoryResponse dbResponse = ChatServiceDatabase.getInstance().getChatHistory(message);

            return(context.Reply(dbResponse));
        }