コード例 #1
0
        public async Task <Result> AddSubscription(Subscription subscription)
        {
            var subscriptionDao = new DAO.Subscription(subscription);
            var mediaResult     = await _mediaDataStore.GetMedia(subscription.Media.MediaName);

            if (mediaResult.IsFailure)
            {
                _logger.LogError("Media {media} that should be subscribed to does not exist.", subscription.Media.MediaName);
                return(Result.Failure(
                           $"Media {subscription.Media.MediaName} that should be subscribed to does not exist."));
            }
            var notificationEndpointResult =
                await _notificationDataStore.GetNotificationEndpoint(subscription.NotificationEndpoint.Identifier);

            if (notificationEndpointResult.IsFailure)
            {
                _logger.LogError("NotificationEndpoint {endpoint} that should be used for the subscription to does not exist.", subscription.NotificationEndpoint.Identifier);
                return(Result.Failure(
                           $"NotificationEndpoint {subscription.NotificationEndpoint.Identifier} that should be used for the subscription to does not exist."));
            }

            subscriptionDao.Media = mediaResult.Value;
            subscriptionDao.NotificationEndpoint = notificationEndpointResult.Value;
            return(await _subscriptionDataStore.AddSubscription(subscriptionDao));
        }
コード例 #2
0
ファイル: SubscriptionService.cs プロジェクト: leherv/VR
        public async Task <Result> AddSubscription(BusinessEntities.Subscription subscription, CancellationToken cancellationToken)
        {
            var mediaResult = await _mediaDataStore.GetMedia(subscription.Media.MediaName, cancellationToken);

            if (mediaResult.IsFailure)
            {
                _logger.LogError("Media {media} that should be subscribed to does not exist.", subscription.Media.MediaName);
                return(Result.Failure(
                           $"Media {subscription.Media.MediaName} that should be subscribed to does not exist."));
            }
            var notificationEndpointResult =
                await _notificationDataStore.GetNotificationEndpoint(subscription.NotificationEndpoint.Identifier, cancellationToken);

            if (notificationEndpointResult.IsFailure)
            {
                _logger.LogError("NotificationEndpoint {endpoint} that should be used for the subscription to does not exist.", subscription.NotificationEndpoint.Identifier);
                return(Result.Failure(
                           $"NotificationEndpoint {subscription.NotificationEndpoint.Identifier} that should be used for the subscription to does not exist."));
            }
            var subscriptionDao = new Subscription(mediaResult.Value, notificationEndpointResult.Value);

            return(await _subscriptionDataStore.AddSubscription(subscriptionDao, cancellationToken));
        }
コード例 #3
0
        public async Task <Result> AddRelease(Release release)
        {
            if (await IsNewNewest(release))
            {
                var releaseDao  = new DAO.Release(release);
                var mediaResult = await _mediaDataStore.GetMedia(release.Media.MediaName);

                if (mediaResult.IsSuccess)
                {
                    releaseDao.Media = mediaResult.Value;
                }
                _logger.LogInformation("Release with releaseNumber {releaseNumber}.{subReleaseNumber} is the newest for {mediaName} so it will be added", release.ReleaseNumber.ToString(), release.SubReleaseNumber.ToString(), release.Media.MediaName);
                return(await _releaseDataStore.AddRelease(releaseDao));
            }
            _logger.LogInformation("Release with releaseNumber {releaseNumber} is not newer for {mediaName} so it will be discarded", release.ReleaseNumber.ToString(), release.Media.MediaName);
            return(Result.Failure($"Release with releaseNumber {release.ReleaseNumber.ToString()} is not newer for {release.Media.MediaName}"));
        }