public void validateChild(IList <IPluglet> children, XmlNodeList nodes, PlugletType type, int index, bool flag) { for (int i = 0; i < children.Count; i++) { if (index >= nodes.Count || !children[i].Name.Equals(nodes[index].Name)) { if (children[i].IsMandatory && !flag) { plug.Error.Add("Missing Mandatory Element " + children[i].Name + " in " + children[i].Parent.Name); } continue; } index++; } if (nodes.Count > index) { if (type == PlugletType.Loop) { validateChild(children, nodes, type, index, true); } else { plug.Error.Add("Extra Element " + nodes[index].Name); } } }
// Depreciated - Use Pluglet(PlugletInput) instead public Pluglet(string name, string definition, PlugletType type, IPluglet parent, int minOccurs, int maxOccurs, bool isIgnore) : this(new PlugletInput() { Name = name, Definition = definition, Type = type, Parent = parent, MinOccurs = minOccurs, MaxOccurs = maxOccurs, IsIgnore = isIgnore, }) { }
private void createPluglet(string name, string description, PlugletType type, IPluglet parent, string mandatory, string repeatable) { int maxOccurs = 1; int minOccurs = 1; if (repeatable.Equals("Y")) { maxOccurs = -1; } if (mandatory == "N") { minOccurs = 0; } //if (type == PlugletType.Loop) // maxOccurs = -1; Pluglet pluglet = new Pluglet(name, description, type, parent, minOccurs, maxOccurs); }
private static Color GetColor(PlugletType type) { Color fillColor = Color.White; switch (type) { case PlugletType.Loop: fillColor = Color.LightBlue; break; case PlugletType.Segment: fillColor = Color.Yellow; break; case PlugletType.Data: fillColor = Color.Green; break; } return(fillColor); }
// Having PlutletInput as constructor parameter will make it easier to add // more overrides easily by setting default value of that property in PlugletInput // c'tor and then setting it wherever we need to override it. public Pluglet(PlugletInput plugletInput) { if (string.IsNullOrWhiteSpace(plugletInput.Name)) { throw new Exception("Element/segment name cannot be empty"); } this.name = plugletInput.Name; if (plugletInput.IsTagSameAsName) { this.Tag = this.name; } else { int index = name.IndexOf('_'); this.Tag = name.Substring(0, index == -1 ? name.Length : index); } this.definition = plugletInput.Definition; this.plugletType = plugletInput.Type; this.parent = plugletInput.Parent; this.repetitionInfo = new RepetitionInfo(plugletInput.MinOccurs, plugletInput.MaxOccurs); this.repetitionInfo.IsMandatory = (this.repetitionInfo.MinOccurs >= 1) ? true : false; this.recursiveMandatory = this.repetitionInfo.IsMandatory; this.IsIgnore = plugletInput.IsIgnore; this.ContainsTriggerChildField = plugletInput.ContainsTriggerChildField; this.IsTriggerField = plugletInput.IsTriggerField; if (parent != null) { this.recursiveMandatory = parent.IsRecursiveMandatory && this.IsMandatory; if (IsTriggerField) { parent.ContainsTriggerChildField = true; } } if (plugletInput.AddToParent && this.parent != null && !this.parent.Children.Contains(this)) { this.parent.Children.Add(this); //set Parent's PlugletType appropriately switch (this.plugletType) { case PlugletType.Data: if (this.parent.PlugletType != PlugletType.CompositeData) { this.parent.PlugletType = PlugletType.Segment; } break; case PlugletType.Segment: this.parent.PlugletType = PlugletType.Loop; break; case PlugletType.Loop: this.parent.PlugletType = PlugletType.Loop; break; case PlugletType.CompositeData: this.parent.PlugletType = PlugletType.Loop; break; } } }
// Depreciated - Use Pluglet(PlugletInput) instead public Pluglet(string name, string definition, PlugletType type, IPluglet parent, int minOccurs, int maxOccurs) : this(name, definition, type, parent, minOccurs, maxOccurs, false) { }
// Depreciated - Use Pluglet(PlugletInput) instead public Pluglet(string name, string desc, PlugletType type, IPluglet parent) : this(name, desc, type, parent, 1, 1) { }
/* * This method is used to parse an element. An element declaration * looks like one of the following * * <xs:element name="name" min="0" max="1" type="ns:type"> * * <xs:element ref="name" min="0" max="1"> * * <xs:element name="name" min="0" max="1"> * <xs:complexType> * <xs:sequence> * <xs:element name = ...> * <xs:element name = ...> * <xs:sequence min=0 max=1> * <xs:element ...> * </xs:sequence> * </xs:complexType> * </xs:element> */ private static IPluglet ParseElement(IPluglet parent, XmlSchemaElement elem, XmlSchema schema) { IPluglet ret = null; XmlSchemaElement refElem = elem; if (elem.Name == null) { refElem = (XmlSchemaElement)schema.Elements[elem.RefName]; } //Console.WriteLine("ParseElement.. " + refElem.Name); Dictionary <string, string> pairs; string description = ReadDocumentationFromElement(elem, !(elem.ElementType is XmlSchemaComplexType), out pairs); if (string.IsNullOrEmpty(description) && string.IsNullOrEmpty(elem.Name)) { description = ReadDocumentationFromElement(refElem, !(elem.ElementType is XmlSchemaComplexType), out pairs); } int maxOccurs = elem.MaxOccursString == "unbounded" ? -1 : (int)elem.MaxOccurs; //int maxOccurs = elem.MaxOccursString == "unbounded" || string.IsNullOrEmpty(elem.MaxOccursString) ? -1 : (int)elem.MaxOccurs; int minOccurs = (int)elem.MinOccurs; //Console.WriteLine("Parsing element " + elem.QualifiedName.Name); XmlSchemaComplexType elemType = elem.ElementType as XmlSchemaComplexType; if (elemType != null) { string name = elem.QualifiedName.Name; if (name.IndexOf("Loop", StringComparison.Ordinal) >= 0) { ret = new Pluglet(name, description, PlugletType.Loop, parent, minOccurs, maxOccurs); } else if (name != "UNA" && name != "UNB" && name != "UNG") { PlugletType type = PlugletType.Segment; if (parent != null && parent.PlugletType == PlugletType.Segment && parent.Parent != null) { type = PlugletType.CompositeData; } //the only exception is for EDI documents where we have component fields, they begin with C0* if (name.StartsWith("C0")) { type = PlugletType.Data; } ret = new Pluglet(name, description, type, parent, minOccurs, maxOccurs); } else // In case of UNA, UNB and UNG elements just return (ignore those elements) { return(null); } XmlSchemaComplexType ct = (XmlSchemaComplexType)refElem.ElementType; ParseComplexType(ret, ct, schema); } /* * If elementType is simple, create a SimpleField and proceed */ else if (elem.ElementType is XmlSchemaSimpleType || elem.ElementType is XmlSchemaDatatype) { string name = elem.QualifiedName.Name; ret = new Pluglet(name, description, PlugletType.Data, parent, minOccurs, maxOccurs); } if (ret.PlugletType == PlugletType.Data) { //This is old behavior for BTS schemas. Raj@5/25/2013 //ret.DataType = DataTypeFactory.CreateDataTypeFromXmlSchema(elem, false); //Now we need to use WPC logic string dataTypeName, minL, maxL; dataTypeName = RetrieveDataTypeAndStampStandarDENumber(ret, elem, out minL, out maxL); if (string.IsNullOrWhiteSpace(dataTypeName)) { ret.DataType = DataTypeFactory.CreateDataTypeFromXmlSchema2(elem, false); } else { ret.DataType = DataTypeFactory.CreateDataTypeFromXmlSchema(elem, false, dataTypeName, minL, maxL); } } return(ret); }