Beispiel #1
0
        private XmlDocument mapNode(XmlDocument destinationDoc, XmlNode destinationParentNode, XmlNode sourceNode)
        {
            try
            {
                // load the xpath from source node
                // x[1]\y[2]\f[1]
                string sourceXPath = XmlUtility.GetDirectXPathToNode(sourceNode);
                // x\y\f
                string sourceXMppingFilePath = XmlUtility.GetXPathToNode(sourceNode);

                //load route from mappingFile of the source node
                XmlMappingRoute route = xmlMapper.GetRoute(sourceXMppingFilePath);

                XmlNode destinationPNode = destinationParentNode;

                // check if this source xpath is mapped in the xmlMapper
                if (xmlMapper.SourceExist(sourceXMppingFilePath))
                {
                    if (!string.IsNullOrEmpty(sourceNode.InnerText) || addAlsoEmptyNode)
                    {
                        // get name of the destination node
                        string destinationTagName = route.GetDestinationTagNames();

                        // get xpath of the destination node
                        // X\XType\Y\F
                        string destinationXMppingFilePath = route.GetDestinationXPath();

                        //ToDo checkif the way to map is intern to extern or extern to intern
                        // X[1]\XType[2]\Y[1]\yType[4]\F[1]\yType[2]
                        string destinationXPath = "";

                        if (this.TransactionDirection == TransactionDirection.ExternToIntern)
                        {
                            destinationXPath = mapExternPathToInternPathWithIndex(sourceXPath, destinationXMppingFilePath);
                        }
                        else
                        {
                            destinationXPath = mapInternPathToExternPathWithIndex(sourceXPath, destinationXMppingFilePath);
                        }

                        // create xmlnode in document

                        XmlNode destinationNode = XmlUtility.GenerateNodeFromXPath(destinationDoc, destinationDoc as XmlNode,
                                                                                   destinationXPath, xmlSchemaManager.Elements, xmlSchemaManager.XmlNamespaceManager); //XmlUtility.CreateNode(destinationTagName, destinationDoc);
                        destinationNode.InnerText = sourceNode.InnerText;

                        //if (type == element), get content
                        if (xmlMapper.IsSourceElement(sourceXPath))
                        {
                        }

                        //destinationParentNode = createMissingNodes(destinationParentXPath, currentParentXPath, destinationParentNode, destinationDoc);

                        ////check if nodes in destination not exist, create them
                        //string destinationParentXPath = route.GetDestinationParentXPath();
                        //string currentParentXPath = XmlUtility.GetDirectXPathToNode(destinationParentNode);
                    }
                }

                if (sourceNode.HasChildNodes)
                {
                    foreach (XmlNode childNode in sourceNode.ChildNodes)
                    {
                        destinationDoc = mapNode(destinationDoc, destinationPNode, childNode);
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }

            return(destinationDoc);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        private XmlMapper addToImportMappingFile(XmlMapper mapper, string sourceXPath, string destinationXPath, decimal max, string name, string nameType)
        {
            string parentExternalName = destinationXPath.Split('/').Last();
            string childSourceXPath = sourceXPath + "/" + name;
            string childDestinationXPath = destinationXPath + "/" + name+ "/" + nameType;

            XmlMappingRoute xmr = new XmlMappingRoute();

            xmr.Source = new Source(childSourceXPath);

            string sequence = parentExternalName;
            if (max > 1)
            {
                sequence = nameType;
            }

            xmr.Destination = new Destination(childDestinationXPath, sequence);

            mapper.Routes.Add(xmr);

            return mapper;
        }