Exemple #1
0
        public Task Handle(AccountCreated message, IMessageHandlerContext context)
        {
            Debug.consoleMsg(message.type.ToString());
            if (message.type.ToString().Equals("business"))
            {
                CompanyServiceDatabase.getInstance().saveAccount(message);
                Debug.consoleMsg("Account has been saved");
            }

            return(Task.CompletedTask);
        }
        /// <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(GetCompanyInfoRequest message, IMessageHandlerContext context)
        {
            Debug.consoleMsg("Got to GetCompanyInfoHandler");

            CompanyInstance temp = CompanyServiceDatabase.getInstance().getCompanyInfo(message.companyInfo.companyName);

            //Format the company list so it looks like what it is below, With ; dividing the different companies //NARINDER
            string response = CompanyServiceDatabase.companyInstanceToString(temp);


            //The context is used to give a reply back to the endpoint that sent the request
            return(context.Reply(new ServiceBusResponse(true, response)));
        }
Exemple #3
0
        /// <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(CompanySearchRequest message, IMessageHandlerContext context)
        {
            Debug.consoleMsg("Got to CompanySearchHandler");
            Debug.consoleMsg(message.searchDeliminator);
            //Save the echo to the database
            CompanyList temp = CompanyServiceDatabase.getInstance().searchCompanies(message.searchDeliminator);

            //Format the company list so it looks like what it is below, With ; dividing the different companies //NARINDER
            string response = CompanyServiceDatabase.companyListToString(temp);



            Debug.consoleMsg(response);
            //The context is used to give a reply back to the endpoint that sent the request
            return(context.Reply(new CompanySearchResponse(true, response, temp)));
        }
Exemple #4
0
        /// <summary>
        /// This method is responsible for initializing the echo endpoint used to receive events and commands
        /// </summary>
        /// <returns>Nothing.</returns>
        static async Task AsyncMain()
        {
            Console.Title = "Company";

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

            //These two lines prevemt the endpoint configuration from scanning the MySql dll.
            //This is done 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.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
            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 AccountCreated event published by the Authentication endpoint
            routing.RegisterPublisher(typeof(AccountCreated), "Authentication");
            routing.RegisterPublisher(typeof(CompanyEvent), "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;

            do
            {
                entry = Console.ReadLine();
                switch (entry)
                {
                case ("DELETEDB"):
                    CompanyServiceDatabase.getInstance().deleteDatabase();
                    Debug.consoleMsg("Delete database attempt complete");
                    break;

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

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

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