public static async Task <SendReceipt> AddMessageAndCreateIfNotExistsAsync(this QueueClient queue,
                                                                                   string message, CancellationToken cancellationToken)
        {
            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            bool isQueueNotFoundException = false;

            SendReceipt receipt = null;

            try
            {
                receipt = await queue.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);

                return(receipt);
            }
            catch (RequestFailedException exception)
            {
                if (!exception.IsNotFoundQueueNotFound())
                {
                    throw;
                }

                isQueueNotFoundException = true;
            }

            Debug.Assert(isQueueNotFoundException);
            await queue.CreateAsync(cancellationToken : cancellationToken).ConfigureAwait(false);

            receipt = await queue.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);

            return(receipt);
        }
Beispiel #2
0
        public ResponseWithHeaders <IReadOnlyList <SendReceipt>, MessagesEnqueueHeaders> Enqueue(QueueMessage queueMessage, int?visibilitytimeout = null, int?messageTimeToLive = null, int?timeout = null, CancellationToken cancellationToken = default)
        {
            if (queueMessage == null)
            {
                throw new ArgumentNullException(nameof(queueMessage));
            }

            using var message = CreateEnqueueRequest(queueMessage, visibilitytimeout, messageTimeToLive, timeout);
            _pipeline.Send(message, cancellationToken);
            var headers = new MessagesEnqueueHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 201:
            {
                IReadOnlyList <SendReceipt> value = default;
                var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
                if (document.Element("QueueMessagesList") is XElement queueMessagesListElement)
                {
                    var array = new List <SendReceipt>();
                    foreach (var e in queueMessagesListElement.Elements("QueueMessage"))
                    {
                        array.Add(SendReceipt.DeserializeSendReceipt(e));
                    }
                    value = array;
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw ClientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
Beispiel #3
0
 public void Handle(SendReceipt command)
 {
     _notificationService.SendTripReceiptEmail(command.OrderId, command.IBSOrderId, command.VehicleNumber, command.DriverInfos, command.Fare, command.Toll, command.Tip,
                                               command.Tax, command.Extra, command.Surcharge, command.BookingFees, command.TotalFare, command.PaymentInfo, command.PickupAddress, command.DropOffAddress,
                                               command.PickupDate, command.UtcDropOffDate, command.EmailAddress, command.ClientLanguageCode, command.AmountSavedByPromotion, command.PromoCode,
                                               command.CmtRideLinqFields, command.BypassNotificationSettings);
 }
        public async Task <Response <string> > Add(string queueName, string message, TimeSpan?visibilityTimeout = null, TimeSpan?timeToLive = null)
        {
            QueueClient queueClient = await QueueClient(queueName);

            SendReceipt sendReceipt = await queueClient.SendMessageAsync(message, visibilityTimeout, timeToLive);

            return(new Response <string>(data: sendReceipt.MessageId));
        }
Beispiel #5
0
        static async Task SendMessageAsync(string connString, string queueName, string message)
        {
            QueueServiceClient serviceClient = new QueueServiceClient(connString);
            QueueClient        queue         = serviceClient.GetQueueClient(queueName);
            SendReceipt        receipt       = await queue.SendMessageAsync(message);

            Console.WriteLine($"Сообщение успешно отправлено в очередь {queueName}");
        }
        public async Task SendQueueMessageAyncTestAsync()
        {
            Configuration config = await TestHelper.GetConfigurationAsync();

            QueueApi queueApi = new QueueApi(config);

            SendReceipt sr = await queueApi.SendQueueMessageAync(ContestFactory.CreateChallengeRequestJson());

            Assert.IsNotNull(sr);
        }
Beispiel #7
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Azure Queue Storage client library v12 - .NET quickstart sample\n");
// another comment,  testing github
// Changed this andded a line.
//Retrieve the connection string for use with the application. The storage
// connection string is stored in an environment variable called
// AZURE_STORAGE_CONNECTION_STRING on the machine running the application.
// If the environment variable is created after the application is launched
// in a console or with Visual Studio, the shell or application needs to be
// closed and reloaded to take the environment variable into account.
            string connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");

//get number of people and create queue for each
            Console.WriteLine("How many people in this shift?");
            int shifters = System.Console.ReadLine();

            Console.WriteLine($"Ok creating setup for {shifters} staff.");

// Create a unique name for the queue

            string queueName = "dispatch-rd-quickstartqueues-" + Guid.NewGuid().ToString();
            string queueName = "dispatch-rd-quickstartqueues-" + Guid.NewGuid().ToString();
            string queueName = "dispatch-rd-quickstartqueues-" + Guid.NewGuid().ToString();

            Console.WriteLine($"Creating queue: {queueName}");

// Instantiate a QueueClient which will be
// used to create and manipulate the queue
            QueueClient queueClient = new QueueClient(connectionString, queueName);

// Create the queue
            await queueClient.CreateAsync();

            Console.WriteLine("\nAdding messages to the queue...");

// Send several messages to the queue
            await queueClient.SendMessageAsync("First message");

            await queueClient.SendMessageAsync("Second message");

// Save the receipt so we can update this message later
            SendReceipt receipt = await queueClient.SendMessageAsync("Third message");

            Console.WriteLine("\nPeek at the messages in the queue...");

// Peek at messages in the queue
            PeekedMessage[] peekedMessages = await queueClient.PeekMessagesAsync(maxMessages : 10);

            foreach (PeekedMessage peekedMessage in peekedMessages)
            {
                // Display the message
                Console.WriteLine($"Message: {peekedMessage.MessageText}");
            }
        }
        public static SendReceipt GetSendReceiptCommand(OrderDetail order, AccountDetail account, int?orderId, string vehicleNumber, DriverInfos driverInfos,
                                                        double?fare, double?toll, double?extra, double?surcharge, double?bookingFees, double?tip, double?tax, OrderPaymentDetail orderPayment = null, double?amountSavedByPromotion = null,
                                                        PromotionUsageDetail promotionUsed = null, CreditCardDetails creditCard = null, SendReceipt.CmtRideLinqReceiptFields cmtRideLinqFields = null)
        {
            var command = new SendReceipt
            {
                Id                 = Guid.NewGuid(),
                OrderId            = order.Id,
                EmailAddress       = account.Email,
                IBSOrderId         = orderId ?? 0,
                PickupDate         = order.PickupDate,
                UtcDropOffDate     = order.DropOffDate,
                VehicleNumber      = vehicleNumber,
                DriverInfos        = driverInfos,
                Fare               = fare.GetValueOrDefault(),
                Extra              = extra.GetValueOrDefault(),
                Tip                = tip.GetValueOrDefault(),
                Tax                = tax.GetValueOrDefault(),
                Toll               = toll.GetValueOrDefault(),
                Surcharge          = surcharge.GetValueOrDefault(),
                BookingFees        = bookingFees.GetValueOrDefault(),
                PickupAddress      = order.PickupAddress,
                DropOffAddress     = order.DropOffAddress,
                ClientLanguageCode = order.ClientLanguageCode,
                CmtRideLinqFields  = cmtRideLinqFields
            };

            if (promotionUsed != null)
            {
                command.AmountSavedByPromotion = amountSavedByPromotion.GetValueOrDefault();
                command.PromoCode          = promotionUsed.Code;
                command.PromoDiscountType  = promotionUsed.DiscountType;
                command.PromoDiscountValue = promotionUsed.DiscountValue;
            }

            if (orderPayment != null)
            {
                command.PaymentInfo = new SendReceipt.Payment(
                    orderPayment.Amount,
                    orderPayment.TransactionId,
                    orderPayment.AuthorizationCode,
                    orderPayment.Type == PaymentType.CreditCard ? "Credit Card" : orderPayment.Type.ToString());

                if ((orderPayment.CardToken.HasValue()) && (creditCard != null))
                {
                    command.PaymentInfo.Last4Digits     = creditCard.Last4Digits;
                    command.PaymentInfo.Company         = creditCard.CreditCardCompany;
                    command.PaymentInfo.NameOnCard      = creditCard.NameOnCard;
                    command.PaymentInfo.ExpirationMonth = creditCard.ExpirationMonth;
                    command.PaymentInfo.ExpirationYear  = creditCard.ExpirationYear;
                }
            }
            return(command);
        }
Beispiel #9
0
        public static async Task SendMessage(QueueClient queueClient)
        {
            Console.WriteLine("\nAdding messages to the queue...");

            // Send several messages to the queue
            await queueClient.SendMessageAsync("First message");

            await queueClient.SendMessageAsync("Second message");

            // Save the receipt so we can update this message later
            SendReceipt receipt = await queueClient.SendMessageAsync("Third message");
        }
        /// <summary>
        /// <see cref="AuditDataProvider.InsertEventAsync(AuditEvent)"/>
        /// </summary>
        /// <exception cref="ArgumentNullException">Parameter is null or empty.</exception>
        public override async Task <object> InsertEventAsync(AuditEvent auditEvent)
        {
            if (auditEvent == null)
            {
                throw new ArgumentNullException(nameof(auditEvent));
            }

            // Create a message and add it to the queue.
#if NET
            string message = JsonSerializer.Serialize(auditEvent, Configuration.JsonSettings);
#else
            string message = JsonConvert.SerializeObject(auditEvent, Configuration.JsonSettings);
#endif
            SendReceipt receipt = await _queueClient.SendMessageAsync(message.ToBase64());

            return(receipt);
        }
Beispiel #11
0
        static async Task Main(string[] args)
        {
            //Storage Access Connection String
            string connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");

            //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            //CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            //CloudQueue queue = queueClient.GetQueueReference("mystoragequeue");


            // Create a unique name for the queue
            string queueName = "quickstartqueues-" + Guid.NewGuid().ToString();

            Console.WriteLine($"Creating queue: {queueName}");

            // Instantiate a QueueClient which will be
            // used to create and manipulate the queue
            QueueClient queueClient = new QueueClient(connectionString, queueName);

            // Create the queue
            await queueClient.CreateAsync();

            Console.WriteLine("\nAdding messages to the queue...");

            // Send several messages to the queue
            await queueClient.SendMessageAsync("First message");

            await queueClient.SendMessageAsync("Second message");

            // Save the receipt so we can update this message later
            SendReceipt receipt = await queueClient.SendMessageAsync("Third message");

            Console.WriteLine("\nPeek at the messages in the queue...");

            // Peek at messages in the queue
            PeekedMessage[] peekedMessages = await queueClient.PeekMessagesAsync(maxMessages : 10);

            foreach (PeekedMessage peekedMessage in peekedMessages)
            {
                // Display the message
                Console.WriteLine($"Message: {peekedMessage.MessageText}");
            }
            Console.WriteLine("\nUpdating the third message in the queue...");

            // Update a message using the saved receipt from sending the message
            await queueClient.UpdateMessageAsync(receipt.MessageId, receipt.PopReceipt, "Third message has been updated");

            Console.WriteLine("\nReceiving messages from the queue...");

            // Get messages from the queue
            QueueMessage[] messages = await queueClient.ReceiveMessagesAsync(maxMessages : 10);

            Console.WriteLine("\nPress Enter key to 'process' messages and delete them from the queue...");
            Console.ReadLine();

            // Process and delete messages from the queue
            foreach (QueueMessage message in messages)
            {
                // "Process" the message
                Console.WriteLine($"Message: {message.MessageText}");

                // Let the service know we're finished with
                // the message and it can be safely deleted.
                await queueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt);
            }
            Console.WriteLine("\nPress Enter key to delete the queue...");
            Console.ReadLine();

            // Clean up
            Console.WriteLine($"Deleting queue: {queueClient.Name}");
            await queueClient.DeleteAsync();

            Console.WriteLine("Done");
        }
 public object Post(SendReceipt request)
 {
     return(Post(new SendReceiptAdmin {
         OrderId = request.OrderId
     }));
 }
Beispiel #13
0
 public QueuedCloudMessage(BinaryData message, SendReceipt reciept) : base(message)
 {
 }
Beispiel #14
0
 public QueuedCloudMessage(string message, SendReceipt reciept) : base(new BinaryData(message))
 {
 }