Ejemplo n.º 1
0
            public void CheckMessages(object sender, System.Timers.ElapsedEventArgs e)
            {
                Debug.Print("PW: Checking notifier queue for messages");
                // Make sure this matches MessagingConfig in FrontDeskSolution
                var connectionString = ConfigurationManager.ConnectionStrings["ServiceBroker"].ConnectionString;

                try
                {
                    using (var sqlConnection = new SqlConnection(connectionString))
                    {
                        sqlConnection.Open();
                        using (var sqlTransaction = sqlConnection.BeginTransaction())
                        {
                            var rawMessage = ServiceBrokerWrapper.WaitAndReceive(sqlTransaction, NotifierQueue, 10 * 1000);

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

                                var emailSender = StructureMap.ObjectFactory.GetInstance <ISendConfirmationEmails>();
                                AppointmentScheduledEvent appointmentScheduledEvent = JsonConvert.DeserializeObject <AppointmentScheduledEvent>(ServiceBrokerWrapper.GetString(rawMessage.Body));

                                emailSender.SendConfirmationEmail(appointmentScheduledEvent.AppointmentScheduled);
                            }
                            sqlTransaction.Commit();
                        }
                        sqlConnection.Close();
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("PW: Error checking notifier queue: " + ex.ToString());
                }
                //Debug.Print("Done checking queue for messages");
            }
Ejemplo n.º 2
0
            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();
                }
            }