Exemple #1
0
        /// <summary>
        /// Creates the schema type representing the node type
        /// </summary>
        /// <returns>Type definition for a node</returns>
        static XmlSchemaType CreateNodeType(Dictionary <string, XmlSchemaComplexType> TaskNameToType)
        {
            XmlSchemaChoice NodeChoice = new XmlSchemaChoice();

            NodeChoice.MinOccurs       = 0;
            NodeChoice.MaxOccursString = "unbounded";
            NodeChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
            NodeChoice.Items.Add(CreateSchemaElement("Local", ScriptSchemaStandardType.Local));
            NodeChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
            NodeChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
            foreach (KeyValuePair <string, XmlSchemaComplexType> Pair in TaskNameToType.OrderBy(x => x.Key))
            {
                NodeChoice.Items.Add(CreateSchemaElement(Pair.Key, new XmlQualifiedName(Pair.Value.Name, NamespaceURI)));
            }

            XmlSchemaComplexType NodeType = new XmlSchemaComplexType();

            NodeType.Name     = GetTypeName(ScriptSchemaStandardType.Node);
            NodeType.Particle = NodeChoice;
            NodeType.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.Name, XmlSchemaUse.Required));
            NodeType.Attributes.Add(CreateSchemaAttribute("Requires", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional));
            NodeType.Attributes.Add(CreateSchemaAttribute("Produces", ScriptSchemaStandardType.TagList, XmlSchemaUse.Optional));
            NodeType.Attributes.Add(CreateSchemaAttribute("After", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional));
            NodeType.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));
            return(NodeType);
        }
        private XmlSchemaParticle GetSchemaArrayElement(XmlSchema currentSchema, XmlTypeMapElementInfoList infos)
        {
            int num = infos.Count;

            if (num > 0 && ((XmlTypeMapElementInfo)infos[0]).IsTextElement)
            {
                num--;
            }
            if (num == 0)
            {
                return(null);
            }
            if (num == 1)
            {
                XmlSchemaParticle schemaElement = this.GetSchemaElement(currentSchema, (XmlTypeMapElementInfo)infos[infos.Count - 1], true);
                schemaElement.MinOccursString = "0";
                schemaElement.MaxOccursString = "unbounded";
                return(schemaElement);
            }
            XmlSchemaChoice xmlSchemaChoice = new XmlSchemaChoice();

            xmlSchemaChoice.MinOccursString = "0";
            xmlSchemaChoice.MaxOccursString = "unbounded";
            foreach (object obj in infos)
            {
                XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)obj;
                if (!xmlTypeMapElementInfo.IsTextElement)
                {
                    xmlSchemaChoice.Items.Add(this.GetSchemaElement(currentSchema, xmlTypeMapElementInfo, true));
                }
            }
            return(xmlSchemaChoice);
        }
Exemple #3
0
        /// <summary>
        /// Creates the schema type representing the body of the node type
        /// </summary>
        /// <returns>Type definition for a node</returns>
        static XmlSchemaType CreateNodeBodyType(Dictionary <string, XmlSchemaComplexType> TaskNameToType)
        {
            XmlSchemaChoice NodeChoice = new XmlSchemaChoice();

            NodeChoice.MinOccurs       = 0;
            NodeChoice.MaxOccursString = "unbounded";
            NodeChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
            NodeChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
            NodeChoice.Items.Add(CreateSchemaElement("Trace", ScriptSchemaStandardType.Trace));
            NodeChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
            NodeChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
            NodeChoice.Items.Add(CreateSchemaElement("Expand", ScriptSchemaStandardType.Expand));
            NodeChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.NodeBody));
            NodeChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.NodeBody));
            NodeChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.NodeBody));
            foreach (KeyValuePair <string, XmlSchemaComplexType> Pair in TaskNameToType.OrderBy(x => x.Key))
            {
                NodeChoice.Items.Add(CreateSchemaElement(Pair.Key, new XmlQualifiedName(Pair.Value.Name, NamespaceURI)));
            }

            XmlSchemaComplexType NodeType = new XmlSchemaComplexType();

            NodeType.Name     = GetTypeName(ScriptSchemaStandardType.NodeBody);
            NodeType.Particle = NodeChoice;
            return(NodeType);
        }
 void Parse_ChoiceContent(TreeNode inner, string ns, XmlSchemaChoice choice, bool multiValue)
 {
     foreach (XmlSchemaObject item in choice.Items)
     {
         Add_Item(inner, ns, item, multiValue);
     }
 }
Exemple #5
0
 void WriteChoiceContent(XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
 {
     foreach (XmlSchemaObject item in choice.Items)
     {
         WriteContentItem(xtw, ns, item, multiValue);
     }
 }
Exemple #6
0
        /// <summary>
        /// Creates the schema type representing the graph type
        /// </summary>
        /// <returns>Type definition for a graph</returns>
        static XmlSchemaType CreateGraphType()
        {
            XmlSchemaChoice GraphChoice = new XmlSchemaChoice();

            GraphChoice.MinOccurs       = 0;
            GraphChoice.MaxOccursString = "unbounded";
            GraphChoice.Items.Add(CreateSchemaElement("Include", ScriptSchemaStandardType.Include));
            GraphChoice.Items.Add(CreateSchemaElement("Option", ScriptSchemaStandardType.Option));
            GraphChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
            GraphChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
            GraphChoice.Items.Add(CreateSchemaElement("Agent", ScriptSchemaStandardType.Agent));
            GraphChoice.Items.Add(CreateSchemaElement("Trigger", ScriptSchemaStandardType.Trigger));
            GraphChoice.Items.Add(CreateSchemaElement("Aggregate", ScriptSchemaStandardType.Aggregate));
            GraphChoice.Items.Add(CreateSchemaElement("Report", ScriptSchemaStandardType.Report));
            GraphChoice.Items.Add(CreateSchemaElement("Badge", ScriptSchemaStandardType.Badge));
            GraphChoice.Items.Add(CreateSchemaElement("Notify", ScriptSchemaStandardType.Notify));
            GraphChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
            GraphChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
            GraphChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.Graph));
            GraphChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.Graph));
            GraphChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.Graph));
            XmlSchemaComplexType GraphType = new XmlSchemaComplexType();

            GraphType.Name     = GetTypeName(ScriptSchemaStandardType.Graph);
            GraphType.Particle = GraphChoice;
            return(GraphType);
        }
        void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns)
        {
            if (accessors.Length == 0)
            {
                return;
            }
            if (accessors.Length == 1)
            {
                ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns);
            }
            else
            {
                XmlSchemaChoice choice = new XmlSchemaChoice();
                choice.MaxOccurs = repeats ? decimal.MaxValue : 1;
                choice.MinOccurs = repeats ? 0 : 1;
                for (int i = 0; i < accessors.Length; i++)
                {
                    ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns);
                }

                if (choice.Items.Count > 0)
                {
                    group.Items.Add(choice);
                }
            }
        }
Exemple #8
0
        private void GetChildElements(XmlSchemaChoice choice, List <string> resultElements)
        {
            if (choice == null)
            {
                return;
            }

            foreach (var c in choice.Items)
            {
                var xse = c as XmlSchemaElement;
                if (xse != null)
                {
                    var name = xse.RefName.Name;
                    if (!string.IsNullOrEmpty(name))
                    {
                        if (char.IsUpper(name, 0))
                        {
                            resultElements.Add(name);
                        }
                        else if (name.StartsWith("sg"))
                        {
                            resultElements.Add(name.Substring(2));
                        }
                    }

                    continue;
                }

                var xsgr = c as XmlSchemaChoice;
                if (xsgr != null)
                {
                    GetChildElements(xsgr, resultElements);
                }
            }
        }
        private static XmlSchemaObject NavigateSchema(XmlSchemaObject navigationObject, XmlQualifiedName xmlQualifiedName)
        {
            XmlSchemaElement parentElement = navigationObject as XmlSchemaElement;

            if (parentElement.SchemaTypeName == XmlQualifiedName.Empty)
            {
                if (parentElement.SchemaType is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType xmlSchemaComplexType = parentElement.SchemaType as XmlSchemaComplexType;
                    if (xmlSchemaComplexType.Particle is XmlSchemaChoice)
                    {
                        XmlSchemaChoice xmlSchemaChoice = xmlSchemaComplexType.Particle as XmlSchemaChoice;
                        foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaChoice.Items)
                        {
                            if (xmlSchemaObject is XmlSchemaElement)
                            {
                                XmlSchemaElement xmlSchemaElement = xmlSchemaObject as XmlSchemaElement;
                                if (xmlSchemaElement.QualifiedName == xmlQualifiedName)
                                {
                                    return(xmlSchemaElement);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemple #10
0
        public static string GetChoiceCommonName(XmlSchemaChoice choice, string ns)
        {
            // TODO: Handle possibility of multiple <xsd:choice> within a single sequence. Name the element differently accordingly.
            List <string[]> choiceWords = GetXmlChoiceNameWords(choice);

            return(GetChoiceCommonName(choiceWords, ns));
        }
        static void AddProperty(ICctsProperty property, XmlSchemaSequence propertiesSequence, GeneratorContext context, XmlSchema schema, List <ICctsProperty> processedProperties)
        {
            var elementProperty = CreatePropertyElement(property, context, schema);

            if (property.otherPropertiesInChoice.Any())
            {
                var choiceElement = new XmlSchemaChoice();
                choiceElement.Items.Add(elementProperty);
                bool isOptional = property.LowerBound == "0";
                foreach (var otherProperty in property.otherPropertiesInChoice)
                {
                    if (!isOptional)
                    {
                        isOptional = otherProperty.LowerBound == "0";
                    }
                    choiceElement.Items.Add(CreatePropertyElement(otherProperty, context, schema));
                    processedProperties.Add(otherProperty);
                }
                //set minoccurs to 0 is the choice is optional
                if (isOptional)
                {
                    choiceElement.MinOccurs = 0;
                }
                //add the choice tot the sequence
                propertiesSequence.Items.Add(choiceElement);
            }
            else
            {
                // add the element created to the sequence
                propertiesSequence.Items.Add(elementProperty);
            }
            // add the property to the list of processed properties
            processedProperties.Add(property);
        }
 protected virtual void Visit(XmlSchemaChoice particle)
 {
     if (particle.MaxOccurs > 0)
     {
         Traverse(particle.Items);
     }
 }
Exemple #13
0
            private void SetChoiceName(XmlSchemaChoice schemaChoice)
            {
                // See if the schema defines the name of the choice element
                if (schemaChoice.Annotation != null)
                {
                    this.Name = GetChoiceAppInfoText(schemaChoice.Annotation);
                }
                else if (schemaChoice.Items.Count > 0 && ((XmlSchemaChoice)schemaChoice.Items[0].Parent).Annotation != null)
                {
                    // Weird bug in System.Xml.Schema where annotations stored in the schema are reflected by the children's parent,
                    // and are never directly on schemaChoice.Annotation
                    this.Name = GetChoiceAppInfoText(((XmlSchemaChoice)schemaChoice.Items[0].Parent).Annotation);
                }

                if (!string.IsNullOrEmpty(this.Name))
                {
                    return;
                }

                this.Name = Shared.Helper.GetChoiceCommonName(schemaChoice, this.SimpleSchema.Schema.TargetNamespace);

                // Save the choice name to the schema
                XmlSchemaAppInfo newAppInfo = new XmlSchemaAppInfo();

                newAppInfo.Source = SimpleSchema.SchemaChoiceAppInfoUri;
                newAppInfo.Markup = new XmlNode[] { new XmlDocument().CreateTextNode(this.Name) };

                if (schemaChoice.Annotation == null)
                {
                    schemaChoice.Annotation = new XmlSchemaAnnotation();
                }

                schemaChoice.Annotation.Items.Add(newAppInfo);
            }
Exemple #14
0
            public void InitializeChoice(XmlSchemaChoice schemaChoice)
            {
                this.IsChoice = true;

                // Name
                this.SetChoiceName(schemaChoice);

                // Cardinality
                string minOccurs = schemaChoice.MinOccurs.ToString();
                string maxOccurs = schemaChoice.MaxOccurs.ToString();

                this.Cardinality = string.Format("{0}..{1}",
                                                 minOccurs != "79228162514264337593543950335" ? minOccurs : "*",
                                                 maxOccurs != "79228162514264337593543950335" ? maxOccurs : "*");

                // Conformance (default based on cardinality)
                if (this.Cardinality == "0..0")
                {
                    this.Conformance = "SHALL NOT";
                }
                else if (this.Cardinality.StartsWith("0.."))
                {
                    this.Conformance = "MAY";
                }
                else if (this.Cardinality.StartsWith("1.."))
                {
                    this.Conformance = "SHALL";
                }
            }
Exemple #15
0
        /**//// <summary>
            /// 获理节点
            /// </summary>
            /// <returns></returns>
        public static System.Collections.Generic.List <XmlSchemaElement> GetDatas()
        {
            XmlSchemaSet xsSet = new XmlSchemaSet();

            xsSet.Add("", GetSchemaPath);
            xsSet.Compile();
            XmlSchema schema = null;

            foreach (XmlSchema xs in xsSet.Schemas())
            {
                schema = xs;
            }
            System.Collections.Generic.List <XmlSchemaElement> elements = new System.Collections.Generic.List <XmlSchemaElement>();
            foreach (XmlSchemaObject obj in schema.Elements.Values)
            {
                if (obj.GetType() == typeof(XmlSchemaElement))
                {
                    elements.Add((XmlSchemaElement)obj);
                }
            }
            return(elements);
        }

        /**//// <summary>
            /// 添加元素
            /// </summary>
            /// <param name="sourceXsd"></param>
            /// <param name="titles"></param>
            /// <param name="sourceXml"></param>
            /// <param name="sourceNd"></param>
            /// <param name="values"></param>
        public static void AddElement(XmlSchemaObject sourceXsd, Hashtable titles, XmlDocument sourceXml, XmlNode sourceNd, string[] values)
        {
            if (sourceXsd.GetType() == typeof(XmlSchemaChoice))
            {
                XmlSchemaChoice choice = sourceXsd as XmlSchemaChoice;
                decimal         min    = choice.MinOccurs;
                foreach (XmlSchemaObject item in choice.Items)
                {
                    if (item.GetType() == typeof(XmlSchemaElement))
                    {
                        string name = ((XmlSchemaElement)item).Name;
                        if (titles.ContainsKey(name))
                        {
                            XmlElement element = sourceXml.CreateElement(name);
                            // element.InnerText = ((Excel.Range)st.Cells[rowIndex, (int)titles[name]]).Value2.ToString();
                            element.InnerText = values[(int)titles[name]];
                            sourceNd.AppendChild(element);
                        }
                    }
                    else
                    {
                        AddElement(item, titles, sourceXml, sourceNd, values);
                    }
                }
            }
            else if (sourceXsd.GetType() == typeof(XmlSchemaElement))
            {
                string name = ((XmlSchemaElement)sourceXsd).Name;
                if (titles.ContainsKey(name))
                {
                    XmlElement element = sourceXml.CreateElement(name);
                    element.InnerText = values[(int)titles[name]];
                    sourceNd.AppendChild(element);
                }
            }
            else if (sourceXsd.GetType() == typeof(XmlSchemaSequence))
            {
                foreach (XmlSchemaObject childItem in ((XmlSchemaSequence)sourceXsd).Items)
                {
                    if (childItem.GetType() == typeof(XmlSchemaElement))
                    {
                        string name = ((XmlSchemaElement)childItem).Name;
                        if (titles.ContainsKey(name))
                        {
                            XmlElement element = sourceXml.CreateElement(name);
                            element.InnerText = values[(int)titles[name]];
                            sourceNd.AppendChild(element);
                        }
                    }
                    else
                    {
                        AddElement(childItem, titles, sourceXml, sourceNd, values);
                    }
                }
            }
            else
            {
                return;
            }
        }
 private XmlSchemaChoice GetSubstitutionChoice(XmlSchemaElement element)
 {
     if (substitutionGroupsTable == null)
     {
         BuildSubstitutionGroups();
     }
     if (substitutionGroupsTable != null)
     {
         SubstitutionGroupWrapper substitutionGroup = (SubstitutionGroupWrapper)substitutionGroupsTable[element.QualifiedName];
         if (substitutionGroup != null)   //Element is head of a substitutionGroup
         {
             XmlSchemaChoice choice = new XmlSchemaChoice();
             foreach (XmlSchemaElement elem in substitutionGroup.Members)
             {
                 choice.Items.Add(elem);
             }
             XmlSchemaElement headElement = (XmlSchemaElement)schemaSet.GlobalElements[element.QualifiedName];
             if (headElement.IsAbstract)   //Should not generate the abstract element
             {
                 choice.Items.Remove(headElement);
             }
             choice.MinOccurs = element.MinOccurs;
             choice.MaxOccurs = element.MaxOccurs;
             return(choice);
         }
     }
     return(null);
 }
 private void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns)
 {
     if (accessors.Length != 0)
     {
         if (accessors.Length == 1)
         {
             this.ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns);
         }
         else
         {
             XmlSchemaChoice choice = new XmlSchemaChoice {
                 MaxOccurs = repeats ? 79228162514264337593543950335M : 1M,
                 MinOccurs = repeats ? 0 : 1
             };
             for (int i = 0; i < accessors.Length; i++)
             {
                 this.ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns);
             }
             if (choice.Items.Count > 0)
             {
                 group.Items.Add(choice);
             }
         }
     }
 }
        private void GenerateParticle(XmlSchemaParticle particle, bool root, InstanceGroup iGrp)
        {
            decimal max;

            max = particle.MaxOccurs >= maxThreshold ? maxThreshold : particle.MaxOccurs;
            max = particle.MinOccurs > max ? particle.MinOccurs : max;

            if (particle is XmlSchemaSequence)
            {
                XmlSchemaSequence seq = (XmlSchemaSequence)particle;
                InstanceGroup     grp = new InstanceGroup();
                grp.Occurs = max;
                iGrp.AddChild(grp);
                GenerateGroupBase(seq, grp);
            }
            else if (particle is XmlSchemaChoice)
            {
                XmlSchemaChoice ch = (XmlSchemaChoice)particle;
                if (ch.MaxOccurs == 1)
                {
                    XmlSchemaParticle pt = (XmlSchemaParticle)(ch.Items[0]);
                    GenerateParticle(pt, false, iGrp);
                }
                else
                {
                    InstanceGroup grp = new InstanceGroup();
                    grp.Occurs   = max;
                    grp.IsChoice = true;
                    iGrp.AddChild(grp);
                    GenerateGroupBase(ch, grp);
                }
            }
            else if (particle is XmlSchemaAll)
            {
                GenerateAll((XmlSchemaAll)particle, iGrp);
            }
            else if (particle is XmlSchemaElement)
            {
                XmlSchemaElement elem = particle as XmlSchemaElement;
                XmlSchemaChoice  ch   = null;
                if (!elem.RefName.IsEmpty)
                {
                    ch = GetSubstitutionChoice(elem);
                }
                if (ch != null)
                {
                    GenerateParticle(ch, false, iGrp);
                }
                else
                {
                    GenerateElement(elem, false, iGrp, null);
                }
            }
            else if (particle is XmlSchemaAny && particle.MinOccurs > 0)   //Generate any only if we should
            {
                GenerateAny((XmlSchemaAny)particle, iGrp);
            }
        }
Exemple #19
0
        /// <summary>
        /// Generates an XML Schema inside the WSDL containing a XmlChoice with the defined pins.
        /// This method was implemented in order to comply to the WSDL 1.1 Spec where only single input/output messages are allowed.
        /// </summary>
        /// <param name="pins">The incoming or outgoing pins of an action Element.</param>
        /// <param name="actionName">The name of the action Element.</param>
        /// <returns>An XML Schema to be used inside the final WSDL containing a XmlChoice element.</returns>
        private XmlSchema generateInnerXmlSchema(IEnumerable <Element> pins, string actionName)
        {
            var schema = new XmlSchema {
                TargetNamespace = "http://inline"
            };
            var i = 1;

            foreach (RetrievedMessage message in targetXSDs.Items)
            {
                if (!message.filePath.Equals(string.Empty))
                {
                    schema.Includes.Add(new XmlSchemaImport {
                        SchemaLocation = message.filePath, Namespace = message.targetNamespace
                    });
                    if (message.prefix.Equals(string.Empty))
                    {
                        message.prefix = "xsd" + i;
                    }
                    schema.Namespaces.Add(message.prefix, message.targetNamespace);

                    i++;
                }
            }

            var xmlSchemaElement = new XmlSchemaElement
            {
                Name =
                    removeWhiteSpaces(actionName) +
                    "Response"
            };
            var xmlSchemaComplexType = new XmlSchemaComplexType();
            var xmlSchemaChoice      = new XmlSchemaChoice();

            foreach (var pin in pins)
            {
                XmlSchemaElement xmlSchemaChoiceElement = null;
                foreach (RetrievedMessage message in targetXSDs.Items)
                {
                    if (message.messageName.Equals(removeWhiteSpaces(repo.GetElementByID(
                                                                         pin.ClassfierID).Name).Replace("Envelope", "")))
                    {
                        xmlSchemaChoiceElement = new XmlSchemaElement
                        {
                            RefName = new XmlQualifiedName(message.messageName, message.targetNamespace)
                        };
                    }
                }

                xmlSchemaChoice.Items.Add(xmlSchemaChoiceElement);
            }


            xmlSchemaComplexType.Particle = xmlSchemaChoice;
            xmlSchemaElement.SchemaType   = xmlSchemaComplexType;
            schema.Items.Add(xmlSchemaElement);
            return(schema);
        }
Exemple #20
0
        private void ProcessChoice(CompoundField compilerInfo, String ancestor, XmlSchemaChoice choice, uint index, uint cardinality)
        {
            //output.WriteLine(feed() + "Processing choice [{0}..{1}]", choice.MinOccurs, choice.MaxOccurs);
            if (choice.MaxOccurs > 1)
            {
                throw new XmlBinaryConverterException("MaxOccurs greater than 1 is not supported on choice nodes");
            }

            ProcessItemCollection(compilerInfo, ancestor, choice.Items, (uint)choice.MaxOccurs);
        }
Exemple #21
0
        /// <summary>
        /// Insert an element above an existing any item.
        /// </summary>
        /// <param name="particle">The particle in which the any item should be found.</param>
        /// <param name="element">The element to insert.</param>
        /// <returns>true if the element was inserted; false otherwise.</returns>
        private bool InsertElement(XmlSchemaParticle particle, XmlSchemaElement element)
        {
            if (particle is XmlSchemaChoice)
            {
                XmlSchemaChoice choice = (XmlSchemaChoice)particle;

                for (int i = 0; i < choice.Items.Count; i++)
                {
                    XmlSchemaParticle childParticle = (XmlSchemaParticle)choice.Items[i];

                    if (childParticle is XmlSchemaAny)
                    {
                        // index this any element for later removal
                        this.anys[childParticle] = choice;

                        choice.Items.Insert(i, element);
                        return(true);
                    }
                    else
                    {
                        if (this.InsertElement(childParticle, element))
                        {
                            return(true);
                        }
                    }
                }
            }
            else if (particle is XmlSchemaSequence)
            {
                XmlSchemaSequence sequence = (XmlSchemaSequence)particle;

                for (int i = 0; i < sequence.Items.Count; i++)
                {
                    XmlSchemaParticle childParticle = (XmlSchemaParticle)sequence.Items[i];

                    if (childParticle is XmlSchemaAny)
                    {
                        // index this any element for later removal
                        this.anys[childParticle] = sequence;

                        sequence.Items.Insert(i, element);
                        return(true);
                    }
                    else
                    {
                        if (this.InsertElement(childParticle, element))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemple #22
0
            protected XmlSchemaComplexType CreateTaskListComplexType(Type[] tasks, Type[] dataTypes, bool includeProjectLevelItems)
            {
                XmlSchemaComplexType tasklistCT = new XmlSchemaComplexType();
                XmlSchemaChoice      choice     = new XmlSchemaChoice();

                choice.MinOccurs       = 0;
                choice.MaxOccursString = "unbounded";

                tasklistCT.Particle = choice;

                foreach (Type t in tasks)
                {
                    XmlSchemaElement     taskElement = new XmlSchemaElement();
                    string               typeId      = GenerateIDFromType(t);
                    XmlSchemaComplexType taskCT      = FindComplexTypeByID(typeId);

                    taskElement.Name           = GetTaskName(t);
                    taskElement.SchemaTypeName = taskCT.QualifiedName;

                    choice.Items.Add(taskElement);
                }

                foreach (Type t in dataTypes)
                {
                    XmlSchemaElement     dataTypeElement = new XmlSchemaElement();
                    string               typeId          = GenerateIDFromType(t);
                    XmlSchemaComplexType dataTypeCT      = FindComplexTypeByID(typeId);

                    dataTypeElement.Name           = GetDataTypeName(t);
                    dataTypeElement.SchemaTypeName = dataTypeCT.QualifiedName;

                    choice.Items.Add(dataTypeElement);
                }

                if (includeProjectLevelItems)
                {
                    XmlSchemaElement targetElement = new XmlSchemaElement();

                    targetElement.Name           = "target";
                    targetElement.SchemaTypeName = _targetCT.QualifiedName;

                    choice.Items.Add(targetElement);
                }

                // allow elements from other namespaces
                XmlSchemaAny otherNamespaceAny = new XmlSchemaAny();

                otherNamespaceAny.MinOccurs       = 0;
                otherNamespaceAny.MaxOccurs       = Decimal.MaxValue;
                otherNamespaceAny.Namespace       = "##other";
                otherNamespaceAny.ProcessContents = XmlSchemaContentProcessing.Strict;
                choice.Items.Add(otherNamespaceAny);

                return(tasklistCT);
            }
Exemple #23
0
        public ChoicePanel(System.Xml.XmlNode renderingDocument, XmlSchemaChoice obj, XmlSchemaSet schemas, List <XmlNode> value)
        {
            this.renderingDocument = renderingDocument;
            this.obj     = obj;
            this.schemas = schemas;
            this.value   = value;

            this.BorderStyle = BorderStyle.Dashed;
            this.BorderColor = Color.FromArgb(167, 167, 167);
            this.BorderWidth = 1;
        }
Exemple #24
0
        protected override void Visit(XmlSchemaChoice particle)
        {
            if (particle.MaxOccurs == 0)
            {
                return;
            }

            PushNode(ChildType.Choice, particle.Parent, particle);
            base.Visit(particle);
            PopNode();
        }
Exemple #25
0
        IEnumerable <XElement> CreateProtoChoice(XmlSchemaChoice choice)
        {
            var particle = choice.Items.OfType <XmlSchemaParticle>().First();

            if (((int)particle.MinOccurs) > 0)
            {
                foreach (var val in CreateProtoParticle(particle).Repeat((int)particle.MinOccurs))
                {
                    yield return(val);
                }
            }
        }
Exemple #26
0
        private void PopulateDataElement(XmlSchemaChoice schemaParticle, string child)
        {
            var pi         = typeof(DataModel).GetProperty(child);
            var pluginAttr = pi.GetAttributes <PluginElementAttribute>().FirstOrDefault();
            var elems      = MakeElement(null, null, pi, pluginAttr);

            foreach (var elem in elems)
            {
                elem.MinOccursString = null;
                elem.MaxOccursString = null;
                schemaParticle.Items.Add(elem);
            }
        }
        /// <summary>Determines whether the specified <paramref name="element"/> is expected.</summary>
        /// <param name="element">Element to check.</param>
        /// <param name="elementName">
        /// <see cref="XmlQualifiedName"/> of the <paramref name="element"/> (passed to avoid recreation).
        /// </param>
        /// <param name="expected">Expected schema particle.</param>
        /// <returns>true if the element is expected; false otherwise.</returns>
        private static bool IsElementExpected(XElement element, XmlQualifiedName elementName, XmlSchemaParticle expected)
        {
            Debug.Assert(element != null, "element != null");
            Debug.Assert(elementName != null, "elementName != null");
            Debug.Assert(expected != null, "expected != null");
            Debug.Assert(
                ToQualifiedName(element.Name) == elementName,
                "ToQualifiedName(element.Name) == elementName -- otherwise the caller get the 'caching' wrong");

            // These are all possibilities for a particle.
            XmlSchemaGroupRef schemaGroupRef = expected as XmlSchemaGroupRef;
            XmlSchemaAny      schemaAny      = expected as XmlSchemaAny;
            XmlSchemaElement  schemaElement  = expected as XmlSchemaElement;
            XmlSchemaAll      schemaAll      = expected as XmlSchemaAll;
            XmlSchemaChoice   schemaChoice   = expected as XmlSchemaChoice;
            XmlSchemaSequence schemaSequence = expected as XmlSchemaSequence;

            Debug.Assert(schemaGroupRef == null, "schemaGroupRef == null -- the validator flattens this out as options.");
            Debug.Assert(schemaSequence == null, "schemaSequence == null -- the validator flattens this out and picks the right one in seq.");
            Debug.Assert(schemaAll == null, "schemaAll == null -- the validator flattens this out as options.");
            Debug.Assert(schemaChoice == null, "schemaChoice == null -- the validator flattens this out as options.");

            if (schemaAny != null)
            {
                Debug.Assert(
                    schemaAny.Namespace == "##other" || schemaAny.Namespace == "##any",
                    "schemaAny.Namespace == '##other' || '##any' -- otherwise CSDL XSD resource was changed");
                if (schemaAny.Namespace == "##any")
                {
                    return(true);
                }
                else if (schemaAny.Namespace == "##other")
                {
                    string realElementNamespace = element.Name.NamespaceName;
                    if (realElementNamespace != GetTargetNamespace(expected))
                    {
                        return(true);
                    }
                }
            }

            if (schemaElement != null)
            {
                if (schemaElement.QualifiedName == elementName)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #28
0
        private XmlSchemaComplexType GetSpecificationTemplateComplexType()
        {
            XmlSchemaChoice choice = new XmlSchemaChoice {
                MinOccurs = 0, MaxOccursString = "unbounded"
            };

            choice.Items.Add(new XmlSchemaElement {
                Name = "SpecificationFieldType", MaxOccursString = "unbounded", SchemaTypeName = new XmlQualifiedName("SpecificationFieldTypeType", InriverNamespace)
            });

            return(new XmlSchemaComplexType {
                Name = "SpecificationTemplateType", Particle = choice
            });
        }
        /// <summary>
        /// Creates a collection of tables found in the schema.
        /// </summary>
        /// <param name="xmlSchema">The schema that describes the data model.</param>
        /// <returns>A list of TableSchema objects that describe the tables found in the data model schema.</returns>
        private void FirstPass(XmlSchemaSet xmlSchemaSet)
        {
            // Scan through the schema set looking for table elements.  These can either be defined at the root element for a standard
            // schema or they can be found as choices of a special element describing a 'DataSet' for the Microsoft version of a
            // schema.
            foreach (XmlSchemaElement xmlSchemaElement in xmlSchemaSet.GlobalElements.Values)
            {
                // If the element read from the schema is the Microsoft DataSet element, then the tables are described as choices
                // associated with an implicit complex type on that element.
                if (ObjectSchema.IsDataSetElement(xmlSchemaElement))
                {
                    // The tables are described as an choices of an implicit (nested) complex type.
                    if (xmlSchemaElement.SchemaType is XmlSchemaComplexType)
                    {
                        // The complex type describes the table.
                        XmlSchemaComplexType xmlSchemaComplexType = xmlSchemaElement.SchemaType as XmlSchemaComplexType;

                        // The data model is described as a set of one or more choices of tables.
                        if (xmlSchemaComplexType.Particle is XmlSchemaChoice)
                        {
                            // The data model is described as a set of choices.  Each choice represents a table.
                            XmlSchemaChoice xmlSchemaChoice = xmlSchemaComplexType.Particle as XmlSchemaChoice;

                            // Create a table for each of the choices described in the complex type.
                            foreach (XmlSchemaObject choiceObject in xmlSchemaChoice.Items)
                            {
                                if (choiceObject is XmlSchemaElement)
                                {
                                    XmlSchemaElement tableElement = choiceObject as XmlSchemaElement;
                                    this.tableList.Add(tableElement.Name, new TableSchema(this, tableElement));
                                }
                            }
                        }
                    }

                    // The constraints describe the columns that are unique for a table.
                    foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in xmlSchemaElement.Constraints)
                    {
                        // This describes the columns that must be unique within a table.
                        if (xmlSchemaIdentityConstraint is XmlSchemaUnique)
                        {
                            XmlSchemaUnique        xmlSchemaUnique        = xmlSchemaIdentityConstraint as XmlSchemaUnique;
                            UniqueConstraintSchema uniqueConstraintSchema = new UniqueConstraintSchema(this, xmlSchemaUnique);
                            uniqueConstraintSchema.Table.Add(uniqueConstraintSchema);
                        }
                    }
                }
            }
        }
        void ParceXsdSchemaChoise(XmlSchemaChoice choise, xsdType xsdtype)
        {
            choise.Items.ForEach(chItem => {
                var schEl  = chItem as XmlSchemaElement;
                var schAny = chItem as XmlSchemaAny;

                if (schEl != null)
                {
                    xsdtype.Content.Add(ParceXsdElement(schEl, ElementTypes.choise));
                }
                if (schAny != null)
                {
                }
            });
        }