Ejemplo n.º 1
0
        public async Task <bool> Handle(EnrollmentRequestCommand request, CancellationToken cancellationToken)
        {
            var message = new BusMessage("CourseEnrollment", request);

            await _Publisher.Publish(message, "course.queue");

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Handle(CourseEnrollmentCommand request, CancellationToken cancellationToken)
        {
            var course = await _CourseRepository.GetCourseInfo(request.CourseId);

            if (course == default)
            {
                throw new ElementNotFoundException();
            }

            var student = await _StudentRepository.FindStudent(request.StudentName, request.StudentAge);

            if (student == default)
            {
                student = new Student(request.StudentName, request.StudentAge);
                await _StudentRepository.Add(student);
            }

            var success = true;

            try
            {
                course.Enroll(student);

                await _CourseRepository.Update(course);

                await _UnitOfWork.Commit();
            }
            catch
            {
                success = false;
                throw;
            }
            finally
            {
                await _Publisher.Publish(new BusMessage("NotifyEnrollment",
                                                        new { Notification = new EmailNotification(success) }),
                                         "course.queue");
            }

            return(true);
        }
Ejemplo n.º 3
0
 public void PublishUserMessage(User message)
 {
     _userQueuePublisher.Publish(message);
 }
Ejemplo n.º 4
0
        private static int RunPublish(IQueuePublisher publisher, string[] args)
        {
            using (var app = new CommandLineApplication())
            {
                app.ThrowOnUnexpectedArgument = false;

                app.HelpOption("-h|--help");
                app.ExtendedHelpText = "Publishes queue message(s) and/or initializes exchange and queue.";

                var optionGaugeIds = app.Option(
                    "-g|--gauges <usgsGaugeIds>",
                    "List of USGS gauge ids to publish",
                    CommandOptionType.MultipleValue);

                var optionAll = app.Option(
                    "-a|--all",
                    "Publishes messages to refresh all USGS gauges",
                    CommandOptionType.NoValue
                    );

                var optionTop = app.Option <int>(
                    "-t|--top",
                    "Publishes messages to refresh top N USGS gauges (i.e. limits for bulk testing)",
                    CommandOptionType.SingleValue
                    ).Accepts(o => o.Range(1, 1000));

                app.Option("--server.urls <urls>", "PCF server urls", CommandOptionType.SingleValue);

                app.OnExecute(() =>
                {
                    publisher.Initialize();

                    if (optionGaugeIds.HasValue())
                    {
                        publisher.Publish(optionGaugeIds.Values);
                    }
                    else if (optionTop.HasValue())
                    {
                        publisher.Publish(top: optionTop.ParsedValue);
                    }
                    else if (optionAll.HasValue())
                    {
                        publisher.Publish(top: null);
                    }
                    else
                    {
                        Console.WriteLine("Producer initialized, no queue messages published");
                    }
                });

                var returnCode = app.Execute(args);

                if (returnCode > 0)
                {
                    // Show help on validation issues.
                    app.ShowHelp();
                }
                else if (returnCode < 0)
                {
                    var color = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine("Program terminated with error; see logs for details.");
                    Console.ForegroundColor = color;
                }
                else
                {
                    Console.WriteLine("Producer processing complete.");
                }

                return(returnCode);
            }
        }
 public static Task Publish <T>(this IQueuePublisher <T> queuePublisher, T data)
 {
     return(queuePublisher.Publish(data, null));
 }