public static async Task <GenerationReturn> Validate(GeoJsonContent geoJsonContent) { var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory(); if (!rootDirectoryCheck.Item1) { return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}", geoJsonContent.ContentId)); } var commonContentCheck = await CommonContentValidation.ValidateContentCommon(geoJsonContent); if (!commonContentCheck.valid) { return(await GenerationReturn.Error(commonContentCheck.explanation, geoJsonContent.ContentId)); } var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(geoJsonContent.UpdateNotesFormat); if (!updateFormatCheck.isValid) { return(await GenerationReturn.Error(updateFormatCheck.explanation, geoJsonContent.ContentId)); } var geoJsonCheck = CommonContentValidation.GeoJsonValidation(geoJsonContent.GeoJson); if (!geoJsonCheck.isValid) { return(await GenerationReturn.Error(geoJsonCheck.explanation, geoJsonContent.ContentId)); } return(await GenerationReturn.Success("GeoJson Content Validation Successful")); }
public async Task G01_GeoJsonGrandCanyonWildfireSave() { var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia", "GrandCanyonHistoricWildfireGeoJson.geojson")); Assert.True(testFile.Exists, "GeoJson Test File Found"); var geoJsonTest = new GeoJsonContent { ContentId = Guid.NewGuid(), BodyContent = "Grand Canyon Historic Wildfire GeoJson Test", BodyContentFormat = ContentFormatDefaults.Content.ToString(), CreatedOn = DateTime.Now, CreatedBy = "GC Test for GeoJson", Folder = "GrandCanyon", Title = "Grand Canyon Historic Wildfire Boundaries", Slug = "grand-canyon-historic-wildfire-boundaries", ShowInMainSiteFeed = true, Summary = "Boundaries for Grand Canyon Wildfires", Tags = "grand-canyon, geojson", UpdateNotesFormat = ContentFormatDefaults.Content.ToString(), GeoJson = await File.ReadAllTextAsync(testFile.FullName) }; var result = await GeoJsonGenerator.SaveAndGenerateHtml(geoJsonTest, null, DebugTrackers.DebugProgressTracker()); Assert.IsFalse(result.generationReturn.HasError); }
SaveAndGenerateHtml(GeoJsonContent toSave, DateTime?generationVersion, IProgress <string> progress) { var validationReturn = await Validate(toSave); if (validationReturn.HasError) { return(validationReturn, null); } Db.DefaultPropertyCleanup(toSave); toSave.Tags = Db.TagListCleanup(toSave.Tags); await Db.SaveGeoJsonContent(toSave); await GenerateHtml(toSave, generationVersion, progress); await Export.WriteLocalDbJson(toSave); DataNotifications.PublishDataNotification("GeoJson Generator", DataNotificationContentType.GeoJson, DataNotificationUpdateType.LocalContent, new List <Guid> { toSave.ContentId }); return(await GenerationReturn.Success($"Saved and Generated Content And Html for {toSave.Title}"), toSave); }
public SingleGeoJsonDiv(GeoJsonContent dbEntry) { DbEntry = dbEntry; var settings = UserSettingsSingleton.CurrentSettings(); SiteUrl = settings.SiteUrl; SiteName = settings.SiteName; PageUrl = settings.GeoJsonPageUrl(DbEntry); }
public static string GeoJsonDivAndScript(GeoJsonContent content) { var divScriptGuidConnector = Guid.NewGuid(); var tag = $"<div id=\"GeoJson-{divScriptGuidConnector}\" class=\"leaflet-container leaflet-retina leaflet-fade-anim leaflet-grab leaflet-touch-drag point-content-map\"></div>"; var script = $"<script>lazyInit(document.querySelector(\"#GeoJson-{divScriptGuidConnector}\"), () => singleGeoJsonMapInit(document.querySelector(\"#GeoJson-{divScriptGuidConnector}\"), \"{content.ContentId}\"))</script>"; return(tag + script); }
public static async Task GenerateHtml(GeoJsonContent toGenerate, DateTime?generationVersion, IProgress <string> progress) { progress?.Report($"GeoJson Content - Generate HTML for {toGenerate.Title}"); var htmlContext = new SingleGeoJsonPage(toGenerate) { GenerationVersion = generationVersion }; await htmlContext.WriteLocalHtml(); }
public SingleGeoJsonPage(GeoJsonContent dbEntry) { DbEntry = dbEntry; var settings = UserSettingsSingleton.CurrentSettings(); SiteUrl = settings.SiteUrl; SiteName = settings.SiteName; PageUrl = settings.GeoJsonPageUrl(DbEntry); if (DbEntry.MainPicture != null) { MainImage = new PictureSiteInformation(DbEntry.MainPicture.Value); } }
public static async Task WriteLocalJsonData(GeoJsonContent geoJsonContent) { var dataFileInfo = new FileInfo(Path.Combine( UserSettingsSingleton.CurrentSettings().LocalSiteGeoJsonDataDirectory().FullName, $"GeoJson-{geoJsonContent.ContentId}.json")); if (dataFileInfo.Exists) { dataFileInfo.Delete(); dataFileInfo.Refresh(); } await FileManagement.WriteAllTextToFileAndLogAsync(dataFileInfo.FullName, await GenerateGeoJson(geoJsonContent.GeoJson, UserSettingsSingleton.CurrentSettings().GeoJsonPageUrl(geoJsonContent))); }
public GeoJsonContentEditorWindow(GeoJsonContent toLoad) { InitializeComponent(); StatusContext = new StatusControlContext(); StatusContext.RunFireAndForgetBlockingTaskWithUiMessageReturn(async() => { GeoJsonContent = await GeoJsonContentEditorContext.CreateInstance(StatusContext, toLoad); GeoJsonContent.RequestContentEditorWindowClose += (sender, args) => { Dispatcher?.Invoke(Close); }; AccidentalCloserHelper = new WindowAccidentalClosureHelper(this, StatusContext, GeoJsonContent); await ThreadSwitcher.ResumeForegroundAsync(); DataContext = this; }); }
public static async Task WriteLocalDbJson(GeoJsonContent dbEntry) { var settings = UserSettingsSingleton.CurrentSettings(); var db = await Db.Context(); var jsonDbEntry = JsonSerializer.Serialize(dbEntry); var jsonFile = new FileInfo(Path.Combine(settings.LocalSiteGeoJsonContentDirectory(dbEntry).FullName, $"{Names.GeoJsonContentPrefix}{dbEntry.ContentId}.json")); if (jsonFile.Exists) { jsonFile.Delete(); } jsonFile.Refresh(); await FileManagement.WriteAllTextToFileAndLogAsync(jsonFile.FullName, jsonDbEntry); var latestHistoricEntries = db.HistoricGeoJsonContents.Where(x => x.ContentId == dbEntry.ContentId) .OrderByDescending(x => x.LastUpdatedOn).Take(10); if (!latestHistoricEntries.Any()) { return; } var jsonHistoricDbEntry = JsonSerializer.Serialize(latestHistoricEntries); var jsonHistoricFile = new FileInfo(Path.Combine( settings.LocalSiteGeoJsonContentDirectory(dbEntry).FullName, $"{Names.HistoricGeoJsonContentPrefix}{dbEntry.ContentId}.json")); if (jsonHistoricFile.Exists) { jsonHistoricFile.Delete(); } jsonHistoricFile.Refresh(); await FileManagement.WriteAllTextToFileAndLogAsync(jsonHistoricFile.FullName, jsonHistoricDbEntry); }
public static string Create(GeoJsonContent content) { return($@"{{{{{BracketCodeToken} {content.ContentId}; {content.Title}}}}}"); }
public static Envelope GeometryBoundingBox(GeoJsonContent content, Envelope envelope = null) { var geometryList = GeoJsonContentToGeometries(content); return(GeometryBoundingBox(geometryList, envelope)); }
public static List <Geometry> GeoJsonContentToGeometries(GeoJsonContent content) { return(GeoJsonToGeometries(content.GeoJson)); }