Exemplo n.º 1
0
        /// <summary>
        /// Searches for company information
        /// </summary>
        /// <param name="message">Information about the company</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)
        {
            GetCompanyInfoResponse infoResponse = CompanyListingsDatabase.getInstance().getCompanyInfo(message);

            // Get Reviews
            string result = "";

            if (infoResponse.result)
            {
                try
                {
                    HttpClient getRevs = new HttpClient();
                    //TODO: --ENSURE THIS IS CORRECT BEFORE DEPLOYMENT--
                    string uri = "http://localhost:50151/DBLS/GetCompanyReviews/%7B%22companyName%22:%22" + infoResponse.companyInfo.companyName + "%22%7D";
                    result = getRevs.GetStringAsync(uri).Result;
                    System.Diagnostics.Debug.WriteLine(result);
                    ReviewList r = new JavaScriptSerializer().Deserialize <ReviewList>(result);
                    infoResponse.companyInfo.reviewList = r;
                }
                catch (Exception a)
                {
                    infoResponse.result   = false;
                    infoResponse.response = "Issue communicating with review system.";
                }
            }

            return(context.Reply(infoResponse));
        }
 /// <summary>
 /// Handles events pertaining to saving company information to the database.
 /// This method will be called by the NServiceBus framework when an event of type "CompanyListingsEvent" is published.
 /// </summary>
 /// <param name="message">Information about the company</param>
 /// <param name="context"></param>
 /// <returns>Nothing</returns>
 public Task Handle(CompanyListingsEvent message, IMessageHandlerContext context)
 {
     CompanyListingsDatabase.getInstance().saveCompany(message);
     return(Task.CompletedTask);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Searches for companys
 /// </summary>
 /// <param name="message">Information about the company</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)
 {
     return(context.Reply(CompanyListingsDatabase.getInstance().searchCompany(message)));
 }
Exemplo n.º 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 = "CompanyListings";

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

            //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 CompanyListingsEvent event published by the Authentication endpoint
            routing.RegisterPublisher(typeof(CompanyListingsEvent), "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"):
                    CompanyListingsDatabase.getInstance().deleteDatabase();
                    Debug.consoleMsg("Delete database attempt complete");
                    break;

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

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

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