Beispiel #1
0
            public override object Invoke(IOwinContext context, GetParameter input)
            {
                var idArray = input.Id.Split(new Char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                if (idArray.Length < 2)
                {
                    throw new NodeMethodException($"[{input.Id}]不是有效的API编号!");
                }

                var req         = context.Request;
                var contextPath = req.Get <String>("ContextPath");

                var path       = contextPath + idArray[0];
                var httpMethod = idArray[1];

                var nodePath     = path.Substring(NodeApiMiddleware.Prefix.Length);
                var nodeSegments = nodePath.Split(new Char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                INode currentNode = NodeManager.Instance;
                IEnumerable <String> currentSegments = nodeSegments;

                while (currentNode != null && currentSegments.Count() > 0)
                {
                    var currentSegment = currentSegments.First();
                    currentNode = currentNode.GetChild(currentSegment);
                    if (currentNode == null)
                    {
                        throw new NodeMethodException($"未找到路径为[{path}]的节点!");
                    }
                    currentSegments = currentSegments.Skip(1);
                }
                var nodeMethod = currentNode.GetMethod(httpMethod);

                if (nodeMethod == null)
                {
                    throw new NodeMethodException($"路径为[{path}]的节点没有[{httpMethod}]方法!");
                }

                return(new
                {
                    nodeMethod.Path,
                    nodeMethod.Name,
                    nodeMethod.Description,
                    nodeMethod.HttpMethod,
                    nodeMethod.InvokeExample,
                    nodeMethod.Tags,
                    Parameters = FormFieldInfo.GetAll(GetTextManager(context), nodeMethod.InputType)
                });
            }
Beispiel #2
0
        private static void writeParameters(XmlDocument document, XmlElement element, IMethod method)
        {
            if (method.InputType == null ||
                method.InputType == typeof(object))
            {
                return;
            }
            var parametersElement = document.CreateElement("Parameters");

            foreach (var parameter in FormFieldInfo.GetAll(TextManager.DefaultInstance, method.InputType))
            {
                var abc = parameter.TypeId;
                var parameterElement = document.CreateElement(typeof(FormFieldInfo).Name);
                parameterElement.SetAttribute(nameof(parameter.Key), parameter.Key);
                parameterElement.SetAttribute(nameof(parameter.Name), parameter.Name);
                parameterElement.SetAttribute(nameof(parameter.Type), parameter.Type);
                parameterElement.SetAttribute(nameof(parameter.Description), parameter.Description);
                parameterElement.SetAttribute(nameof(parameter.NotEmpty), parameter.NotEmpty.ToString());
                parameterElement.SetAttribute(nameof(parameter.ValueFormatType), parameter.ValueFormatType);
                //parameterElement.SetAttribute(nameof(parameter.ValueFormatValue), DataUtils.Serialize(parameter.ValueFormatValue));
                parametersElement.AppendChild(parameterElement);
            }
            element.AppendChild(parametersElement);
        }