//----------------------------------------------------------------------- // // Copyright (c) 2010 Deltares. All rights reserved. // // B.S.T.I.M. The // tom.the@deltares.nl // 18-05-2010 // xml file creator for DGSMStabDam.dll //----------------------------------------------------------------------- using Deltares.Geometry; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard.IO.DtoAssembler; namespace Deltares.Dam.Data.Assemblers { using System; using System.IO; using System.Linq; using System.Reflection; using System.Xml; using System.Xml.Linq; using System.Xml.Schema; using Deltares.Soilbase; using Deltares.Standard; using Deltares.Geotechnics; using Standard.Extensions; /// /// /// public class DamMStabAssembler : DtoDocumentAssembler { #region Constant declarations /// /// Holds the common part of the path to the embedded resource /// private const string EmbeddedResourcePath = "Deltares.Dam.Data.Xsd"; public const string XmlAttributeBottomLevel = "BottomLevel"; public const string XmlAttributeBoundaryLayer = "BoundaryLayer"; public const string XmlAttributeHasPhreaticLevel = "HasPhreaticLevel"; public const string XmlAttributeID = "ID"; public const string XmlAttributeIsPhreatic = "IsPhreatic"; public const string XmlAttributeMStabFileName = "MStabFileName"; public const string XmlAttributeName = "Name"; public const string XmlAttributePhreaticLevel = "PhreaticLevel"; public const string XmlAttributeSoilDBName = "SoilDBName"; public const string XmlAttributeSoilID = "SoilID"; public const string XmlAttributeTopLevel = "TopLevel"; public const string XmlAttributeXCoord = "XCoord"; public const string XmlAttributeXCoordinate = "XCoordinate"; public const string XmlAttributeYCoord = "YCoord"; public const string XmlAttributeYCoordinate = "YCoordinate"; public const string XmlAttributeCharacteristicPointType = "CharacteristicPointType"; public const string XmlElementExternalPLLines = "ExternalPLLines"; public const string XmlElementLayer = "Layer"; public const string XmlElementLayers = "Layers"; public const string XmlAttributeSoilType = "SoilType"; public const string XmlAttributeInBetweenSandLayerID = "InBetweenSandLayerID"; public const string XmlAttributeBottomSandLayerID = "BottomSandLayerID"; public const string XmlAttributeInfiltrationLayerID = "InfiltrationLayerID"; /// /// Holds the xml element name /// public const string XmlElementName = "DamMStabDoc"; public const string XmlElementNameInput = "DamMStabInput"; /// /// Holds the xml namespace /// public const string XmlElementNamespace = "http://deltares.nl/2008/" + XmlSchemaName; public const string XmlElementNamespaceInput = "http://deltares.nl/2008/" + XmlSchemaNameInput; public const string XmlElementPLLine = "PLLine"; public const string XmlElementPLPoint = "PLPoint"; public const string XmlElementProfile = "Profile"; public const string XmlElementSurfaceLine = "SurfaceLine"; public const string XmlElementSurfacePoint = "SurfacePoint"; public const string XmlElementCharacteristicPoints = "CharacteristicPoints"; public const string XmlElementCharacteristicPoint = "CharacteristicPoint"; public const string XmlElementZoneAreas = "ZoneAreas"; public const string XmlElementForbiddenZone = "ForbiddenZone"; public const string XmlElementSheetPiling = "SheetPiling"; public const string XmlElementHorizontalBalanceArea = "HorizontalBalanceArea"; public const string XmlElementSlipCircleDefinition = "SlipCircleDefinition"; /// /// Holds the model xml element and attribute names /// public const string XmlElementModel = "Model"; public const string XmlAttributeCalculationModel = "CalculationModel"; public const string XmlAttributeShearStrength = "ShearStrength"; public const string XmlAttributeProbabilistic = "Probabilistic"; public const string XmlAttributeSearchMethod = "SearchMethod"; public const string XmlAttributeGridPosition = "GridPosition"; /// /// Holds the TrafficLoad xml element and attribute names /// public const string XmlElementTrafficLoad = "TrafficLoad"; public const string XmlAttributeXCoordinateAtRiver = "XCoordinateAtRiver"; public const string XmlAttributeXCoordinateAtPolder = "XCoordinateAtPolder"; public const string XmlAttributeLoad = "Load"; /// /// Holds the CalculationOptions xml element and attribute names /// public const string XmlElementCalculationOptions = "CalculationOptions"; public const string XmlAttributeMinimalCircleDepth = "MinimalCircleDepth"; public const string XmlAttributeZonesType = "ZonesType"; /// /// Holds the GeometryCreationOptions xml element and attribute names /// public const string XmlElementGeometryCreationOptions = "GeometryCreationOptions"; public const string XmlAttributeSoilGeometryType = "SoilGeometryType"; public const string XmlAttributeSoilGeometry2DFilename = "SoilGeometry2DFilename"; public const string XmlAttributeXOffsetSoilGeometry2DOrigin = "XOffsetSoilGeometry2DOrigin"; public const string XmlAttributeMaterialForDike = "MaterialForDike"; public const string XmlAttributeMaterialForShoulder = "MaterialForShoulder"; public const string XmlAttributeIsUseOriginalPLLineAssignments = "IsUseOriginalPLLineAssignments"; public const string XmlAttributeIsUseOriginalCalculationOptions = "IsUseOriginalCalculationOptions"; public const string XmlAttributeIsDrySituation = "IsDrySituation"; public const string XmlAttributePLLineAssignment = "PLLineAssignment"; public const string XmlAttributeIntrusionVerticalWaterPressure = "IntrusionVerticalWaterPressure"; public const string XmlAttributePenetrationLength = "PenetrationLength"; public const string XmlAttributeIsDesign = "IsDesign"; public const string XmlElementDesign = "Design"; public const string XmlAttributeEmbankmentMaterialName = "EmbankmentMaterialName"; public const string XmlAttributePreviousGeometry2DFilename = "PreviousGeometry2DFilename"; /// /// Holds the name of the xml schema /// private const string XmlSchemaName = "DamMStabDocDefinition"; private const string XmlSchemaNameInput = "DamMStabInputDefinition"; /// /// Holds the xsd resource path /// public const string XsdEmbeddedResourcePath = EmbeddedResourcePath + "." + XmlSchemaName + ".xsd"; private const string XsdEmbeddedResourcePathInput = EmbeddedResourcePath + "." + XmlSchemaNameInput + ".xsd"; #endregion /// /// /// public DamMStabAssembler() : base(XmlElementName, XmlElementNamespace, XsdEmbeddedResourcePath) { } /// /// /// /// /// public override XDocument CreateDataTransferObject(FailureMechanismeParamatersMStab failureMechanismeParamatersMStab) { XDocument doc = base.CreateDataTransferObject(failureMechanismeParamatersMStab); XNamespace tns = ElementNamespace; Location location = failureMechanismeParamatersMStab.Location; // Todo: Sheetpiling should be done correctly (SheetpilePointLevel vs SheetpileLength) // For now: disable this //if (location.SheetPileLength > 0.0) //{ // SheetPiling sheetPiling = new SheetPiling(); // sheetPiling.Length = location.SheetPileLength; // sheetPiling.XCoordinate = location.SheetPilePoint.X; // sheetPiling.YCoordinate = location.SheetPilePoint.Y; // sheetPiling.ZCoordinate = location.SheetPilePoint.Z; // damFailureMechanismeCalculation.FailureMechanismeParamatersMStab.MStabParameters.SheetPiling = // sheetPiling; //} // DAMMStabInput var inputElement = new XElement(tns + XmlElementNameInput); doc.Root.Add(inputElement); XNamespace tnsb = XmlElementNamespaceInput; doc.Root.Add(new XAttribute(XNamespace.Xmlns + "tnsb", tnsb.NamespaceName)); // Soil database inputElement.Add(new XAttribute(XmlAttributeMStabFileName,failureMechanismeParamatersMStab.MStabParameters.ProjectFileName)); inputElement.Add(new XAttribute(XmlAttributeSoilDBName, failureMechanismeParamatersMStab.MStabParameters.SoilDatabaseName)); // Surface line XElement surfaceLineElement = GetSurfaceLineElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(surfaceLineElement); // Surface line XElement characteristicPointsElement = GetCharacteristicPointsElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(characteristicPointsElement); // External PL lines XElement externalPLLinesElement = GetExternalPlLinesElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(externalPLLinesElement); // Model XElement modelElement = GetModelElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(modelElement); // Zone Area if (failureMechanismeParamatersMStab.MStabParameters.ZoneAreas != null) { XElement zoneAreasElement = GetZoneAreasElement(failureMechanismeParamatersMStab.MStabParameters.ZoneAreas, tnsb); inputElement.Add(zoneAreasElement); } // Forbidden zone if (failureMechanismeParamatersMStab.MStabParameters.ForbiddenZone != null) { XElement forbiddenZoneElement = GetForbiddenZoneElement(failureMechanismeParamatersMStab.MStabParameters.ForbiddenZone, tnsb); inputElement.Add(forbiddenZoneElement); } // Traffic load if ( failureMechanismeParamatersMStab.SurfaceLine.HasAnnotation(CharacteristicPointType.TrafficLoadInside) && failureMechanismeParamatersMStab.SurfaceLine.HasAnnotation(CharacteristicPointType.TrafficLoadOutside)) { XElement trafficLoadElement = GetTrafficLoadElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(trafficLoadElement); } // Calculation Options if (failureMechanismeParamatersMStab.MStabParameters.CalculationOptions != null) { XElement calculationOptionsElement = GetCalculationOptionsElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(calculationOptionsElement); } // GeometryCreationOptions Options if (failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions != null) { XElement geometryCreationOptionsElement = GetGeometryCreationOptionsElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(geometryCreationOptionsElement); } // SheetPiling if (failureMechanismeParamatersMStab.MStabParameters.SheetPiling != null) { XElement sheetPilingElement = GetSheetPilingElement(failureMechanismeParamatersMStab.MStabParameters.SheetPiling, tnsb); inputElement.Add(sheetPilingElement); } // Horizontal Balance Area if (failureMechanismeParamatersMStab.MStabParameters.HorizontalBalanceArea != null) { XElement horizontalBalanceAreaElement = GetHorizontalBalanceAreaElement(failureMechanismeParamatersMStab.MStabParameters.HorizontalBalanceArea, tnsb); inputElement.Add(horizontalBalanceAreaElement); } // Slip Circle Definition if (failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition != null) { XElement slipCircleDefinitionElement = GetSlipCircleDefinitionElement( failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition, tnsb); inputElement.Add(slipCircleDefinitionElement); } // Design data if (failureMechanismeParamatersMStab.Design != null) { XElement designElement = GetDesignElement(failureMechanismeParamatersMStab, tnsb); inputElement.Add(designElement); } // Profile SoilProfile1D profile = failureMechanismeParamatersMStab.SoilProfile; if (profile != null) { var soilProfileAssembler = new SoilProfileAssembler(); XNamespace tnsa = soilProfileAssembler.ElementNamespace; doc.Root.Add(new XAttribute(XNamespace.Xmlns + "tnsa", tnsa.NamespaceName)); //TODO: Remove duplicate code. The method GetProfileElement should call the SoilProfileAssembler already defined in another namespace XElement profileElement = GetProfileElement(profile, tns, tnsa); // XElement profileElement = soilProfileAssembler.CreateDataTransferObject(profile); //GetProfileElement(profile, tns, tnsa); // profileElement.Name = tns.GetName(profileElement.Name.LocalName);// .SetNamespace(DamMStabAssembler.XmlElementProfile, tns.NamespaceName); doc.Root.Add(profileElement); } return doc; } private static XElement GetZoneAreasElement(MStabZoneAreas zoneAreas, XNamespace tns) { if (zoneAreas == null) throw new ArgumentNullException("zoneAreas"); return zoneAreas.ToXElement(XmlElementZoneAreas, tns); } private static XElement GetForbiddenZoneElement(MStabForbiddenZone forbiddenZone, XNamespace tns) { if (forbiddenZone == null) throw new ArgumentNullException("forbiddenZone"); return forbiddenZone.ToXElement(XmlElementForbiddenZone, tns); } private static XElement GetSheetPilingElement(Deltares.Dam.Data.SheetPiling sheetPiling, XNamespace tns) { if (sheetPiling == null) throw new ArgumentNullException("sheetPiling"); return sheetPiling.ToXElement(XmlElementSheetPiling, tns); } private static XElement GetHorizontalBalanceAreaElement(HorizontalBalanceArea horizontalBalanceArea, XNamespace tns) { if (horizontalBalanceArea == null) throw new ArgumentNullException("horizontalBalanceArea"); return horizontalBalanceArea.ToXElement(XmlElementHorizontalBalanceArea, tns); } /// /// Gets the slip circle definition element. /// /// The slip circle definition. /// The namespace /// private static XElement GetSlipCircleDefinitionElement(SlipCircleDefinition slipCircleDefinition, XNamespace tns) { if (slipCircleDefinition == null) throw new ArgumentNullException("slipCircleDefinition"); return slipCircleDefinition.ToXElement(XmlElementSlipCircleDefinition, tns); } #region Private Assembler Methods /// /// /// /// /// /// /// private static XElement GetProfileElement(SoilProfile1D profile, XNamespace tns, XNamespace tnsa) { var profileElement = new XElement(tns + XmlElementProfile); profileElement.Add(new XAttribute(XmlAttributeName, profile.Name)); profileElement.Add(new XAttribute(XmlAttributeXCoordinate, profile.X)); profileElement.Add(new XAttribute(XmlAttributeYCoordinate, profile.Y)); profileElement.Add(new XAttribute(XmlAttributePhreaticLevel, profile.PhreaticLevel)); profileElement.Add(new XAttribute(XmlAttributeHasPhreaticLevel, profile.HasPhreaticLevel)); profileElement.Add(new XAttribute(XmlAttributeBottomLevel, profile.BottomLevel)); if (profile.Layers.Count > 0) { var layersElement = new XElement(tnsa + XmlElementLayers); GetProfileLayersElement(profile, tnsa, layersElement); profileElement.Add(layersElement); } // Bottom sand layer if (profile.BottomAquiferLayer != null) profileElement.Add(new XAttribute(XmlAttributeBottomSandLayerID, profile.BottomAquiferLayer.Id)); // In-between sand layer if (profile.InBetweenAquiferLayer != null) profileElement.Add(new XAttribute(XmlAttributeInBetweenSandLayerID, profile.InBetweenAquiferLayer.Id)); // Infiltration layer if (profile.InfiltrationLayer != null) profileElement.Add(new XAttribute(XmlAttributeInfiltrationLayerID, profile.InfiltrationLayer.Id)); return profileElement; } // Assembles the layer elements for the profile private static void GetProfileLayersElement(SoilProfile1D profile, XNamespace tnsa, XElement layersElement) { profile.EnsureUniqueLayerIds(); foreach (SoilLayer1D layer in profile.Layers) { var layerElement = new XElement(tnsa + XmlElementLayer); layersElement.Add(layerElement); layerElement.Add(new XAttribute(XmlAttributeID, String.Format("{0}", layer.Id))); layerElement.Add(new XAttribute(XmlAttributeSoilID, layer.Soil.Name)); layerElement.Add(new XAttribute(XmlAttributeTopLevel, layer.TopLevel)); } } /// /// Assembles the pl lines /// /// /// /// private static XElement GetExternalPlLinesElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { XElement externalPLLinesElement = null; if (failureMechanismeParamatersMStab.PLLines != null) { externalPLLinesElement = new XElement(tnsb + XmlElementExternalPLLines); foreach (PLLineType plLineType in Enum.GetValues(typeof(PLLineType))) { PLLine line = failureMechanismeParamatersMStab.PLLines.Lines[plLineType]; var PLLineElement = new XElement(tnsb + XmlElementPLLine); externalPLLinesElement.Add(PLLineElement); PLLineElement.Add(new XAttribute(XmlAttributeIsPhreatic, line.IsPhreatic)); PLLineElement.Add(new XAttribute(XmlAttributeBoundaryLayer, line.BoundaryLayer)); foreach (PLLinePoint point in line.Points) { var PLPointElement = new XElement(tnsb + XmlElementPLPoint); PLPointElement.Add(new XAttribute(XmlAttributeXCoord, point.X)); PLPointElement.Add(new XAttribute(XmlAttributeYCoord, point.Z)); PLLineElement.Add(PLPointElement); } } } if (failureMechanismeParamatersMStab.DupuitPLLines != null) { externalPLLinesElement = new XElement(tnsb + XmlElementExternalPLLines); for (int plLineIndex = 0; plLineIndex < failureMechanismeParamatersMStab.DupuitPLLines.PLLines.Count; plLineIndex++) { PLLine line = failureMechanismeParamatersMStab.DupuitPLLines.PLLines[plLineIndex]; line.IsPhreatic = (plLineIndex == failureMechanismeParamatersMStab.DupuitPLLines.PLLines.Count - 1); line.BoundaryLayer = plLineIndex; var PLLineElement = new XElement(tnsb + XmlElementPLLine); externalPLLinesElement.Add(PLLineElement); PLLineElement.Add(new XAttribute(XmlAttributeIsPhreatic, line.IsPhreatic)); PLLineElement.Add(new XAttribute(XmlAttributeBoundaryLayer, line.BoundaryLayer)); for (int pointIndex = 1; pointIndex < line.Points.Count - 1; pointIndex++) { GeometryPoint point = line.Points[pointIndex]; var PLPointElement = new XElement(tnsb + XmlElementPLPoint); PLPointElement.Add(new XAttribute(XmlAttributeXCoord, point.X)); PLPointElement.Add(new XAttribute(XmlAttributeYCoord, point.Z)); PLLineElement.Add(PLPointElement); } } } return externalPLLinesElement; } /// /// Assembles the surface line element /// /// /// /// private static XElement GetSurfaceLineElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { var surfaceLineElement = new XElement(tnsb + XmlElementSurfaceLine); foreach (GeometryPoint point in failureMechanismeParamatersMStab.SurfaceLine.Geometry.Points) { var surfacePointElement = new XElement(tnsb + XmlElementSurfacePoint); surfacePointElement.Add(new XAttribute(XmlAttributeXCoord, point.X)); surfacePointElement.Add(new XAttribute(XmlAttributeYCoord, point.Z)); surfaceLineElement.Add(surfacePointElement); } return surfaceLineElement; } /// /// Assembles the characteristic points element /// /// /// /// private static XElement GetCharacteristicPointsElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { var characteristicPointsElement = new XElement(tnsb + XmlElementCharacteristicPoints); foreach (CharacteristicPointType characteristicPointType in Enum.GetValues(typeof(CharacteristicPointType))) { GeometryPoint point = failureMechanismeParamatersMStab.SurfaceLine.CharacteristicPoints.GetGeometryPoint(characteristicPointType); if (point != null) { var characteristicPointElement = new XElement(tnsb + XmlElementCharacteristicPoint); characteristicPointElement.Add(new XAttribute(XmlAttributeXCoord, point.X)); characteristicPointElement.Add(new XAttribute(XmlAttributeYCoord, point.Z)); characteristicPointElement.Add(new XAttribute(XmlAttributeCharacteristicPointType, characteristicPointType.ToString())); characteristicPointsElement.Add(characteristicPointElement); } } return characteristicPointsElement; } /// /// Assembles the model element /// /// /// /// private static XElement GetModelElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { return new XElement(tnsb + XmlElementModel, new XAttribute(XmlAttributeCalculationModel, failureMechanismeParamatersMStab.MStabParameters.Model), new XAttribute(XmlAttributeShearStrength, failureMechanismeParamatersMStab.MStabParameters.ShearStrength), new XAttribute(XmlAttributeProbabilistic, failureMechanismeParamatersMStab.MStabParameters.IsProbabilistic), new XAttribute(XmlAttributeSearchMethod, failureMechanismeParamatersMStab.MStabParameters.SearchMethod), new XAttribute(XmlAttributeGridPosition, failureMechanismeParamatersMStab.MStabParameters.GridPosition.ToString().ToLower()) ); } /// /// Assembles the traffic load element /// /// /// /// private static XElement GetTrafficLoadElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { return new XElement(tnsb + XmlElementTrafficLoad, new XAttribute(XmlAttributeXCoordinateAtRiver, failureMechanismeParamatersMStab. SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.TrafficLoadOutside).X), new XAttribute(XmlAttributeXCoordinateAtPolder, failureMechanismeParamatersMStab. SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.TrafficLoadInside).X), new XAttribute(XmlAttributeLoad, failureMechanismeParamatersMStab.TrafficLoad) ); } /// /// Assembles the calculation options element /// /// /// /// private static XElement GetCalculationOptionsElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { return new XElement(tnsb + XmlElementCalculationOptions, new XAttribute(XmlAttributeMinimalCircleDepth, failureMechanismeParamatersMStab. MStabParameters.CalculationOptions.MinimalCircleDepth), new XAttribute(XmlAttributeZonesType, failureMechanismeParamatersMStab. MStabParameters.CalculationOptions.ZonesType.ToString()) ); } /// /// Assembles the GeometryCreationOptions element /// /// /// /// private static XElement GetGeometryCreationOptionsElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { string soilGeometryName = failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.SoilGeometry2DFilename; soilGeometryName = (soilGeometryName == null ? "" : soilGeometryName); string materialForDike = failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.MaterialForDike; materialForDike = (materialForDike == null ? "" : materialForDike); string materialForShoulder = failureMechanismeParamatersMStab.MStabParameters.GeometryCreationOptions.MaterialForShoulder; materialForShoulder = (materialForShoulder == null ? "" : materialForShoulder); return new XElement(tnsb + XmlElementGeometryCreationOptions, new XAttribute(XmlAttributeSoilGeometryType, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.SoilGeometryType), new XAttribute(XmlAttributeSoilGeometry2DFilename, soilGeometryName), new XAttribute(XmlAttributeXOffsetSoilGeometry2DOrigin, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.XOffsetSoilGeometry2DOrigin), new XAttribute(XmlAttributeMaterialForDike, materialForDike), new XAttribute(XmlAttributeMaterialForShoulder, materialForShoulder), new XAttribute(XmlAttributeIsUseOriginalPLLineAssignments, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.IsUseOriginalPLLineAssignments), new XAttribute(XmlAttributeIsUseOriginalCalculationOptions, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.IsUseOriginalCalculationOptions), new XAttribute(XmlAttributeIsDrySituation, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.IsDrySituation), new XAttribute(XmlAttributePLLineAssignment, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.PLLineAssignment), new XAttribute(XmlAttributeIntrusionVerticalWaterPressure, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.IntrusionVerticalWaterPressureType), new XAttribute(XmlAttributePenetrationLength, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.PenetrationLength), new XAttribute(XmlAttributeIsDesign, failureMechanismeParamatersMStab. MStabParameters.GeometryCreationOptions.IsDesign)); } /// /// /// /// /// /// private static XElement GetDesignElement( FailureMechanismeParamatersMStab failureMechanismeParamatersMStab, XNamespace tnsb) { string embankmentMaterialname = failureMechanismeParamatersMStab.Design.EmbankmentMaterialname; embankmentMaterialname = (embankmentMaterialname == null ? "" : embankmentMaterialname); string previousGeometry2DFilename = failureMechanismeParamatersMStab.Design.PreviousGeometry2DFilename; previousGeometry2DFilename = (previousGeometry2DFilename == null ? "" : previousGeometry2DFilename); return new XElement(tnsb + XmlElementDesign, new XAttribute(XmlAttributeEmbankmentMaterialName, embankmentMaterialname), new XAttribute(XmlAttributePreviousGeometry2DFilename, previousGeometry2DFilename)); } #endregion #region Schema Validator Method public bool ValidateSchema(XDocument doc, out string message) { bool result = true; string errorMessage = String.Empty; // DAMMStabDefinition XmlSchemaSet schemas = new XmlSchemaSet(); Stream xsdStream = Common.GetEmbeddedFile(Assembly.GetExecutingAssembly(), XsdEmbeddedResourcePath); schemas.Add(XmlElementNamespace, XmlReader.Create(xsdStream)); xsdStream = Common.GetEmbeddedFile(Assembly.GetExecutingAssembly(), XsdEmbeddedResourcePathInput); schemas.Add(XmlElementNamespaceInput, XmlReader.Create(xsdStream)); Assembly assembly; string schemaName; string resourceName; // FileIdentificationDefinition var fileIdentificationAssembler = new FileIdentificationAssembler(); if (!schemas.Contains(fileIdentificationAssembler.ElementNamespace)) { assembly = fileIdentificationAssembler.GetType().Assembly; schemaName = Path.GetFileName(fileIdentificationAssembler.ElementNamespace); string schemaFileName = schemaName + ".xsd"; resourceName = (from string name in assembly.GetManifestResourceNames() where name.EndsWith(schemaFileName) select name).Single(); xsdStream = Common.GetEmbeddedFile(assembly, resourceName); schemas.Add(fileIdentificationAssembler.ElementNamespace, XmlReader.Create(xsdStream)); } // ProfileDefinition var soilProfileAssembler = new SoilProfileAssembler(); assembly = soilProfileAssembler.GetType().Assembly; schemaName = Path.GetFileName(soilProfileAssembler.ElementNamespace); resourceName = (from string name in assembly.GetManifestResourceNames() where name.EndsWith(schemaName + ".xsd") select name).Single(); xsdStream = Common.GetEmbeddedFile(assembly, resourceName); schemas.Add(soilProfileAssembler.ElementNamespace, XmlReader.Create(xsdStream)); doc.Validate(schemas, (o, e) => { result = false; errorMessage = e.Message; }, true); message = errorMessage; return result; } #endregion } }