/// <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(ReverseEchoRequest message, IMessageHandlerContext context)
        {
            //Save the echo to the database
            EchoServiceDatabase.getInstance().saveReverseEcho(message);

            //Reverse the string
            char[] charArray = message.data.ToCharArray();
            Array.Reverse(charArray);

            //The context is used to give a reply back to the endpoint that sent the request
            return(context.Reply(new ServiceBusResponse(true, new string(charArray))));
        }
Exemplo n.º 2
0
 /// <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(AsIsEchoEvent message, IMessageHandlerContext context)
 {
     Debug.consoleMsg("Got to EchoEventHandler");
     EchoServiceDatabase.getInstance().saveAsIsEcho(message);
     return(Task.CompletedTask);
 }
Exemplo n.º 3
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 = "Echo";

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

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

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

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

            await endpointInstance.Stop().ConfigureAwait(false);
        }
 /// <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(AsIsEchoEvent message, IMessageHandlerContext context)
 {
     EchoServiceDatabase.getInstance().saveAsIsEcho(message);
     return(Task.CompletedTask);
 }