Пример #1
0
        public static XDocument CreateOperationHelpPage(Uri baseUri, OperationHelpInformation operationInfo)
        {
            XDocument document = CreateBaseDocument(SR2.GetString(SR2.HelpPageReferenceFor, BuildFullUriTemplate(baseUri, operationInfo.UriTemplate)));
            XElement  table    = new XElement(HtmlTableElementName,
                                              new XElement(HtmlTrElementName,
                                                           new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageMessageDirection)),
                                                           new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageFormat)),
                                                           new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageBody))));

            RenderMessageInformation(table, operationInfo, true);
            RenderMessageInformation(table, operationInfo, false);

            XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
                                        new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR2.GetString(SR2.HelpPageReferenceFor, BuildFullUriTemplate(baseUri, operationInfo.UriTemplate))),
                                        new XElement(HtmlPElementName, operationInfo.Description),
                                        XElement.Parse(SR2.GetString(SR2.HelpPageOperationUri, HttpUtility.HtmlEncode(BuildFullUriTemplate(baseUri, operationInfo.UriTemplate)))),
                                        XElement.Parse(SR2.GetString(SR2.HelpPageOperationMethod, HttpUtility.HtmlEncode(operationInfo.Method))));

            if (!String.IsNullOrEmpty(operationInfo.JavascriptCallbackParameterName))
            {
                div.Add(XElement.Parse(SR2.GetString(SR2.HelpPageCallbackText, HttpUtility.HtmlEncode(operationInfo.JavascriptCallbackParameterName))), table);
            }
            else
            {
                div.Add(table);
            }
            document.Descendants(HtmlBodyElementName).First().Add(div);

            CreateOperationSamples(document.Descendants(HtmlDivElementName).First(), operationInfo);

            return(document);
        }
Пример #2
0
        static void RenderMessageInformation(XElement table, OperationHelpInformation operationInfo, bool isRequest)
        {
            MessageHelpInformation info  = isRequest ? operationInfo.Request : operationInfo.Response;
            string direction             = isRequest ? SR2.GetString(SR2.HelpPageRequest) : SR2.GetString(SR2.HelpPageResponse);
            string nonLocalizedDirection = isRequest ? HtmlRequestXmlId : HtmlResponseXmlId;

            if (info.BodyDescription != null)
            {
                table.Add(new XElement(HtmlTrElementName,
                                       new XElement(HtmlTdElementName, direction),
                                       new XElement(HtmlTdElementName, info.FormatString),
                                       new XElement(HtmlTdElementName, info.BodyDescription)));
            }
            else
            {
                if (info.XmlExample != null || info.Schema != null)
                {
                    XElement contentTd;
                    table.Add(new XElement(HtmlTrElementName,
                                           new XElement(HtmlTdElementName, direction),
                                           new XElement(HtmlTdElementName, "Xml"),
                                           contentTd = new XElement(HtmlTdElementName)));

                    if (info.XmlExample != null)
                    {
                        contentTd.Add(new XElement(HtmlAElementName, new XAttribute(HtmlHrefAttributeName, "#" + (isRequest ? HtmlRequestXmlId : HtmlResponseXmlId)), SR2.GetString(SR2.HelpPageExample)));
                        if (info.Schema != null)
                        {
                            contentTd.Add(",");
                        }
                    }
                    if (info.Schema != null)
                    {
                        contentTd.Add(new XElement(HtmlAElementName, new XAttribute(HtmlHrefAttributeName, "#" + (isRequest ? HtmlRequestSchemaId : HtmlResponseSchemaId)), SR2.GetString(SR2.HelpPageSchema)));
                    }
                }
                if (info.JsonExample != null)
                {
                    table.Add(new XElement(HtmlTrElementName,
                                           new XElement(HtmlTdElementName, direction),
                                           new XElement(HtmlTdElementName, "Json"),
                                           new XElement(HtmlTdElementName,
                                                        new XElement(HtmlAElementName, new XAttribute(HtmlHrefAttributeName, "#" + (isRequest ? HtmlRequestJsonId : HtmlResponseJsonId)), SR2.GetString(SR2.HelpPageExample)))));
                }
            }
        }
Пример #3
0
        static void CreateOperationSamples(XElement element, OperationHelpInformation operationInfo)
        {
            if (operationInfo.Request.XmlExample != null)
            {
                element.Add(GenerateSampleXml(operationInfo.Request.XmlExample, SR2.GetString(SR2.HelpPageXmlRequest), HtmlRequestXmlId));
            }
            if (operationInfo.Request.JsonExample != null)
            {
                element.Add(AddSampleJson(operationInfo.Request.JsonExample, SR2.GetString(SR2.HelpPageJsonRequest), HtmlRequestJsonId));
            }
            if (operationInfo.Response.XmlExample != null)
            {
                element.Add(GenerateSampleXml(operationInfo.Response.XmlExample, SR2.GetString(SR2.HelpPageXmlResponse), HtmlResponseXmlId));
            }
            if (operationInfo.Response.JsonExample != null)
            {
                element.Add(AddSampleJson(operationInfo.Response.JsonExample, SR2.GetString(SR2.HelpPageJsonResponse), HtmlResponseJsonId));
            }

            if (operationInfo.Request.Schema != null)
            {
                element.Add(GenerateSampleXml(XmlSchemaToXElement(operationInfo.Request.Schema), SR2.GetString(SR2.HelpPageRequestSchema), HtmlRequestSchemaId));
                int count = 0;
                foreach (XmlSchema schema in operationInfo.Request.SchemaSet.Schemas())
                {
                    if (schema.TargetNamespace != operationInfo.Request.Schema.TargetNamespace)
                    {
                        element.Add(GenerateSampleXml(XmlSchemaToXElement(schema), ++count == 1 ? SR2.GetString(SR2.HelpPageAdditionalRequestSchema) : null, HtmlRequestSchemaId));
                    }
                }
            }
            if (operationInfo.Response.Schema != null)
            {
                element.Add(GenerateSampleXml(XmlSchemaToXElement(operationInfo.Response.Schema), SR2.GetString(SR2.HelpPageResponseSchema), HtmlResponseSchemaId));
                int count = 0;
                foreach (XmlSchema schema in operationInfo.Response.SchemaSet.Schemas())
                {
                    if (schema.TargetNamespace != operationInfo.Response.Schema.TargetNamespace)
                    {
                        element.Add(GenerateSampleXml(XmlSchemaToXElement(schema), ++count == 1 ? SR2.GetString(SR2.HelpPageAdditionalResponseSchema) : null, HtmlResponseSchemaId));
                    }
                }
            }
        }
        static void CreateOperationSamples(XElement element, OperationHelpInformation operationInfo)
        {
            if (operationInfo.Request.XmlExample != null)
            {
                element.Add(GenerateSampleXml(operationInfo.Request.XmlExample, SR2.GetString(SR2.HelpPageXmlRequest), HtmlRequestXmlId));
            }
            if (operationInfo.Request.JsonExample != null)
            {
                element.Add(AddSampleJson(operationInfo.Request.JsonExample, SR2.GetString(SR2.HelpPageJsonRequest), HtmlRequestJsonId));
            }
            if (operationInfo.Response.XmlExample != null)
            {
                element.Add(GenerateSampleXml(operationInfo.Response.XmlExample, SR2.GetString(SR2.HelpPageXmlResponse), HtmlResponseXmlId));
            }
            if (operationInfo.Response.JsonExample != null)
            {
                element.Add(AddSampleJson(operationInfo.Response.JsonExample, SR2.GetString(SR2.HelpPageJsonResponse), HtmlResponseJsonId));
            }

            if (operationInfo.Request.Schema != null)
            {
                element.Add(GenerateSampleXml(XmlSchemaToXElement(operationInfo.Request.Schema), SR2.GetString(SR2.HelpPageRequestSchema), HtmlRequestSchemaId));
                int count = 0;
                foreach (XmlSchema schema in operationInfo.Request.SchemaSet.Schemas())
                {
                    if (schema.TargetNamespace != operationInfo.Request.Schema.TargetNamespace)
                    {
                        element.Add(GenerateSampleXml(XmlSchemaToXElement(schema), ++count == 1 ? SR2.GetString(SR2.HelpPageAdditionalRequestSchema) : null, HtmlRequestSchemaId));
                    }
                }
            }
            if (operationInfo.Response.Schema != null)
            {
                element.Add(GenerateSampleXml(XmlSchemaToXElement(operationInfo.Response.Schema), SR2.GetString(SR2.HelpPageResponseSchema), HtmlResponseSchemaId));
                int count = 0;
                foreach (XmlSchema schema in operationInfo.Response.SchemaSet.Schemas())
                {
                    if (schema.TargetNamespace != operationInfo.Response.Schema.TargetNamespace)
                    {
                        element.Add(GenerateSampleXml(XmlSchemaToXElement(schema), ++count == 1 ? SR2.GetString(SR2.HelpPageAdditionalResponseSchema) : null, HtmlResponseSchemaId));
                    }
                }
            }
        }
        static void RenderMessageInformation(XElement table, OperationHelpInformation operationInfo, bool isRequest)
        {       
            MessageHelpInformation info = isRequest ? operationInfo.Request : operationInfo.Response;
            string direction = isRequest ? SR2.GetString(SR2.HelpPageRequest) : SR2.GetString(SR2.HelpPageResponse);
            string nonLocalizedDirection = isRequest ? HtmlRequestXmlId : HtmlResponseXmlId;

            if (info.BodyDescription != null)
            {
                table.Add(new XElement(HtmlTrElementName,
                    new XElement(HtmlTdElementName, direction),
                    new XElement(HtmlTdElementName, info.FormatString),
                    new XElement(HtmlTdElementName, info.BodyDescription)));                
            }
            else
            {
                if (info.XmlExample != null || info.Schema != null)
                {
                    XElement contentTd;
                    table.Add(new XElement(HtmlTrElementName,
                        new XElement(HtmlTdElementName, direction),
                        new XElement(HtmlTdElementName, "Xml"),
                        contentTd = new XElement(HtmlTdElementName)));

                    if (info.XmlExample != null)
                    {
                        contentTd.Add(new XElement(HtmlAElementName, new XAttribute(HtmlHrefAttributeName, "#" + (isRequest ? HtmlRequestXmlId : HtmlResponseXmlId)), SR2.GetString(SR2.HelpPageExample)));
                        if (info.Schema != null)
                        {
                            contentTd.Add(",");
                        }
                    }
                    if (info.Schema != null)
                    {
                        contentTd.Add(new XElement(HtmlAElementName, new XAttribute(HtmlHrefAttributeName, "#" + (isRequest ? HtmlRequestSchemaId : HtmlResponseSchemaId)), SR2.GetString(SR2.HelpPageSchema)));
                    }
                }
                if (info.JsonExample != null)
                {
                    table.Add(new XElement(HtmlTrElementName,
                        new XElement(HtmlTdElementName, direction),
                        new XElement(HtmlTdElementName, "Json"),
                        new XElement(HtmlTdElementName,
                            new XElement(HtmlAElementName, new XAttribute(HtmlHrefAttributeName, "#" + (isRequest ? HtmlRequestJsonId : HtmlResponseJsonId)), SR2.GetString(SR2.HelpPageExample)))));
                }
            }
        }
        public static XDocument CreateOperationHelpPage(Uri baseUri, OperationHelpInformation operationInfo)
        {            
            XDocument document = CreateBaseDocument(SR2.GetString(SR2.HelpPageReferenceFor, BuildFullUriTemplate(baseUri, operationInfo.UriTemplate)));
            XElement table = new XElement(HtmlTableElementName,
                new XElement(HtmlTrElementName,
                    new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageMessageDirection)),
                    new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageFormat)),
                    new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageBody))));

            RenderMessageInformation(table, operationInfo, true);
            RenderMessageInformation(table, operationInfo, false);

            XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
                new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR2.GetString(SR2.HelpPageReferenceFor, BuildFullUriTemplate(baseUri, operationInfo.UriTemplate))),
                new XElement(HtmlPElementName, operationInfo.Description),
                XElement.Parse(SR2.GetString(SR2.HelpPageOperationUri, HttpUtility.HtmlEncode(BuildFullUriTemplate(baseUri, operationInfo.UriTemplate)))),
                XElement.Parse(SR2.GetString(SR2.HelpPageOperationMethod, HttpUtility.HtmlEncode(operationInfo.Method))));
            if (!String.IsNullOrEmpty(operationInfo.JavascriptCallbackParameterName))
            {
                div.Add(XElement.Parse(SR2.GetString(SR2.HelpPageCallbackText, HttpUtility.HtmlEncode(operationInfo.JavascriptCallbackParameterName))), table);
            }
            else
            {
                div.Add(table);
            }
            document.Descendants(HtmlBodyElementName).First().Add(div);

            CreateOperationSamples(document.Descendants(HtmlDivElementName).First(), operationInfo);

            return document;
        }