//
// (C)2003 Novell inc.
//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
}
-#if true // Use CodeDom
public virtual Type GetScriptClass (string code, string classSuffix, XPathNavigator scriptNode, Evidence evidence)
{
PermissionSet ps = SecurityManager.ResolvePolicy (evidence);
IXmlLineInfo li = scriptNode as IXmlLineInfo;
string lineInfoLine =
li != null && li.LineNumber > 0 ?
- "\n#line " + li.LineNumber + " \"" + filename + "\"" :
+ String.Format (CultureInfo.InvariantCulture, "\n#line {0} \"{1}\"", li.LineNumber, filename) :
String.Empty;
string source = SourceTemplate.Replace ("{0}", DateTime.Now.ToString ()).Replace ("{1}", classSuffix).Replace ("{2}", lineInfoLine + code);
throw new XsltCompileException ("Cannot compile stylesheet script", null, scriptNode);
return res.CompiledAssembly.GetType ("GeneratedAssembly.Script" + classSuffix);
}
-#else // obsolete code - uses external process
- [MonoTODO ("Should use Assembly.LoadFile() instead of LoadFrom() after its implementation has finished.")]
- public virtual Type GetScriptClass (string code, string classSuffix, XPathNavigator scriptNode, Evidence evidence)
- {
- string tmpPath = Path.GetTempPath ();
- if (!tmpPath.EndsWith (Path.DirectorySeparatorChar.ToString ()))
- tmpPath += Path.DirectorySeparatorChar;
- string tmpbase = tmpPath + Guid.NewGuid ();
- ProcessStartInfo psi = new ProcessStartInfo ();
- psi.UseShellExecute = false;
- psi.RedirectStandardError = true;
- psi.RedirectStandardOutput = true;
- Process proc = new Process ();
- proc.StartInfo = psi;
- StreamWriter sw = null;
- try {
- PermissionSet ps = SecurityManager.ResolvePolicy (evidence);
- if (ps != null)
- ps.Demand ();
- sw = File.CreateText (tmpbase + Extension);
- IXmlLineInfo li = scriptNode as IXmlLineInfo;
- string lineInfoLine = li != null ? "\n#line " + li.LineNumber + " \"" + scriptNode.BaseURI + "\"\n" : String.Empty;
- sw.WriteLine (SourceTemplate.Replace ("{0}", DateTime.Now.ToString ()).Replace ("{1}", classSuffix).Replace ("{2}", lineInfoLine + code));
-
- sw.Close ();
- psi.FileName = CompilerCommand;
- psi.Arguments = String.Concat (GetCompilerArguments (tmpbase + Extension));
- psi.WorkingDirectory = tmpPath;
- proc.Start ();
-// Console.WriteLine (proc.StandardOutput.ReadToEnd ());
-// Console.WriteLine (proc.StandardError.ReadToEnd ());
- proc.WaitForExit (); // should we configure timeout?
- Assembly generated = Assembly.LoadFrom (tmpbase + ".dll");
-
- if (generated == null)
- throw new XsltCompileException ("Could not load script assembly", null, scriptNode);
- return generated.GetType ("GeneratedAssembly.Script" + classSuffix);
- } catch (Exception ex) {
- throw new XsltCompileException ("Script compilation error: " + ex.Message, ex, scriptNode);
- } finally {
- try {
- File.Delete (tmpbase + Extension);
- File.Delete (tmpbase + ".dll");
- if (sw != null)
- sw.Close ();
- } catch (Exception) {
- }
- }
- }
-#endif
private string FormatErrorMessage (CompilerResults res)
{
{
static Type providerType;
- static JScriptCompilerInfo ()
- {
- Assembly jsasm = Assembly.LoadWithPartialName ("Microsoft.JScript.dll", null);
- providerType = jsasm.GetType ("Microsoft.JScript.JScriptCodeProvider");
- }
-
public JScriptCompilerInfo ()
{
this.CompilerCommand = "mjs";
this.DefaultCompilerOptions = "/t:library /r:Microsoft.VisualBasic.dll";
}
- public override CodeDomProvider CodeDomProvider {\r
- get { return (CodeDomProvider) Activator.CreateInstance (providerType); }\r
- }\r
+ public override CodeDomProvider CodeDomProvider {
+ get {
+ // no need for locking
+ if (providerType == null) {
+ Assembly jsasm = Assembly.LoadWithPartialName ("Microsoft.JScript", null);
+ if (jsasm != null)
+ providerType = jsasm.GetType ("Microsoft.JScript.JScriptCodeProvider");
+ }
+ return (CodeDomProvider) Activator.CreateInstance (providerType);
+ }
+ }
public override string Extension {
get { return ".js"; }