public void Publish(AppointmentConfirmedEvent eventToPublish)
        {
            Guard.Against.Null(eventToPublish, nameof(eventToPublish));

            var channel = _objectPool.Get();

            object message = (object)eventToPublish;

            try
            {
                string exchangeName = MessagingConstants.Exchanges.FRONTDESK_VETCLINICPUBLIC_EXCHANGE;
                channel.ExchangeDeclare(exchangeName, "direct", true, false, null);

                var sendBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(message));

                var properties = channel.CreateBasicProperties();
                properties.Persistent = true;

                channel.BasicPublish(
                    exchange: exchangeName,
                    routingKey: "appointment-confirmation",
                    basicProperties: properties,
                    body: sendBytes);
            }
            finally
            {
                _objectPool.Return(channel);
            }
        }
            public void CheckMessages(object sender, System.Timers.ElapsedEventArgs e)
            {
                Debug.Print("Checking scheduler queue for messages");
                try
                {
                    using (var sqlConnection = new SqlConnection(ConnectionString))
                    {
                        sqlConnection.Open();
                        using (var sqlTransaction = sqlConnection.BeginTransaction())
                        {
                            var rawMessage = ServiceBrokerWrapper.WaitAndReceive(sqlTransaction, SchedulerQueue, 10 * 1000);

                            if (rawMessage != null && rawMessage.Body.Length > 0)
                            {
                                Debug.Print("Raw Message: " + ServiceBrokerWrapper.GetString(rawMessage.Body));

                                AppointmentConfirmedEvent appointmentConfirmedEvent = JsonConvert.DeserializeObject <AppointmentConfirmedEvent>(ServiceBrokerWrapper.GetString(rawMessage.Body));

                                DomainEvents.Raise(appointmentConfirmedEvent);
                            }
                            sqlTransaction.Commit();
                        }
                        sqlConnection.Close();
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("Error checking scheduler queue: " + ex.ToString());
                }
                //Debug.Print("Done checking scheduler queue for messages");
            }
        public ActionResult Confirm(Guid id)
        {
            var appEvent = new AppointmentConfirmedEvent(id);

            _messagePublisher.Publish(appEvent);
            return(View());
        }
        public ActionResult Confirm(Guid id)
        {
            var appEvent = new AppointmentConfirmedEvent(id);

            _messagePublisher.Publish(appEvent);
            // 4A071770-35A3-42D7-A1AE-4244870BA158
            return(View());
        }
Example #5
0
        public void Confirm(DateTime dateConfirmed)
        {
            if (DateTimeConfirmed.HasValue)
            {
                return;                             // no need to reconfirm
            }
            DateTimeConfirmed = dateConfirmed;

            var appointmentConfirmedEvent = new AppointmentConfirmedEvent(this);

            DomainEvents.Raise(appointmentConfirmedEvent);
        }
Example #6
0
        public void Confirm(DateTimeOffset dateConfirmed)
        {
            if (DateTimeConfirmed.HasValue)
            {
                return;                       // no need to reconfirm
            }
            DateTimeConfirmed = dateConfirmed;

            var appointmentConfirmedEvent = new AppointmentConfirmedEvent(this);

            Events.Add(appointmentConfirmedEvent);
        }
        public void CallEmailConfirmationServiceForAppointmentConfirmedEvent()
        {
            // Arrange
            var e = new AppointmentConfirmedEvent();

            e.AppointmentId = Guid.NewGuid();
            // TODO: add mock for EmailConfirmationService


            // Act
            DomainEvents.Raise(e);

            // Assert
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var cont = Container.For <BasicScanning>();

            var allServices = cont.GetAllInstances <IService>();

            foreach (var i in allServices)
            {
                i.CallMe();
            }

            AppointmentConfirmedEvent e = new AppointmentConfirmedEvent();

            DomainEvents.Raise(e);
        }
            public void SendConfirmationMessageToScheduler(AppointmentConfirmedEvent confirmationEvent)
            {
                using (var sqlConnection = new SqlConnection(connectionString))
                {
                    sqlConnection.Open();
                    using (var sqlTransaction = sqlConnection.BeginTransaction())
                    {
                        var conversationHandle = ServiceBrokerWrapper.BeginConversation(sqlTransaction, NotifierService, SchedulerService, Contract);

                        string json = JsonConvert.SerializeObject(confirmationEvent, Formatting.None);

                        ServiceBrokerWrapper.Send(sqlTransaction, conversationHandle, MessageType, ServiceBrokerWrapper.GetBytes(json));

                        ServiceBrokerWrapper.EndConversation(sqlTransaction, conversationHandle);

                        sqlTransaction.Commit();
                    }
                    sqlConnection.Close();
                }
            }
        public IEnumerable <string> Get()
        {
            var appointmentConfirmedEvent = new AppointmentConfirmedEvent();

            DomainEvents.Raise(appointmentConfirmedEvent);

            var appointmentScheduledEvent = new AppointmentScheduledEvent(null);

            DomainEvents.Raise(appointmentScheduledEvent);

            Debug.WriteLine(DomainEvents.Container.WhatDidIScan());
            Debug.WriteLine(DomainEvents.Container.WhatDoIHave());

            var handlers  = DomainEvents.Container.GetAllInstances <IHandle <AppointmentConfirmedEvent> >();
            var handlers1 = DomainEvents.Container.GetAllInstances <EmailConfirmationHandler>();
            var handlers2 = DomainEvents.Container.GetAllInstances(typeof(IHandle <AppointmentConfirmedEvent>));
            var handlers3 = DomainEvents.Container.GetAllInstances(typeof(EmailConfirmationHandler));

            //var handlers4 = DomainEvents.Container.GetAllInstances(typeof(IHandle<>));


            return(new string[] { "value1", "value2" });
        }
        public void SendConfirmationMessageToScheduler(AppointmentConfirmedEvent confirmationEvent)
        {
            var messageBroker = new MessageBroker();

            messageBroker.SendConfirmationMessageToScheduler(confirmationEvent);
        }