- PermissionSet ps = SecurityManager.ResolvePolicy (evidence);
- if (ps != null)
- ps.Demand ();
- sw = File.CreateText (tmpbase + Extension);
- sw.WriteLine (SourceTemplate.Replace ("{0}", DateTime.Now.ToString ()).Replace ("{1}", classSuffix).Replace ("{2}", 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 (); // FIXME: 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) {
- }
+ if (scriptNode.BaseURI != String.Empty)
+ filename = new Uri (scriptNode.BaseURI).LocalPath;
+ } catch (FormatException) {
+ }
+ if (filename == String.Empty)
+ filename = "__baseURI_not_supplied__";
+
+ // get source location
+ IXmlLineInfo li = scriptNode as IXmlLineInfo;
+ string lineInfoLine =
+ li != null && li.LineNumber > 0 ?
+ 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);
+
+ CompilerResults res = compiler.CompileAssemblyFromSource (parameters, source);
+ if (res.Errors.Count != 0)
+ throw new XsltCompileException ("Stylesheet script compile error: \n" + FormatErrorMessage (res) /*+ "Code :\n" + source*/, null, scriptNode);
+ if (res.CompiledAssembly == null)
+ throw new XsltCompileException ("Cannot compile stylesheet script", null, scriptNode);
+ return res.CompiledAssembly.GetType ("GeneratedAssembly.Script" + classSuffix);
+ }
+
+ private string FormatErrorMessage (CompilerResults res)
+ {
+ string s = String.Empty;
+ foreach (CompilerError e in res.Errors) {
+ object [] parameters = new object [] {"\n",
+ e.FileName,
+ e.Line > 0 ? " line " + e.Line : String.Empty,
+ e.IsWarning ? " WARNING: " : " ERROR: ",
+ e.ErrorNumber,
+ ": ",
+ e.ErrorText};
+ s += String.Concat (parameters);