The Labs \ Source Viewer \ SSCLI \ System.Runtime.Remoting.MetadataServices \ MetaData

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. //============================================================
  16. //
  17. // File: MetaDataServices
  18. // Purpose: Defines APIs for Metadata
  19. //
  20. // Date: April 01, 2000
  21. //
  22. //============================================================
  23. namespace System.Runtime.Remoting.MetadataServices
  24. {
  25.     using System;
  26.     using System.Threading;
  27.     using System.Collections;
  28.     using System.Reflection;
  29.     using System.Xml;
  30.     using System.Diagnostics;
  31.     using System.IO;
  32.     using System.Net;
  33.     using System.Text;
  34.     using System.Runtime.InteropServices;
  35.     using System.Runtime.Remoting.Channels;
  36.     using System.Runtime.Remoting.Metadata;
  37.    
  38.     using Microsoft.CSharp;
  39.     using System.CodeDom.Compiler;
  40.     using System.Globalization;
  41.    
  42.     public class MetaData
  43.     {
  44.        
  45.         public static void ConvertTypesToSchemaToFile(Type[] types, SdlType sdlType, string path)
  46.         {
  47.             Util.Log("MetaData.ConvertTypesToSchemaToFile 1 " + path);
  48.             ConvertTypesToSchemaToStream(types, sdlType, File.Create(path));
  49.         }
  50.         // ConvertTypesToSchemaToFile
  51.         public static void ConvertTypesToSchemaToStream(Type[] types, SdlType sdlType, Stream outputStream)
  52.         {
  53.             Util.Log("MetaData.ConvertTypesToSchemaToFile 2 ");
  54.            
  55.             ServiceType[] serviceTypes = new ServiceType[types.Length];
  56.             for (int i = 0; i < types.Length; i++)
  57.                 serviceTypes[i] = new ServiceType(types[i]);
  58.            
  59.             ConvertTypesToSchemaToStream(serviceTypes, sdlType, outputStream);
  60.            
  61.         }
  62.         // ConvertTypesToSchemaToStream
  63.        
  64.         public static void ConvertTypesToSchemaToFile(ServiceType[] types, SdlType sdlType, string path)
  65.         {
  66.             Util.Log("MetaData.ConvertTypesToSchemaToFile 3 " + path);
  67.             ConvertTypesToSchemaToStream(types, sdlType, File.Create(path));
  68.         }
  69.         // ConvertTypesToSchemaToFile
  70.        
  71.         public static void ConvertTypesToSchemaToStream(ServiceType[] serviceTypes, SdlType sdlType, Stream outputStream)
  72.         {
  73.             Util.Log("MetaData.ConvertTypesToSchemaToStream 4");
  74.             if (sdlType == SdlType.Sdl)
  75.                 throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Sdl generation is not supported")));
  76.             TextWriter tw = new StreamWriter(outputStream, new UTF8Encoding(false, true));
  77.             SUDSGenerator sgen = new SUDSGenerator(serviceTypes, sdlType, tw);
  78.             sgen.Generate();
  79.             tw.Flush();
  80.            
  81.         }
  82.         // ConvertTypesToSchemaToStream
  83.         public static void RetrieveSchemaFromUrlToStream(string url, Stream outputStream)
  84.         {
  85.             WebRequest Request;
  86.             WebResponse Response;
  87.             Stream RespStream;
  88.             Util.Log("MetaData.RetrieveSchemaFromUrlToStream " + url);
  89.             TextWriter tw = new StreamWriter(outputStream, new UTF8Encoding(false, true));
  90.            
  91.             Request = WebRequest.Create(url);
  92.             Response = Request.GetResponse();
  93.             RespStream = Response.GetResponseStream();
  94.             StreamReader sr = new StreamReader(RespStream);
  95.             tw.Write(sr.ReadToEnd());
  96.             tw.Flush();
  97.         }
  98.        
  99.         public static void RetrieveSchemaFromUrlToFile(string url, string path)
  100.         {
  101.             Util.Log("MetaData.RetrieveSchemaFromUrlToFile " + url + " file " + path);
  102.             RetrieveSchemaFromUrlToStream(url, File.Create(path));
  103.         }
  104.        
  105.        
  106.        
  107.        
  108.         public static void ConvertSchemaStreamToCodeSourceStream(bool clientProxy, string outputDirectory, Stream inputStream, ArrayList outCodeStreamList, string proxyUrl, string proxyNamespace)
  109.         {
  110.             Util.Log("MetaData.ConvertSchemaStreamToCodeSourceStream 1 " + outputDirectory + " proxyUrl " + proxyNamespace);
  111.             TextReader input;
  112.            
  113.             input = (TextReader)new StreamReader(inputStream);
  114.            
  115.             SUDSParser parser = new SUDSParser(input, outputDirectory, outCodeStreamList, proxyUrl, clientProxy, proxyNamespace);
  116.             parser.Parse();
  117.         }
  118.        
  119.         public static void ConvertSchemaStreamToCodeSourceStream(bool clientProxy, string outputDirectory, Stream inputStream, ArrayList outCodeStreamList, string proxyUrl)
  120.         {
  121.             Util.Log("MetaData.ConvertSchemaStreamToCodeSourceStream 3 " + outputDirectory);
  122.             ConvertSchemaStreamToCodeSourceStream(clientProxy, outputDirectory, inputStream, outCodeStreamList, proxyUrl, "");
  123.         }
  124.        
  125.         public static void ConvertSchemaStreamToCodeSourceStream(bool clientProxy, string outputDirectory, Stream inputStream, ArrayList outCodeStreamList)
  126.         {
  127.             Util.Log("MetaData.ConvertSchemaStreamToCodeSourceStream 2 " + outputDirectory);
  128.             ConvertSchemaStreamToCodeSourceStream(clientProxy, outputDirectory, inputStream, outCodeStreamList, "", "");
  129.         }
  130.        
  131.        
  132.         public static void ConvertCodeSourceStreamToAssemblyFile(ArrayList outCodeStreamList, string assemblyPath, string strongNameFilename)
  133.         {
  134.             throw new NotImplementedException("Not Implemented in Rotor");
  135.         }
  136.        
  137.        
  138. /*
  139. /target:module -> Name="target", Value="module"
  140. /target:library -> Name="target", Value="library"
  141. /main:MyClass -> Name="m", Value="MyClass"
  142. /debug+ -> Name="debug", Value=true
  143. // The dictionary of options takes almost ALL of the normal command-line options, but only using their 'short form' and without the preceding slash or dash.
  144. */       
  145.        
  146.         public static void ConvertCodeSourceFileToAssemblyFile(string codePath, string assemblyPath, string strongNameFilename)
  147.         {
  148.             Util.Log("MetaData.ConvertCodeSourceFileToAssemblyFile codePath " + codePath + " assemblyPath " + assemblyPath);
  149.             ArrayList arrayList = new ArrayList();
  150.             arrayList.Add(codePath);
  151.             ConvertCodeSourceStreamToAssemblyFile(arrayList, assemblyPath, strongNameFilename);
  152.         }
  153.        
  154.         // Helpers
  155.        
  156.         public static void SaveStreamToFile(Stream inputStream, string path)
  157.         {
  158.             Util.Log("MetaData.SaveStreamToFile " + path);
  159.             Stream outputStream = File.Create(path);
  160.             TextWriter tw = new StreamWriter(outputStream, new UTF8Encoding(false, true));
  161.             StreamReader sr = new StreamReader(inputStream);
  162.             tw.Write(sr.ReadToEnd());
  163.             tw.Flush();
  164.             tw.Close();
  165.             outputStream.Close();
  166.         }
  167.        
  168.        
  169.     }
  170.     // class MetaData
  171.    
  172.     public class ServiceType
  173.     {
  174.         private Type _type;
  175.         // Type of object being exported.
  176.         private string _url;
  177.         // This may be null if no address is available.
  178.         public ServiceType(Type type)
  179.         {
  180.             _type = type;
  181.             _url = null;
  182.         }
  183.         // ServiceType
  184.         public ServiceType(Type type, string url)
  185.         {
  186.             _type = type;
  187.             _url = url;
  188.         }
  189.         // ServiceType
  190.         public Type ObjectType {
  191.             get { return _type; }
  192.         }
  193.         public string Url {
  194.             get { return _url; }
  195.         }
  196.        
  197.     }
  198.     // ServiceType
  199.    
  200.    
  201. }
  202. // namespace System.Runtime.Remoting.MetadataServices

Developer Fusion