示例#1
0
        public static async Task <GenerationReturn> Validate(MapComponentDto mapComponent)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    mapComponent.Map.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateMapComponent(mapComponent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, mapComponent.Map.ContentId));
            }

            var updateFormatCheck =
                CommonContentValidation.ValidateUpdateContentFormat(mapComponent.Map.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, mapComponent.Map.ContentId));
            }

            return(await GenerationReturn.Success("GeoJson Content Validation Successful"));
        }
示例#2
0
        public static async Task <GenerationReturn> Validate(LinkContent linkContent)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    linkContent.ContentId));
            }

            if (linkContent == null)
            {
                return(await GenerationReturn.Error("Link Content is Null?"));
            }

            var(createdUpdatedValid, createdUpdatedValidationMessage) =
                CommonContentValidation.ValidateCreatedAndUpdatedBy(linkContent, linkContent.Id < 1);

            if (!createdUpdatedValid)
            {
                return(await GenerationReturn.Error(createdUpdatedValidationMessage, linkContent.ContentId));
            }

            var urlValidation =
                await CommonContentValidation.ValidateLinkContentLinkUrl(linkContent.Url, linkContent.ContentId);

            if (!urlValidation.isValid)
            {
                return(await GenerationReturn.Error(urlValidation.explanation, linkContent.ContentId));
            }

            return(await GenerationReturn.Success("Link Content Validation Successful"));
        }
        public static async Task <GenerationReturn> Validate(TagExclusion toValidate)
        {
            if (toValidate == null)
            {
                return(await GenerationReturn.Error("Excluded Tag can not be empty"));
            }

            if (string.IsNullOrWhiteSpace(toValidate.Tag))
            {
                return(await GenerationReturn.Error("Excluded Tag can not be blank"));
            }

            var validationResult = CommonContentValidation.ValidateTags(toValidate.Tag.TrimNullToEmpty());

            if (!validationResult.isValid)
            {
                return(await GenerationReturn.Error(validationResult.explanation));
            }

            var cleanedTag = Db.TagListItemCleanup(toValidate.Tag);

            var db = await Db.Context();

            if (db.TagExclusions.Any(x => x.Id != toValidate.Id && x.Tag == cleanedTag))
            {
                return(await GenerationReturn.Error(
                           $"It appears that the tag '{cleanedTag}' is already in the Exclusion List?"));
            }

            return(await GenerationReturn.Success("Tag Exclusion is Valid"));
        }
示例#4
0
        public static async Task <GenerationReturn> Validate(ImageContent imageContent, FileInfo selectedFile)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    imageContent.ContentId));
            }

            var mediaArchiveCheck = UserSettingsUtilities.ValidateLocalMediaArchive();

            if (!mediaArchiveCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Media Archive: {mediaArchiveCheck.Item2}",
                                                    imageContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(imageContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, imageContent.ContentId));
            }

            var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(imageContent.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, imageContent.ContentId));
            }

            selectedFile.Refresh();

            if (!selectedFile.Exists)
            {
                return(await GenerationReturn.Error("Selected File doesn't exist?", imageContent.ContentId));
            }

            if (!FolderFileUtility.IsNoUrlEncodingNeeded(Path.GetFileNameWithoutExtension(selectedFile.Name)))
            {
                return(await GenerationReturn.Error("Limit File Names to A-Z a-z - . _", imageContent.ContentId));
            }

            if (!FolderFileUtility.PictureFileTypeIsSupported(selectedFile))
            {
                return(await GenerationReturn.Error("The file doesn't appear to be a supported file type.",
                                                    imageContent.ContentId));
            }

            if (await(await Db.Context()).ImageFilenameExistsInDatabase(selectedFile.Name, imageContent.ContentId))
            {
                return(await GenerationReturn.Error(
                           "This filename already exists in the database - image file names must be unique.",
                           imageContent.ContentId));
            }

            return(await GenerationReturn.Success("Image Content Validation Successful"));
        }
        public static async Task <GenerationReturn> Validate(PhotoContent photoContent, FileInfo selectedFile)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    photoContent.ContentId));
            }

            var mediaArchiveCheck = UserSettingsUtilities.ValidateLocalMediaArchive();

            if (!mediaArchiveCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Media Archive: {mediaArchiveCheck.Item2}",
                                                    photoContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(photoContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, photoContent.ContentId));
            }

            var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(photoContent.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, photoContent.ContentId));
            }

            selectedFile.Refresh();

            var photoFileValidation =
                await CommonContentValidation.PhotoFileValidation(selectedFile, photoContent?.ContentId);

            if (!photoFileValidation.isValid)
            {
                return(await GenerationReturn.Error(photoFileValidation.explanation, photoContent.ContentId));
            }

            return(await GenerationReturn.Success("Photo Content Validation Successful"));
        }
示例#6
0
        public static async Task <GenerationReturn> Validate(NoteContent noteContent)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    noteContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(noteContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, noteContent.ContentId));
            }

            return(await GenerationReturn.Success("Note Content Validation Successful"));
        }
示例#7
0
        public static async Task <GenerationReturn> Validate(PointContentDto pointContent)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    pointContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(pointContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, pointContent.ContentId));
            }

            var latitudeCheck = CommonContentValidation.LatitudeValidation(pointContent.Latitude);

            if (!latitudeCheck.isValid)
            {
                return(await GenerationReturn.Error(latitudeCheck.explanation, pointContent.ContentId));
            }

            var longitudeCheck = CommonContentValidation.LongitudeValidation(pointContent.Longitude);

            if (!longitudeCheck.isValid)
            {
                return(await GenerationReturn.Error(longitudeCheck.explanation, pointContent.ContentId));
            }

            var elevationCheck = CommonContentValidation.ElevationValidation(pointContent.Elevation);

            if (!elevationCheck.isValid)
            {
                return(await GenerationReturn.Error(elevationCheck.explanation, pointContent.ContentId));
            }

            var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(pointContent.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, pointContent.ContentId));
            }

            foreach (var loopDetails in pointContent.PointDetails)
            {
                if (loopDetails.ContentId == Guid.Empty)
                {
                    return(await GenerationReturn.Error("Point Detail Data must have a valid Content Id",
                                                        loopDetails.ContentId));
                }
                if (loopDetails.PointContentId != pointContent.ContentId)
                {
                    return(await GenerationReturn.Error(
                               $"{loopDetails.DataType} Point Detail isn't assigned to the current point?",
                               loopDetails.ContentId));
                }
                if (string.IsNullOrWhiteSpace(loopDetails.DataType))
                {
                    return(await GenerationReturn.Error("Point Detail Data Type doesn't have a value",
                                                        loopDetails.ContentId));
                }
                if (string.IsNullOrWhiteSpace(loopDetails.StructuredDataAsJson))
                {
                    return(await GenerationReturn.Error($"{loopDetails.DataType} Point Detail doesn't have any data?",
                                                        loopDetails.ContentId));
                }
                try
                {
                    var content =
                        Db.PointDetailDataFromIdentifierAndJson(loopDetails.DataType, loopDetails.StructuredDataAsJson);
                    var contentValidation = content.Validate();

                    if (!contentValidation.isValid)
                    {
                        return(await GenerationReturn.Error(
                                   $"{loopDetails.DataType} Point Detail: {contentValidation.validationMessage}",
                                   pointContent.ContentId));
                    }
                }
                catch (Exception e)
                {
                    return(await GenerationReturn.Error(
                               $"Exception loading the Structured Data for {loopDetails.DataType} Point Detail {e.Message}",
                               pointContent.ContentId));
                }
            }

            return(await GenerationReturn.Success("Point Content Validation Successful"));
        }
示例#8
0
        public static async Task <GenerationReturn> Validate(LineContent lineContent)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    lineContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(lineContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, lineContent.ContentId));
            }

            var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(lineContent.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, lineContent.ContentId));
            }

            try
            {
                var serializer = GeoJsonSerializer.Create(SpatialHelpers.Wgs84GeometryFactory(), 3);

                using var stringReader = new StringReader(lineContent.Line);
                using var jsonReader   = new JsonTextReader(stringReader);
                var featureCollection = serializer.Deserialize <FeatureCollection>(jsonReader);
                if (featureCollection.Count < 1)
                {
                    return(await GenerationReturn.Error(
                               "The GeoJson for the line appears to have an empty Feature Collection?", lineContent.ContentId));
                }
                if (featureCollection.Count > 1)
                {
                    return(await GenerationReturn.Error(
                               "The GeoJson for the line appears to contain multiple elements? It should only contain 1 line...",
                               lineContent.ContentId));
                }
                if (featureCollection[0].Geometry is not LineString)
                {
                    return(await GenerationReturn.Error(
                               "The GeoJson for the line has one element but it isn't a LineString?", lineContent.ContentId));
                }
                var lineString = featureCollection[0].Geometry as LineString;
                if (lineString == null || lineString.Count < 1 || lineString.Length == 0)
                {
                    return(await GenerationReturn.Error("The LineString doesn't have any points or is zero length?",
                                                        lineContent.ContentId));
                }
            }
            catch (Exception e)
            {
                return(await GenerationReturn.Error(
                           $"Error parsing the FeatureCollection and/or problems checking the LineString {e.Message}",
                           lineContent.ContentId));
            }

            return(await GenerationReturn.Success("Line Content Validation Successful"));
        }