예제 #1
0
        static void AddOrUpdateSelectedAttribute(XmlAttribute attr, XmlNode menuItem)
        {
            var existingAttribute = menuItem.Attributes[attr.Name];

            if (existingAttribute == null)
            {
                menuItem.Attributes.Append((XmlAttribute)attr.CloneNode(false));
            }
            else
            {
                existingAttribute.Value += " " + attr.Value;
            }
        }
예제 #2
0
        public void Translate(string operationName, string operationNS, bool isInput)
        {
            elem.ParentNode.InsertBefore(elem.OwnerDocument.CreateComment(elem.OuterXml), elem);
            XmlElement schemaElem = (XmlElement)elem.OwnerDocument.SelectSingleNode("wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='" + operationNS + "']", nsmgr);

            if (schemaElem == null)
            {
                XmlElement typesElem = (XmlElement)elem.OwnerDocument.SelectSingleNode("wsdl:definitions/wsdl:types", nsmgr);
                if (typesElem == null)
                {
                    throw new Rpc2DocumentLiteralTranslationException("<wsdl:types> not found.");
                }
                schemaElem = typesElem.OwnerDocument.CreateElement("xsd", "schema", "http://www.w3.org/2001/XMLSchema");
                schemaElem.Attributes.Append(typesElem.OwnerDocument.CreateAttribute("targetNamespace"));
                schemaElem.Attributes["targetNamespace"].Value = operationNS;
                typesElem.AppendChild(schemaElem);
            }

            string        targetNamespace         = schemaElem.Attributes["targetNamespace"].Value;
            string        targetNamespacePrefix   = "r2dtns";
            StringBuilder targetNamespacePrefixSb = new StringBuilder(targetNamespacePrefix);
            XmlAttribute  tnsAttr = schemaElem.Attributes[targetNamespacePrefix];

            while (tnsAttr != null)
            {
                if (tnsAttr.Value != targetNamespace)
                {
                    //targetNamespacePrefix += "x";
                    targetNamespacePrefixSb.Append("x");
                    tnsAttr = schemaElem.Attributes[targetNamespacePrefixSb.ToString()];
                }
            }

            targetNamespacePrefix = targetNamespacePrefixSb.ToString();

            if (tnsAttr == null)
            {
                tnsAttr       = schemaElem.OwnerDocument.CreateAttribute("xmlns:" + targetNamespacePrefix);
                tnsAttr.Value = targetNamespace;
                schemaElem.Attributes.Append(tnsAttr);
            }

            XmlElement   elemElem      = elem.OwnerDocument.CreateElement("xsd", "element", "http://www.w3.org/2001/XMLSchema");
            XmlElement   typeElem      = elem.OwnerDocument.CreateElement("xsd", "complexType", "http://www.w3.org/2001/XMLSchema");
            XmlAttribute nameAttribute = typeElem.OwnerDocument.CreateAttribute("name");
            XmlAttribute typeAttribute = typeElem.OwnerDocument.CreateAttribute("type");

            nameAttribute.Value = GetSchemaElementName(operationName, isInput);

            typeAttribute.Value = targetNamespacePrefix + ":" + nameAttribute.Value;

            typeElem.Attributes.Append(nameAttribute);
            elemElem.Attributes.Append((XmlAttribute)nameAttribute.CloneNode(true));
            elemElem.Attributes.Append(typeAttribute);
            schemaElem.InsertBefore(elemElem, schemaElem.FirstChild);
            schemaElem.InsertAfter(typeElem, elemElem);
            XmlElement sequenceElem = elem.OwnerDocument.CreateElement("xsd", "sequence", "http://www.w3.org/2001/XMLSchema");

            typeElem.InsertBefore(sequenceElem, typeElem.FirstChild);
            schemaElem.InsertBefore(elem.OwnerDocument.CreateComment("Begin of generated message type"), elemElem);
            schemaElem.InsertAfter(elem.OwnerDocument.CreateComment("End of generated message type"), typeElem);

            XmlElement part = (XmlElement)elem.FirstChild;

            foreach (R2DType p in parameters)
            {
                p.Translate(sequenceElem, part.Attributes["name"].Value, targetNamespacePrefix);
                part = (XmlElement)part.NextSibling;
            }

            XmlNode n = elem.LastChild;

            while (n != null)
            {
                XmlNode toDelete = n;
                n = n.PreviousSibling;
                elem.RemoveChild(toDelete);
            }

            XmlElement paramElem = elem.OwnerDocument.CreateElement("wsdl", "part", "http://schemas.xmlsoap.org/wsdl/");

            elem.AppendChild(paramElem);
            XmlAttribute typeNsAttr = elem.OwnerDocument.CreateAttribute("xmlns:typens");

            typeNsAttr.Value = targetNamespace;
            elem.Attributes.Append(typeNsAttr);
            paramElem.Attributes.Append(paramElem.OwnerDocument.CreateAttribute("", "name", ""));
            paramElem.Attributes["name"].Value = "parameter";
            paramElem.Attributes.Append(paramElem.OwnerDocument.CreateAttribute("", "element", ""));
            paramElem.Attributes["element"].Value = "typens:" + GetSchemaElementName(operationName, isInput);
        }
예제 #3
0
        public MGParamParser(Stream xmlInput)
        {
            this.xmlInput = xmlInput;
            try
            {
                XmlNodeList temp;
                IEnumerator nodeEnum;

                // Make document out of stream

                // Begin by adding schema
                Assembly            thisAssm              = Assembly.GetExecutingAssembly();
                Stream              xmlInputSchema        = thisAssm.GetManifestResourceStream("inputSchema");
                XmlSchemaCollection myXmlSchemaCollection = new XmlSchemaCollection();
                myXmlSchemaCollection.Add(null, new XmlTextReader(xmlInputSchema));

                // Then validate file (validation fills in defaults)
                XmlTextReader       myXmlTextReader       = new XmlTextReader(xmlInput);
                XmlValidatingReader myXmlValidatingReader = new XmlValidatingReader(myXmlTextReader);
                myXmlValidatingReader.Schemas.Add(myXmlSchemaCollection);
                myXmlValidatingReader.ValidationType = ValidationType.Schema;

                this.paramInput = new XmlDocument();
                paramInput.Load(myXmlValidatingReader);

                // Extract nodes we care about
                temp = paramInput.GetElementsByTagName("assemblyIdentity");
                if (temp.Count != 1)
                {
                    throw new MGParseErrorException("XML parameters should only have 1 assemblyIdentity element");
                }
                else
                {
                    nodeEnum = temp.GetEnumerator();
                    nodeEnum.MoveNext();
                    assmIDNode = (XmlNode)nodeEnum.Current;
                }

                temp = paramInput.GetElementsByTagName("description");
                if (temp.Count != 1)
                {
                    throw new MGParseErrorException("XML parameters should only have 1 description element");
                }
                else
                {
                    nodeEnum = temp.GetEnumerator();
                    nodeEnum.MoveNext();
                    descNode = (XmlNode)nodeEnum.Current;
                }

                temp = paramInput.GetElementsByTagName("applicationParams");
                if (temp.Count != 1)
                {
                    throw new MGParseErrorException("XML parameters should only have 1 applicationParams element");
                }
                else
                {
                    nodeEnum = temp.GetEnumerator();
                    nodeEnum.MoveNext();
                    appNode = (XmlNode)nodeEnum.Current;
                }

                temp = paramInput.GetElementsByTagName("subscriptionParams");
                if (temp.Count != 1)
                {
                    throw new MGParseErrorException("XML parameters should only have 1 subscriptionParams element");
                }
                else
                {
                    nodeEnum = temp.GetEnumerator();
                    nodeEnum.MoveNext();
                    subNode = (XmlNode)nodeEnum.Current;
                }

                temp = paramInput.GetElementsByTagName("platformParams");
                if (temp.Count > 1)
                {
                    throw new MGParseErrorException("XML parameters should have at most 1 platformParams element");
                }
                else if (temp.Count == 1)
                {
                    nodeEnum = temp.GetEnumerator();
                    nodeEnum.MoveNext();
                    platNode = (XmlNode)nodeEnum.Current;
                }

                // Extract application name
                appName = assmIDNode.Attributes["name"].Value;

                // Set up specialized assembly ID nodes
                appAssmIDNode = assmIDNode.Clone();
                subAssmIDNode = assmIDNode.Clone();

                XmlAttribute typeAttr1 = paramInput.CreateAttribute("type");
                XmlAttribute typeAttr2 = (XmlAttribute)typeAttr1.CloneNode(true);
                typeAttr1.Value = "application";
                appAssmIDNode.Attributes.Prepend(typeAttr1);
                typeAttr2.Value = "subscription";
                subAssmIDNode.Attributes.Prepend(typeAttr2);
            }
            catch (XmlException xmle)
            {
                throw new MGParseErrorException("XML parameter parsing failed", xmle);
            }
            catch (XmlSchemaException xmlse)
            {
                throw new MGParseErrorException("XML parameter validation failed", xmlse);
            }
        }