ReportServiceList.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. using System.ServiceModel;
  5. using System.Text;
  6. using System.IO;
  7. using System.Configuration;
  8. using System.Collections;
  9. using FastReport;
  10. using FastReport.Utils;
  11. using System.ServiceModel.Web;
  12. namespace FastReport.Service
  13. {
  14. public partial class ReportService : IFastReportService
  15. {
  16. public List<ReportItem> GetReportsList()
  17. {
  18. return GetReportsListByPath("");
  19. }
  20. public List<ReportItem> GetReportsListXml()
  21. {
  22. return GetReportsListByPath("");
  23. }
  24. public List<ReportItem> GetReportsListByPathXml(string path)
  25. {
  26. return GetReportsListByPath(path);
  27. }
  28. public List<ReportItem> GetReportsListByPath(string path)
  29. {
  30. string reportsRoot = GetReportsPath();
  31. List<ReportItem> list = new List<ReportItem>();
  32. if (Directory.Exists(Path.Combine(reportsRoot, path)))
  33. {
  34. if (string.IsNullOrEmpty(path))
  35. path = "";
  36. List<string> reports = GetReportFiles(Path.Combine(reportsRoot, path));
  37. Report report = new Report();
  38. try
  39. {
  40. foreach (string s in reports)
  41. {
  42. ReportItem item = new ReportItem();
  43. item.Path = s.Replace(reportsRoot + Path.DirectorySeparatorChar, "");
  44. item.ID = Crypter.ComputeHash(item.Path);
  45. report.Load(s);
  46. item.Name = !string.IsNullOrEmpty(report.ReportInfo.Name) ? report.ReportInfo.Name : Path.GetFileNameWithoutExtension(s);
  47. item.Description = report.ReportInfo.Description;
  48. list.Add(item);
  49. }
  50. }
  51. catch (Exception e)
  52. {
  53. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = e.Message, ErrorCode = 105 },
  54. System.Net.HttpStatusCode.InternalServerError);
  55. }
  56. }
  57. else
  58. throw new WebFaultException<ErrorHandler>(new ErrorHandler { Cause = "Reports directory not found", ErrorCode = 104 },
  59. System.Net.HttpStatusCode.NotFound);
  60. return list;
  61. }
  62. private List<string> GetReportFiles(string path)
  63. {
  64. List<string> list = new List<string>();
  65. if (Directory.Exists(path))
  66. {
  67. string[] reports = Directory.GetFiles(path, "*.frx");
  68. list.AddRange(reports);
  69. list.Sort();
  70. string[] dirs = Directory.GetDirectories(path);
  71. foreach (string dir in dirs)
  72. {
  73. List<string> folders = GetReportFiles(Path.Combine(path, dir));
  74. folders.Sort();
  75. list.AddRange(folders);
  76. }
  77. }
  78. return list;
  79. }
  80. }
  81. }