BExIS.Xml.Helpers.Mapping.XmlSchemaManager.generateXmlMappingFile C# (CSharp) Метод

generateXmlMappingFile() приватный Метод

private generateXmlMappingFile ( XmlMapper mapperInfos, string sourceName, string DestinationName, int direction ) : XmlDocument
mapperInfos BExIS.Xml.Models.Mapping.XmlMapper
sourceName string
DestinationName string
direction int
Результат System.Xml.XmlDocument
        private XmlDocument generateXmlMappingFile(XmlMapper mapperInfos,string sourceName, string DestinationName,  int direction = 0)
        {
            XmlDocument mappingFile = new XmlDocument();

            // create root
            XmlNode root = XmlUtility.CreateNode("mapping", mappingFile);
            root = XmlUtility.AddAttribute(root, "name", SchemaName, mappingFile);
            mappingFile.AppendChild(root);

            //  create header

            XmlNode header = XmlUtility.CreateNode("header", mappingFile);
            XmlMappingHeader xmlMapperheader = mapperInfos.Header;

                // create destination

                XmlNode destination = XmlUtility.CreateNode("destination", mappingFile);

                if (xmlMapperheader.Destination !=null)
                {
                    destination = XmlUtility.AddAttribute(destination, "namespaceUri", xmlMapperheader.Destination.NamepsaceURI, mappingFile);
                    destination = XmlUtility.AddAttribute(destination, "prefix", xmlMapperheader.Destination.Prefix, mappingFile);
                    destination = XmlUtility.AddAttribute(destination, "sequence", xmlMapperheader.Destination.ParentSequence, mappingFile);
                    destination = XmlUtility.AddAttribute(destination, "xPath", xmlMapperheader.Destination.XPath, mappingFile);
                }
                header.AppendChild(destination);

                // create attributes
                XmlNode attributes = XmlUtility.CreateNode("attributes", mappingFile);

                if (mapperInfos.Header.Attributes.Count > 0)
                {
                    foreach (var attr in mapperInfos.Header.Attributes)
                    {
                        XmlNode attribute = XmlUtility.CreateNode("attribute", mappingFile);
                        attribute = XmlUtility.AddAttribute(attribute, "name", attr.Key, mappingFile);
                        attribute = XmlUtility.AddAttribute(attribute, "value", attr.Value, mappingFile);

                        attributes.AppendChild(attribute);
                    }
                }

                header.AppendChild(attributes);

                // create packages
                XmlNode packages = XmlUtility.CreateNode("packages", mappingFile);

                if (mapperInfos.Header.Packages.Count > 0)
                {
                    foreach (var pack in mapperInfos.Header.Packages)
                    {
                        XmlNode package = XmlUtility.CreateNode("package", mappingFile);
                        package = XmlUtility.AddAttribute(package, "abbreviation", pack.Key, mappingFile);
                        package = XmlUtility.AddAttribute(package, "url", pack.Value, mappingFile);

                        packages.AppendChild(package);
                    }
                }
                header.AppendChild(packages);

                // create schema

                if (mapperInfos.Header.Schemas.Count > 0)
                {
                    foreach (var s in mapperInfos.Header.Schemas)
                    {
                        XmlNode schema = XmlUtility.CreateNode("schema", mappingFile);
                        schema = XmlUtility.AddAttribute(schema, "abbreviation", s.Key, mappingFile);
                        schema = XmlUtility.AddAttribute(schema, "url", s.Value, mappingFile);

                        header.AppendChild(schema);
                    }
                }

             root.AppendChild(header);

            // create routes

            XmlNode routes = XmlUtility.CreateNode("routes", mappingFile);

            if (mapperInfos.Routes.Count > 0)
            {
                foreach (XmlMappingRoute mapRoute in mapperInfos.Routes)
                {
                    // create route
                    XmlNode route = XmlUtility.CreateNode("route", mappingFile);

                    // create source
                    XmlNode Source = XmlUtility.CreateNode("source", mappingFile);
                    Source = XmlUtility.AddAttribute(Source, "xPath", mapRoute.Source.XPath, mappingFile);

                    route.AppendChild(Source);
                    // create destination
                    XmlNode Destination = XmlUtility.CreateNode("destination", mappingFile);
                    Destination = XmlUtility.AddAttribute(Destination, "xPath", mapRoute.Destination.XPath, mappingFile);
                    Destination = XmlUtility.AddAttribute(Destination, "sequence", mapRoute.Destination.ParentSequence, mappingFile);

                    route.AppendChild(Destination);
                    routes.AppendChild(route);
                }
            }

            root.AppendChild(routes);

            if (direction == 0)
            {
                mappingFileNameExport = "MappingFile_intern_" + sourceName + "_to_extern_" + DestinationName +".xml";
                mappingFile.Save(Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), mappingFileNameExport));
            }
            else
            {
                mappingFileNameImport = "MappingFile_extern_" + sourceName + "_to_intern_" + DestinationName + ".xml";
                mappingFile.Save(Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), mappingFileNameImport));
            }

            return mappingFile;
        }