/// <summary>
 /// Sends the given multicast message to all the FCM registration tokens specified in it.
 /// <para>If the <paramref name="dryRun"/> option is set to true, the message will not be
 /// actually sent to the recipients. Instead, the FCM service performs all the necessary
 /// validations, and emulates the send operation. This is a good way to check if a
 /// certain message will be accepted by FCM for delivery.</para>
 /// </summary>
 /// <exception cref="FirebaseMessagingException">If an error occurs while sending the
 /// messages.</exception>
 /// <param name="message">The message to be sent. Must not be null.</param>
 /// <param name="dryRun">A boolean indicating whether to perform a dry run (validation
 /// only) of the send. If set to true, the message will be sent to the FCM backend service,
 /// but it will not be delivered to any actual recipients.</param>
 /// <param name="cancellationToken">A cancellation token to monitor the asynchronous
 /// operation.</param>
 /// <returns>A <see cref="BatchResponse"/> containing details of the batch operation's
 /// outcome.</returns>
 public async Task <BatchResponse> SendMulticastAsync(
     MulticastMessage message, bool dryRun, CancellationToken cancellationToken)
 {
     return(await this.SendAllAsync(
                message.GetMessageList(), dryRun, cancellationToken)
            .ConfigureAwait(false));
 }
Exemplo n.º 2
0
        // Methods
        public void Send(Notification notification, List <Registration> registrationList)
        {
            #region Contracts

            if (notification == null)
            {
                throw new ArgumentException(nameof(notification));
            }
            if (registrationList == null)
            {
                throw new ArgumentException(nameof(registrationList));
            }

            #endregion

            // Message
            var message = new FirebaseAdmin.Messaging.MulticastMessage()
            {
                Notification = new FirebaseAdmin.Messaging.Notification()
                {
                    Title = notification.Title,
                    Body  = notification.Text,
                },
                Tokens = registrationList.Select(registration => registration.Token).ToList()
            };

            // Formatter
            foreach (var firebaseFormatter in _firebaseFormatterList.Where(x => x.NotificationType == notification.Type))
            {
                // Configure
                firebaseFormatter.Configure(message);
            }

            // Send
            var response = _firebaseMessaging.SendMulticastAsync(message).GetAwaiter().GetResult();
            if (response == null)
            {
                throw new InvalidOperationException($"{nameof(response)}=null");
            }
        }
 /// <summary>
 /// Sends the given multicast message to all the FCM registration tokens specified in it.
 /// <para>If the <paramref name="dryRun"/> option is set to true, the message will not be
 /// actually sent to the recipients. Instead, the FCM service performs all the necessary
 /// validations, and emulates the send operation. This is a good way to check if a
 /// certain message will be accepted by FCM for delivery.</para>
 /// </summary>
 /// <exception cref="FirebaseMessagingException">If an error occurs while sending the
 /// messages.</exception>
 /// <param name="message">The message to be sent. Must not be null.</param>
 /// <param name="dryRun">A boolean indicating whether to perform a dry run (validation
 /// only) of the send. If set to true, the message will be sent to the FCM backend service,
 /// but it will not be delivered to any actual recipients.</param>
 /// <returns>A <see cref="BatchResponse"/> containing details of the batch operation's
 /// outcome.</returns>
 public async Task <BatchResponse> SendMulticastAsync(MulticastMessage message, bool dryRun)
 {
     return(await this.SendMulticastAsync(message, dryRun, default)
            .ConfigureAwait(false));
 }
 /// <summary>
 /// Sends the given multicast message to all the FCM registration tokens specified in it.
 /// </summary>
 /// <exception cref="FirebaseMessagingException">If an error occurs while sending the
 /// messages.</exception>
 /// <param name="message">The message to be sent. Must not be null.</param>
 /// <param name="cancellationToken">A cancellation token to monitor the asynchronous
 /// operation.</param>
 /// <returns>A <see cref="BatchResponse"/> containing details of the batch operation's
 /// outcome.</returns>
 public async Task <BatchResponse> SendMulticastAsync(MulticastMessage message, CancellationToken cancellationToken)
 {
     return(await this.SendMulticastAsync(message, false, cancellationToken)
            .ConfigureAwait(false));
 }
 /// <summary>
 /// Sends the given multicast message to all the FCM registration tokens specified in it.
 /// </summary>
 /// <exception cref="FirebaseMessagingException">If an error occurs while sending the
 /// messages.</exception>
 /// <param name="message">The message to be sent. Must not be null.</param>
 /// <returns>A <see cref="BatchResponse"/> containing details of the batch operation's
 /// outcome.</returns>
 public async Task <BatchResponse> SendMulticastAsync(MulticastMessage message)
 {
     return(await this.SendMulticastAsync(message, false)
            .ConfigureAwait(false));
 }