internal FlightHistoryCore.Model.RouteDestination Convert() { DbModel.Destination origin = null; DbModel.Destination destination = null; DbModel.Estimate real = null; if (Origin != null) { origin = Origin.Convert(); } if (Destination != null) { destination = Destination.Convert(); } if (Real != null && Real is Estimated) { real = ((Estimated)Real).Convert(); } return(new DbModel.RouteDestination() { Origin = origin, Destination = destination, Real = real }); }
/// <summary> /// Load from mapping file /// create a XmlMapper /// </summary> /// <returns></returns> public XmlMapper Load(string mappingFilePath, string username) { xmlMapper = new XmlMapper(); mappingFile = new XmlDocument(); mappingFile.Load(mappingFilePath); XmlNode root = mappingFile.DocumentElement; #region get id and name of standard XmlNode mapping = mappingFile.GetElementsByTagName(XmlMapperTags.mapping.ToString())[0]; if (mapping.Attributes.Count > 0) { foreach (XmlAttribute attr in mapping.Attributes) { if (attr.Name.Equals(XmlMapperAttributes.id.ToString())) { xmlMapper.Id = Convert.ToInt32(attr.Value); } if (attr.Name.Equals(XmlMapperAttributes.name.ToString())) { xmlMapper.Name = attr.Value; } } } #endregion get id and name of standard #region create Header as xmlMappingHeader XmlMappingHeader xmlMappingHeader = new XmlMappingHeader(); XmlNode header = mappingFile.GetElementsByTagName(XmlMapperTags.header.ToString())[0]; foreach (XmlNode xmlNode in header.ChildNodes) { if (xmlNode.NodeType.Equals(System.Xml.XmlNodeType.Element)) { #region create destination if (xmlNode.Name.Equals(XmlMapperTags.destination.ToString())) { xmlMappingHeader.Destination = Destination.Convert(xmlNode); } #endregion create destination #region read & add packages if (xmlNode.Name.Equals(XmlMapperTags.packages.ToString())) { foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode.Name.Equals(XmlMapperTags.package.ToString())) { xmlMappingHeader.AddToPackages(childNode); } } } #endregion read & add packages #region read & add Attributes if (xmlNode.Name.Equals(XmlMapperTags.attributes.ToString())) { foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode.Name.Equals(XmlMapperTags.attribute.ToString())) { xmlMappingHeader.AddToAttributes(childNode); } } } #endregion read & add Attributes #region read & add schemas if (xmlNode.Name.Equals(XmlMapperTags.schema.ToString())) { xmlMappingHeader.AddToSchemas(xmlNode); } #endregion read & add schemas } } xmlMapper.Header = xmlMappingHeader; #endregion create Header as xmlMappingHeader #region create Routes XmlNodeList routes = mappingFile.GetElementsByTagName(XmlMapperTags.routes.ToString())[0].ChildNodes; foreach (XmlNode childNode in routes) { xmlMapper.Routes.Add(XmlMappingRoute.Convert(childNode)); } #endregion create Routes #region xmlschema xmlSchemaManager = new XmlSchemaManager(); if (xmlMapper.Header.Schemas.Count > 0) { xmlSchemaManager = new XmlSchemaManager(); string schemaPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), xmlMapper.Header.Schemas.First().Value); xmlSchemaManager.Load(schemaPath, username); } #endregion xmlschema return(xmlMapper); }