public static async Task WriteLocalJsonData(MapComponentDto dto) { var dtoElementGuids = dto.Elements.Select(x => x.ElementContentId).ToList(); var db = await Db.Context(); var pointGuids = await db.PointContents.Where(x => dtoElementGuids.Contains(x.ContentId)) .Select(x => x.ContentId).ToListAsync(); var lineGuids = await db.LineContents.Where(x => dtoElementGuids.Contains(x.ContentId)) .Select(x => x.ContentId).ToListAsync(); var geoJsonGuids = await db.GeoJsonContents.Where(x => dtoElementGuids.Contains(x.ContentId)) .Select(x => x.ContentId).ToListAsync(); var showDetailsGuid = dto.Elements.Where(x => x.ShowDetailsDefault).Select(x => x.MapComponentContentId) .Distinct().ToList(); var mapDtoJson = new MapSiteJsonData(dto.Map, geoJsonGuids, lineGuids, pointGuids, showDetailsGuid); var dataFileInfo = new FileInfo(Path.Combine( UserSettingsSingleton.CurrentSettings().LocalSiteMapComponentDataDirectory().FullName, $"Map-{dto.Map.ContentId}.json")); if (dataFileInfo.Exists) { dataFileInfo.Delete(); dataFileInfo.Refresh(); } await FileManagement.WriteAllTextToFileAndLogAsync(dataFileInfo.FullName, JsonSerializer.Serialize(mapDtoJson)); }
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")); }
public static async Task <(GenerationReturn generationReturn, MapComponentDto mapDto)> SaveAndGenerateData( MapComponentDto toSave, DateTime?generationVersion, IProgress <string> progress) { var validationReturn = await Validate(toSave); if (validationReturn.HasError) { return(validationReturn, null); } Db.DefaultPropertyCleanup(toSave); var savedComponent = await Db.SaveMapComponent(toSave); await GenerateData(savedComponent, progress); await Export.WriteLocalDbJson(savedComponent.Map); DataNotifications.PublishDataNotification("Map Component Generator", DataNotificationContentType.Map, DataNotificationUpdateType.LocalContent, new List <Guid> { savedComponent.Map.ContentId }); return( await GenerationReturn.Success( $"Saved and Generated Map Component {savedComponent.Map.ContentId} - {savedComponent.Map.Title}"), savedComponent); }
public async Task M01_GenerateMap() { var newMap = new MapComponent { ContentId = Guid.NewGuid(), CreatedBy = "Map Test D01", CreatedOn = DateTime.Now, Title = "Grand Canyon Map", Summary = "Grand Canyon Test Grouping", UpdateNotesFormat = ContentFormatDefaults.Content.ToString() }; var db = await Db.Context(); var piutePoint = await db.PointContents.SingleAsync(x => x.Title == "Piute Point"); var pointsNearPiutePoint = await db.PointContents.Where(x => Math.Abs(x.Longitude - piutePoint.Longitude) < .1 && Math.Abs(x.Latitude - piutePoint.Latitude) < .1 && x.Title.EndsWith("Point")).ToListAsync(); var pointElements = new List <MapElement>(); foreach (var loopPoints in pointsNearPiutePoint) { pointElements.Add(new MapElement { ElementContentId = loopPoints.ContentId, ShowDetailsDefault = false, IncludeInDefaultView = true, MapComponentContentId = newMap.ContentId, IsFeaturedElement = true }); } var lineElement = await db.LineContents.FirstAsync(); pointElements.Add(new MapElement { ElementContentId = lineElement.ContentId, ShowDetailsDefault = false, IncludeInDefaultView = true, MapComponentContentId = newMap.ContentId, IsFeaturedElement = true }); var grandCanyonFireGeoJson = await db.GeoJsonContents.FirstAsync(); pointElements.Add(new MapElement { ElementContentId = grandCanyonFireGeoJson.ContentId, ShowDetailsDefault = false, IncludeInDefaultView = true, MapComponentContentId = newMap.ContentId, IsFeaturedElement = true }); pointElements.First().ShowDetailsDefault = true; var newMapDto = new MapComponentDto(newMap, pointElements); var validationResult = await MapComponentGenerator.Validate(newMapDto); Assert.IsFalse(validationResult.HasError); var saveResult = await MapComponentGenerator.SaveAndGenerateData(newMapDto, null, DebugTrackers.DebugProgressTracker()); Assert.IsFalse(saveResult.generationReturn.HasError); }
public static async Task <(bool valid, string explanation)> ValidateMapComponent(MapComponentDto mapComponent) { var isNewEntry = mapComponent.Map.Id < 1; var isValid = true; var errorMessage = new List <string>(); if (mapComponent.Map.ContentId == Guid.Empty) { isValid = false; errorMessage.Add("Content ID is Empty"); } var titleValidation = ValidateTitle(mapComponent.Map.Title); if (!titleValidation.isValid) { isValid = false; errorMessage.Add(titleValidation.explanation); } var summaryValidation = ValidateSummary(mapComponent.Map.Summary); if (!summaryValidation.isValid) { isValid = false; errorMessage.Add(summaryValidation.explanation); } var(createdUpdatedIsValid, createdUpdatedExplanation) = ValidateCreatedAndUpdatedBy(mapComponent.Map, isNewEntry); if (!createdUpdatedIsValid) { isValid = false; errorMessage.Add(createdUpdatedExplanation); } if (!mapComponent.Elements.Any()) { isValid = false; errorMessage.Add("A map must have at least one element"); } if (!isValid) { return(false, string.Join(Environment.NewLine, errorMessage)); } if (mapComponent.Elements.Any(x => x.ElementContentId == Guid.Empty)) { isValid = false; errorMessage.Add("Not all map elements have a valid Content Id."); } if (mapComponent.Elements.Any(x => x.MapComponentContentId != mapComponent.Map.ContentId)) { isValid = false; errorMessage.Add("Not all map elements are correctly associated with the map."); } if (!isValid) { return(false, string.Join(Environment.NewLine, errorMessage)); } foreach (var loopElements in mapComponent.Elements) { if (loopElements.Id < 1 || await Db.ContentIdIsSpatialContentInDatabase(loopElements.MapComponentContentId)) { continue; } isValid = false; errorMessage.Add("Could not find all Elements Content Items in Db?"); break; } return(isValid, string.Join(Environment.NewLine, errorMessage)); }
public static async Task GenerateData(MapComponentDto toGenerate, IProgress <string> progress) { progress?.Report($"Map Component - Generate Data for {toGenerate.Map.ContentId}, {toGenerate.Map.Title}"); await MapData.WriteLocalJsonData(toGenerate); }