Beispiel #1
0
        public GetChatContactsResponse getAllChatContacts(GetChatContactsRequest request)
        {
            send(request);
            ServiceBusResponse resp = readUntilEOF();

            return((GetChatContactsResponse)resp);
        }
        private ServiceBusResponse getChatContacts(GetChatContactsRequest getChatContactsRequest)
        {
            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("Chat");
            return(requestingEndpoint.Request <ServiceBusResponse>(getChatContactsRequest, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult());
        }
        private ServiceBusResponse getContacts(GetChatContactsRequest request)
        {
            if (authenticated == false)
            {
                return(new GetChatContactsResponse(false, "Error: You must be logged in to use the get contacts functionality.", request.getCommand));
            }

            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("Chat");
            return(requestingEndpoint.Request <ServiceBusResponse>(request, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult());
        }
Beispiel #4
0
        /// <summary>
        /// Selects the names of all other users that the given user has made chat contact with in the past
        /// </summary>
        /// <param name="usersname">The name of the user</param>
        /// <returns>A list of usernames the user has sent at least one chat message to</returns>
        public GetChatContactsResponse getAllChatContactsForUser(GetChatContactsRequest request)
        {
            //TODO low importance: Turn this from max 3 queries to 2 for added efficiency
            bool   result   = false;
            string response = "";

            GetChatContacts requestData = request.getCommand;

            if (openConnection() == true)
            {
                List <string>   contacts = new List <string>();
                MySqlDataReader reader   = null;
                try
                {
                    string query = "SELECT * FROM " + databaseName + ".chats " +
                                   "WHERE usersname='" + requestData.usersname + "' OR companyname='" + requestData.usersname + "';";

                    MySqlCommand command = new MySqlCommand(query, connection);
                    reader = command.ExecuteReader();

                    while (reader.Read() == true)
                    {
                        if (requestData.usersname.Equals(reader.GetString("usersname")))
                        {
                            contacts.Add(reader.GetString("companyname"));
                        }
                        else
                        {
                            contacts.Add(reader.GetString("usersname"));
                        }
                    }

                    requestData.contactNames = contacts;
                    result = true;
                }
                catch (Exception e)
                {
                    response = e.Message;
                }
                finally
                {
                    if (reader != null && reader.IsClosed == false)
                    {
                        reader.Close();
                    }
                    closeConnection();
                }

                return(new GetChatContactsResponse(result, response, requestData));
            }

            return(new GetChatContactsResponse(false, "Could not connect to database", requestData));
        }
        /// <summary>
        /// Asks the ChatService endpoint to get a list of usernames the given user has contacted via chat in the past
        /// </summary>
        /// <param name="usersname">The name of the user</param>
        /// <returns>A single string containing the usernames of users the given user has contacted via chat. A " " response indicates no other users were found</returns>
        private GetChatContactsResponse getAllChatContactsForUser(GetChatContactsRequest request)
        {
            if (authenticated == false)
            {
                return(new GetChatContactsResponse(false, "You must be logged in to use the chat service", null));
            }

            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("Chat");

            return(requestingEndpoint.Request <GetChatContactsResponse>(request, sendOptions).
                   ConfigureAwait(false).GetAwaiter().GetResult());
        }
Beispiel #6
0
        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 getChatContacts(GetChatContactsRequest 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 GetChatContactsResponse getAllChatContacts(GetChatContactsRequest request)
        {
            if (authenticated == false)
            {
                return(new GetChatContactsResponse(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 <GetChatContactsResponse>(request, sendOptions).
                   ConfigureAwait(false).GetAwaiter().GetResult());
        }
Beispiel #9
0
        /// <summary>
        /// Gets the contacts for a user from DB.
        /// </summary>
        /// <param name="request"></param>
        public GetChatContactsResponse getChatContacts(GetChatContactsRequest request)
        {
            bool            result       = false;
            string          message      = "";
            GetChatContacts chatContacts = new GetChatContacts();

            chatContacts.contactNames = new List <string>();
            if (openConnection() == true)
            {
                string query = @"SELECT RECEIVER FROM " + dbname + @".CHAT WHERE SENDER = '" + request.getCommand.usersname +
                               @"' UNION SELECT SENDER FROM " + dbname + @".CHAT WHERE RECEIVER = '" + request.getCommand.usersname +
                               @"';";
                try
                {
                    MySqlCommand    command = new MySqlCommand(query, connection);
                    MySqlDataReader reader  = command.ExecuteReader();
                    while (reader.Read())
                    {
                        chatContacts.contactNames.Add(reader.GetString("RECEIVER"));
                    }
                    reader.Close();
                    result = true;
                } 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);
                    chatContacts.contactNames.Add(e.Message);
                    message = e.Message;
                } finally
                {
                    closeConnection();
                }
            }
            else
            {
                Debug.consoleMsg("Unable to connect to database");
                message = "Unable to connect to database";
            }
            return(new GetChatContactsResponse(result, message, chatContacts));
        }
 /// <summary>
 /// Makes a request to the service bus for a list of usernames the current user has contacted via chat in the past
 /// </summary>
 /// <returns>The response from the server containing the list of usernames</returns>
 public GetChatContactsResponse getAllChatContacts(GetChatContactsRequest request)
 {
     send(request);
     return((GetChatContactsResponse)readUntilEOF());
 }