Beispiel #1
0
        public async Task <PublishToTagResult> PublishToTagAsync()
        {
            if (!tagOperator.IsTaggingAvailable())
            {
                return(new PublishToTagFailedResult(new TaggingNotAvailableException()));
            }

            string    tag      = model.Tag;
            DynamoTag tagEntry = await tagOperator.tagTableOperator.GetTagAsync(tag);

            if (tagEntry == null)
            {
                return(new PublishToTagFailedResult(new TagNotFoundException(tag)));
            }
            switch (tagEntry.TaggingTypeEnum)
            {
            case PNTagType.Iterative:
                List <DynamoIterativeTag> tags = await tagOperator.iterativeTagTableOperator.GetAllSubscribersForTagAsync(tagEntry.Tag);

                IterativeTagResponseTuple resultTuples = await PublishToIterativeTagAsync(tags);
                await RemoveUnsuccessfulEndpoints(resultTuples);

                var returnTuples = resultTuples.Select(t => new Tuple <PublishToSNSResult, PushNotificationSubscriber>(t.Item1, PushNotificationSubscriber.From(t.Item2.Subscriber)));
                return(new PublishToIterativeTagResult(tag, returnTuples));

            case PNTagType.SNSTopic:
                PublishToSNSResult result = await PublishToSnsTopicTag(tagEntry.SnsTopicArn);

                return(new PublishToSNSTopicTagResult(tag, result));

            default:
                throw new TagNotFoundException(tag);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validate and make the request.
        /// </summary>
        public new async Task <PublishToSNSResult> SendAsync()
        {
            try
            {
                Validate();
                PublishToUserOperator publishService = new PublishToUserOperator(new PublishToUserOperatorModel(this), base.Provider);
                PublishToSNSResult    result         = await publishService.PublishToSubscriberAsync(NotificationToken);

                return(result);
            }
            catch (AWSMobilePushNotificationServiceException ex)
            {
                return(new PublishToSNSFailedResult(ex.Message));
            }
            catch (Exception ex)
            {
                if (Provider.CatchAllExceptions)
                {
                    return(new PublishToSNSFailedResult(ex.Message));
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #3
0
        private async Task RemoveUnsuccessfulEndpoints(IterativeTagResponseTuple resultTuples)
        {
            // Parallel tasks are not implemented because of AWS-SDK SNS bug in parellel execution cause high memory usage
            // List<Task> tasks = new List<Task>();

            foreach (var responseTagTuple in resultTuples)
            {
                PublishToSNSResult result = responseTagTuple.Item1;
                DynamoIterativeTag tag    = responseTagTuple.Item2;

                if (result.ErrorAlias == ErrorReason.SNSEndpointDisabled ||
                    result.ErrorAlias == ErrorReason.SNSEndpointNotFound)
                {
                    await unRegisterService.UnRegisterSubscriberAsync(tag.Subscriber.UserId, tag.Subscriber.Token);
                }
            }
        }