public override void Execute() { Types.RavenDb.Dataleveranse dataleveranse; using (var streamReader = File.OpenText(dataFile)) { var fileContent = streamReader.ReadToEnd(); XDocument dataDeliveryXml = XDocument.Parse(fileContent); dataleveranse = DataleveranseXmlGreier.ParseDataDelivery(dataDeliveryXml); } //DataleveranseXmlGreier.ValidateDataDeliveryContent(dataDelivery); var dataDeliveryMsSql = new Dataleveranse(dataleveranse); MapProjection.ConvertGeometry(dataDeliveryMsSql); foreach (var natureArea in dataDeliveryMsSql.Metadata.NatureAreas) { natureArea.Institution = "Institution"; } dataDeliveryMsSql.Id = "1"; dataDeliveryMsSql.Created = DateTime.Now; SqlServer.DeleteDataDelivery(dataDeliveryMsSql.Metadata.UniqueId.LocalId); SqlServer.LagreDataleveranse(dataDeliveryMsSql); }
public static void PubliserLeveranse(string id, NinRavenDb arkiv, IUserDatabase userDb) { Log.i("DDL", "Publiser dataleveranse #" + id); var dataDelivery = arkiv.HentDataleveranse(id); switch (dataDelivery.Publisering) { case Status.Gjeldende: throw new Exception("Leveransen er allerede gjeldende."); case Status.Utgått: throw new Exception("Leveransen er utgått og kan ikke publiseres."); } var dataDeliveryMsSql = new Dataleveranse(dataDelivery); MapProjection.ConvertGeometry(dataDeliveryMsSql); var userInstitution = userDb.GetUserInstitution(dataDelivery.Username); foreach (var natureArea in dataDeliveryMsSql.Metadata.NatureAreas) { natureArea.Institution = userInstitution; } SqlServer.DeleteDataDelivery(dataDeliveryMsSql.Metadata.UniqueId.LocalId); SqlServer.LagreDataleveranse(dataDeliveryMsSql); MarkerSistGjeldendeLeveranseSomUtgått(arkiv, dataDelivery); dataDelivery.Publisering = Status.Gjeldende; arkiv.LagreDataleveranse(dataDelivery); arkiv.SaveChanges(); }
public XDocument ToXml(Dataleveranse dataleveranse) { var xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "no")); var dataDeliveryElement = new NinXElement("DataLeveranse", "", new XAttribute(XNamespace.Xmlns + "gml", gmlNs), new XAttribute(XNamespace.Xmlns + "nin", Config.Settings.Namespace.Nin), new NinXElement("navn", "dataDelivery.Name", dataleveranse.Name), new NinXElement("leveranseDato", "dataDelivery.DeliveryDate", dataleveranse.DeliveryDate), XmlSkriver.ContactElement("operatoer", dataleveranse.Operator), new NinXElement("grunnForEndring", "dataDelivery.ReasonForChange", dataleveranse.ReasonForChange), new NinXElement("beskrivelse", "dataDelivery.Description", dataleveranse.Description), AddMetadataElements(new Collection <Metadata> { dataleveranse.Metadata }) ); dataDeliveryElement.Print(""); xDocument.Add(dataDeliveryElement); var emptyElements = from element in xDocument.Descendants() where element.IsEmpty select element; while (emptyElements.Any()) { emptyElements.Remove(); } return(xDocument); }
private void ImporterDataleveranse(Dataleveranse dataleveranse, string username) { dataleveranse.Created = DateTime.Now; dataleveranse.Publisering = Status.Importert; dataleveranse.Username = username; LagreDataleveranse(dataleveranse); }
public string LagreDataleveranse(Dataleveranse dataleveranse) { ravenDbStore.Session.Store(dataleveranse); var dataDeliveryId = dataleveranse.Id; // Id is set by database //_ravenDbStore.Session.SaveChanges(); return(dataDeliveryId); }
public static void ConvertGeometry(Dataleveranse dataleveranse) { MapProjection reproject = new MapProjection(Config.Settings.Map.SpatialReferenceSystemIdentifier); dataleveranse.Metadata.Area = reproject.Reproject(dataleveranse.Metadata.Area); foreach (var natureArea in dataleveranse.Metadata.NatureAreas) { natureArea.Area = reproject.Reproject(natureArea.Area); } }
public void ParseDataDeliveryTest_ParseOk() { string path = FileLocator.FindFileInTree(@"Data\NatureArea\NiNCoreImportExample.xml"); string dataDeliveryXmlText = File.ReadAllText(path, Encoding.GetEncoding("iso-8859-1")); XDocument dataDeliveryXml = XDocument.Parse(dataDeliveryXmlText); Dataleveranse dataleveranse = DataleveranseParser.ParseDataleveranse(dataDeliveryXml); Assert.NotNull(dataleveranse); }
private void OvertaForForrigeVersjon(Dataleveranse dataleveranse) { var importedDataDelivery = HentDataleveranseImportert(dataleveranse.Metadata.UniqueId.LocalId); if (importedDataDelivery == null) { return; } importedDataDelivery.Expired = DateTime.Now; importedDataDelivery.Publisering = Status.Utgått; LagreDataleveranse(importedDataDelivery); dataleveranse.ParentId = importedDataDelivery.Id; }
public static Dataleveranse ParseDataleveranse(XDocument dataDeliveryXml) { var dataDelivery = new Dataleveranse(); if (dataDeliveryXml.Root == null) { return(dataDelivery); } var dataDeliveryNames = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "navn", TillatAntall.AkkuratEn); dataDelivery.Name = dataDeliveryNames[0].Value; var dataDeliveryDeliveryDates = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "leveranseDato", TillatAntall.AkkuratEn); dataDelivery.DeliveryDate = Convert.ToDateTime(dataDeliveryDeliveryDates[0].Value); var dataDeliveryOperators = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "operatoer", TillatAntall.AkkuratEn); dataDelivery.Operator = NinXmlParser.ParseContact(dataDeliveryOperators[0]); var dataDeliveryMetadatas = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "metadata", TillatAntall.AkkuratEn); dataDelivery.Metadata = ParseMetadata(dataDeliveryMetadatas[0]); var dataDeliveryReasonForChanges = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "grunnForEndring", TillatAntall.MaksimaltEn); if (dataDeliveryReasonForChanges.Count == 1) { dataDelivery.ReasonForChange = dataDeliveryReasonForChanges[0].Value; } var dataDeliveryDescriptions = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "beskrivelse", TillatAntall.MaksimaltEn); if (dataDeliveryDescriptions.Count == 1) { dataDelivery.Description = dataDeliveryDescriptions[0].Value; } return(dataDelivery); }
public void CheckDocuments(Dataleveranse dataleveranse) { int documentCount = 0; CheckDocuments(dataleveranse.Metadata.Documents); documentCount += dataleveranse.Metadata.Documents.Count; foreach (var natureArea in dataleveranse.Metadata.NatureAreas) { CheckDocuments(natureArea.Documents); documentCount += natureArea.Documents.Count; } if (Count > documentCount) { throw new DataDeliveryParseException( "The data delivery contains file(s) without document reference(s)"); } }
private void ValidateGeometries(Dataleveranse dataleveranse) { var metadataGeometry = SqlGeometry.STGeomFromText(new SqlChars(dataleveranse.Metadata.Area), dataleveranse.Metadata.AreaEpsgCode); var bounds = GetExtent(dataleveranse.Metadata.AreaEpsgCode); if (!bounds.STContains(metadataGeometry)) { throw new Exception("Område ligger utenfor Norge."); } foreach (var natureArea in dataleveranse.Metadata.NatureAreas) { var natureAreaGeometry = SqlGeometry.STGeomFromText(new SqlChars(natureArea.Area), natureArea.AreaEpsgCode); if (!metadataGeometry.STContains(natureAreaGeometry)) { throw new Exception( "Metadata area does not contain the area in nature area with id: " + natureArea.UniqueId.LocalId); } } }
public static void ValidateDataDeliveryContent(Dataleveranse dataleveranse) { var validator = new DataDeliveryContentValidator(); validator.ValidateDataDeliveryContent(dataleveranse); }
public static Dataleveranse Create(string shpFilepath, int shpSpatialReference, int offset, int count) { const string fylke = "Sør-Trøndelag"; const string knr = "1648"; Collection <NatureArea> natureAreas = GenerateNatureAreasFromShapeFile(shpFilepath, shpSpatialReference, knr, offset, count); if (natureAreas.Count <= 0) { return(null); } foreach (var area in natureAreas) { area.Institution = "BOCI"; area.Description = "boci description"; } SqlGeometry metadataArea = CreateMetadataArea(fylke, shpSpatialReference); HashSet <string> variableDefinitions = new HashSet <string>(); foreach (var natureArea in natureAreas) { metadataArea = metadataArea.STUnion(natureArea.Area); foreach (var parameter in natureArea.Parameters) { variableDefinitions.Add(parameter.Code); foreach (var variable in ((NatureAreaType)parameter).AdditionalVariables) { variableDefinitions.Add(variable.Code); } } } var dataDelivery = new Dataleveranse { Id = "-1" }; var rangeString = "" + offset + "-" + (offset + count - 1); dataDelivery.Name = Path.GetFileNameWithoutExtension(shpFilepath) + " (" + rangeString + ")"; dataDelivery.Created = DateTime.Now; dataDelivery.DeliveryDate = DateTime.Now; dataDelivery.Operator = natureAreas[0].Surveyer; var metadata = new Metadata { UniqueId = new Identification() }; var numberString = offset.ToString(); var guid = "00000000-0000-" + knr + "-0000-"; for (int i = 0; i < (12 - numberString.Length); ++i) { guid += "0"; } metadata.UniqueId.LocalId = new Guid(guid + numberString); metadata.UniqueId.NameSpace = "NBIC"; metadata.UniqueId.VersionId = "1.0"; metadata.Program = "Program name"; metadata.ProjectName = "Project name"; metadata.Contractor = natureAreas[0].Surveyer; metadata.Owner = natureAreas[0].Surveyer; metadata.SurveyedFrom = DateTime.Now; metadata.SurveyedTo = DateTime.Now; metadata.SurveyScale = "1:50000"; metadata.Area = metadataArea; metadata.Quality = new Quality { MeasuringMethod = "10", Accuracy = 5, Visibility = "0", MeasuringMethodHeight = "10", AccuracyHeight = 6, MaxDeviation = 7 }; metadata.NatureAreas = natureAreas; foreach (var variableDefinition in variableDefinitions) { metadata.VariabelDefinitions.Add(new NinStandardVariabel { VariableDefinition = new Code { Value = variableDefinition, Registry = "NiN", Version = "2.0" } }); } dataDelivery.Metadata = metadata; return(dataDelivery); }
public void ValidateDataDeliveryContent(Dataleveranse dataleveranse) { ValidateDefinitionsAndParameters(dataleveranse.Metadata.VariabelDefinitions, dataleveranse.Metadata.NatureAreas); ValidateGeometries(dataleveranse); }
public void CreatePerformanceTestData() { var dataDelivery = new Dataleveranse { Id = "DataDeliveries/0", Name = "DataleveranseTestYtelse", DeliveryDate = DateTime.Now, Operator = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, Created = DateTime.Now }; var metadata = new Metadata { UniqueId = new Identification { LocalId = Guid.NewGuid(), NameSpace = "DataAccessTest", VersionId = "1.0" }, Program = "Test", ProjectName = "Naturtyper i Norge", ProjectDescription = "Kartlegging av naturtyper i Norge", Purpose = "Kartlegging og dokumentasjon", Contractor = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, Owner = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, SurveyedFrom = DateTime.Now, SurveyedTo = DateTime.Now, SurveyScale = "1:50000" }; const int sourceEpsgCode = 32633; metadata.Area = SqlGeometry.STPolyFromText(new SqlChars("POLYGON EMPTY"), sourceEpsgCode); metadata.Quality = new Quality { MeasuringMethod = "Terrengmålt: Uspesifisert måleinstrument", Accuracy = 1, Visibility = "Fullt ut synlig/gjenfinnbar i terrenget", MeasuringMethodHeight = "Terrengmålt: Totalstasjon", AccuracyHeight = 2, MaxDeviation = 3, }; for (int i = 1; i < 33; ++i) { metadata.VariabelDefinitions.Add(new NinStandardVariabel { VariableDefinition = new Code { Registry = "NiN", Version = "2.0", Value = "NA V1-" + i } }); } dataDelivery.Metadata = metadata; using (var reader = new StreamReader(@"C:\Artsdatabanken\gml_landskap\polygons.gml")) { Random random = new Random(); string polygon; while ((polygon = reader.ReadLine()) != null) { var xmlTextReader = new XmlTextReader(polygon, XmlNodeType.Document, null); SqlXml sqlXml = new SqlXml(xmlTextReader); SqlGeometry sqlGeometry = SqlGeometry.GeomFromGml(sqlXml, sourceEpsgCode); var natureArea = new NatureArea { UniqueId = new Identification { LocalId = Guid.NewGuid(), NameSpace = "DataAccessTest", VersionId = "1.0" }, Version = "Test versjon", Nivå = NatureLevel.Natursystem, Area = sqlGeometry, Institution = "Tøndel Consulting" }; int randomCode = random.Next(1, 33); natureArea.Parameters.Add(new NatureAreaType { Code = "NA V1-" + randomCode, Share = 1 }); natureArea.Surveyed = new DateTime(random.Next(2000, 2016), 1, 1); metadata.NatureAreas.Add(natureArea); } } SqlServer.LagreDataleveranse(dataDelivery); }
public void StoreDataDeliveryTest() { var natureArea = new NatureArea { Version = "Version", Nivå = NatureLevel.Natursystem, Surveyed = new DateTime(2015, 9, 18, 19, 00, 00), Description = "Description", UniqueId = new Identification { LocalId = Guid.NewGuid(), NameSpace = "DataAccessTest", VersionId = "1.0" }, Area = SqlGeometry.STPolyFromText(new SqlChars("POLYGON ((-11 55, -10 35, -5.5 36, -1 36, 1 38, 5 38, 11 38, 14 36, 26 33, 29 36, 26 39, 29 46, 39 47, 40 49, 27 56, 27 60, 25 60, 20 58, 21 56, 19 55, 11 55, 10 57, 7 57, 8 54, 3 53, -2 60, -8 58, -11 55))"), 25832), Surveyer = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, }; natureArea.Documents.Add(new Document { Title = "NatureAreaDocumentOne", Description = "Description", FileName = "C:\\Document\\TestNatureAreaOne", Author = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" } }); natureArea.Documents.Add(new Document { Title = "NatureAreaDocumentTwo", Description = "Description", FileName = "C:\\Document\\TestNatureAreaTwo", Author = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" } }); natureArea.Parameters.Add(new DescriptionVariable { Code = "DescriptionVariableCode1", Value = "DescriptionVariableValue1", Description = "DescriptionVariableDescription1" }); var descriptionVariable = new DescriptionVariable { Code = "DescriptionVariableCode2", Value = "DescriptionVariableValue2", Description = "DescriptionVariableDescription2" }; var natureAreaType = new NatureAreaType { Code = "NatureAreaTypeCode2", Share = 1.0 }; natureAreaType.AdditionalVariables.Add(descriptionVariable); natureAreaType.CustomVariables.Add(new CustomVariable { Specification = "Specification", Value = "Value" }); natureArea.Parameters.Add(natureAreaType); var metadata = new Metadata { Program = "Program", ProjectName = "ProjectName", ProjectDescription = "ProjectDescription", Purpose = "Purpose", SurveyedFrom = new DateTime(2015, 1, 1, 1, 0, 0), SurveyedTo = new DateTime(2015, 2, 2, 2, 0, 0), SurveyScale = "SurveyScale", Resolution = "Resolution", UniqueId = new Identification { LocalId = Guid.NewGuid(), NameSpace = "DataAccessTest", VersionId = "1.0" }, Contractor = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, Owner = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, Area = SqlGeometry.STPolyFromText(new SqlChars("POLYGON ((-11 55, -10 35, -5.5 36, -1 36, 1 38, 5 38, 11 38, 14 36, 26 33, 29 36, 26 39, 29 46, 39 47, 40 49, 27 56, 27 60, 25 60, 20 58, 21 56, 19 55, 11 55, 10 57, 7 57, 8 54, 3 53, -2 60, -8 58, -11 55))"), 25832), Quality = new Quality { MeasuringMethod = "Terrengmålt: Uspesifisert måleinstrument", Accuracy = 1, Visibility = "Fullt ut synlig/gjenfinnbar i terrenget", MeasuringMethodHeight = "Terrengmålt: Totalstasjon", AccuracyHeight = 2, MaxDeviation = 3, } }; metadata.NatureAreas.Add(natureArea); metadata.Documents.Add(new Document { Title = "NatureAreaDocument", Description = "Description", FileName = "C:\\Document\\TestMetadata", Author = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" } } ); metadata.VariabelDefinitions.Add(new CustomVariableDefinition { Specification = "Specification", Description = "Description" }); metadata.VariabelDefinitions.Add(new NinStandardVariabel { VariableDefinition = new Code { Registry = "Registry", Version = "Version", Value = "DescriptionVariableCode1" } }); metadata.VariabelDefinitions.Add(new NinStandardVariabel { VariableDefinition = new Code { Registry = "Registry", Version = "Version", Value = "DescriptionVariableCode2" } }); metadata.VariabelDefinitions.Add(new NinStandardVariabel { VariableDefinition = new Code { Registry = "Registry", Version = "Version", Value = "NatureAreaTypeCode2" } }); var dataDelivery = new Dataleveranse { Id = "DataDeliveries/100", Name = "Name", DeliveryDate = new DateTime(2015, 1, 1, 13, 00, 00), ReasonForChange = "Reason for change", Description = "Description", ParentId = null, Created = DateTime.Now, Expired = null, Publisering = Status.Gjeldende, Operator = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, Metadata = metadata }; SqlServer.LagreDataleveranse(dataDelivery); }
public void StoreDataDeliveryTest() { var identification = new Identification { LocalId = Guid.NewGuid(), NameSpace = "DataAccessTest", VersionId = "1.0" }; var natureArea = new NatureArea { UniqueId = identification, Version = "2.0", Nivå = NatureLevel.Natursystem, //Area = SqlGeometry.STPolyFromText(new SqlChars("POLYGON ((5 5, 10 5, 10 10, 5 5))"), 0), //Area = SqlGeometry.STPolyFromText(new SqlChars("POLYGON ((-11 55, -10 35, -5.5 36, -1 36, 1 38, 5 38, 11 38, 14 36, 26 33, 29 36, 26 39, 29 46, 39 47, 40 49, 27 56, 27 60, 25 60, 20 58, 21 56, 19 55, 11 55, 10 57, 7 57, 8 54, 3 53, -2 60, -8 58, -11 55))"), 0), Area = "POLYGON ((-11 55, -10 35, -5.5 36, -1 36, 1 38, 5 38, 11 38, 14 36, 26 33, 29 36, 26 39, 29 46, 39 47, 40 49, 27 56, 27 60, 25 60, 20 58, 21 56, 19 55, 11 55, 10 57, 7 57, 8 54, 3 53, -2 60, -8 58, -11 55))", AreaEpsgCode = 25832, Surveyer = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, Surveyed = new DateTime(2015, 9, 18, 19, 00, 00), Description = "Description" }; natureArea.Documents.Add(new Document { Title = "NatureAreaDocumentOne", Description = "Description", Author = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, FileName = "C:\\Document\\TestNatureAreaOne" }); natureArea.Documents.Add(new Document { Title = "NatureAreaDocumentTwo", Description = "Description", Author = new Contact { Company = "Norconsult informasjonssystemer AS", ContactPerson = "Magne Tøndel", Email = "*****@*****.**", Phone = "+4748164614", Homesite = "www.nois.no" }, FileName = "C:\\Document\\TestNatureAreaTwo" }); var metadata = new Metadata { UniqueId = identification, Program = "Program", ProjectName = "ProjectName", ProjectDescription = "ProjectDescription", Quality = new Quality { MeasuringMethod = "Terrengmålt: Uspesifisert måleinstrument", Accuracy = 1, Visibility = "Fullt ut synlig/gjenfinnbar i terrenget", MeasuringMethodHeight = "Terrengmålt: Totalstasjon", AccuracyHeight = 2, MaxDeviation = 3, }, }; metadata.NatureAreas.Add(natureArea); metadata.Documents.Add( new Document { Title = "NatureAreaDocument", Description = "Description", FileName = "C:\\Document\\TestMetadata" } ); var dataDelivery = new Dataleveranse { Name = "DataDeliveryTest", DeliveryDate = DateTime.Now, Metadata = metadata, Created = new DateTime(2015, 9, 17, 12, 30, 30), Publisering = Status.Importert }; var id = dbInterface.LagreDataleveranse(dataDelivery); Assert.IsNotEmpty(id); }