WebServiceCompiler.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // System.Web.Compilation.WebServiceCompiler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.IO;
  11. using System.Web.UI;
  12. using System.CodeDom.Compiler;
  13. //temp:
  14. using Microsoft.CSharp;
  15. namespace System.Web.Compilation
  16. {
  17. class WebServiceCompiler : BaseCompiler
  18. {
  19. SimpleWebHandlerParser wService;
  20. ICodeCompiler compiler;
  21. public WebServiceCompiler (SimpleWebHandlerParser wService)
  22. : base (null)
  23. {
  24. this.wService = wService;
  25. }
  26. public static Type CompileIntoType (SimpleWebHandlerParser wService)
  27. {
  28. WebServiceCompiler wsc = new WebServiceCompiler (wService);
  29. return wsc.GetCompiledType ();
  30. }
  31. public override Type GetCompiledType ()
  32. {
  33. if (wService.Program.Trim () == "")
  34. return wService.GetTypeFromBin (wService.ClassName);
  35. //FIXME: update when we support other languages
  36. string fname = Path.ChangeExtension (Path.GetTempFileName (), ".cs");
  37. StreamWriter sw = new StreamWriter (File.OpenWrite (fname));
  38. sw.WriteLine (wService.Program);
  39. sw.Close ();
  40. //TODO: get the compiler and default options from system.web/compileroptions
  41. CompilerResults results = CachingCompiler.Compile (this, fname);
  42. CheckCompilerErrors (results);
  43. return results.CompiledAssembly.GetType (wService.ClassName, true);
  44. }
  45. void CheckCompilerErrors (CompilerResults results)
  46. {
  47. if (results.NativeCompilerReturnValue == 0)
  48. return;
  49. throw new CompilationException (wService.PhysicalPath, results.Errors, wService.Program);
  50. }
  51. internal new SimpleWebHandlerParser Parser {
  52. get { return wService; }
  53. }
  54. internal override ICodeCompiler Compiler {
  55. get {
  56. if (compiler == null) {
  57. //TODO: get the compiler and default options from system.web/compileroptions
  58. compiler = new CSharpCodeProvider ().CreateCompiler ();
  59. }
  60. return compiler;
  61. }
  62. }
  63. }
  64. }