public void CheckAvailabilityOfQueue(QueueName queue)
        {
            var userName = WindowsIdentity.GetCurrent().Name;

            if (!MessageQueue.Exists(queue.GetQueueLocalName()))
            {
                MessageQueue.Create(queue.GetQueueLocalName(), true); // transactional
                MsmqPermissionManager.SetPermissionsForQueue(queue.GetQueueLocalName(), userName, _configuration.Name);
            }
            else
            {
                MsmqPermissionManager.SetPermissionsForQueue(queue.GetQueueLocalName(), userName, _configuration.Name);
            }
        }
        public void CheckAvailabilityOfQueue(QueueName queue)
        {
            var userName = WindowsIdentity.GetCurrent().Name;

            if (!MessageQueue.Exists(queue.GetQueueLocalName()))
            {
                MessageQueue.Create(queue.GetQueueLocalName(), true); // transactional
                MsmqPermissionManager.SetPermissionsForQueue(queue.GetQueueLocalName(), userName, _configuration.Name);
            }
            else
            {
                MsmqPermissionManager.SetPermissionsForQueue(queue.GetQueueLocalName(), userName, _configuration.Name);
            }
        }
        private void SendToErrorQueue(Message message, MessageQueueTransaction transaction, Exception exception)
        {
            if (message == null)
            {
                return;
            }

            if (exception != null)
            {
                _logger.ErrorException(String.Format("Message {0} was handled maximum number of times and moved to the error queue. ",
                                                     message.Label), exception);
            }

            // Open the queue.
            using (var queue = new MessageQueue(_errorQueue.GetQueueLocalName()))
            {
                // Set the formatter to JSON.
                queue.Formatter   = new MsmqMessageFormatter();
                message.Formatter = new MsmqMessageFormatter();

                // Send the message.
                queue.Send(message, transaction);
            }
        }