Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <string> PublishAsync(SelfReportRequest request, long timeAtRequest, CancellationToken cancellationToken = default)
        {
            // Validate inputs
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            RequestValidationResult validationResult = request.Validate();

            validationResult.Combine(Validator.ValidateTimestamp(timeAtRequest));

            if (validationResult.Passed)
            {
                // Build MatchMessage from submitted content
                MatchMessage   message = new MatchMessage();
                BluetoothMatch matches = new BluetoothMatch();
                matches.Seeds.AddRange(request.Seeds);

                // Store in data repository
                message.BluetoothMatches.Add(matches);
                return(await this._messageRepo.InsertAsync(message, request.Region, cancellationToken));
            }
            else
            {
                throw new RequestValidationFailedException(validationResult);
            }
        }