public GetChatHistoryResponse getChatHistory(GetChatHistoryRequest request) { send(request); ServiceBusResponse resp = readUntilEOF(); return((GetChatHistoryResponse)resp); }
private ServiceBusResponse getChatHistory(GetChatHistoryRequest getChatHistoryRequest) { SendOptions sendOptions = new SendOptions(); sendOptions.SetDestination("Chat"); return(requestingEndpoint.Request <ServiceBusResponse>(getChatHistoryRequest, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Obtains the chat history for a particular conversation pair. /// </summary> /// <param name="echo">Information about the echo</param> public GetChatHistoryResponse getChatHistory(GetChatHistoryRequest request) { bool result = false; string message = ""; string user1 = request.getCommand.history.user1; string user2 = request.getCommand.history.user2; List <ChatMessage> msgs = new List <ChatMessage>(); if (openConnection() == true) { GetChatHistory ChatHistory = new GetChatHistory(); string query = @"SELECT * FROM " + dbname + @".CHAT WHERE (SENDER = '" + user1 + @"' AND RECEIVER = '" + user2 + @"') OR (SENDER = '" + user2 + @"' AND RECEIVER = '" + user1 + @"') ORDER BY timestamp ASC;"; try { MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ChatMessage msg = new ChatMessage(); msg.sender = reader.GetString("sender"); msg.receiver = reader.GetString("receiver"); msg.unix_timestamp = reader.GetInt32("timestamp"); msg.messageContents = reader.GetString("message"); msgs.Add(msg); } reader.Close(); request.getCommand.history.messages = msgs; result = true; message = "successfuly found history for users"; } catch (MySqlException e) { message = e.Message; } catch (Exception e) { Messages.Debug.consoleMsg("Unable to complete select from chat contacts database." + " Error :" + e.Message); Messages.Debug.consoleMsg("The query was:" + query); message = e.Message; } finally { closeConnection(); } } else { Debug.consoleMsg("Unable to connect to database"); message = "Unable to connect to database"; } return(new GetChatHistoryResponse(result, message, request.getCommand)); }
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)); }
private ServiceBusResponse getHistory(GetChatHistoryRequest request) { if (authenticated == false) { return(new GetChatHistoryResponse(false, "Error: You must be logged in to use the get history functionality.", request.getCommand)); } SendOptions sendOptions = new SendOptions(); sendOptions.SetDestination("Chat"); return(requestingEndpoint.Request <ServiceBusResponse>(request, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Sends a request to the chat service for the chat history between the 2 specified users. /// </summary> /// <param name="info">Should contain the two users whos chat history is being requested. in the form "userone=whatev1&usertwo=whatev2"</param> /// <returns>A string representation of the chat history between the 2 given users.</returns> private GetChatHistoryResponse getChatHistory(GetChatHistoryRequest request) { if (authenticated == false) { return(new GetChatHistoryResponse(false, "You must be logged in to use the chat service", null)); } SendOptions sendOptions = new SendOptions(); sendOptions.SetDestination("Chat"); return(requestingEndpoint.Request <GetChatHistoryResponse>(request, sendOptions) .ConfigureAwait(false).GetAwaiter().GetResult()); }
public ActionResult Index() { if (Globals.isLoggedIn() == false) { return(RedirectToAction("Index", "Authentication")); } ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser()); if (connection == null) { return(RedirectToAction("Index", "Authentication")); } GetChatContacts getContactsCommand = new GetChatContacts { usersname = Globals.getUser(), contactNames = null }; GetChatContactsRequest contactsRequest = new GetChatContactsRequest(getContactsCommand); GetChatContactsResponse contactsResponse = connection.getAllChatContacts(contactsRequest); ChatHistory firstDisplayedChatHistory = null; if (contactsResponse.responseData.contactNames.Count != 0) { GetChatHistory getHistoryCommand = new GetChatHistory() { history = new ChatHistory { user1 = Globals.getUser(), user2 = contactsResponse.responseData.contactNames[0] } }; GetChatHistoryRequest historyRequest = new GetChatHistoryRequest(getHistoryCommand); firstDisplayedChatHistory = connection.getChatHistory(historyRequest).responseData.history; } else { firstDisplayedChatHistory = new ChatHistory(); } ViewBag.ChatInstances = contactsResponse.responseData.contactNames; ViewBag.DisplayedChatHistory = firstDisplayedChatHistory; return(View()); }
private ServiceBusResponse getChatHistory(GetChatHistoryRequest request) { // check that the user is logged in. if (authenticated == false) { return(new ServiceBusResponse(false, "Error: You must be logged in to use the chat functionality.")); } // This class indicates to the request function where SendOptions sendOptions = new SendOptions(); sendOptions.SetDestination("Chat"); return(requestingEndpoint.Request <ServiceBusResponse>(request, sendOptions). ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Sends the data to the chat service, and returns the response. /// </summary> /// <param name="request">The data sent by the client</param> /// <returns>The response from the chat service</returns> private GetChatHistoryResponse getChatHistory(GetChatHistoryRequest request) { if (authenticated == false) { return(new GetChatHistoryResponse(false, "Error: You must be logged in to use the chat service functionality.", null)); } // This class indicates to the request function where SendOptions sendOptions = new SendOptions(); sendOptions.SetDestination("Chat"); // The Request<> funtion itself is an asynchronous operation. However, since we do not want to continue execution until the Request // function runs to completion, we call the ConfigureAwait, GetAwaiter, and GetResult functions to ensure that this thread // will wait for the completion of Request before continueing. return(requestingEndpoint.Request <GetChatHistoryResponse>(request, sendOptions). ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Sends a message to the bus requesting the chat history between the current user and the other specified user /// </summary> /// <param name="otherUser">A request containing information needed for the request to be completed</param> /// <returns>The chat history between two users</returns> public GetChatHistoryResponse getChatHistory(GetChatHistoryRequest request) { send(request); return((GetChatHistoryResponse)readUntilEOF()); }
/// <summary> /// This function will search the chat database for all of the chat messages passed between the 2 specified users. /// </summary> /// <param name="usersname">The name of the user</param> /// <param name="companyname">The name of the company</param> /// <returns>The chat history of the two users</returns> public GetChatHistoryResponse getChatHistory(GetChatHistoryRequest request) { GetChatHistory requestData = request.getCommand; string user1 = requestData.history.user1; string user2 = requestData.history.user2; List <ChatMessage> messages = new List <ChatMessage>(); bool result = false; string response = ""; if (openConnection() == true) { MySqlDataReader reader = null; try { string query = "SELECT m.message, m.timestamp, m.sender " + "FROM " + databaseName + ".messages AS m LEFT JOIN " + databaseName + ".chats AS c ON m.id = c.id " + "WHERE (c.usersname='" + user1 + "' AND c.companyname='" + user2 + "') " + "OR (c.usersname='" + user2 + "' AND c.companyname='" + user1 + "');"; MySqlCommand command = new MySqlCommand(query, connection); reader = command.ExecuteReader(); while (reader.Read() == true) { ChatMessage msg = new ChatMessage { messageContents = reader.GetString("message"), unix_timestamp = reader.GetInt32("timestamp") }; string sender = reader.GetString("sender"); msg.sender = sender; if (user1.Equals(sender)) { msg.receiver = user2; } else { msg.receiver = user1; } messages.Add(msg); } requestData.history.messages = messages; result = true; } catch (Exception e) { response = e.Message; } finally { if (reader != null && reader.IsClosed == false) { reader.Close(); } closeConnection(); } return(new GetChatHistoryResponse(result, response, requestData)); } else { return(new GetChatHistoryResponse(false, "Could not connect to Database.", requestData)); } }
public ServiceBusResponse getChatHistory(GetChatHistoryRequest request) { send(request); return(readUntilEOF()); }