Fixed handling of modifier keys in KeyEventArgs constructor (bug #6707)
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.MetadataServices / MetaData.cs
1 //
2 // System.Runtime.Remoting.MetadataServices.MetaData
3 //
4 // Authors:
5 //      Martin Willemoes Hansen (mwh@sysrq.dk)
6 //              Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // (C) 2003 Martin Willemoes Hansen
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using System.Collections;
33 using System.IO;
34 using System.Text;
35 using System.Xml;
36 using System.Reflection;
37 using System.Net;
38 #if !TARGET_JVM
39 using System.CodeDom.Compiler;
40 using Microsoft.CSharp;
41 #endif
42
43 namespace System.Runtime.Remoting.MetadataServices
44 {
45         public class MetaData 
46         {
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/";
54                 
55                 public MetaData() 
56                 {
57                 }
58
59 #if !TARGET_JVM
60                 [MonoTODO ("strong name")]
61                 public static void ConvertCodeSourceFileToAssemblyFile (
62                                    string codePath,
63                                    string assemblyPath,
64                                    string strongNameFilename)
65                 {
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);
71                         CheckResult (cr);
72                 }
73
74                 [MonoTODO ("strong name")]
75                 public static void ConvertCodeSourceStreamToAssemblyFile (
76                                    ArrayList outCodeStreamList,
77                                    string assemblyPath,
78                                    string strongNameFilename)
79                 {
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)));
85                         CheckResult (cr);
86                 }
87                 
88                 static void CheckResult (CompilerResults cr)
89                 {
90                         if (cr.Errors.Count > 0)
91                         {
92                                 foreach (string s in cr.Output)
93                                         Console.WriteLine (s);
94                                         
95                                 string errs = "";
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);
100                         }
101                 }
102                 public static void ConvertSchemaStreamToCodeSourceStream (
103                                    bool clientProxy, 
104                                    string outputDirectory, 
105                                    Stream inputStream, 
106                                    ArrayList outCodeStreamList)
107                 {
108                         ConvertSchemaStreamToCodeSourceStream (clientProxy, outputDirectory, inputStream, outCodeStreamList, null, null);
109                 }
110
111                 public static void ConvertSchemaStreamToCodeSourceStream (
112                                    bool clientProxy, 
113                                    string outputDirectory, 
114                                    Stream inputStream, 
115                                    ArrayList outCodeStreamList, 
116                                    string proxyUrl)
117                 {
118                         ConvertSchemaStreamToCodeSourceStream (clientProxy, outputDirectory, inputStream, outCodeStreamList, proxyUrl, null);
119                 }
120
121                 public static void ConvertSchemaStreamToCodeSourceStream (
122                                    bool clientProxy, 
123                                    string outputDirectory, 
124                                    Stream inputStream, 
125                                    ArrayList outCodeStreamList, 
126                                    string proxyUrl, 
127                                    string proxyNamespace)
128                 {
129                         MetaDataCodeGenerator cg = new MetaDataCodeGenerator ();
130                         
131                         MemoryStream memStream = new MemoryStream ();
132                         CopyStream (inputStream, memStream);
133                         memStream.Position = 0;
134                         cg.GenerateCode (clientProxy, outputDirectory, memStream, outCodeStreamList, proxyUrl, proxyNamespace);
135                 }
136 #endif
137
138                 public static void ConvertTypesToSchemaToFile (ServiceType [] types, SdlType sdlType, string path)
139                 {
140                         FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
141                         ConvertTypesToSchemaToStream (types, sdlType, fs);
142                         fs.Close ();
143                 }
144
145                 public static void ConvertTypesToSchemaToFile (Type [] types, SdlType sdlType, string path)
146                 {
147                         FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
148                         ConvertTypesToSchemaToStream (types, sdlType, fs);
149                         fs.Close ();
150                 }
151
152                 public static void ConvertTypesToSchemaToStream (Type [] types, SdlType sdlType, Stream outputStream)
153                 {
154                         ServiceType[] st = new ServiceType [types.Length];
155                         for (int n=0; n<types.Length; n++)
156                                 st [n] = new ServiceType (types[n]);
157
158                         ConvertTypesToSchemaToStream (st, sdlType, outputStream);
159                 }
160
161                 public static void ConvertTypesToSchemaToStream (ServiceType [] serviceTypes, SdlType sdlType, Stream outputStream)
162                 {
163                         MetaDataExporter exporter = new MetaDataExporter ();
164                         MemoryStream memStream = new MemoryStream ();
165                         
166                         StreamWriter sw = new StreamWriter (memStream);
167                         XmlTextWriter tw = new XmlTextWriter (sw);
168
169                         exporter.ExportTypes (serviceTypes, sdlType, tw);
170                         tw.Flush ();
171                         
172                         memStream.Position = 0;
173                         CopyStream (memStream, outputStream);
174                 }
175                 
176                 public static void RetrieveSchemaFromUrlToFile (string url, string path)
177                 {
178                         FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
179                         RetrieveSchemaFromUrlToStream (url, fs);
180                         fs.Close ();
181                 }
182
183                 public static void RetrieveSchemaFromUrlToStream (string url, Stream outputStream)
184                 {
185                         WebRequest req = WebRequest.Create (url);
186                         Stream st = req.GetResponse().GetResponseStream();
187                         CopyStream (st, outputStream);
188                         st.Close ();
189                 }
190
191                 public static void SaveStreamToFile (Stream inputStream, string path)
192                 {
193                         FileStream fs = new FileStream (path, FileMode.Create, FileAccess.Write);
194                         CopyStream (inputStream, fs);
195                         fs.Close ();
196                 }
197                 
198                 static void CopyStream (Stream inputStream, Stream outputStream)
199                 {
200                         byte[] buffer = new byte [1024*5];
201                         int nr = 0;
202                         
203                         while ((nr = inputStream.Read (buffer, 0, buffer.Length)) > 0)
204                                 outputStream.Write (buffer, 0, nr);
205                 }
206         }
207 }