ReportService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. using System.ServiceModel;
  5. using System.Web.Hosting;
  6. using System.Text;
  7. using System.IO;
  8. using System.Configuration;
  9. using System.Collections;
  10. using System.Drawing;
  11. using System.Drawing.Drawing2D;
  12. using System.Drawing.Imaging;
  13. using FastReport;
  14. using FastReport.Utils;
  15. using FastReport.Data;
  16. using FastReport.Export.Pdf;
  17. using FastReport.Export.OoXML;
  18. using FastReport.Export.RichText;
  19. using FastReport.Export.Odf;
  20. using FastReport.Export.Mht;
  21. using FastReport.Export.Csv;
  22. using FastReport.Export.Dbf;
  23. using FastReport.Export.Xml;
  24. using FastReport.Export.Text;
  25. using FastReport.Export.Html;
  26. using FastReport.Export.XAML;
  27. using FastReport.Export.Image;
  28. using FastReport.Export;
  29. using System.Net;
  30. using System.ServiceModel.Web;
  31. namespace FastReport.Service
  32. {
  33. public partial class ReportService : IFastReportService
  34. {
  35. public string About()
  36. {
  37. string s = "FastReport.NET Service " + Config.Version;
  38. return s;
  39. }
  40. public bool CheckPreparedReport(string uuid)
  41. {
  42. if (!PreparedPathExists())
  43. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Upload disabled", ErrorCode = 102 },
  44. System.Net.HttpStatusCode.InternalServerError);
  45. string preparedPath = GetPreparedPath();
  46. string preparedFile = GetPreparedFileName(uuid);
  47. return File.Exists(Path.Combine(preparedPath, preparedFile));
  48. }
  49. public string PutPreparedReport(Stream preparedReport)
  50. {
  51. if (!PreparedPathExists())
  52. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Upload disabled", ErrorCode = 102 },
  53. System.Net.HttpStatusCode.InternalServerError);
  54. string uuid = "";
  55. string preparedPath = GetPreparedPath();
  56. if (Directory.Exists(preparedPath))
  57. {
  58. MemoryStream preparedStream = PreparePostStream(preparedReport);
  59. if (preparedReport != null && preparedStream.Length > 0)
  60. {
  61. using (Report r = new Report())
  62. {
  63. Config.WebMode = true;
  64. try
  65. {
  66. MemoryStream checkPrepared = new MemoryStream();
  67. preparedStream.WriteTo(checkPrepared);
  68. checkPrepared.Position = 0;
  69. r.LoadPrepared(checkPrepared);
  70. preparedStream.Position = 0;
  71. string tempUuid = Guid.NewGuid().ToString();
  72. StorePrepared(tempUuid, preparedPath, preparedStream);
  73. uuid = tempUuid;
  74. }
  75. catch (Exception e)
  76. {
  77. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = e.Message, ErrorCode = 100 },
  78. System.Net.HttpStatusCode.InternalServerError);
  79. }
  80. }
  81. }
  82. else
  83. {
  84. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Empty input data", ErrorCode = 101 },
  85. System.Net.HttpStatusCode.BadRequest);
  86. }
  87. }
  88. else
  89. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Upload directory not found", ErrorCode = 107 },
  90. System.Net.HttpStatusCode.BadRequest);
  91. return uuid;
  92. }
  93. public string PutReport(Stream report)
  94. {
  95. if (!PreparedPathExists())
  96. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Upload disabled", ErrorCode = 102 },
  97. System.Net.HttpStatusCode.InternalServerError);
  98. string uuid = "";
  99. string preparedPath = GetPreparedPath();
  100. if (Directory.Exists(preparedPath))
  101. {
  102. MemoryStream reportStream = PreparePostStream(report);
  103. if (report != null && reportStream.Length > 0)
  104. {
  105. using (Report r = new Report())
  106. {
  107. Config.WebMode = true;
  108. try
  109. {
  110. reportStream.Position = 0;
  111. r.Load(reportStream);
  112. r.PreparePhase1();
  113. r.PreparePhase2();
  114. MemoryStream reportPrepared = new MemoryStream();
  115. r.SavePrepared(reportPrepared);
  116. string tempUuid = Guid.NewGuid().ToString();
  117. StorePrepared(tempUuid, preparedPath, reportPrepared);
  118. uuid = tempUuid;
  119. }
  120. catch (Exception e)
  121. {
  122. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = e.Message, ErrorCode = 100 },
  123. System.Net.HttpStatusCode.InternalServerError);
  124. }
  125. }
  126. }
  127. else
  128. {
  129. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Empty input data", ErrorCode = 101 },
  130. System.Net.HttpStatusCode.BadRequest);
  131. }
  132. }
  133. else
  134. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Upload directory not found", ErrorCode = 107 },
  135. System.Net.HttpStatusCode.BadRequest);
  136. return uuid;
  137. }
  138. private void StorePrepared(string uuid, string preparedPath, MemoryStream preparedStream)
  139. {
  140. if (Directory.Exists(preparedPath))
  141. {
  142. int storageTimeoutInMinutes = 0;
  143. string s = ConfigurationManager.AppSettings["FastReport.PreparedCleanupDelay"];
  144. if (Int32.TryParse(s, out storageTimeoutInMinutes))
  145. CleanStorage(preparedPath, "*.fpx", storageTimeoutInMinutes, 1);
  146. string fileName = GetPreparedFileName(uuid);
  147. string fullPath = Path.Combine(preparedPath, fileName);
  148. using (FileStream fileStream = new FileStream(fullPath, FileMode.Create))
  149. preparedStream.WriteTo(fileStream);
  150. }
  151. }
  152. private int CleanStorage(string FileStoragePath, string maskStorage, int StorageTimeoutInMinutes, int CleanupInMinutes)
  153. {
  154. string touch = Path.Combine(FileStoragePath, "FRS-touch");
  155. int filesCount = 0;
  156. if (StorageTimeoutInMinutes > 0 &&
  157. CleanupInMinutes > 0 &&
  158. !String.IsNullOrEmpty(FileStoragePath) &&
  159. Directory.Exists(FileStoragePath))
  160. {
  161. if (File.Exists(touch))
  162. {
  163. DateTime created = File.GetLastWriteTime(touch);
  164. if (DateTime.Now > created.AddMinutes(CleanupInMinutes))
  165. {
  166. File.SetLastWriteTime(touch, DateTime.Now);
  167. string[] dir = Directory.GetFiles(FileStoragePath, maskStorage);
  168. foreach (string file in dir)
  169. {
  170. try
  171. {
  172. if (DateTime.Now > File.GetLastWriteTime(file).AddMinutes(StorageTimeoutInMinutes))
  173. File.Delete(file);
  174. }
  175. catch
  176. {
  177. //nothing
  178. }
  179. }
  180. }
  181. }
  182. else
  183. using (FileStream file = File.Create(touch)) { };
  184. filesCount = Directory.GetFiles(FileStoragePath, maskStorage).Length;
  185. }
  186. return filesCount;
  187. }
  188. private string GetPreparedFileName(string uuid)
  189. {
  190. if (!String.IsNullOrEmpty(uuid))
  191. return String.Concat(uuid.Replace("-", ""), ".fpx");
  192. else
  193. return String.Empty;
  194. }
  195. private bool PreparedPathExists()
  196. {
  197. string s = ConfigurationManager.AppSettings["FastReport.PreparedPath"];
  198. return !string.IsNullOrEmpty(s);
  199. }
  200. private bool ReportsPathExists()
  201. {
  202. string s = ConfigurationManager.AppSettings["FastReport.ReportsPath"];
  203. return !string.IsNullOrEmpty(s);
  204. }
  205. private string GetPreparedPath()
  206. {
  207. string s = ConfigurationManager.AppSettings["FastReport.PreparedPath"];
  208. string result = HostingEnvironment.MapPath(s);
  209. if (String.IsNullOrEmpty(result))
  210. result = s;
  211. return result;
  212. }
  213. private string GetReportsPath()
  214. {
  215. string s = ConfigurationManager.AppSettings["FastReport.ReportsPath"];
  216. string result = HostingEnvironment.MapPath(s);
  217. if (String.IsNullOrEmpty(result))
  218. result = s;
  219. return result;
  220. }
  221. public Stream GetPreparedByUUID(string uuid)
  222. {
  223. if (!PreparedPathExists())
  224. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Upload disabled", ErrorCode = 102 },
  225. System.Net.HttpStatusCode.InternalServerError);
  226. string preparedPath = GetPreparedPath();
  227. string preparedFile = GetPreparedFileName(uuid);
  228. string fullPath = Path.Combine(preparedPath, preparedFile);
  229. MemoryStream resultFile = new MemoryStream();
  230. if (File.Exists(fullPath))
  231. {
  232. File.SetLastWriteTime(fullPath, DateTime.Now);
  233. using (FileStream file = new FileStream(fullPath, FileMode.Open))
  234. {
  235. file.CopyTo(resultFile);
  236. resultFile.Position = 0;
  237. }
  238. }
  239. else
  240. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "File not found", ErrorCode = 404 },
  241. System.Net.HttpStatusCode.NotFound);
  242. return resultFile;
  243. }
  244. public Stream GetLogoByUUIDFixed(string uuid)
  245. {
  246. return GetLogoByUUID(uuid, "200", "200");
  247. }
  248. public Stream GetLogoByUUID(string uuid, string width, string height)
  249. {
  250. int dx, dy;
  251. MemoryStream stream = new MemoryStream();
  252. if (Int32.TryParse(width, out dx) && Int32.TryParse(height, out dy))
  253. {
  254. Stream preparedStream = GetPreparedByUUID(uuid);
  255. using (Report r = new Report())
  256. {
  257. Config.WebMode = true;
  258. try
  259. {
  260. r.LoadPrepared(preparedStream);
  261. MemoryStream pngStream = new MemoryStream();
  262. ImageExport pngExport = new ImageExport();
  263. pngExport.ImageFormat = ImageExportFormat.Png;
  264. pngExport.Resolution = 96;
  265. pngExport.PageRange = PageRange.PageNumbers;
  266. pngExport.PageNumbers = "1";
  267. r.Export(pngExport, pngStream);
  268. pngStream.Position = 0;
  269. ResizePNG(pngStream, stream, dx, dy);
  270. }
  271. catch (Exception e)
  272. {
  273. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = e.Message, ErrorCode = 103 },
  274. System.Net.HttpStatusCode.InternalServerError);
  275. }
  276. stream.Position = 0;
  277. }
  278. }
  279. else
  280. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Wrong width or height", ErrorCode = 106 },
  281. System.Net.HttpStatusCode.BadRequest);
  282. return stream;
  283. }
  284. private void ResizePNG(Stream sourceStream, Stream targetStream, int maxWidth, int maxHeight)
  285. {
  286. Bitmap image = new Bitmap(sourceStream);
  287. float scaleX = (float)maxWidth / (float)image.Width;
  288. float scaleY = (float)maxHeight / (float)image.Height;
  289. float ratio = Math.Min(scaleX, scaleY);
  290. int newWidth = (int)Math.Round(image.Width * ratio);
  291. int newHeight = (int)Math.Round(image.Height * ratio);
  292. Bitmap newImage = new Bitmap(newWidth, newHeight, PixelFormat.Format24bppRgb);
  293. using (Graphics graphics = Graphics.FromImage(newImage))
  294. {
  295. graphics.CompositingQuality = CompositingQuality.HighQuality;
  296. graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
  297. graphics.SmoothingMode = SmoothingMode.HighQuality;
  298. graphics.DrawImage(image, 0, 0, newWidth, newHeight);
  299. }
  300. newImage.Save(targetStream, System.Drawing.Imaging.ImageFormat.Png);
  301. }
  302. private void Write(Stream stream, string line)
  303. {
  304. byte[] b = Encoding.UTF8.GetBytes(line);
  305. stream.Write(b, 0, b.Length);
  306. }
  307. public Stream GetTest(Stream preparedReport)
  308. {
  309. return PreparePostStream(preparedReport);
  310. }
  311. private MemoryStream PreparePostStream(Stream preparedReport)
  312. {
  313. MemoryStream stream = new MemoryStream();
  314. if (preparedReport != null)
  315. {
  316. preparedReport.CopyTo(stream);
  317. stream.Position = 0;
  318. MultipartParser parser = new MultipartParser(stream);
  319. if (parser.Success)
  320. stream = new MemoryStream(parser.FileContents);
  321. else
  322. stream.Position = 0;
  323. }
  324. return stream;
  325. }
  326. public Stream GetReportXml(ReportRequest request)
  327. {
  328. return GetReport(request);
  329. }
  330. public Stream GetReport(ReportRequest request)
  331. {
  332. ReportItem report = request.Report;
  333. GearItem gear = request.Gear;
  334. MemoryStream stream = new MemoryStream();
  335. try
  336. {
  337. string reportsRoot = GetReportsPath();
  338. string reportPath = Path.GetFullPath(Path.Combine(reportsRoot, report.Path));
  339. if (report != null && gear != null && CheckReportAccess(reportPath, reportsRoot))
  340. {
  341. using (Report r = new Report())
  342. {
  343. Config.WebMode = true;
  344. r.Load(reportPath);
  345. if (report.Parameters != null)
  346. foreach (KeyValuePair<string, string> param in report.Parameters)
  347. {
  348. r.SetParameterValue(param.Key, param.Value);
  349. }
  350. string connectionStringName = ConfigurationManager.AppSettings["FastReport.ConnectionStringName"];
  351. string connectionString = null;
  352. if (!string.IsNullOrEmpty(connectionStringName))
  353. connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
  354. if (!string.IsNullOrEmpty(connectionString))
  355. {
  356. // change first connection on default
  357. foreach (DataConnectionBase connection in r.Dictionary.Connections)
  358. {
  359. connection.ConnectionString = connectionString;
  360. break;
  361. }
  362. }
  363. // prepare without dialogs
  364. r.PreparePhase1();
  365. r.PreparePhase2();
  366. // export
  367. PrepareOutput(gear, r, stream);
  368. }
  369. }
  370. else
  371. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Wrong report or gear", ErrorCode = 130 },
  372. System.Net.HttpStatusCode.InternalServerError);
  373. }
  374. catch (Exception e)
  375. {
  376. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = e.Message, ErrorCode = 131 },
  377. System.Net.HttpStatusCode.InternalServerError);
  378. }
  379. stream.Position = 0;
  380. return stream;
  381. }
  382. public Stream GetPreparedReportByID(string id)
  383. {
  384. List<ReportItem> list = GetReportsList();
  385. ReportItem report = null;
  386. GearItem gear = new GearItem();
  387. gear.Name = "FPX";
  388. foreach (ReportItem item in list)
  389. if (item.ID == id)
  390. {
  391. report = item;
  392. break;
  393. }
  394. if (report != null)
  395. {
  396. ReportRequest request = new ReportRequest();
  397. request.Gear = gear;
  398. request.Report = report;
  399. return GetReport(request);
  400. }
  401. else
  402. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "File not found", ErrorCode = 404 },
  403. System.Net.HttpStatusCode.NotFound);
  404. }
  405. private void PrepareOutput(GearItem gear, Report r, MemoryStream stream)
  406. {
  407. switch (gear.Name)
  408. {
  409. case "FPX":
  410. {
  411. r.SavePrepared(stream);
  412. break;
  413. }
  414. case "PDF":
  415. {
  416. ExportPDF(r, stream, gear.Properties);
  417. break;
  418. }
  419. case "XLSX":
  420. {
  421. ExportXLSX(r, stream, gear.Properties);
  422. break;
  423. }
  424. case "DOCX":
  425. {
  426. ExportDOCX(r, stream, gear.Properties);
  427. break;
  428. }
  429. case "PPTX":
  430. {
  431. ExportPPTX(r, stream, gear.Properties);
  432. break;
  433. }
  434. case "ODS":
  435. {
  436. ExportODS(r, stream, gear.Properties);
  437. break;
  438. }
  439. case "ODT":
  440. {
  441. ExportODT(r, stream, gear.Properties);
  442. break;
  443. }
  444. case "MHT":
  445. {
  446. ExportMHT(r, stream, gear.Properties);
  447. break;
  448. }
  449. case "CSV":
  450. {
  451. ExportCSV(r, stream, gear.Properties);
  452. break;
  453. }
  454. case "DBF":
  455. {
  456. ExportDBF(r, stream, gear.Properties);
  457. break;
  458. }
  459. case "XML":
  460. {
  461. ExportXML(r, stream, gear.Properties);
  462. break;
  463. }
  464. case "TXT":
  465. {
  466. ExportTXT(r, stream, gear.Properties);
  467. break;
  468. }
  469. case "RTF":
  470. {
  471. ExportRTF(r, stream, gear.Properties);
  472. break;
  473. }
  474. case "HTML":
  475. {
  476. ExportHTML(r, stream, gear.Properties);
  477. break;
  478. }
  479. }
  480. }
  481. private void ExportRTF(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  482. {
  483. RTFExport rtf = new RTFExport();
  484. if (parameters != null)
  485. {
  486. FillGeneralProperties(rtf, parameters);
  487. // add parameters
  488. }
  489. r.Export(rtf, stream);
  490. }
  491. private void ExportTXT(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  492. {
  493. TextExport txt = new TextExport();
  494. if (parameters != null)
  495. {
  496. FillGeneralProperties(txt, parameters);
  497. // add parameters
  498. }
  499. r.Export(txt, stream);
  500. }
  501. private void ExportXML(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  502. {
  503. XMLExport xml = new XMLExport();
  504. if (parameters != null)
  505. {
  506. FillGeneralProperties(xml, parameters);
  507. // add parameters
  508. }
  509. r.Export(xml, stream);
  510. }
  511. private void ExportDBF(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  512. {
  513. DBFExport dbf = new DBFExport();
  514. if (parameters != null)
  515. {
  516. FillGeneralProperties(dbf, parameters);
  517. // add parameters
  518. }
  519. r.Export(dbf, stream);
  520. }
  521. private void ExportCSV(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  522. {
  523. CSVExport csv = new CSVExport();
  524. if (parameters != null)
  525. {
  526. FillGeneralProperties(csv, parameters);
  527. // add parameters
  528. }
  529. r.Export(csv, stream);
  530. }
  531. private void ExportMHT(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  532. {
  533. MHTExport mht = new MHTExport();
  534. if (parameters != null)
  535. {
  536. FillGeneralProperties(mht, parameters);
  537. // add parameters
  538. }
  539. r.Export(mht, stream);
  540. }
  541. private void ExportODT(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  542. {
  543. ODTExport odt = new ODTExport();
  544. if (parameters != null)
  545. {
  546. FillGeneralProperties(odt, parameters);
  547. // add parameters
  548. }
  549. r.Export(odt, stream);
  550. }
  551. private void ExportODS(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  552. {
  553. ODSExport ods = new ODSExport();
  554. if (parameters != null)
  555. {
  556. FillGeneralProperties(ods, parameters);
  557. // add parameters
  558. }
  559. r.Export(ods, stream);
  560. }
  561. private void ExportPPTX(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  562. {
  563. PowerPoint2007Export pptx = new PowerPoint2007Export();
  564. if (parameters != null)
  565. {
  566. FillGeneralProperties(pptx, parameters);
  567. // add parameters
  568. }
  569. r.Export(pptx, stream);
  570. }
  571. private void ExportDOCX(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  572. {
  573. Word2007Export docx = new Word2007Export();
  574. if (parameters != null)
  575. {
  576. FillGeneralProperties(docx, parameters);
  577. // add parameters
  578. }
  579. r.Export(docx, stream);
  580. }
  581. private void ExportXLSX(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  582. {
  583. Excel2007Export xlsx = new Excel2007Export();
  584. if (parameters != null)
  585. {
  586. FillGeneralProperties(xlsx, parameters);
  587. // add parameters
  588. }
  589. r.Export(xlsx, stream);
  590. }
  591. private void ExportPDF(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  592. {
  593. PDFExport pdf = new PDFExport();
  594. if (parameters != null)
  595. {
  596. FillGeneralProperties(pdf, parameters);
  597. bool value;
  598. if (parameters.ContainsKey("EmbeddingFonts") && bool.TryParse(parameters["EmbeddingFonts"], out value))
  599. pdf.EmbeddingFonts = value;
  600. if (parameters.ContainsKey("PdfA") && bool.TryParse(parameters["PdfA"], out value))
  601. pdf.PdfCompliance = value ? PDFExport.PdfStandard.PdfA_2a : PDFExport.PdfStandard.None;
  602. if (parameters.ContainsKey("Background") && bool.TryParse(parameters["Background"], out value))
  603. pdf.Background = value;
  604. if (parameters.ContainsKey("PrintOptimized") && bool.TryParse(parameters["PrintOptimized"], out value))
  605. pdf.PrintOptimized = value;
  606. if (parameters.ContainsKey("Title"))
  607. pdf.Title = parameters["Title"];
  608. if (parameters.ContainsKey("Author"))
  609. pdf.Author = parameters["Author"];
  610. if (parameters.ContainsKey("Subject"))
  611. pdf.Subject = parameters["Subject"];
  612. if (parameters.ContainsKey("Keywords"))
  613. pdf.Keywords = parameters["Keywords"];
  614. if (parameters.ContainsKey("Creator"))
  615. pdf.Creator = parameters["Creator"];
  616. if (parameters.ContainsKey("Producer"))
  617. pdf.Producer = parameters["Producer"];
  618. }
  619. r.Export(pdf, stream);
  620. }
  621. private void ExportHTML(Report r, MemoryStream stream, Dictionary<string, string> parameters)
  622. {
  623. HTMLExport html = new HTMLExport();
  624. if (parameters != null)
  625. {
  626. FillGeneralProperties(html, parameters);
  627. bool value;
  628. if (parameters.ContainsKey("Layers") && bool.TryParse(parameters["Layers"], out value))
  629. html.Layers = value;
  630. else
  631. html.Layers = false;
  632. if (parameters.ContainsKey("SinglePage") && bool.TryParse(parameters["SinglePage"], out value))
  633. html.SinglePage = value;
  634. else
  635. html.SinglePage = false;
  636. }
  637. html.Navigator = false;
  638. html.SubFolder = false;
  639. html.SaveStreams = true;
  640. r.Export(html, (Stream)null);
  641. ZipArchive zip = new ZipArchive();
  642. for (int i = 0; i < html.GeneratedStreams.Count; i++)
  643. zip.AddStream(html.GeneratedFiles[i], html.GeneratedStreams[i]);
  644. zip.SaveToStream(stream);
  645. }
  646. private void FillGeneralProperties(ExportBase export, Dictionary<string, string> parameters)
  647. {
  648. if (parameters.ContainsKey("PageRange"))
  649. {
  650. if (parameters["PageRange"] == "All")
  651. export.PageRange = PageRange.All;
  652. else
  653. export.PageRange = PageRange.PageNumbers;
  654. }
  655. if (parameters.ContainsKey("PageNumbers"))
  656. {
  657. export.PageNumbers = parameters["PageNumbers"];
  658. }
  659. if (parameters.ContainsKey("Zoom"))
  660. {
  661. float zoom;
  662. if (float.TryParse(parameters["Zoom"], out zoom))
  663. export.Zoom = zoom;
  664. }
  665. }
  666. private bool CheckReportAccess(string reportPath, string reportsRoot)
  667. {
  668. if (File.Exists(reportPath) && Path.GetExtension(reportPath) == ".frx")
  669. return reportPath.IndexOf(reportsRoot) != -1;
  670. else
  671. return false;
  672. }
  673. }
  674. }