Example #1
0
        private static void Enqueue(AzureMessage broker, bool retry = false)
        {
            try
            {
                BrokeredMessage message = new BrokeredMessage(broker);
                //Criando um identificador para a mensage
                message.MessageId = Guid.NewGuid().ToString();

                QueueNotification.Send(message);
            }
            catch (MessagingException e)
            {
                if (retry)
                {
                    throw new Exception(e.Message, e);
                }

                if (!e.IsTransient)
                {
                    throw new Exception(e.Message, e);
                }
                else
                {
                    //If transient error/exception, let's back-off for 1 seconds and retry
                    Enqueue(broker, true);
                    Thread.Sleep(1000);
                }
            }
        }
        private static void Enqueue(AzureMessage broker, bool retry = false)
        {
            try
            {
                BrokeredMessage message = new BrokeredMessage(broker);
                //Criando um identificador para a mensage
                message.MessageId = Guid.NewGuid().ToString();

                QueueNotification.Send(message);
            }
            catch (MessagingException e)
            {
                if (retry)
                    throw new Exception(e.Message, e);

                if (!e.IsTransient)
                    throw new Exception(e.Message, e);
                else
                {
                    //If transient error/exception, let's back-off for 1 seconds and retry
                    Enqueue(broker, true);
                    Thread.Sleep(1000);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Cria a instancia do AzureQueueNotification
        /// </summary>
        /// <param name="senderUserId">Usuario que gerou a Notificação</param>
        /// <param name="value">Objeto que gerou a Notificação</param>
        /// <param name="notificationType">Tipo de Notificação </param>
        /// <returns>AzureQueueNotification</returns>
        public static AzureMessage CreateAzureMessage(string senderUserId, string senderUserName, string objectRef, AzureMessageType messageType, Dictionary <string, object> extraData = null)
        {
            AzureMessage notification = new AzureMessage();

            notification.SenderUserId   = senderUserId;
            notification.ObjectRef      = objectRef;
            notification.ExtraData      = extraData;
            notification.CreationDate   = DateTime.Now;
            notification.SenderUserName = senderUserName;
            notification.MessageType    = (int)messageType;

            return(notification);
        }
Example #4
0
        /// <summary>
        /// Cria a instancia do AzureQueueNotification
        /// </summary>
        /// <param name="senderUserId">Usuario que gerou a Notificação</param>
        /// <param name="value">Objeto que gerou a Notificação</param>
        /// <param name="notificationType">Tipo de Notificação </param>
        /// <returns>AzureQueueNotification</returns>
        public static AzureMessage CreateAzureMessage(string senderUserId, string senderUserName, string objectRef, AzureMessageType messageType , Dictionary<string, object> extraData = null)
        {
            AzureMessage notification = new AzureMessage();

            notification.SenderUserId = senderUserId;
            notification.ObjectRef = objectRef;
            notification.ExtraData = extraData;
            notification.CreationDate = DateTime.Now;
            notification.SenderUserName = senderUserName;
            notification.MessageType = (int)messageType;

            return notification;

        }
        private void ProcessTransaction(AzureMessage azureMessage)
        {

            var jsonPayment = (string)azureMessage.ExtraData["payment"];
            var jsonTicket = (string)azureMessage.ExtraData["ticket"];

            CustomerPayment payment = JsonConvert.DeserializeObject<CustomerPayment>(jsonPayment);
            CustomerTicket ticket = JsonConvert.DeserializeObject<CustomerTicket>(jsonTicket);
            Customer customer = this.customerService.GetCustomerById(new Guid(azureMessage.SenderUserId));

            ticket.IdEvent = ticket.Event.Id;
            ticket.IdCustomer = customer.Id;

            Guid instantBuy;

            if (MundiPaggProxy.ProcessPayment(ticket, payment, out instantBuy))
            {
                var ticketUpdate = this.customerTicketService.GetTicketById(ticket.Id);
                ticketUpdate.Status = ticket.Status;

                this.customerTicketService.Update(ticketUpdate);
                this.SendEmail(ticket, customer);

                if (payment.KeepSave)
                {
                    if (!customer.PaymentTokenizer.Any(x => x.Token == instantBuy.ToString()))
                    {
                        var customerToken = new CustomerPaymentTokenizer()
                        {
                            Id = Guid.NewGuid(),
                            IdCustomer = customer.Id,
                            SecurityCode = payment.SecurityCode,
                            Token = instantBuy.ToString()
                        };

                        customer.PaymentTokenizer.Add(customerToken);
                        this.customerService.Update(customer);
                    }
                }
            }

        }
        private void ProcessQuickTransaction(AzureMessage azureMessage)
        {
            var jsonTicket = (string)azureMessage.ExtraData["ticket"];
            var jsonPayment = (string)azureMessage.ExtraData["payment"];

            CustomerTicket ticket = JsonConvert.DeserializeObject<CustomerTicket>(jsonTicket);
            CustomerPayment payment = JsonConvert.DeserializeObject<CustomerPayment>(jsonPayment);
            Customer customer = this.customerService.GetCustomerById(new Guid(azureMessage.SenderUserId));

            ticket.IdEvent = ticket.Event.Id;
            ticket.IdCustomer = customer.Id;

            if (MundiPaggProxy.ProcessPayment(ticket, payment.InstantBuy, payment.SecurityCode))
            {
                var ticketUpdate = this.customerTicketService.GetTicketById(ticket.Id);
                ticketUpdate.Status = ticket.Status;

                this.customerTicketService.Update(ticketUpdate);
                this.SendEmail(ticket, customer);
            }

        }
Example #7
0
        private static AzureMessage Dequeue(bool retry = false)
        {
            try
            {
                BrokeredMessage message = null;

                message = QueueNotification.Receive(TIMEOUT);

                if (message == null)
                {
                    return(null);
                }

                AzureMessage notification = message.GetBody <AzureMessage>();
                message.Complete();

                return(notification);
            }
            catch (MessagingException e)
            {
                if (retry)
                {
                    throw new Exception(e.Message, e);
                }

                if (!e.IsTransient)
                {
                    throw new Exception(e.Message, e);
                }
                else
                {
                    //If transient error/exception, let's back-off for 1 seconds and retry
                    Thread.Sleep(1000);
                    return(Dequeue(true));
                }
            }
        }
 private static void Enqueue(AzureMessage broker)
 {
     Enqueue(broker, retry: false);
 }
Example #9
0
 private static void Enqueue(AzureMessage broker)
 {
     Enqueue(broker, retry: false);
 }
Example #10
0
        /// <summary>
        /// Cria a instancia do AzureQueueNotification
        /// </summary>
        /// <param name="senderUserId">Usuario que gerou a Notificação</param>
        /// <param name="senderUsername">Nome do Usuario que gerou a Notificação</param>
        /// <param name="objectRef">Referencia do objeto que gerou a notificação</param>
        /// <param name="notificationTypeEnum">Tipo de Notificação </param>
        /// <param name="extraData">Dados Extras da notificações</param>
        /// <returns>AzureQueueNotification</returns>
        public static void Enqueue(string senderUserId, string senderUsername, string objectRef, AzureMessageType messageTypeEnum, Dictionary <string, object> extraData = null)
        {
            AzureMessage notification = Infra.Queue.AzureMessage.CreateAzureMessage(senderUserId, senderUsername, objectRef, messageTypeEnum, extraData);

            Enqueue(notification);
        }