Ejemplo n.º 1
0
        public static void OutputXml(IOwinContext context, DocParameter input, String xsltPath, bool outputXml = true)
        {
            var xmlSetting = new XmlWriterSettings()
            {
                Encoding = Encoding.UTF8
            };

            var uri = context.Request.Uri;

            xsltPath = $"{uri.Scheme}://{uri.Host}:{uri.Port}{xsltPath}";
            //if (!outputXml)
            //    xsltPath = "Plugins" + xsltPath;

            var document = getDocument(context, input, xsltPath);
            var rep      = context.Response;

            if (outputXml)
            {
                rep.ContentType = "text/xml";
                using (var writer = XmlWriter.Create(rep.Body, xmlSetting))
                {
                    document.WriteTo(writer);
                }
            }
            else
            {
                rep.ContentType = "text/html";
                var myXslTransform = new XslCompiledTransform();
                myXslTransform.Load(xsltPath);
                myXslTransform.Transform(document, null, rep.Body);
            }
            rep.Body.Flush();
        }
Ejemplo n.º 2
0
        private static XmlDocument getDocument(IOwinContext context, DocParameter input, String xsltPath)
        {
            XmlDocument document = new XmlDocument();

            if (!String.IsNullOrEmpty(xsltPath))
            {
                document.AppendChild(document.CreateProcessingInstruction(
                                         "xml-stylesheet",
                                         $"type='text/xsl' href='{xsltPath}'"));
            }
            var rootElement = document.CreateElement("Api");

            if (!String.IsNullOrEmpty(input.Tag))
            {
                rootElement.SetAttribute("Tag", input.Tag);
            }
            document.AppendChild(rootElement);

            writeLevel1Nodes(context, document, rootElement, NodeManager.Instance, input);
            return(document);
        }
Ejemplo n.º 3
0
        private static void writeMethods(IOwinContext context, XmlDocument document, XmlElement element, INode node, DocParameter input)
        {
            foreach (var method in node.GetMethods()
                     .Where(t =>
            {
                if (input.Tag == null)
                {
                    return(t.Value.Tags == null ||
                           !t.Value.Tags.Contains("hidden"));
                }
                else
                {
                    return(input.Tag == "all" ||
                           (t.Value.Tags != null &&
                            t.Value.Tags.Contains(input.Tag)));
                }
            }
                            ))
            {
                var HttpMethod = method.Key;
                var Method     = method.Value;

                var methodElement = document.CreateElement(typeof(IMethod).Name);

                methodElement.SetAttribute(nameof(HttpMethod), HttpMethod);
                methodElement.SetAttribute(nameof(Method.Path), Method.Path);
                methodElement.SetAttribute(nameof(Method.Name), Method.Name);
                methodElement.SetAttribute(nameof(Method.Description), Method.Description);
                methodElement.SetAttribute(nameof(Method.InvokeExample), Method.InvokeExample);
                methodElement.SetAttribute(nameof(Method.ReturnValueExample), Method.ReturnValueExample);
                writePermissions(context, document, methodElement, Method);
                writeTags(document, methodElement, Method);
                writeParameters(document, methodElement, Method);

                element.AppendChild(methodElement);
            }

            foreach (var childNode in node.GetChildren())
            {
                writeMethods(context, document, element, childNode, input);
            }
        }
Ejemplo n.º 4
0
        //第二级节点(功能)
        private static void writeLevel2Nodes(IOwinContext context, XmlDocument document, XmlElement parentElement, INode parentNode, DocParameter input)
        {
            foreach (var childNode in parentNode.GetChildren())
            {
                var childElement = document.CreateElement("Feature");
                childElement.SetAttribute(nameof(childNode.Id), childNode.Id);
                childElement.SetAttribute(nameof(childNode.Name), childNode.Name);

                writeMethods(context, document, childElement, childNode, input);
                if (childElement.GetElementsByTagName(typeof(IMethod).Name).Count > 0)
                {
                    parentElement.AppendChild(childElement);
                }
            }
        }