Esempio n. 1
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Validate location
            if (this.Location == null)
            {
                result.Fail(
                    RequestValidationIssue.InputNull,
                    nameof(this.Location),
                    ValidationMessages.NullLocation
                    );
            }
            else
            {
                // Validate using Coordinates.Validate()
                result.Combine(this.Location.Validate());
            }

            // Validate timestamps
            result.Combine(Validator.ValidateTimestamp(this.BeginTimestamp,
                                                       asOf: DateTimeOffset.UtcNow.AddDays(FUTURE_TIME_WINDOW_DAYS).ToUnixTimeMilliseconds(),
                                                       maxAgeDays: FUTURE_TIME_WINDOW_DAYS + PAST_TIME_WINDOW_DAYS,
                                                       parameterName: nameof(this.BeginTimestamp)));
            result.Combine(Validator.ValidateTimestamp(this.EndTimestamp,
                                                       asOf: DateTimeOffset.UtcNow.AddDays(FUTURE_TIME_WINDOW_DAYS).ToUnixTimeMilliseconds(),
                                                       maxAgeDays: FUTURE_TIME_WINDOW_DAYS + PAST_TIME_WINDOW_DAYS,
                                                       parameterName: nameof(this.EndTimestamp)));
            result.Combine(Validator.ValidateTimeRange(this.BeginTimestamp, this.EndTimestamp));

            return(result);
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Validate location
            if (this.Location == null)
            {
                result.Fail(
                    RequestValidationIssue.InputNull,
                    nameof(this.Location),
                    ValidationMessages.NullLocation
                    );
            }
            else
            {
                // Validate using Coordinates.Validate()
                result.Combine(this.Location.Validate());
            }

            // Validate timestamps
            result.Combine(Validator.ValidateTimestamp(this.BeginTimestamp, parameterName: nameof(this.BeginTimestamp)));
            result.Combine(Validator.ValidateTimestamp(this.EndTimestamp, parameterName: nameof(this.EndTimestamp)));
            result.Combine(Validator.ValidateTimeRange(this.BeginTimestamp, this.EndTimestamp));

            return(result);
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Must contain at least one of either BluetoothSeeds or AreaMatches
            if (this.AreaMatches.Count == 0 && this.BluetoothMatches.Count == 0)
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    RequestValidationProperty.Multiple,
                    ValidationMessages.EmptyMessage
                    );
            }
            if (this.AreaMatches.Count > 0)
            {
                // Validate individual area matches
                foreach (AreaMatch areaMatch in this.AreaMatches)
                {
                    // Use AreaMatch.Validate()
                    result.Combine(areaMatch.Validate());
                }
            }
            if (this.BluetoothMatches.Count > 0)
            {
                // Validate individual Bluetooth matches
                foreach (BluetoothMatch btMatch in this.BluetoothMatches)
                {
                    // User BluetoothMatch.Validate()
                    result.Combine(btMatch.Validate());
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Ensure lat/lng are within range
            result.Combine(Validator.ValidateLatitude(this.Latitude, nameof(this.Latitude)));
            result.Combine(Validator.ValidateLongitude(this.Longitude, nameof(this.Longitude)));

            return(result);
        }
Esempio n. 5
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // MessageId validation
            result.Combine(Validator.ValidateGuid(this.MessageId, nameof(this.MessageId)));

            // Timestamp validation
            result.Combine(Validator.ValidateTimestamp(this.MessageTimestamp, nameof(this.MessageTimestamp)));

            return(result);
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Seed validation
            result.Combine(Validator.ValidateSeed(this.Seed, nameof(this.Seed)));

            // Ensure times are valid
            result.Combine(Validator.ValidateTimestamp(this.SequenceStartTime, nameof(this.SequenceStartTime)));
            result.Combine(Validator.ValidateTimestamp(this.SequenceEndTime, nameof(this.SequenceEndTime)));
            result.Combine(Validator.ValidateTimeRange(this.SequenceStartTime, this.SequenceEndTime));

            return(result);
        }
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Seed validation
            result.Combine(Validator.ValidateSeed(this.Seed, nameof(this.Seed)));

            // Ensure times are valid
            result.Combine(Validator.ValidateTimestamp(this.BeginTimestamp, parameterName: nameof(this.BeginTimestamp)));
            result.Combine(Validator.ValidateTimestamp(this.EndTimestamp, parameterName: nameof(this.EndTimestamp)));
            result.Combine(Validator.ValidateTimeRange(this.BeginTimestamp, this.EndTimestamp));

            return(result);
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Validate provided NarrowcastArea
            if (this.Area != null)
            {
                // Use NarrowcastArea.Validate()
                result.Combine(this.Area.Validate());
            }
            else
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    nameof(this.Area),
                    ValidationMessages.EmptyAreas
                    );
            }

            // Validate message
            if (String.IsNullOrEmpty(this.UserMessage))
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    nameof(this.UserMessage),
                    ValidationMessages.EmptyMessage
                    );
            }

            return(result);
        }
        /// <inheritdoc/>
        public async Task <string> PublishAsync(InfectionReport report, Region region, CancellationToken cancellationToken = default)
        {
            // Validate inputs
            if (report == null)
            {
                throw new ArgumentNullException(nameof(report));
            }
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            RequestValidationResult validationResult = report.Validate();

            validationResult.Combine(region.Validate());

            if (validationResult.Passed)
            {
                // Push to upstream data repository
                return(await this._reportRepo.InsertAsync(report, region, cancellationToken));
            }
            else
            {
                throw new RequestValidationFailedException(validationResult);
            }
        }
Esempio n. 11
0
        /// <inheritdoc/>
        public async Task <IEnumerable <MessageContainerMetadata> > GetLatestInfoAsync(Region region, long lastTimestamp, CancellationToken cancellationToken = default)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }
            else
            {
                // Validate region
                RequestValidationResult validationResult = region.Validate();

                // Validate timestamp
                validationResult.Combine(Validator.ValidateFromRange(
                                             lastTimestamp,
                                             0,
                                             DateTimeOffset.UtcNow.AddDays(1).ToUnixTimeMilliseconds(),
                                             Entities.Validation.Resources.ValidationMessages.InvalidTimestamp));

                lastTimestamp = Math.Max(lastTimestamp, DateTimeOffset.UtcNow.AddDays(-MAX_MESSAGE_AGE_DAYS).ToUnixTimeMilliseconds());

                if (validationResult.Passed)
                {
                    // Get message information from database
                    return(await this._reportRepo.GetLatestAsync(RegionHelper.AdjustToPrecision(region), lastTimestamp, cancellationToken));
                }
                else
                {
                    throw new RequestValidationFailedException(validationResult);
                }
            }
        }
        /// <inheritdoc/>
        public async Task <IEnumerable <InfectionReportMetadata> > GetLatestInfoAsync(Region region, long lastTimestamp, CancellationToken cancellationToken = default)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }
            else
            {
                // Validate region
                RequestValidationResult validationResult = region.Validate();

                // Validate timestamp
                validationResult.Combine(Validator.ValidateTimestamp(lastTimestamp));

                if (validationResult.Passed)
                {
                    // Get message information from database
                    return(await this._reportRepo.GetLatestAsync(region, lastTimestamp, cancellationToken));
                }
                else
                {
                    throw new RequestValidationFailedException(validationResult);
                }
            }
        }
Esempio n. 13
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Validate areas
            if (this.Areas.Count > 0)
            {
                // Validate individual areas
                foreach (Area area in this.Areas)
                {
                    // Use Area.Validate()
                    result.Combine(area.Validate());
                }
            }
            else
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    nameof(this.Areas),
                    ValidationMessages.EmptyAreas
                    );
            }

            // Validate message
            if (String.IsNullOrEmpty(this.UserMessage))
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    nameof(this.UserMessage),
                    ValidationMessages.EmptyMessage
                    );
            }

            return(result);
        }
        /// <inheritdoc/>
        public async Task <IEnumerable <InfectionReport> > GetByIdsAsync(IEnumerable <string> ids, CancellationToken cancellationToken = default)
        {
            if (ids == null || ids.Count() == 0)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            // Confirm IDs are valid
            RequestValidationResult result = new RequestValidationResult();

            foreach (string messageId in ids)
            {
                result.Combine(Validator.ValidateGuid(messageId, nameof(messageId)));
            }

            // Verify results were validated
            if (result.Passed)
            {
                return(await this._reportRepo.GetRangeAsync(ids, cancellationToken));
            }
            else
            {
                throw new RequestValidationFailedException(result);
            }
        }
Esempio n. 15
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Only validate if collection contains message information
            if (this.Seeds == null || this.Seeds.Count == 0)
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    nameof(this.Seeds),
                    ValidationMessages.EmptySeeds
                    );
            }
            else
            {
                // Validate each seed
                foreach (BlueToothSeed seed in this.Seeds)
                {
                    // Use BlueToothSeed.Validate()
                    result.Combine(seed.Validate());
                }
            }

            // Validate Region
            if (this.Region == null)
            {
                result.Fail(
                    RequestValidationIssue.InputNull,
                    nameof(this.Region),
                    ValidationMessages.NullRegion
                    );
            }
            else
            {
                // Use Region.Validate()
                result.Combine(this.Region.Validate());
            }

            return(result);
        }
Esempio n. 16
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Check if lat/lng are in expected values
            result.Combine(Validator.ValidateLatitude(this.LatitudePrefix, nameof(this.LatitudePrefix)));
            result.Combine(Validator.ValidateLongitude(this.LongitudePrefix, nameof(this.LongitudePrefix)));

            // Validate precision
            if (this.Precision < MIN_PRECISION || this.Precision > MAX_PRECISION)
            {
                result.Fail(
                    RequestValidationIssue.InputInvalid,
                    nameof(this.Precision),
                    ValidationMessages.InvalidPrecision,
                    this.Precision.ToString(),
                    MIN_PRECISION.ToString(),
                    MAX_PRECISION.ToString()
                    );
            }

            return(result);
        }
Esempio n. 17
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Validate timestamp
            result.Combine(Validator.ValidateTimestamp(this.LastQueryTime, nameof(this.LastQueryTime)));

            // Validate region
            if (this.Region == null)
            {
                result.Fail(
                    RequestValidationIssue.InputNull,
                    nameof(this.Region),
                    ValidationMessages.NullRegion
                    );
            }
            else
            {
                // Use Region.Validate()
                result.Combine(this.Region.Validate());
            }

            return(result);
        }
Esempio n. 18
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Must contain at least one of either BluetoothSeeds or NarrowcastMessages
            if (this.BluetoothSeeds.Count == 0 && this.Narrowcasts.Count == 0)
            {
                result.Fail(
                    RequestValidationIssue.InputEmpty,
                    RequestValidationProperty.Multiple,
                    ValidationMessages.EmptyMessage
                    );
            }

            // Validate individual messages
            if (this.BluetoothSeeds.Count > 0)
            {
                // Validate individual Bluetooth matches
                foreach (BluetoothSeedMessage seed in this.BluetoothSeeds)
                {
                    // Use BluetoothSeed.Validate()
                    result.Combine(seed.Validate());
                }
            }
            if (this.Narrowcasts.Count > 0)
            {
                // Validate individual area matches
                foreach (NarrowcastMessage message in this.Narrowcasts)
                {
                    // Use NarrowcastMessage.Validate()
                    result.Combine(message.Validate());
                }
            }

            return(result);
        }
Esempio n. 19
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Only validate if collection contains seeds
            if (this.Seeds.Count > 0)
            {
                foreach (BlueToothSeed seed in this.Seeds)
                {
                    // Use Validate() from BlueToothSeed
                    result.Combine(seed.Validate());
                }
            }

            return(result);
        }
Esempio n. 20
0
        /// <inheritdoc/>
        public RequestValidationResult Validate()
        {
            RequestValidationResult result = new RequestValidationResult();

            // Only validate if collection contains message information
            if (this.RequestedQueries.Count > 0)
            {
                foreach (MessageInfo info in this.RequestedQueries)
                {
                    // Use Validate() method in MessageInfo
                    result.Combine(info.Validate());
                }
            }

            return(result);
        }
        /// <inheritdoc/>
        public async Task <string> PublishAsync(IEnumerable <BluetoothSeed> seeds, Region region, long timeAtRequest, CancellationToken cancellationToken = default)
        {
            // Validate inputs
            if (seeds == null || seeds.Count() == 0)
            {
                throw new ArgumentNullException(nameof(seeds));
            }
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            // Validate timestamp
            RequestValidationResult validationResult = Validator.ValidateTimestamp(timeAtRequest);

            // Validate seeds
            foreach (BluetoothSeed seed in seeds)
            {
                validationResult.Combine(seed.Validate());
            }

            if (validationResult.Passed)
            {
                // Build MatchMessage from submitted content
                InfectionReport report = new InfectionReport();

                if (report.BluetoothSeeds is List <BluetoothSeed> asList)
                {
                    asList.AddRange(seeds);
                }
                else
                {
                    foreach (BluetoothSeed seed in seeds)
                    {
                        report.BluetoothSeeds.Add(seed);
                    }
                }

                // Store in data repository
                return(await this._reportRepo.InsertAsync(report, region, cancellationToken));
            }
            else
            {
                throw new RequestValidationFailedException(validationResult);
            }
        }
        /// <inheritdoc/>
        public async Task <long> GetLatestRegionDataSizeAsync(Region region, long lastTimestamp, CancellationToken cancellationToken = default)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            RequestValidationResult validationResult = region.Validate();

            validationResult.Combine(Validator.ValidateTimestamp(lastTimestamp, parameterName: nameof(lastTimestamp)));

            if (validationResult.Passed)
            {
                // Get messages from database
                return(await this._reportRepo.GetLatestRegionSizeAsync(region, lastTimestamp, cancellationToken));
            }
            else
            {
                throw new RequestValidationFailedException(validationResult);
            }
        }