2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / disco / disco.cs
blob6d1b0d57afe813022da53c1ec4903b16ab686be5
1 //
2 // disco.cs
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // Copyright (C) 2003 Ximian, Inc.
8 //
10 using System;
11 using System.Net;
12 using System.Web.Services.Discovery;
13 using System.IO;
15 public class Driver
17 static bool save = true;
18 static bool logo = true;
19 static string url;
20 static string directory = ".";
21 static DiscoveryClientProtocol prot;
23 static void Main (string[] args)
25 try
27 ReadParameters (args);
29 if (logo)
30 WriteLogo ();
32 if (args.Length == 0 || args[0] == "--help")
34 WriteHelp ();
35 return;
38 if (url == null) throw new Exception ("URL to discover not provided");
40 prot.DiscoverAny (url);
41 prot.ResolveAll ();
43 if (prot.References.Count > 0)
45 Console.WriteLine ("Disco found documents at the following URLs:");
46 foreach (DiscoveryReference refe in prot.References.Values)
48 if (refe is ContractReference) Console.Write ("- WSDL document at ");
49 else if (refe is DiscoveryDocumentReference) Console.Write ("- DISCO document at ");
50 else Console.Write ("- Xml Schema at ");
51 Console.WriteLine (refe.Url);
54 else
55 Console.WriteLine ("Disco didn't find any document at the specified URL");
57 if (save)
59 DiscoveryClientResultCollection col = prot.WriteAll (directory, "results.discomap");
60 Console.WriteLine ();
61 Console.WriteLine ("The following files hold the content found at the corresponding URLs:");
62 foreach (DiscoveryClientResult res in col)
63 Console.WriteLine ("- " + res.Filename + " <- " + res.Url);
64 Console.WriteLine ();
65 Console.WriteLine ("The file " + Path.Combine (directory,"results.discomap") + " holds links to each of there files");
66 Console.WriteLine ();
69 catch (Exception ex)
71 Console.WriteLine ("ERROR: " + ex.Message);
72 Console.WriteLine (ex);
76 static void WriteLogo ()
78 Console.WriteLine ("Mono Web Service Discovery Tool " + Consts.MonoVersion);
79 Console.WriteLine ();
82 static void WriteHelp ()
84 Console.WriteLine ("Usage: disco [options] url");
85 Console.WriteLine ();
86 Console.WriteLine ("Options:");
87 Console.WriteLine (" -nologo Supress the startup logo");
88 Console.WriteLine (" -nosave Do not save the discovered documents to disk.");
89 Console.WriteLine (" The default is to save the documents.");
90 Console.WriteLine (" -o -out:directory The directory where to save the discovered documents.");
91 Console.WriteLine (" By default, documents are saved in the current");
92 Console.WriteLine (" directory.");
93 Console.WriteLine (" -u -username:username ");
94 Console.WriteLine (" -p -password:password ");
95 Console.WriteLine (" -d -domain:domain The credentials to use when connecting to the server.");
96 Console.WriteLine (" -proxy:url The url of the proxy server to use for http requests.");
97 Console.WriteLine (" -proxyusername:name");
98 Console.WriteLine (" -proxypassword:pwd");
99 Console.WriteLine (" -proxydomin:domain The credentials to use when connection to the proxy.");
100 Console.WriteLine ();
103 static void ReadParameters (string[] args)
105 prot = new DiscoveryClientProtocol ();
106 NetworkCredential cred = new NetworkCredential ();
107 NetworkCredential proxyCred = new NetworkCredential ();
108 WebProxy proxy = new WebProxy ();
109 url = null;
111 foreach (string arg in args)
113 if (arg.StartsWith ("/") || arg.StartsWith ("-"))
115 string parg = arg.Substring (1);
116 int i = parg.IndexOf (":");
117 string param = null;
118 if (i != -1) {
119 param = parg.Substring (i+1);
120 parg = parg.Substring (0,i);
123 switch (parg)
125 case "nologo":
126 logo = false;
127 break;
129 case "nosave":
130 save = false;
131 break;
133 case "out": case "o":
134 directory = param;
135 break;
137 case "username": case "u":
138 cred.UserName = param;
139 break;
141 case "password": case "p":
142 cred.Password = param;
143 break;
145 case "domain": case "d":
146 cred.Domain = param;
147 break;
149 case "proxy":
150 proxy.Address = new Uri (param);
151 break;
153 case "proxyusername":
154 proxyCred.UserName = param;
155 break;
157 case "proxypassword":
158 proxyCred.Password = param;
159 break;
161 case "proxydomain":
162 proxyCred.Domain = param;
163 break;
166 if (cred.UserName != null)
167 prot.Credentials = cred;
169 if (proxyCred.UserName != null)
170 proxy.Credentials = proxyCred;
172 if (proxy.Address != null)
173 prot.Proxy = proxy;
175 else
177 url = arg;