Ejemplo n.º 1
0
        public String addTopic(String topicName)
        {
            String responseMessage = "";

            String[] existingTopicNames = _topReadWrite.getTopicNames();
            //makes absolutely sure that the topicname has not already been taken.
            if (Array.Find(existingTopicNames, element => element.Equals(topicName)) == null)
            {
                _topReadWrite.createNewTopic(topicName);
                responseMessage = CommunicationProtocol.NO_ACTION_REQUIRED + "Topic successfully created.";
                _profReadWrite.addTopic(_username, topicName);
            }
            else
            {
                responseMessage = CommunicationProtocol.NAME_TAKEN + "Sorry, that topic name was taken while you were deciding.";
            }

            return(responseMessage);
        }
Ejemplo n.º 2
0
        public string getResponse(string message)
        {
            string response  = "You probably forgot to restart the server, dummy.";
            string indicator = message.Substring(0, 2);

            message = message.Substring(2);
            message = message.Trim((char)0);

            if (indicator.Equals(CommunicationProtocol.REQUEST_USERNAMES))
            {
                String[] usernamesArray = profReadWrite.getUsernames();
                response = prepareStringArray(usernamesArray) + ";";
            }
            else if (indicator.Equals(CommunicationProtocol.LOG_IN))
            {
                response = loadProfile(message);
            }
            else if (indicator.Equals(CommunicationProtocol.CREATE_PROFILE))
            {
                response = createProfile(message);
            }
            else if (indicator.Equals(CommunicationProtocol.CREATE_TOPIC))
            {
                response = _userProfile.addTopic(message);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_TOPIC_NAMES))
            {
                String[] topicNames = topReadWrite.getTopicNames();
                response = prepareStringArray(topicNames) + ";";
            }
            else if (indicator.Equals(CommunicationProtocol.ADD_SUBSCRIPTION))
            {
                _userProfile.subscribe(message);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_NOT_SUBSCRIBED_TOPIC_NAMES))
            {
                response = _userProfile.getNotSubscribedTopicNames();
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_USERS_TOPIC_NAMES))
            {
                response = _userProfile.getMyTopicNames();
            }
            else if (indicator.Equals(CommunicationProtocol.PUBLISH_MESSAGE))
            {
                String[] names            = parseString(message);
                String   topicName        = names[0];
                String   publishedMessage = names[1];
                publishMessage(topicName, publishedMessage);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_SUBSCRIPTION_NAMES))
            {
                response = _userProfile.getSubscriptionNames();
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_SUBSCRIPTION_MESSAGES))
            {
                response = _userProfile.getSubscriptionMessages(message);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_NEW_MESSAGE_COUNT))
            {
                response = _userProfile.getNewMessageCount(message);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_AUTO_RUN_STATUS))
            {
                String status = topReadWrite.getAutoRun(message);
                response = status;
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_DEFAULT_MESSAGES))
            {
                String status = topReadWrite.getDefaultMessages(message);
                response = status;
            }
            else if (indicator.Equals(CommunicationProtocol.TOGGLE_AUTO_RUN))
            {
                String status = topReadWrite.toggleAutoRun(message);
                response = status;
            }
            else if (indicator.Equals(CommunicationProtocol.ADD_DEFAULT_MESSAGE))
            {
                String[] messages = parseString(message);
                topReadWrite.addDefaultMessage(messages[0], messages[1]);
            }
            else if (indicator.Equals(CommunicationProtocol.DELETE_DEFAULT_MESSAGE))
            {
                String[] messages       = parseString(message);
                String   topicName      = messages[0];
                String   deletedMessage = messages[1];
                response = deleteDefaultMessage(topicName, deletedMessage);
            }
            else if (indicator.Equals(CommunicationProtocol.REMOVE_SUBSCRIPTION))
            {
                _userProfile.unsubscribe(message);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_WELCOME_MESSAGE))
            {
                response = topReadWrite.getWelcomeMessage(message);
            }
            else if (indicator.Equals(CommunicationProtocol.SET_WELCOME_MESSAGE))
            {
                String[] messages       = parseString(message);
                String   topicName      = messages[0];
                String   welcomeMessage = messages[1];
                topReadWrite.setWelcomeMessage(topicName, welcomeMessage);
            }
            else if (indicator.Equals(CommunicationProtocol.REQUEST_TOPIC_HISTORY))
            {
                String[] messages = topReadWrite.getTopicMessages(message, 0);
                messages[0] = message;
                messages[1] = "Start of message history";
                response    = prepareStringArray(messages);
            }

            return(response);
        }