/// <summary>
 /// This handler will add the newly created account to the list of companies upon the creation of a business account
 /// This function will do nothing if the new account is a regular user account
 /// </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(AccountCreated message, IMessageHandlerContext context)
 {
     //return Task.CompletedTask;
     if (message.type == AccountType.business)
     {
         if (CompanyDirectoryDB.getInstance().insertNewCompany(message) == false)
         {
             throw new Exception("Failed to enter company into database;");
         }
     }
     return(Task.CompletedTask);
 }
        /// <summary>
        /// Searches the CompanyDirectory database for a company matching the one in the comand object and returns its information if it exists
        /// </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>A CompanyInstance response containing information about the requested company, or null if the company was not found</returns>
        public Task Handle(GetCompanyInfoRequest message, IMessageHandlerContext context)
        {
            GetCompanyInfoResponse dbResponse = CompanyDirectoryDB.getInstance().getCompanyInfo(message);

            return(context.Reply(dbResponse));
        }
        /// <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 = "CompanyDirectory";
//#endif
            //Create a new Endpoint configuration with the name "CompanyDirectory"
            var endpointConfiguration = new EndpointConfiguration("CompanyDirectory");

            //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();

            routing.RegisterPublisher(typeof(AccountCreated), "Authentication");//Register to events of type AccountCreated from Authentication endpoint

            //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);

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

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

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

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

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

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

//#endif
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Searches the Company Directory Service database for any company's that match the description given in the command object
        /// </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>An object containing a list of companies matching the given description</returns>
        public Task Handle(CompanySearchRequest message, IMessageHandlerContext context)
        {
            CompanySearchResponse dbResponse = CompanyDirectoryDB.getInstance().searchByName(message);

            return(context.Reply(dbResponse));
        }