コード例 #1
0
        public async Task <IActionResult> Confirm(string id, [FromQuery] string?channel = null, [FromQuery] string?deviceIdentifier = null)
        {
            var token = TrackingToken.Parse(id, channel, deviceIdentifier);

            await userNotificationService.TrackConfirmedAsync(token);

            var notification = await userNotificationStore.FindAsync(token.Id, HttpContext.RequestAborted);

            if (notification == null)
            {
                return(View());
            }

            var app = await appStore.GetCachedAsync(notification.AppId, HttpContext.RequestAborted);

            if (app?.ConfirmUrl != null && Uri.IsWellFormedUriString(app.ConfirmUrl, UriKind.Absolute))
            {
                var url = app.ConfirmUrl !;

                if (url.Contains('?', StringComparison.OrdinalIgnoreCase))
                {
                    url += $"&id={id:notEmpty}";
                }
                else
                {
                    url += $"?id={id:notEmpty}";
                }

                return(Redirect(url));
            }

            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> ConfirmPost(string id, [FromQuery] string?channel = null, [FromQuery] string?deviceIdentifier = null)
        {
            var token = TrackingToken.Parse(id, channel, deviceIdentifier);

            await userNotificationService.TrackConfirmedAsync(token);

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> Delivered(string id, [FromQuery] string?channel = null, [FromQuery] string?deviceIdentifier = null)
        {
            var tokens = Enumerable.Repeat(TrackingToken.Parse(id, channel, deviceIdentifier), 1);

            await userNotificationService.TrackDeliveredAsync(tokens);

            return(TrackingPixel());
        }
コード例 #4
0
        public void Should_not_override_channel_device_identifier()
        {
            var sourceToken  = new TrackingToken(Guid.NewGuid(), "push", "123");
            var sourceString = sourceToken.ToParsableString();

            var result = TrackingToken.Parse(sourceString, "web", "456");

            Assert.Equal(result, sourceToken);
        }
コード例 #5
0
        public void Should_parse_and_override_channel_and_device_identifier_if_not_set()
        {
            var sourceToken  = new TrackingToken(Guid.NewGuid());
            var sourceString = sourceToken.ToParsableString();

            var result = TrackingToken.Parse(sourceString, "push", "123");

            Assert.Equal(result, new TrackingToken(sourceToken.Id, "push", "123"));
        }
コード例 #6
0
        public void Should_parse_from_guid()
        {
            var sourceToken  = Guid.NewGuid();
            var sourceString = sourceToken.ToString();

            var result = TrackingToken.Parse(sourceString);

            Assert.Equal(result, new TrackingToken(sourceToken));
        }
コード例 #7
0
        public void Should_parse_from_formatted_token_with_complex_device_identifier()
        {
            var sourceToken  = new TrackingToken(Guid.NewGuid(), "web", "a|very|complex|token");
            var sourceString = sourceToken.ToParsableString();

            var result = TrackingToken.Parse(sourceString);

            Assert.Equal(result, sourceToken);
        }
コード例 #8
0
        public void Should_parse_from_formatted_token_without_channel()
        {
            var sourceToken  = new TrackingToken(Guid.NewGuid());
            var sourceString = sourceToken.ToParsableString();

            var result = TrackingToken.Parse(sourceString);

            Assert.Equal(result, sourceToken);
        }
コード例 #9
0
        public async Task <IActionResult> ConfirmMe([FromBody] TrackNotificationDto request)
        {
            if (request.Confirmed != null)
            {
                var token = TrackingToken.Parse(request.Confirmed, request.Channel, request.DeviceIdentifier);

                await userNotificationService.TrackConfirmedAsync(token);
            }

            if (request.Seen?.Length > 0)
            {
                var tokens = request.Seen.Select(x => TrackingToken.Parse(x, request.Channel, request.DeviceIdentifier));

                await userNotificationService.TrackSeenAsync(tokens);
            }

            return(NoContent());
        }
コード例 #10
0
        public async Task <IActionResult> GetMyPolling([FromBody] PollRequest request)
        {
            var requestToken = request.Token ?? default;

            if (requestToken != default)
            {
                requestToken = requestToken.Minus(Duration.FromSeconds(10));
            }

#pragma warning disable MA0040 // Flow the cancellation token
            if (request.Delivered?.Length > 0)
            {
                var tokens = request.Delivered.Select(x => TrackingToken.Parse(x));

                await userNotificationStore.TrackSeenAsync(tokens);
            }

            if (request.Seen?.Length > 0)
            {
                var tokens = request.Seen.Select(x => TrackingToken.Parse(x));

                await userNotificationStore.TrackSeenAsync(tokens);
            }

            foreach (var id in request.Confirmed.OrEmpty())
            {
                var token = TrackingToken.Parse(id);

                await userNotificationStore.TrackConfirmedAsync(token);
            }
#pragma warning restore MA0040 // Flow the cancellation token

            foreach (var id in request.Deleted.OrEmpty())
            {
                await userNotificationStore.DeleteAsync(id, HttpContext.RequestAborted);
            }

            var notifications = await userNotificationStore.QueryAsync(App.Id, UserId, DefaultQuery with {
                After = requestToken
            }, HttpContext.RequestAborted);
コード例 #11
0
        public void Should_not_throw_if_null_or_empty(string value)
        {
            var result = TrackingToken.Parse(value);

            Assert.False(result.IsValid);
        }