PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/tools/soapsuds/soapsuds.cs

https://github.com/ccflo/mono
C# | 332 lines | 269 code | 55 blank | 8 comment | 42 complexity | 124df5e368ea105d06f95bc3dc38d264 MD5 | raw file
  1. //
  2. // soapsuds.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual (lluis@ximian.com)
  6. //
  7. // Copyright (C) 2003 Ximian, Inc.
  8. //
  9. using System;
  10. using System.Reflection;
  11. using System.Collections;
  12. using System.Runtime.Remoting.MetadataServices;
  13. using System.Net;
  14. using System.IO;
  15. public class Driver
  16. {
  17. static void Main (string[] args)
  18. {
  19. Runner run = new Runner (args);
  20. AppDomain domain = AppDomain.CreateDomain ("runner", null, Directory.GetCurrentDirectory(), "", false);
  21. domain.DoCallBack (new CrossAppDomainDelegate (run.Main));
  22. }
  23. }
  24. [Serializable]
  25. class Runner
  26. {
  27. static bool logo = true;
  28. static string inputUrl = null;
  29. static string inputTypes = null;
  30. static string inputSchema = null;
  31. static string inputAssembly = null;
  32. static string inputDirectory = null;
  33. static string serviceEndpoint = null;
  34. static string outputSchema = null;
  35. static string outputDirectory = null;
  36. static string outputAssembly = null;
  37. static bool outputCode = false;
  38. static bool wrappedProxy = true;
  39. static string proxyNamespace = null;
  40. static string strongNameFile = null;
  41. static string userName = null;
  42. static string password = null;
  43. static string domain = null;
  44. static string httpProxyName = null;
  45. static string httpProxyPort = null;
  46. string[] args;
  47. public Runner (string[] args)
  48. {
  49. this.args = args;
  50. }
  51. public void Main ()
  52. {
  53. try
  54. {
  55. ReadParameters (args);
  56. if (logo)
  57. WriteLogo ();
  58. if (args.Length == 0 || args[0] == "--help")
  59. {
  60. WriteHelp ();
  61. return;
  62. }
  63. ArrayList types = new ArrayList ();
  64. Assembly assembly = null;
  65. if (inputAssembly != null)
  66. {
  67. assembly = Assembly.LoadFile (inputAssembly);
  68. foreach (Type t in assembly.GetTypes ())
  69. types.Add (new ServiceType (t, serviceEndpoint));
  70. }
  71. if (inputTypes != null)
  72. {
  73. string[] ts = inputTypes.Split (';');
  74. foreach (string type in ts)
  75. {
  76. Type t = null;
  77. string url = null;
  78. string[] typeParts = type.Split (',');
  79. if (typeParts.Length == 1)
  80. throw new Exception ("Type assembly not specified");
  81. if (typeParts.Length >= 2)
  82. {
  83. t = Type.GetType (typeParts[0] + ", " + typeParts [1]);
  84. if (typeParts.Length > 2)
  85. url = typeParts [2];
  86. }
  87. types.Add (new ServiceType (t, url));
  88. }
  89. }
  90. ArrayList writtenFiles = new ArrayList ();
  91. MemoryStream schemaStream = null;
  92. if (types.Count > 0)
  93. {
  94. schemaStream = new MemoryStream ();
  95. MetaData.ConvertTypesToSchemaToStream ((ServiceType[]) types.ToArray (typeof(ServiceType)), SdlType.Wsdl, schemaStream);
  96. }
  97. if (inputUrl != null)
  98. {
  99. if (schemaStream != null) throw new Exception ("Only one type source can be specified");
  100. schemaStream = new MemoryStream ();
  101. MetaData.RetrieveSchemaFromUrlToStream (inputUrl, schemaStream);
  102. }
  103. if (inputSchema != null)
  104. {
  105. if (schemaStream != null) throw new Exception ("Only one type source can be specified");
  106. schemaStream = new MemoryStream ();
  107. FileStream fs = new FileStream (inputSchema, FileMode.Open, FileAccess.Read);
  108. byte[] buffer = new byte [1024*5];
  109. int nr = 0;
  110. while ((nr = fs.Read (buffer, 0, buffer.Length)) > 0)
  111. schemaStream.Write (buffer, 0, nr);
  112. }
  113. if (outputSchema != null)
  114. {
  115. if (schemaStream == null) throw new Exception ("No input schema or assembly has been specified");
  116. schemaStream.Position = 0;
  117. MetaData.SaveStreamToFile (schemaStream, outputSchema);
  118. Console.WriteLine ("Written file " + outputSchema);
  119. }
  120. if (outputCode)
  121. {
  122. if (schemaStream == null) throw new Exception ("No input schema or assembly has been specified");
  123. schemaStream.Position = 0;
  124. MetaData.ConvertSchemaStreamToCodeSourceStream (wrappedProxy, outputDirectory, schemaStream, writtenFiles, null, null);
  125. }
  126. if (outputAssembly != null)
  127. {
  128. if (schemaStream == null) throw new Exception ("No input schema or assembly has been specified");
  129. schemaStream.Position = 0;
  130. if (outputCode)
  131. MetaData.ConvertCodeSourceStreamToAssemblyFile (writtenFiles, outputAssembly, strongNameFile);
  132. else
  133. {
  134. MetaData.ConvertSchemaStreamToCodeSourceStream (wrappedProxy, outputDirectory, schemaStream, writtenFiles, null, null);
  135. MetaData.ConvertCodeSourceStreamToAssemblyFile (writtenFiles, outputAssembly, strongNameFile);
  136. foreach (string file in writtenFiles)
  137. File.Delete (file);
  138. writtenFiles.Clear ();
  139. }
  140. writtenFiles.Add (outputAssembly);
  141. }
  142. foreach (string fn in writtenFiles)
  143. Console.WriteLine ("Written file " + fn);
  144. }
  145. catch (Exception ex)
  146. {
  147. Console.WriteLine ("ERROR: " + ex.Message);
  148. if (ex.GetType() != typeof(Exception))
  149. Console.WriteLine (ex);
  150. }
  151. Console.WriteLine ();
  152. }
  153. static void WriteLogo ()
  154. {
  155. Console.WriteLine ("Mono SOAPSUDS Tool");
  156. Console.WriteLine ();
  157. }
  158. static void WriteHelp ()
  159. {
  160. Console.WriteLine ("Usage: soapsuds [inputs] [outputs] [options]");
  161. Console.WriteLine ();
  162. Console.WriteLine ("Inputs:");
  163. Console.WriteLine (" -url urltoschema:url Url from which to retrieve the schema");
  164. Console.WriteLine (" -types:type1,assembly[,serviceEndpoint][;type2,assembly,...] ");
  165. Console.WriteLine (" List of types from which to generate");
  166. Console.WriteLine (" a schema or proxy");
  167. Console.WriteLine (" -ia -inputassemblyfile:assembly Assembly that contains the types to export");
  168. Console.WriteLine (" -is -inputschemafile:schemafile Schema from which to generate proxy classes");
  169. Console.WriteLine ();
  170. Console.WriteLine ("Input Options:");
  171. Console.WriteLine (" -id -inputdirectory:directory Directory where DLLs are located");
  172. Console.WriteLine (" -se -serviceendpoint:url Url of the service to be placed in the");
  173. Console.WriteLine (" WSDL document");
  174. Console.WriteLine ();
  175. Console.WriteLine ("Outputs:");
  176. Console.WriteLine (" -oa -outputassemblyfile:assembly Generate an assembly");
  177. Console.WriteLine (" -os -outputschemafile:file Generate a schema");
  178. Console.WriteLine (" -gc -generatecode Generate proxy source code");
  179. Console.WriteLine ();
  180. Console.WriteLine ("Output Options:");
  181. Console.WriteLine (" -od -outputdirectory:directory Directory where output will be generated");
  182. Console.WriteLine (" -pn -proxynamespace:namespace Namespace of the generated proxy");
  183. Console.WriteLine (" -nowp -nowrappedproxy Generate a wrapped proxy");
  184. Console.WriteLine (" -wp -wrappedproxy Generate a wrapped proxy");
  185. Console.WriteLine (" -sn -strongnamefile:snfile Strong name file");
  186. Console.WriteLine ();
  187. Console.WriteLine ("General Options:");
  188. Console.WriteLine (" -u -username:name User name for server authentication");
  189. Console.WriteLine (" -p -password:pwd Password for server authentication");
  190. Console.WriteLine (" -d -domain:domain Domain of the server");
  191. Console.WriteLine (" -hpn -httpProxyName:name Name of http proxy");
  192. Console.WriteLine (" -hpp -httpProxyPort:port Port of http proxy");
  193. Console.WriteLine (" -nologo Supress the startup logo");
  194. Console.WriteLine ();
  195. }
  196. static void ReadParameters (string[] args)
  197. {
  198. NetworkCredential cred = new NetworkCredential ();
  199. NetworkCredential proxyCred = new NetworkCredential ();
  200. WebProxy proxy = new WebProxy ();
  201. foreach (string arg in args)
  202. {
  203. if (!arg.StartsWith ("/") && !arg.StartsWith ("-"))
  204. continue;
  205. string parg = arg.Substring (1);
  206. int i = parg.IndexOf (":");
  207. string param = null;
  208. if (i != -1) {
  209. param = parg.Substring (i+1);
  210. parg = parg.Substring (0,i);
  211. }
  212. switch (parg.ToLower ())
  213. {
  214. case "nologo":
  215. logo = false;
  216. break;
  217. case "urltoschema": case "url":
  218. inputUrl = param;
  219. break;
  220. case "types":
  221. inputTypes = param;
  222. break;
  223. case "inputassemblyfile": case "ia":
  224. inputAssembly = param;
  225. break;
  226. case "outputassemblyfile": case "oa":
  227. outputAssembly = param;
  228. break;
  229. case "inputdirectory": case "id":
  230. inputDirectory = param;
  231. break;
  232. case "outputdirectory": case "od":
  233. outputDirectory = param;
  234. break;
  235. case "inputschemafile": case "is":
  236. inputSchema = param;
  237. break;
  238. case "outputschemafile": case "os":
  239. outputSchema = param;
  240. break;
  241. case "proxynamespace": case "pn":
  242. proxyNamespace = param;
  243. break;
  244. case "serviceendpoint": case "se":
  245. serviceEndpoint = param;
  246. break;
  247. case "strongnamefile": case "sn":
  248. strongNameFile = param;
  249. break;
  250. case "nowrappedproxy": case "nowp":
  251. wrappedProxy = false;
  252. break;
  253. case "wrappedproxy": case "wp":
  254. wrappedProxy = true;
  255. break;
  256. case "generatecode": case "gc":
  257. outputCode = true;
  258. break;
  259. case "username": case "u":
  260. userName = param;
  261. break;
  262. case "password": case "p":
  263. password = param;
  264. break;
  265. case "domain": case "d":
  266. domain = param;
  267. break;
  268. case "httpProxyName": case "hpn":
  269. httpProxyName = param;
  270. break;
  271. case "httpProxyPort": case "hpp":
  272. httpProxyPort = param;
  273. break;
  274. }
  275. }
  276. }
  277. }