// Handle the processing of a report private byte[] ProcessReportFile(string url, string file, string parms, DateTime lastUpdateTime, out string mimeType) { byte[] result = null; string source; mimeType = "text/html"; // set the default // try finding report in the server cache! IList il = _server.Cache.Find(url + (parms == null?"":parms), lastUpdateTime); if (il != null) { try { string cfile = (string)il[il.Count - 1]; result = _server.ReadCache.Read(cfile); mimeType = GetMimeType(cfile); // set mimetype based on file's extension } catch (Exception ex) { if (_server.TraceLevel >= 0) { Console.WriteLine("Cache read exception in ProcessReportFile: {0} {1}", il[0], ex.Message); } } return(result); } // Obtain the source if (!ProcessReportGetSource(file, out source)) { return(Encoding.ASCII.GetBytes(source)); // we got an error opening file; source contains html error text } // Compile the report string msgs = ""; Report report = ProcessReportCompile(file, source, out msgs); if (report == null) { mimeType = "text/html"; // force to html return(Encoding.ASCII.GetBytes(String.Format("<H2>Report '{0}' has the following syntax errors.</H2><p>{1}", url, msgs))); } // Obtain the result HTML from running the report string dbgFilename = ""; try { ListDictionary ld = ProcessReportGetParms(parms); // split parms into dictionary OutputPresentationType type; string stype = (string)ld["rs:Format"]; if (stype == null) { stype = "html"; } else { stype = stype.ToLower(); } switch (stype) { case "pdf": type = OutputPresentationType.PDF; break; case "xml": type = OutputPresentationType.XML; string ext = (string)ld["rs:FileExtension"]; if (ext != null) { stype = ext; } break; case "html": type = OutputPresentationType.HTML; break; default: type = OutputPresentationType.HTML; stype = "html"; break; } StreamGen sg = new StreamGen(serverRoot, WorkingDir, stype); ProcessReport pr = new ProcessReport(report, sg); pr.Run(ld, type); // handle any error messages if (report.ErrorMaxSeverity > 0) { string errs = null; if (report.ErrorMaxSeverity > 4) { mimeType = "text/html"; // force to html errs = "<H2>Severe errors encountered when running report.</H2>"; } foreach (String emsg in report.ErrorItems) { if (report.ErrorMaxSeverity > 4) { errs += ("<p>" + emsg + "</p>"); } else { if (_server.TraceLevel > 0) { Console.WriteLine(emsg); // output message to console } } } if (errs != null) { result = Encoding.ASCII.GetBytes(errs); } report.ErrorReset(); } // Only read the result if significant errors didn't occur if (result == null) { ReportRender rr = new ReportRender(report); rr.ActionUrl = "/" + url; string p = rr.ParameterHtml(ld); // put this into a file. string parmUrl; StreamWriter sw = null; try { sw = new StreamWriter(sg.GetIOStream(out parmUrl, "html")); sw.Write(p); } finally { if (sw != null) { sw.Close(); } } // Add it to the file list IList newlist = _server.Cache.Add(url + (parms == null?"":parms), sg.FileList); dbgFilename = (string)newlist[0]; // this is the first fully qualified name FileInfo fi = new FileInfo(dbgFilename); string mHtml = rr.MainHtml(report, parmUrl, sg.RelativeDirectory + fi.Name); string mUrl; sw = null; try { sw = new StreamWriter(sg.GetIOStream(out mUrl, "html")); sw.Write(mHtml); } finally { if (sw != null) { sw.Close(); } } result = Encoding.ASCII.GetBytes(mHtml); } } catch (Exception ex) { if (_server.TraceLevel >= 0) { Console.WriteLine("Exception in ProcessReportFile: {0} {1}", file, ex.Message); } result = Encoding.ASCII.GetBytes(string.Format("<H2>{0}</H2><p>{1}</p>", ex.Message, ex.StackTrace)); mimeType = "text/html"; // force to html } return(result); }
// Handle the processing of a report private byte[] ProcessReportFile(string url, string file, string parms, DateTime lastUpdateTime, out string mimeType) { byte[] result=null; string source; mimeType = "text/html"; // set the default // try finding report in the server cache! IList il = _server.Cache.Find(url + (parms==null?"":parms), lastUpdateTime); if (il != null) { try { string cfile = (string) il[il.Count-1]; result = _server.ReadCache.Read(cfile); mimeType = GetMimeType(cfile); // set mimetype based on file's extension } catch (Exception ex) { if (_server.TraceLevel >= 0) Console.WriteLine("Cache read exception in ProcessReportFile: {0} {1}", il[0], ex.Message); } return result; } // Obtain the source if (!ProcessReportGetSource(file, out source)) { return Encoding.ASCII.GetBytes(source); // we got an error opening file; source contains html error text } // Compile the report string msgs=""; Report report = ProcessReportCompile(file, source, out msgs); if (report == null) { mimeType = "text/html"; // force to html return Encoding.ASCII.GetBytes(String.Format("<H2>Report '{0}' has the following syntax errors.</H2><p>{1}", url, msgs)); } // Obtain the result HTML from running the report string dbgFilename=""; try { ListDictionary ld = ProcessReportGetParms(parms); // split parms into dictionary OutputPresentationType type; string stype = (string) ld["rs:Format"]; if (stype == null) stype = "html"; else stype = stype.ToLower(); switch (stype) { case "pdf": type = OutputPresentationType.PDF; break; case "xml": type = OutputPresentationType.XML; string ext = (string) ld["rs:FileExtension"]; if (ext != null) stype = ext; break; case "html": type = OutputPresentationType.HTML; break; default: type = OutputPresentationType.HTML; stype = "html"; break; } StreamGen sg = new StreamGen(serverRoot, WorkingDir, stype); ProcessReport pr = new ProcessReport(report, sg); pr.Run(ld, type); // handle any error messages if (report.ErrorMaxSeverity > 0) { string errs=null; if (report.ErrorMaxSeverity > 4) { mimeType = "text/html"; // force to html errs = "<H2>Severe errors encountered when running report.</H2>"; } foreach (String emsg in report.ErrorItems) { if (report.ErrorMaxSeverity > 4) errs += ("<p>" + emsg + "</p>"); else { if (_server.TraceLevel > 0) Console.WriteLine(emsg); // output message to console } } if (errs != null) result = Encoding.ASCII.GetBytes(errs); report.ErrorReset(); } // Only read the result if significant errors didn't occur if (result == null) { ReportRender rr = new ReportRender(report); rr.ActionUrl = "/" + url; string p = rr.ParameterHtml(ld); // put this into a file. string parmUrl; StreamWriter sw=null; try { sw = new StreamWriter(sg.GetIOStream(out parmUrl, "html")); sw.Write(p); } finally { if (sw != null) sw.Close(); } // Add it to the file list IList newlist = _server.Cache.Add(url + (parms==null?"":parms), sg.FileList); dbgFilename = (string) newlist[0]; // this is the first fully qualified name FileInfo fi = new FileInfo(dbgFilename); string mHtml = rr.MainHtml(report, parmUrl, sg.RelativeDirectory+fi.Name); string mUrl; sw=null; try { sw = new StreamWriter(sg.GetIOStream(out mUrl, "html")); sw.Write(mHtml); } finally { if (sw != null) sw.Close(); } result = Encoding.ASCII.GetBytes(mHtml); } } catch (Exception ex) { if (_server.TraceLevel >= 0) Console.WriteLine("Exception in ProcessReportFile: {0} {1}", file, ex.Message); result = Encoding.ASCII.GetBytes(string.Format("<H2>{0}</H2><p>{1}</p>", ex.Message, ex.StackTrace)); mimeType = "text/html"; // force to html } return result; }