public Task <object> Validate(IDocument document, IReporter reporter)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (reporter == null)
            {
                throw new ArgumentNullException(nameof(reporter));
            }

            var histogram = this.GetHistogramOfIdValues(document);

            var nonUniqueIds = histogram.Where(p => p.Value > 1L).Select(p => p.Key).ToList();

            if (nonUniqueIds.Count > 0)
            {
                reporter.AppendContent(string.Format("Duplicated ID definitions: {0}", string.Join(", ", nonUniqueIds)));
            }

            var invalidReferences = this.GetInvalidReferences(document, histogram).ToList();

            if (invalidReferences.Count > 0)
            {
                reporter.AppendContent(string.Format("Invalid ID references: {0}", string.Join(", ", invalidReferences)));
            }

            return(Task.FromResult <object>(true));
        }
Exemple #2
0
        public async Task <object> Validate(IDocument document, IReporter reporter)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            string fileName = Path.GetTempFileName() + ".xml";

            reporter.AppendContent(string.Format("File name = {0}", fileName));

            await this.WriteXmlFileWithDoctype(document, fileName);

            await this.ReadXmlFileWithDtdValidation(fileName);

            reporter.AppendContent(this.reportBuilder.ToString());
            return(true);
        }
        public async Task <object> Validate(IDocument document, IReporter reporter)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (reporter == null)
            {
                throw new ArgumentNullException(nameof(reporter));
            }

            var data = await this.harvester.Harvest(document.XmlDocument.DocumentElement);

            var externalLinks = data?.Select(e => e.FullAddress)
                                .Distinct()
                                .ToArray();

            if (externalLinks == null || externalLinks.Length < 1)
            {
                reporter.AppendContent("Warning: No external links found.");
                return(false);
            }

            var result = await this.validationService.Validate(externalLinks);

            var nonValidItems = result.Where(r => r.ValidationStatus != ValidationStatus.Valid)
                                .Select(r => $"{r.ValidatedObject} / {r.ValidationStatus.ToString()} /")
                                .OrderBy(i => i);

            reporter.AppendContent("Non-valid external links:");
            foreach (var taxonName in nonValidItems)
            {
                reporter.AppendContent(string.Format("\t{0}", taxonName));
            }

            return(true);
        }
Exemple #4
0
        public async Task <object> Validate(IDocument document, IReporter reporter)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (reporter == null)
            {
                throw new ArgumentNullException(nameof(reporter));
            }

            var data = await this.harvester.Harvest(document.XmlDocument);

            var scientificNames = data?.Distinct().ToArray();

            if (scientificNames == null || scientificNames.Length < 1)
            {
                reporter.AppendContent("Warning: No taxon names found.");
                return(false);
            }

            var result = await this.validationService.Validate(scientificNames);

            var nonValidItems = result.Where(r => r.ValidationStatus != ValidationStatus.Valid)
                                .Select(r => r.ValidatedObject)
                                .OrderBy(i => i);

            reporter.AppendContent("Non-valid taxon names:");
            foreach (var taxonName in nonValidItems)
            {
                reporter.AppendContent(string.Format("\t{0}", taxonName));
            }

            return(true);
        }