2003-11-06 Zoltan Varga <zovarga@ws-zovarga2>
[mono.git] / data / DefaultWsdlHelpGenerator.aspx
1 <%
2 //
3 // DefaultWsdlHelpGenerator.aspx: 
4 //
5 // Author:
6 //   Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // (C) 2003 Ximian, Inc.  http://www.ximian.com
9 //
10 %>
11
12 <%@ Import Namespace="System.Collections" %>
13 <%@ Import Namespace="System.IO" %>
14 <%@ Import Namespace="System.Xml.Serialization" %>
15 <%@ Import Namespace="System.Xml" %>
16 <%@ Import Namespace="System.Xml.Schema" %>
17 <%@ Import Namespace="System.Web.Services.Description" %>
18 <%@ Import Namespace="System" %>
19 <%@ Import Namespace="System.Net" %>
20 <%@ Import Namespace="System.Globalization" %>
21 <%@ Import Namespace="System.Resources" %>
22 <%@ Import Namespace="System.Diagnostics" %>
23 <%@ Import Namespace="System.CodeDom" %>
24 <%@ Import Namespace="System.CodeDom.Compiler" %>
25 <%@ Import Namespace="Microsoft.CSharp" %>
26 <%@ Import Namespace="Microsoft.VisualBasic" %>
27 <%@ Import Namespace="System.Text.RegularExpressions" %>
28 <%@ Assembly name="System.Web.Services" %>
29 <%@ Page debug="true" %>
30
31 <html>
32 <script language="C#" runat="server">
33
34 ServiceDescriptionCollection descriptions;
35 XmlSchemas schemas;
36
37 string WebServiceName;
38 string WebServiceDescription;
39 string PageName;
40
41 string DefaultBinding;
42 ArrayList ServiceProtocols;
43
44 string CurrentOperationName;
45 string CurrentOperationBinding;
46 string OperationDocumentation;
47 string CurrentOperationFormat;
48 bool CurrentOperationSupportsTest;
49 ArrayList InParams;
50 ArrayList OutParams;
51 string CurrentOperationProtocols;
52 int CodeTextColumns = 95;
53
54 void Page_Load(object sender, EventArgs e)
55 {
56         descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
57         schemas = (XmlSchemas) Context.Items["schemas"];
58
59         ServiceDescription desc = descriptions [0];
60         if (schemas.Count == 0) schemas = desc.Types.Schemas;
61         
62         Service service = desc.Services[0];
63         WebServiceName = service.Name;
64         DefaultBinding = desc.Bindings[0].Name;
65         WebServiceDescription = service.Documentation;
66         ServiceProtocols = FindServiceProtocols (null);
67         
68         CurrentOperationName = Request.QueryString["op"];
69         CurrentOperationBinding = Request.QueryString["bnd"];
70         if (CurrentOperationName != null) BuildOperationInfo ();
71
72         PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
73
74         ArrayList list = new ArrayList ();
75         foreach (ServiceDescription sd in descriptions) {
76                 foreach (Binding bin in sd.Bindings)
77                         if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
78         }
79
80         BindingsRepeater.DataSource = list;
81         Page.DataBind();
82 }
83
84 void BuildOperationInfo ()
85 {
86         InParams = new ArrayList ();
87         OutParams = new ArrayList ();
88         
89         Binding binding = FindBinding (CurrentOperationBinding);
90         PortType portType = descriptions.GetPortType (binding.Type);
91         Operation oper = FindOperation (portType, CurrentOperationName);
92         
93         OperationDocumentation = oper.Documentation;
94         if (OperationDocumentation == null || OperationDocumentation == "")
95                 OperationDocumentation = "No additional remarks";
96         
97         foreach (OperationMessage opm in oper.Messages)
98         {
99                 if (opm is OperationInput)
100                         BuildParameters (InParams, opm);
101                 else if (opm is OperationOutput)
102                         BuildParameters (OutParams, opm);
103         }
104         
105         // Protocols supported by the operation
106         CurrentOperationProtocols = "";
107         ArrayList prots = FindServiceProtocols (CurrentOperationName);
108         for (int n=0; n<prots.Count; n++) {
109                 if (n != 0) CurrentOperationProtocols += ", ";
110                 CurrentOperationProtocols += (string) prots[n];
111         }
112         
113         CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
114
115         // Operation format
116         OperationBinding obin = FindOperation (binding, CurrentOperationName);
117         if (obin != null)
118                 CurrentOperationFormat = GetOperationFormat (obin);
119
120         InputParamsRepeater.DataSource = InParams;
121         InputFormParamsRepeater.DataSource = InParams;
122         OutputParamsRepeater.DataSource = OutParams;
123 }
124
125 void BuildParameters (ArrayList list, OperationMessage opm)
126 {
127         Message msg = descriptions.GetMessage (opm.Message);
128         if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
129         {
130                 MessagePart part = msg.Parts[0];
131                 XmlSchemaComplexType ctype;
132                 if (part.Element == XmlQualifiedName.Empty)
133                 {
134                         ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
135                 }
136                 else
137                 {
138                         XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
139                         ctype = (XmlSchemaComplexType) elem.SchemaType;
140                 }
141                 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
142                 if (seq == null) return;
143                 
144                 foreach (XmlSchemaObject ob in seq.Items)
145                 {
146                         Parameter p = new Parameter();
147                         p.Description = "No additional remarks";
148                         
149                         if (ob is XmlSchemaElement)
150                         {
151                                 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
152                                 p.Name = selem.Name;
153                                 p.Type = selem.SchemaTypeName.Name;
154                         }
155                         else
156                         {
157                                 p.Name = "Unknown";
158                                 p.Type = "Unknown";
159                         }
160                         list.Add (p);
161                 }
162         }
163         else
164         {
165                 foreach (MessagePart part in msg.Parts)
166                 {
167                         Parameter p = new Parameter ();
168                         p.Description = "No additional remarks";
169                         p.Name = part.Name;
170                         if (part.Element == XmlQualifiedName.Empty)
171                                 p.Type = part.Type.Name;
172                         else
173                         {
174                                 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
175                                 p.Type = elem.SchemaTypeName.Name;
176                         }
177                         list.Add (p);
178                 }
179         }
180 }
181
182 string GetOperationFormat (OperationBinding obin)
183 {
184         string format = "";
185         SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
186         if (sob != null) {
187                 format = sob.Style.ToString ();
188                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
189                 if (sbb != null)
190                         format += " / " + sbb.Use;
191         }
192         return format;
193 }
194
195 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
196 {
197         if (!elem.RefName.IsEmpty)
198                 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
199         else
200                 return elem;
201 }
202
203 ArrayList FindServiceProtocols(string operName)
204 {
205         ArrayList table = new ArrayList ();
206         Service service = descriptions[0].Services[0];
207         foreach (Port port in service.Ports)
208         {
209                 string prot = null;
210                 Binding bin = descriptions.GetBinding (port.Binding);
211                 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
212                         prot = "Soap";
213                 else 
214                 {
215                         HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
216                         if (hb != null && hb.Verb == "POST") prot = "HttpPost";
217                         else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
218                 }
219                 
220                 if (prot != null && operName != null)
221                 {
222                         if (FindOperation (bin, operName) == null)
223                                 prot = null;
224                 }
225
226                 if (prot != null && !table.Contains (prot))
227                         table.Add (prot);
228         }
229         return table;
230 }
231
232 Binding FindBinding (string portName)
233 {
234         Service service = descriptions[0].Services[0];
235         foreach (Port port in service.Ports)
236                 if (port.Name == portName)
237                         return descriptions.GetBinding (port.Binding);
238         return null;
239 }
240
241 Operation FindOperation (PortType portType, string name)
242 {
243         foreach (Operation oper in portType.Operations) {
244                 if (oper.Messages.Input.Name != null) {
245                         if (oper.Messages.Input.Name == name) return oper;
246                 }
247                 else
248                         if (oper.Name == name) return oper;
249         }
250                 
251         return null;
252 }
253
254 OperationBinding FindOperation (Binding binding, string name)
255 {
256         foreach (OperationBinding oper in binding.Operations) {
257                 if (oper.Input.Name != null) {
258                         if (oper.Input.Name == name) return oper;
259                 }
260                 else 
261                         if (oper.Name == name) return oper;
262         }
263                 
264         return null;
265 }
266
267 string FormatBindingName (string name)
268 {
269         if (name == DefaultBinding) return "Methods";
270         else return "Methods for binding<br>" + name;
271 }
272
273 string GetOpName (object op)
274 {
275         OperationBinding ob = op as OperationBinding;
276         if (ob == null) return "";
277         if (ob.Input.Name != null) return ob.Input.Name;
278         else return ob.Name;
279 }
280
281 bool HasFormResult
282 {
283         get { return Request.QueryString ["ext"] == "testform"; }
284 }
285
286 string GetTestResult ()
287
288         if (!HasFormResult) return null;
289         
290         bool fill = false;
291         string qs = "";
292         for (int n=0; n<Request.QueryString.Count; n++)
293         {
294                 if (fill) {
295                         if (qs != "") qs += "&";
296                         qs += Request.QueryString.GetKey(n) + "=" + Request.QueryString [n];
297                 }
298                 if (Request.QueryString.GetKey(n) == "ext") fill = true;
299         }
300                 
301         string location = null;
302         ServiceDescription desc = descriptions [0];
303         Service service = desc.Services[0];
304         foreach (Port port in service.Ports)
305                 if (port.Name == CurrentOperationBinding)
306                 {
307                         SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
308                         if (sbi != null)
309                                 location = sbi.Location;
310                 }
311
312         if (location == null) 
313                 return "Could not locate web service";
314         
315         try
316         {
317                 WebRequest req = WebRequest.Create (location + "/" + CurrentOperationName + "?" + qs);
318                 WebResponse resp = req.GetResponse();
319                 StreamReader sr = new StreamReader (resp.GetResponseStream());
320                 string s = sr.ReadToEnd ();
321                 sr.Close ();
322                 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
323         }
324         catch (Exception ex)
325         { 
326                 string res = "<b style='color:red'>" + ex.Message + "</b>";
327                 WebException wex = ex as WebException;
328                 if (wex != null)
329                 {
330                         WebResponse resp = wex.Response;
331                         if (resp != null) {
332                                 StreamReader sr = new StreamReader (resp.GetResponseStream());
333                                 string s = sr.ReadToEnd ();
334                                 sr.Close ();
335                                 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
336                         }
337                 }
338                 return res;
339         }
340 }
341
342 //
343 // Proxy code generation
344 //
345
346 string GetProxyCode ()
347 {
348         CodeNamespace codeNamespace = new CodeNamespace();
349         CodeCompileUnit codeUnit = new CodeCompileUnit();
350         
351         codeUnit.Namespaces.Add (codeNamespace);
352
353         ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
354         
355         foreach (ServiceDescription sd in descriptions)
356                 importer.AddServiceDescription(sd, null, null);
357
358         foreach (XmlSchema sc in schemas)
359                 importer.Schemas.Add (sc);
360
361         importer.Import(codeNamespace, codeUnit);
362
363         string langId = Request.QueryString ["lang"];
364         if (langId == null || langId == "") langId = "cs";
365         CodeDomProvider provider = GetProvider (langId);
366         ICodeGenerator generator = provider.CreateGenerator();
367         CodeGeneratorOptions options = new CodeGeneratorOptions();
368         
369         StringWriter sw = new StringWriter ();
370         generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
371
372         return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
373 }
374
375 public string CurrentLanguage
376 {
377         get {
378                 string langId = Request.QueryString ["lang"];
379                 if (langId == null || langId == "") langId = "cs";
380                 return langId;
381         }
382 }
383
384 public string CurrentProxytName
385 {
386         get {
387                 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
388                 return lan + " Client Proxy";
389         }
390 }
391
392 private CodeDomProvider GetProvider(string langId)
393 {
394         switch (langId.ToUpper())
395         {
396                 case "CS": return new CSharpCodeProvider();
397                 case "VB": return new VBCodeProvider();
398                 default: return null;
399         }
400 }
401
402 //
403 // Document generation
404 //
405
406 string GenerateDocument ()
407 {
408         StringWriter sw = new StringWriter ();
409         
410         if (CurrentDocType == "wsdl")
411                 descriptions [CurrentDocInd].Write (sw);
412         else if (CurrentDocType == "schema")
413                 schemas [CurrentDocInd].Write (sw);
414                 
415         return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
416 }
417
418 public string CurrentDocType
419 {
420         get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
421 }
422
423 public int CurrentDocInd
424 {
425         get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
426 }
427
428 public string CurrentDocumentName
429 {
430         get {
431                 if (CurrentDocType == "wsdl")
432                         return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
433                 else
434                         return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
435         }
436 }
437
438 //
439 // Pages and tabs
440 //
441
442 bool firstTab = true;
443 ArrayList disabledTabs = new ArrayList ();
444
445 string CurrentTab
446 {
447         get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
448 }
449
450 string CurrentPage
451 {
452         get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
453 }
454
455 void WriteTabs ()
456 {
457         if (CurrentOperationName != null)
458         {
459                 WriteTab ("main","Overview");
460                 WriteTab ("test","Test Form");
461                 WriteTab ("msg","Message Layout");
462         }
463 }
464
465 void WriteTab (string id, string label)
466 {
467         if (!firstTab) Response.Write("&nbsp;|&nbsp;");
468         firstTab = false;
469         
470         string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
471         Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
472         Response.Write ("<span class='" + cname + "'>" + label + "</span>");
473         Response.Write ("</a>");
474 }
475
476 string GetTabContext (string pag, string tab)
477 {
478         if (tab == null) tab = CurrentTab;
479         if (pag == null) pag = CurrentPage;
480         if (pag != CurrentPage) tab = "main";
481         return "page=" + pag + "&tab=" + tab + "&"; 
482 }
483
484 string GetPageContext (string pag)
485 {
486         if (pag == null) pag = CurrentPage;
487         return "page=" + pag + "&"; 
488 }
489
490 class Tab
491 {
492         public string Id;
493         public string Label;
494 }
495
496 //
497 // Syntax coloring
498 //
499
500 static string keywords_cs =
501         "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
502         "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
503         "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
504         "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
505         "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
506         "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
507         "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
508         "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
509         "\\bnamespace\\b|\\bstring\\b)";
510
511 static string keywords_vb =
512         "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
513         "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
514         "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
515         "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
516         "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
517         "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
518         "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
519         "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
520         "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
521         "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
522         "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
523         "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
524         "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
525         "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
526         "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
527         "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
528         "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
529
530 string Colorize (string text, string lang)
531 {
532         if (lang == "xml") return ColorizeXml (text);
533         else if (lang == "cs") return ColorizeCs (text);
534         else if (lang == "vb") return ColorizeVb (text);
535         else return text;
536 }
537
538 string ColorizeXml (string text)
539 {
540         text = text.Replace (" ", "&nbsp;");
541         Regex re = new Regex ("\r\n|\r|\n");
542         text = re.Replace (text, "_br_");
543         
544         re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
545         text = re.Replace (text,"{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
546         
547         re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
548         text = re.Replace (text,"<span style='color:$1'>$2</span>");
549
550         re = new Regex ("\"(.*?)\"");
551         text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
552
553         
554         text = text.Replace ("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
555         text = text.Replace ("_br_", "<br>");
556         return text;
557 }
558
559 string ColorizeCs (string text)
560 {
561         text = text.Replace (" ", "&nbsp;");
562
563         text = text.Replace ("<", "&lt;");
564         text = text.Replace (">", "&gt;");
565
566         Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
567         text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
568
569         re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
570         text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
571         
572         re = new Regex (keywords_cs);
573         text = re.Replace (text,"<span style='color:blue'>$1</span>");
574         
575         text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
576         text = text.Replace ("\n","<br/>");
577         
578         return text;
579 }
580
581 string ColorizeVb (string text)
582 {
583         text = text.Replace (" ", "&nbsp;");
584         
585 /*      Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
586         text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
587
588         re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
589         text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
590         
591         re = new Regex (keywords_vb);
592         text = re.Replace (text,"<span style='color:blue'>$1</span>");
593 */      
594         text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
595         text = text.Replace ("\n","<br/>");
596         return text;
597 }
598
599 //
600 // Helper methods and classes
601 //
602
603 string GetDataContext ()
604 {
605         return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
606 }
607
608 string GetOptionSel (string v1, string v2)
609 {
610         string op = "<option ";
611         if (v1 == v2) op += "selected ";
612         return op + "value='" + v1 + "'>";
613 }
614
615 string WrapText (string text, int maxChars)
616 {
617         text =  text.Replace(" />","/>");
618         
619         string linspace = null;
620         int lincount = 0;
621         int breakpos = 0;
622         int linstart = 0;
623         bool inquotes = false;
624         char lastc = ' ';
625         string sublineIndent = "";
626         System.Text.StringBuilder sb = new System.Text.StringBuilder ();
627         for (int n=0; n<text.Length; n++)
628         {
629                 char c = text [n];
630                 
631                 if (c=='\r' || c=='\n' || n==text.Length-1)
632                 {
633                         sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
634                         linspace = null;
635                         lincount = 0;
636                         linstart = n+1;
637                         breakpos = linstart;
638                         sublineIndent = "";
639                         lastc = c;
640                         continue;
641                 }
642                 
643                 if (lastc==',' || lastc=='(')
644                 {
645                         if (!inquotes) breakpos = n;
646                 }
647                 
648                 if (lincount > maxChars && breakpos >= linstart)
649                 {
650                         if (linspace != null)
651                                 sb.Append (linspace + sublineIndent);
652                         sb.Append (text.Substring (linstart, breakpos-linstart));
653                         sb.Append ("\n");
654                         sublineIndent = "     ";
655                         lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
656                         linstart = breakpos;
657                 }
658                 
659                 if (c==' ' || c=='\t')
660                 {
661                         if (!inquotes)
662                                 breakpos = n;
663                 }
664                 else if (c=='"')
665                 {
666                         inquotes = !inquotes;
667                 }
668                 else 
669                         if (linspace == null) {
670                                 linspace = text.Substring (linstart, n-linstart);
671                                 linstart = n;
672                         }
673
674                 lincount++;
675                 lastc = c;
676         }
677         return sb.ToString ();
678 }
679
680 class Parameter
681 {
682         string name;
683         string type;
684         string description;
685
686         public string Name { get { return name; } set { name = value; } }
687         public string Type { get { return type; } set { type = value; } }
688         public string Description { get { return description; } set { description = value; } }
689 }
690
691 </script>
692
693 <head>
694         <title><%=WebServiceName%> Web Service</title>
695     <style type="text/css">
696                 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
697                 TABLE { font-size: x-small }
698                 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
699                 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
700                 .method { font-size: x-small }
701                 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
702                 .label { font-size: small; font-weight:bold; color:darkgray }
703                 .paramTable { font-size: x-small }
704                 .paramTable TR { background-color: gainsboro }
705                 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
706                 .paramFormTable TR { background-color: gainsboro }
707                 .paramInput { border: solid 1px gray }
708                 .button {border: solid 1px gray }
709                 .smallSeparator { height:3px; overflow:hidden }
710                 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver  }
711                 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
712                 .code-xml { font-size:10pt; font-family:courier }
713                 .code-cs { font-size:10pt; font-family:courier }
714                 .code-vb { font-size:10pt; font-family:courier }
715                 .tabLabelOn { font-weight:bold }
716                 .tabLabelOff {color: darkgray }
717                 A:link { color: black; }
718                 A:visited { color: black; }
719                 A:active { color: black; }
720                 A:hover { color: blue }
721     </style>
722         
723 <script>
724 function clearForm ()
725 {
726         document.getElementById("testFormResult").style.display="none";
727 }
728 </script>
729
730 </head>
731
732 <body>
733 <div class="title" style="margin-left:20px">
734 <span class="label">Web Service</span><br>
735 <%=WebServiceName%>
736 </div>
737
738 <!--
739         **********************************************************
740         Left panel
741 -->
742
743 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
744 <tr valign="top"><td width="150px" class="panel">
745 <div style="width:150px"></div>
746 <a class="method" href='<%=PageName%>'>Overview</a><br>
747 <div class="smallSeparator"></div>
748 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
749 <div class="smallSeparator"></div>
750 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
751 <br><br>
752         <asp:repeater id="BindingsRepeater" runat=server>
753                 <itemtemplate name="itemtemplate">
754                         <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
755                         <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
756                                 <itemtemplate>
757                                         <a class="method" href="<%#PageName%>?<%#GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
758                                         <div class="smallSeparator"></div>
759                                 </itemtemplate>
760                         </asp:repeater>
761                         <br>
762                 </itemtemplate>
763         </asp:repeater>
764
765 </td><td class="panel">
766
767 <% if (CurrentPage == "main") {%>
768
769 <!--
770         **********************************************************
771         Web service overview
772 -->
773
774         <p class="label">Web Service Overview</p>
775         <%#WebServiceDescription%>
776         
777 <%} if (CurrentPage == "op") {%>
778
779 <!--
780         **********************************************************
781         Operation description
782 -->
783
784         <span class="operationTitle"><%#CurrentOperationName%></span>
785         <br><br>
786         <% WriteTabs (); %>
787         <br><br><br>
788         
789         <% if (CurrentTab == "main") { %>
790                 <span class="label">Input Parameters</span>
791                 <div class="smallSeparator"></div>
792                 <% if (InParams.Count == 0) { %>
793                         No input parameters<br>
794                 <% } else { %>
795                         <table class="paramTable" cellspacing="1" cellpadding="5">
796                         <asp:repeater id="InputParamsRepeater" runat=server>
797                                 <itemtemplate>
798                                         <tr>
799                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
800                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
801                                         </tr>
802                                 </itemtemplate>
803                         </asp:repeater>
804                         </table>
805                 <% } %>
806                 <br>
807                 
808                 <% if (OutParams.Count > 0) { %>
809                 <span class="label">Output Parameters</span>
810                         <div class="smallSeparator"></div>
811                         <table class="paramTable" cellspacing="1" cellpadding="5">
812                         <asp:repeater id="OutputParamsRepeater" runat=server>
813                                 <itemtemplate>
814                                         <tr>
815                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
816                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
817                                         </tr>
818                                 </itemtemplate>
819                         </asp:repeater>
820                         </table>
821                 <br>
822                 <% } %>
823                 
824                 <span class="label">Remarks</span>
825                 <div class="smallSeparator"></div>
826                 <%#OperationDocumentation%>
827                 <br><br>
828                 <span class="label">Technical information</span>
829                 <div class="smallSeparator"></div>
830                 Format: <%#CurrentOperationFormat%>
831                 <br>Supported protocols: <%#CurrentOperationProtocols%>
832         <% } %>
833         
834         <% if (CurrentTab == "test") { 
835                 if (CurrentOperationSupportsTest) {%>
836                         Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
837                         <form action="<%#PageName%>" method="GET">
838                         <input type="hidden" name="page" value="<%#CurrentPage%>">
839                         <input type="hidden" name="tab" value="<%#CurrentTab%>">
840                         <input type="hidden" name="op" value="<%#CurrentOperationName%>">
841                         <input type="hidden" name="bnd" value="<%#CurrentOperationBinding%>">
842                         <input type="hidden" name="ext" value="testform">
843                         <table class="paramFormTable" cellspacing="0" cellpadding="3">
844                         <asp:repeater id="InputFormParamsRepeater" runat=server>
845                                 <itemtemplate>
846                                         <tr>
847                                         <td><%#DataBinder.Eval(Container.DataItem, "Name")%>:&nbsp;</td>
848                                         <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
849                                         </tr>
850                                 </itemtemplate>
851                         </asp:repeater>
852                         <tr><td></td><td><input class="button" type="submit" value="Invoke">&nbsp;<input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
853                         </table>
854                         </form>
855                         <div id="testFormResult" style="display:<%# (HasFormResult?"block":"none") %>">
856                         The web service returned the following result:<br/><br/>
857                         <div class="codePanel"><%#GetTestResult()%></div>
858                         </div>
859                 <% } else {%>
860                 The test form is not available for this operation because it has parameters with a complex structure.
861                 <% } %>
862         <% } %>
863         <% if (CurrentTab == "msg") { %>
864                 TODO
865         <% } %>
866 <%}%>
867
868 <% if (CurrentPage == "proxy") {%>
869 <!--
870         **********************************************************
871         Client Proxy
872 -->
873         <form action="<%#PageName%>" name="langForm" method="GET">
874                 Select the language for which you want to generate a proxy 
875                 <input type="hidden" name="page" value="<%#CurrentPage%>">&nbsp;
876                 <SELECT name="lang" onchange="langForm.submit()">
877                         <%#GetOptionSel("cs",CurrentLanguage)%>C#</option>
878                         <%#GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
879                 </SELECT>
880                 &nbsp;&nbsp;
881         </form>
882         <br>
883         <span class="label"><%#CurrentProxytName%></span>&nbsp;&nbsp;&nbsp;
884         <a href="<%#PageName + "?code=" + CurrentLanguage%>">Download</a>
885         <br><br>
886         <div class="codePanel">
887         <div class="code-<%#CurrentLanguage%>"><%#GetProxyCode ()%></div>
888         </div>
889 <%}%>
890
891 <% if (CurrentPage == "wsdl") {%>
892 <!--
893         **********************************************************
894         Service description
895 -->
896         <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
897         The description of this web service is composed by several documents. Click on the document you want to see:
898         
899         <ul>
900         <% 
901                 for (int n=0; n<descriptions.Count; n++)
902                         Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
903                 for (int n=0; n<schemas.Count; n++)
904                         Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
905         %>
906         </ul>
907         
908         <%} else {%>
909         <%}%>
910         <br>
911         <span class="label"><%#CurrentDocumentName%></span>&nbsp;&nbsp;&nbsp;
912         <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
913         <br><br>
914         <div class="codePanel">
915         <div class="code-xml"><%#GenerateDocument ()%></div>
916         </div>
917
918 <%}%>
919
920 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
921 </td>
922 <td withd="20px"></td>
923 </tr>
924
925 </table>
926 </body>
927 </html>