Exemple #1
0
        public static string GetAnnotationText(XMLSchema.annotation annotation)
        {
            string textDocumentation = "";

            foreach (object o in annotation.Items)
            {
                if (o is XMLSchema.documentation)
                {
                    string text = "";
                    XMLSchema.documentation documentation = o as XMLSchema.documentation;
                    if (documentation.Any != null && documentation.Any.Length > 0 && documentation.Any[0].Value != null)
                    {
                        text = documentation.Any[0].Value;
                        text = text.Replace("\n", " ");
                        text = text.Replace("\t", " ");
                        text = text.Replace("\r", "");
                        text = Regex.Replace(text, " +", " ");
                        text = text.Trim();
                    }
                    else if (documentation.source != null)
                    {
                        text = documentation.source;
                    }
                    if (!string.IsNullOrEmpty(textDocumentation))
                    {
                        textDocumentation += "\r\n";
                    }
                    textDocumentation += text;
                    if (!string.IsNullOrEmpty(documentation.lang) || !string.IsNullOrEmpty(documentation.source))
                    {
                        textDocumentation += " (";
                        if (!string.IsNullOrEmpty(documentation.lang))
                        {
                            textDocumentation += documentation.lang;
                        }
                        if (!string.IsNullOrEmpty(documentation.lang) && !string.IsNullOrEmpty(documentation.source))
                        {
                            textDocumentation += ", ";
                        }
                        if (!string.IsNullOrEmpty(documentation.source))
                        {
                            textDocumentation += documentation.source;
                        }
                        textDocumentation += ")";
                    }
                }
            }

            return(textDocumentation);
        }
Exemple #2
0
        /// <summary>
        /// Renders the specified drawing item.
        /// </summary>
        /// <param name="drawingItem">The drawing item.</param>
        public override void Render(DiagramItem drawingItem)
        {
            string type = "";

            if (drawingItem.TabSchema is XMLSchema.element)
            {
                type = "element";
            }
            else if (drawingItem.TabSchema is XMLSchema.simpleType)
            {
                type = "simpleType";
            }
            else if (drawingItem.TabSchema is XMLSchema.complexType)
            {
                type = "complexType";
            }

            string occurences = String.Format("{0}..", drawingItem.MinOccurrence) +
                                (drawingItem.MaxOccurrence == -1 ? "∞" : string.Format("{0}", drawingItem.MaxOccurrence));

            if (type.Length > 0)
            {
                string      path          = '/' + drawingItem.Name;
                DiagramItem parentElement = drawingItem.Parent;
                while (parentElement != null)
                {
                    //if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
                    if ((type == "element" || type == "simpleType" || type == "complexType") && !string.IsNullOrEmpty(parentElement.Name))
                    {
                        path = '/' + parentElement.Name + path;
                    }
                    parentElement = parentElement.Parent;
                }

                // Get the comment/documentation
                string comment = "";
                XMLSchema.annotated annotated = drawingItem.TabSchema as XMLSchema.annotated;
                if (annotated != null && annotated.annotation != null)
                {
                    foreach (object o in annotated.annotation.Items)
                    {
                        if (o is XMLSchema.documentation)
                        {
                            XMLSchema.documentation documentation = o as XMLSchema.documentation;
                            if (documentation.Any != null && documentation.Any.Length > 0 && documentation.Any[0].Value != null)
                            {
                                string text = documentation.Any[0].Value;
                                text    = text.Replace("\n", " ");
                                text    = text.Replace("\t", " ");
                                text    = text.Replace("\r", "");
                                text    = Regex.Replace(text, " +", " ");
                                text    = text.Trim();
                                comment = text;
                            }
                            else if (documentation.source != null)
                            {
                                comment = documentation.source;
                            }
                            break;
                        }
                    }
                }

                //bool lastChild = drawingItem.Parent.ChildElements[drawingItem.Parent.ChildElements.Count - 1] == drawingItem;

                // Output the item
                string            t;
                XMLSchema.element el;
                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                {
                    el = drawingItem.TabSchema as XMLSchema.element;
                    if (el != null)
                    {
                        string et = "" + el.type;
                        if (et == "")
                        {
                            t = "[none]";
                        }
                        else
                        {
                            t = et.Substring(et.LastIndexOf(':') + 1);
                            if (t == "")
                            {
                                t = "[none]";
                            }
                        }
                    }
                    else
                    {
                        t = "[none]";
                    }
                    if (i > 0)
                    {
                        _writer.Write(_fieldSeparator);
                    }
                    string field = _finalTextOutputFields[i];
                    switch (field)
                    {
                    case "PATH": _writer.Write(path); break;

                    case "NAME": _writer.Write(drawingItem.Name); break;

                    case "TYPE": _writer.Write(type); break;

                    case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;

                    case "COMMENT": _writer.Write(comment); break;

                    case "SEQ": _writer.Write(occurences); break;

                    case "LASTCHILD": _writer.Write(this.iteratingLastChild ? "1" : "0"); break;

                    case "XSDTYPE": _writer.Write(t); break;
                    }
                }
                _writer.WriteLine();


                // Output the item attributes
                if (this.Schema != null && this.DisplayAttributes)
                {
                    string nameSpace = drawingItem.NameSpace;
                    if (annotated != null)
                    {
                        // Attributes enumeration
                        List <XSDAttribute> listAttributes = DiagramHelpers.GetAnnotatedAttributes(this.Schema, annotated, nameSpace);
                        listAttributes.Reverse();
                        for (int a = 0; a < listAttributes.Count; a++)
                        {
                            XSDAttribute xsdAttribute = listAttributes[a];
                            if (xsdAttribute != null)
                            {
                                string commentAttribute       = "";
                                XMLSchema.attribute attribute = xsdAttribute.Tag;
                                if (attribute != null && attribute.annotation != null)
                                {
                                    commentAttribute = DiagramHelpers.GetAnnotationText(attribute.annotation);
                                }

                                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                                {
                                    if (i > 0)
                                    {
                                        _writer.Write(_fieldSeparator);
                                    }
                                    string field = _finalTextOutputFields[i];
                                    switch (field)
                                    {
                                    case "PATH": _writer.Write(path + "@" + xsdAttribute.Name); break;

                                    case "NAME": _writer.Write(drawingItem.Name + "@" + xsdAttribute.Name); break;

                                    case "TYPE": _writer.Write(xsdAttribute.Type); break;

                                    case "NAMESPACE": _writer.Write(xsdAttribute.NameSpace); break;

                                    case "COMMENT": _writer.Write(commentAttribute); break;
                                    }
                                }
                                _writer.WriteLine();
                            }

                            //this.listViewAttributes.Items.Add(new ListViewItem(new string[] { attribute.Name, attribute.Type, attribute.Use, attribute.DefaultValue, s })).Tag = attribute;
                        }
                    }
                }


                //// Draw the inheritor line
                //if (drawingItem.InheritFrom != null)
                //{
                //}

                //switch (drawingItem.ItemType)
                //{
                //    case DiagramItemType.element:
                //        break;

                //    case DiagramItemType.type:
                //        break;

                //    case DiagramItemType.group:
                //        {
                //            // Draw the main shape following the min/max occurences

                //            // Draw the group type
                //            switch (drawingItem.GroupType)
                //            {
                //                case DiagramItemGroupType.Sequence: break;
                //                case DiagramItemGroupType.Choice: break;
                //                case DiagramItemGroupType.All: break;
                //            }
                //            break;
                //        }
                //}

                //// Draw text
                //if (drawingItem.Name.Length > 0)
                //{
                //    //drawingItem.Name;
                //}

                //// Draw occurences small text
                //if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1) {}

                //// Draw type
                //if (drawingItem.IsSimpleContent) {}

                //// Draw reference arrow
                //if (drawingItem.IsReference) {}
            }

            // Draw children expand box
            if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
            {
                int c = 0;
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.iteratingLastChild = drawingItem.ChildElements.Count == ++c;
                    this.Render(element);
                    //_writer.WriteLine();
                }
            }
        }
Exemple #3
0
        public override void Render(DiagramItem drawingItem)
        {
            string type = "";

            if (drawingItem.TabSchema is XMLSchema.element)
            {
                type = "element";
            }
            else if (drawingItem.TabSchema is XMLSchema.simpleType)
            {
                type = "simpleType";
            }
            else if (drawingItem.TabSchema is XMLSchema.complexType)
            {
                type = "complexType";
            }

            if (type.Length > 0)
            {
                string      path          = '/' + drawingItem.Name;
                DiagramItem parentElement = drawingItem.Parent;
                while (parentElement != null)
                {
                    //if (parentElement.ItemType == DiagramItemType.element && !string.IsNullOrEmpty(parentElement.Name))
                    if ((type == "element" || type == "simpleType" || type == "complexType") && !string.IsNullOrEmpty(parentElement.Name))
                    {
                        path = '/' + parentElement.Name + path;
                    }
                    parentElement = parentElement.Parent;
                }

                string comment = "";
                XMLSchema.annotated annotated = drawingItem.TabSchema as XMLSchema.annotated;
                if (annotated != null && annotated.annotation != null)
                {
                    foreach (object o in annotated.annotation.Items)
                    {
                        if (o is XMLSchema.documentation)
                        {
                            XMLSchema.documentation documentation = o as XMLSchema.documentation;
                            if (documentation.Any != null && documentation.Any.Length > 0)
                            {
                                string text = documentation.Any[0].Value;
                                text    = text.Replace("\n", " ");
                                text    = text.Replace("\t", " ");
                                text    = text.Replace("\r", "");
                                text    = Regex.Replace(text, " +", " ");
                                text    = text.Trim();
                                comment = text;
                            }
                            else if (documentation.source != null)
                            {
                                comment = documentation.source;
                            }
                            break;
                        }
                    }
                }

                for (int i = 0; i < _finalTextOutputFields.Count; i++)
                {
                    if (i > 0)
                    {
                        _writer.Write(_fieldSeparator);
                    }
                    string field = _finalTextOutputFields[i];
                    switch (field)
                    {
                    case "PATH": _writer.Write(path); break;

                    case "NAME": _writer.Write(drawingItem.Name); break;

                    case "TYPE": _writer.Write(type); break;

                    case "NAMESPACE": _writer.Write(drawingItem.NameSpace); break;

                    case "COMMENT": _writer.Write(comment); break;
                    }
                }
                _writer.WriteLine();


                //// Draw the inheritor line
                //if (drawingItem.InheritFrom != null)
                //{
                //}

                //switch (drawingItem.ItemType)
                //{
                //    case DiagramItemType.element:
                //        break;

                //    case DiagramItemType.type:
                //        break;

                //    case DiagramItemType.group:
                //        {
                //            // Draw the main shape following the min/max occurences

                //            // Draw the group type
                //            switch (drawingItem.GroupType)
                //            {
                //                case DiagramItemGroupType.Sequence: break;
                //                case DiagramItemGroupType.Choice: break;
                //                case DiagramItemGroupType.All: break;
                //            }
                //            break;
                //        }
                //}

                //// Draw text
                //if (drawingItem.Name.Length > 0)
                //{
                //    //drawingItem.Name;
                //}

                //// Draw occurences small text
                //if (drawingItem.MaxOccurrence > 1 || drawingItem.MaxOccurrence == -1) {}

                //// Draw type
                //if (drawingItem.IsSimpleContent) {}

                //// Draw reference arrow
                //if (drawingItem.IsReference) {}
            }

            // Draw children expand box
            if (drawingItem.HasChildElements && drawingItem.ShowChildElements)
            {
                foreach (DiagramItem element in drawingItem.ChildElements)
                {
                    this.Render(element);
                    //_writer.WriteLine();
                }
            }
        }