|
| 1 | +// Copyright 2018, Google Inc. All rights reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.Collections.Generic; |
| 17 | + |
| 18 | +namespace FirebaseAdmin.Messaging |
| 19 | +{ |
| 20 | + /// <summary> |
| 21 | + /// Response from an operation that sends FCM messages to multiple recipients. |
| 22 | + /// See <see cref="FirebaseMessaging.SendMulticastAsync(MulticastMessage)"/>. |
| 23 | + /// </summary> |
| 24 | + public sealed class BatchResponse |
| 25 | + { |
| 26 | + /// <summary> |
| 27 | + /// Initializes a new instance of the <see cref="BatchResponse"/> class. |
| 28 | + /// </summary> |
| 29 | + /// <param name="responses">The responses.</param> |
| 30 | + public BatchResponse(IEnumerable<SendResponse> responses) |
| 31 | + { |
| 32 | + if (responses == null) |
| 33 | + { |
| 34 | + throw new ArgumentNullException(nameof(responses)); |
| 35 | + } |
| 36 | + |
| 37 | + this.Responses = responses.Copy(); |
| 38 | + |
| 39 | + var successCount = 0; |
| 40 | + |
| 41 | + foreach (var response in responses) |
| 42 | + { |
| 43 | + if (response.IsSuccessful) |
| 44 | + { |
| 45 | + ++successCount; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + this.SuccessCount = successCount; |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Gets information about all responses for the batch. |
| 54 | + /// </summary> |
| 55 | + public IReadOnlyList<SendResponse> Responses { get; } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Gets a count of how many of the responses in <see cref="Responses"/> were |
| 59 | + /// successful. |
| 60 | + /// </summary> |
| 61 | + public int SuccessCount { get; } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Gets a count of how many of the responses in <see cref="Responses"/> were |
| 65 | + /// unsuccessful. |
| 66 | + /// </summary> |
| 67 | + public int FailureCount => this.Responses.Count - this.SuccessCount; |
| 68 | + } |
| 69 | +} |
0 commit comments