2 // System.Runtime.Remoting.MetadataServices.MetaData
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // (C) 2003 Martin Willemoes Hansen
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
36 using System.Reflection;
39 using System.CodeDom.Compiler;
40 using Microsoft.CSharp;
43 namespace System.Runtime.Remoting.MetadataServices
47 internal const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
48 internal const string XmlnsNamespace = "http://www.w3.org/2000/xmlns/";
49 internal const string SchemaNamespace = "http://www.w3.org/2001/XMLSchema";
50 internal const string SchemaInstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
51 internal const string SudsNamespace = "http://www.w3.org/2000/wsdl/suds";
52 internal const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
53 internal const string SoapNamespace = "http://schemas.xmlsoap.org/wsdl/soap/";
60 [MonoTODO ("strong name")]
61 public static void ConvertCodeSourceFileToAssemblyFile (
64 string strongNameFilename)
66 CSharpCodeProvider prov = new CSharpCodeProvider ();
67 ICodeCompiler comp = prov.CreateCompiler ();
68 CompilerParameters pars = new CompilerParameters ();
69 pars.OutputAssembly = assemblyPath;
70 CompilerResults cr = comp.CompileAssemblyFromFile(pars, codePath);
74 [MonoTODO ("strong name")]
75 public static void ConvertCodeSourceStreamToAssemblyFile (
76 ArrayList outCodeStreamList,
78 string strongNameFilename)
80 CSharpCodeProvider prov = new CSharpCodeProvider ();
81 ICodeCompiler comp = prov.CreateCompiler ();
82 CompilerParameters pars = new CompilerParameters ();
83 pars.OutputAssembly = assemblyPath;
84 CompilerResults cr = comp.CompileAssemblyFromFileBatch (pars, (string[]) outCodeStreamList.ToArray(typeof(string)));
88 static void CheckResult (CompilerResults cr)
90 if (cr.Errors.Count > 0)
92 foreach (string s in cr.Output)
93 Console.WriteLine (s);
96 foreach (CompilerError error in cr.Errors)
97 if (error.FileName != "")
98 errs += error.ToString () + "\n";
99 throw new Exception ("There where errors during compilation of the assembly:\n" + errs);
102 public static void ConvertSchemaStreamToCodeSourceStream (
104 string outputDirectory,
106 ArrayList outCodeStreamList)
108 ConvertSchemaStreamToCodeSourceStream (clientProxy, outputDirectory, inputStream, outCodeStreamList, null, null);
111 public static void ConvertSchemaStreamToCodeSourceStream (
113 string outputDirectory,
115 ArrayList outCodeStreamList,
118 ConvertSchemaStreamToCodeSourceStream (clientProxy, outputDirectory, inputStream, outCodeStreamList, proxyUrl, null);
121 public static void ConvertSchemaStreamToCodeSourceStream (
123 string outputDirectory,
125 ArrayList outCodeStreamList,
127 string proxyNamespace)
129 MetaDataCodeGenerator cg = new MetaDataCodeGenerator ();
131 MemoryStream memStream = new MemoryStream ();
132 CopyStream (inputStream, memStream);
133 memStream.Position = 0;
134 cg.GenerateCode (clientProxy, outputDirectory, memStream, outCodeStreamList, proxyUrl, proxyNamespace);
138 public static void ConvertTypesToSchemaToFile (ServiceType [] types, SdlType sdlType, string path)
140 FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
141 ConvertTypesToSchemaToStream (types, sdlType, fs);
145 public static void ConvertTypesToSchemaToFile (Type [] types, SdlType sdlType, string path)
147 FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
148 ConvertTypesToSchemaToStream (types, sdlType, fs);
152 public static void ConvertTypesToSchemaToStream (Type [] types, SdlType sdlType, Stream outputStream)
154 ServiceType[] st = new ServiceType [types.Length];
155 for (int n=0; n<types.Length; n++)
156 st [n] = new ServiceType (types[n]);
158 ConvertTypesToSchemaToStream (st, sdlType, outputStream);
161 public static void ConvertTypesToSchemaToStream (ServiceType [] serviceTypes, SdlType sdlType, Stream outputStream)
163 MetaDataExporter exporter = new MetaDataExporter ();
164 MemoryStream memStream = new MemoryStream ();
166 StreamWriter sw = new StreamWriter (memStream);
167 XmlTextWriter tw = new XmlTextWriter (sw);
169 exporter.ExportTypes (serviceTypes, sdlType, tw);
172 memStream.Position = 0;
173 CopyStream (memStream, outputStream);
176 public static void RetrieveSchemaFromUrlToFile (string url, string path)
178 FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
179 RetrieveSchemaFromUrlToStream (url, fs);
183 public static void RetrieveSchemaFromUrlToStream (string url, Stream outputStream)
185 WebRequest req = WebRequest.Create (url);
186 Stream st = req.GetResponse().GetResponseStream();
187 CopyStream (st, outputStream);
191 public static void SaveStreamToFile (Stream inputStream, string path)
193 FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
194 CopyStream (inputStream, fs);
198 static void CopyStream (Stream inputStream, Stream outputStream)
200 byte[] buffer = new byte [1024*5];
203 while ((nr = inputStream.Read (buffer, 0, buffer.Length)) > 0)
204 outputStream.Write (buffer, 0, nr);