Beispiel #1
0
 public XmlSchemaManager()
 {
     Elements = new List<XmlSchemaElement>();
     RefElementNames = new List<string>();
     ComplexTypes = new List<XmlSchemaComplexType>();
     ComplexTypesWithSimpleTypesAsChildrens = new List<XmlSchemaComplexType>();
     SimpleTypes = new List<XmlSchemaSimpleType>();
     MetadataAttributes = new List<MetadataAttribute>();
     ConvertedSimpleTypes = new Dictionary<string, List<Constraint>>();
     Groups = new List<XmlSchemaGroup>();
     Attributes = new List<XmlSchemaAttribute>();
     xsdFileName = "";
     additionalFiles = new List<string>();
     mappingFileInternalToExternal = new XmlMapper();
     mappingFileExternalToInternal = new XmlMapper();
     createdAttributesDic = new Dictionary<long, string>();
     createdCompoundsDic = new Dictionary<long, string>();
     createdPackagesDic = new Dictionary<long, string>();
 }
Beispiel #2
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;
        }
Beispiel #3
0
        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;
        }
Beispiel #4
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

            #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

                    #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

                    #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

                    #region read & add schemas

                    if (xmlNode.Name.Equals(XmlMapperTags.schema.ToString()))
                    {
                        xmlMappingHeader.AddToSchemas(xmlNode);
                    }

                    #endregion
                }
            }

            xmlMapper.Header = xmlMappingHeader;

            #endregion

            #region create Routes

            XmlNodeList routes = mappingFile.GetElementsByTagName(XmlMapperTags.routes.ToString())[0].ChildNodes;
            foreach (XmlNode childNode in routes)
            {
                xmlMapper.Routes.Add(XmlMappingRoute.Convert(childNode));
            }

            #endregion

            #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

            return xmlMapper;
        }