/// <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));
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the echo to the database, reverses the data, and returns it back to the calling endpoint.
        /// </summary>
        /// <param name="request">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(GetChatContactsRequest request, IMessageHandlerContext context)
        {
            //Save the echo to the database
            GetChatContactsResponse response = ChatServiceDatabase.getInstance().getContacts(request.getCommand.usersname);

            //The context is used to give a reply back to the endpoint that sent the request
            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="request">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(SendMessageRequest request, IMessageHandlerContext context)
        {
            //Save the echo to the database
            ServiceBusResponse response = ChatServiceDatabase.getInstance().sendMessage(request.message);

            //The context is used to give a reply back to the endpoint that sent the request
            return(context.Reply(response));
        }
        public Task Handle(SendMessageRequest message, IMessageHandlerContext context)
        {
            Debug.consoleMsg("Got to SendMessageRequestHandler");

            //Error Checking
            string response = "Success";

            ChatServiceDatabase.getInstance().saveMessage(message.message);
            Debug.consoleMsg("Leaving to SendMessageRequestHandler");
            return(context.Reply(new ServiceBusResponse(true, response)));
        }
        public Task Handle(GetChatHistoryRequest message, IMessageHandlerContext context)
        {
            Debug.consoleMsg("Got to GetChatHistoryHandler");

            //Error Checking
            string response  = "Success";
            var    returnVal = ChatServiceDatabase.getInstance().getChatHistory(message.getCommand.history.user1, message.getCommand.history.user2);

            Debug.consoleMsg("Leaving to GetChatHistoryHandler");
            return(context.Reply(new GetChatHistoryResponse(true, response, returnVal)));
        }
Esempio n. 6
0
        public Task Handle(GetChatContactsRequest message, IMessageHandlerContext context)
        {
            Debug.consoleMsg("Got to GetChatContactHandler");


            //Error Checking
            string          response  = "Success";
            GetChatContacts returnVal = ChatServiceDatabase.getInstance().getChatContacts(message.getCommand.usersname);

            Debug.consoleMsg("Size:" + returnVal.contactNames.Count);

            return(context.Reply(new GetChatContactsResponse(true, response, returnVal)));
        }
 /// <summary>
 /// Saves the message to the Chat Service database
 /// </summary>
 /// <param name="message">The event object that was published</param>
 /// <param name="context">Contains information relevent to the current event being handled.</param>
 /// <returns>A completed task, which basically means it returns nothing</returns>
 public Task Handle(MessageSent message, IMessageHandlerContext context)
 {
     ChatServiceDatabase.getInstance().saveMessage(message.msg);
     return(Task.CompletedTask);
 }
        /// <summary>
        /// Saves the echo to the database
        /// This method will be called by the NServiceBus framework when an event of type "AsIsEchoEvent" is published.
        /// </summary>
        /// <param name="message">Information about the echo</param>
        /// <param name="context"></param>
        /// <returns>Nothing</returns>
        public Task Handle(SendMessageRequest message, IMessageHandlerContext context)
        {
            ServiceBusResponse response = ChatServiceDatabase.getInstance().saveMessage(message);

            return(context.Reply(response));
        }
Esempio n. 9
0
        /// <summary>
        /// This method is responsible for initializing the chat endpoint used to receive events and commands
        /// </summary>
        /// <returns>Nothing. Execution ends when this function ends</returns>
        static async Task AsyncMain()
        {
//#if DEBUG
            Console.Title = "Chat";
//#endif

            //Create a new Endpoint configuration with the name "Authentication"
            EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Chat");

            //These two lines prevemt the endpoint configuration from scanning the MySql dll.
            //This is donw because it speeds up the startup time, and it prevents a rare but
            //very confusing error sometimes caused by NServiceBus scanning the file. If you
            //wish to know morw about this, google it, then ask your TA(since they will probably
            //just google it anyway)
            var scanner = endpointConfiguration.AssemblyScanner();

            scanner.ExcludeAssemblies("MySql.Data.dll");

            //Allows the endpoint to run installers upon startup. This includes things such as the creation of message queues.
            endpointConfiguration.EnableInstallers();
            //Instructs the queue to serialize messages with Json, should it need to serialize them
            endpointConfiguration.UseSerialization <JsonSerializer>();
            //Instructs the endpoint to use local RAM to store queues. TODO: Good during development, not during deployment (According to the NServiceBus tutorial)
            endpointConfiguration.UsePersistence <InMemoryPersistence>();
            //Instructs the endpoint to send messages it cannot process to a queue named "error"
            endpointConfiguration.SendFailedMessagesTo("error");

            //Instructs the endpoint to use Microsoft Message Queuing TOD): Consider using RabbitMQ instead, only because Arcurve reccomended it.
            var transport = endpointConfiguration.UseTransport <MsmqTransport>();
            //This variable is used to configure how messages are routed. Using this, you may set the default reciever of a particular command, and/or subscribe to any number of events
            var routing = transport.Routing();

            //Register to the MessageSent events published by the authentication endpoint
            routing.RegisterPublisher(typeof(MessageSent), "Authentication");

            //Start the endpoint with the configuration defined above.It should be noted that any changes made to the endpointConfiguration after an endpoint is instantiated will not apply to any endpoints that have already been instantiated
            var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

            Debug.consoleMsg("Press Enter to exit.");
            string entry;

//#if DEBUG
            do
            {
                entry = Console.ReadLine();

                switch (entry)
                {
                case ("DELETEDB"):
                    ChatServiceDatabase.getInstance().deleteDatabase();
                    Debug.consoleMsg("Delete database attempt complete");
                    break;

                case ("CREATEDB"):
                    ChatServiceDatabase.getInstance().createDB();
                    Debug.consoleMsg("Completed Database Creation Attempt.");
                    break;

                default:
                    Debug.consoleMsg("Command not understood");
                    break;
                }
            } while (!entry.Equals(""));

            await endpointInstance.Stop().ConfigureAwait(false);

//#endif
        }
        /// <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));
        }
Esempio n. 11
0
        /// <summary>
        /// Searches the chat database for the names of all other users the given user has made chat contact with
        /// </summary>
        /// <param name="message">The command object that was sent</param>
        /// <param name="context">Contains information relevent to the current command being handled.</param>
        /// <returns>The command object with the contactnames property filled</returns>
        public Task Handle(GetChatContactsRequest message, IMessageHandlerContext context)
        {
            GetChatContactsResponse dbResponse = ChatServiceDatabase.getInstance().getAllChatContactsForUser(message);

            return(context.Reply(dbResponse));
        }