예제 #1
0
파일: FcmBroker.cs 프로젝트: sunche/mccm
        private static async Task <NotificationResult> GetErrorResult(HttpResponseMessage response)
        {
            var content = await response.Content.ReadAsStringAsync();

            FcmResponse           fcmResponse = TryGetFcmResponse(content);
            NotificationErrorCode errorCode   = GetErrorCodeFromResponse(fcmResponse);

            return(NotificationResult.WithError(errorCode, $"{response.StatusCode}:{fcmResponse?.Error.Message}; Details: {content}"));
        }
예제 #2
0
파일: ApnsBroker.cs 프로젝트: sunche/mccm
        private async Task <NotificationResult> GetErrorResult(HttpResponseMessage response)
        {
            var content = await response.Content.ReadAsStringAsync();

            ApnsError apnsError = TryGetApnsError(content);

            NotificationErrorCode errorCode = GetErrorCodeFromResponse(response, apnsError);

            return(NotificationResult.WithError(errorCode, $"{response.StatusCode}:{content}"));
        }
예제 #3
0
 /// <summary>
 /// Occurs when a notification failed to send.
 /// </summary>
 /// <param name="notification">The notification that failed to send.</param>
 /// <param name="errorCode">The error code for the notification.</param>
 /// <param name="accountId">The id of the account the notification was intended for.</param>
 /// <param name="description">A description of the failure.</param>
 /// <param name="destination">The id of the destination for the notification.</param>
 /// <param name="endpointName">The endpoint the notification was intended for.</param>
 protected void OnFailed(
     Notification notification,
     NotificationErrorCode errorCode,
     string accountId,
     string description,
     string destination  = null,
     string endpointName = null)
 {
     this.eventPublisher.Publish(
         new NotificationSendFailure(
             notification,
             errorCode,
             accountId,
             description,
             destination,
             endpointName));
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the NotificationSendFailure class.
        /// </summary>
        /// <param name="notification">The notification that failed to send.</param>
        /// <param name="errorCode">The error code for the notification.</param>
        /// <param name="accountId">The id of the account the notification was intended for.</param>
        /// <param name="description">A description of the failure.</param>
        /// <param name="destination">The id of the destination for the notification.</param>
        /// <param name="endpointName">The endpoint the notification was intended for.</param>
        internal NotificationSendFailure(
            Notification notification,
            NotificationErrorCode errorCode,
            string accountId,
            string description,
            string destination  = null,
            string endpointName = null)
            : base(notification)
        {
            Throw.IfArgumentNullOrWhitespace(description, nameof(description));

            this.AccountId    = accountId;
            this.ErrorCode    = errorCode;
            this.Description  = description;
            this.Destination  = destination;
            this.EndpointName = endpointName;
        }
예제 #5
0
 /// <summary>
 /// Get response with error.
 /// </summary>
 /// <param name="errorCode"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static NotificationResult WithError(NotificationErrorCode errorCode, string message)
 {
     return(new NotificationResult {
         Success = false, Error = new NotificationError(errorCode, message)
     });
 }
예제 #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="code">Error code.</param>
 /// <param name="message">Message.</param>
 public NotificationError(NotificationErrorCode code, string message)
 {
     Code    = code;
     Message = message;
 }
예제 #7
0
 public NotificationException(NotificationErrorCode errorCode, string message, Exception innerException) : base(message, innerException)
 {
     ErrorCode = errorCode;
 }
예제 #8
0
 public NotificationException(NotificationErrorCode errorCode, string message) : base(message)
 {
     ErrorCode = errorCode;
 }
예제 #9
0
        private void AssertSentFailed(NotificationTest test, NotificationAccount <Guid> account, PushNotification expectedNotification, NotificationErrorCode expectedErrorCode)
        {
            NotificationSendFailure notificationSendFailure = test.RaisedEvents.OfType <NotificationSendFailure>().SingleOrDefault();

            notificationSendFailure.Should().NotBeNull();
            notificationSendFailure.AccountId.ShouldBeEquivalentTo(account.AccountId.ToString());
            notificationSendFailure.Description.Should().NotBeNull();
            notificationSendFailure.ErrorCode.ShouldBeEquivalentTo(expectedErrorCode);

            if (expectedErrorCode == NotificationErrorCode.RouteFailure)
            {
                notificationSendFailure.EndpointName.ShouldBeEquivalentTo(Constants.PushNotificationEndPoint);
            }
            else
            {
                notificationSendFailure.EndpointName.Should().BeNull();
            }

            if (account.MobileDevices != null && account.MobileDevices.Any())
            {
                notificationSendFailure.Destination.ShouldBeEquivalentTo(account.MobileDevices.Single().DeviceId);
            }
            else
            {
                notificationSendFailure.Destination.Should().BeNull();
            }

            this.AssertNotification((PushNotification)notificationSendFailure.Notification, expectedNotification);
        }